- by admin
At some point, you may have a situation where you want to center multiple elements (maybe<div>
elements, or other block elements) on a single line in a fixed-width area. Centering a single element in a fixed area is easy. Just add margin: auto
and a fixed width to the element you want to center, and the margins will force the element to center.display: inline
in an IE6-only declaration, but your code will still be somewhat messy because of the extra code to get the first and/or last item to behave. Also, the last box could fall to the next line in IE.inline-block
and control white space#parent {
width: 615px;
border: solid 1px #aaa;
text-align: center;
font-size: 20px;
letter-spacing: 35px;
white-space: nowrap;
line-height: 12px;
overflow: hidden;
}
.child {
width: 100px;
height: 100px;
border: solid 1px #ccc;
display: inline-block;
vertical-align: middle;
}
child
, and each 100 pixels by 100 pixels. The boxes are naturally block-level elements, but the CSS changes them to inline-block
, which allows them to flow naturally with text and white space. Of course, since we don’t have any text in the parent container, controlling the text and white space will not be a problem.parent
in this example) has four key text properties set, and the children have two:text-align
makes all inline child elements centeredletter-spacing
controls the size of each white space unit between boxeswhite-space: nowrap
keeps the last element from potentially dropping to the next lineoverflow: hidden
prevents the box from stretching in IE6vertical-align: middle
(on the children) keeps the boxes on the same vertical plane as each other when content is addeddisplay: inline-block
(obviously)inline-block
. To get those browsers to show virtually the same result, you need to add the following CSS:.child {
*display: inline;
*margin: 0 20px 0 20px;
}
display
property is taking advantage of a bug in those browsers that makes a block element work like its inline when you declare display: inline-block
followed by display: inline
.- by admin
This property specifies whether the current rendered line should break if the content exceeds the boundary of the specified rendering box for an element (this is similar in some ways to the ‘clip’ and ‘overflow’ properties in intent.) This property should only apply if the element has a visual rendering, is an inline element with explicit height/width, is absolutely positioned and/or is a block element.div { word-wrap: break-word } <div style=”word-wrap: break-word”>Here is some content for the div element</div> |
Value | Description |
---|---|
normal | Content will exceed the boundaries of the specified rendering box. |
break-word | Content will wrap to the next line when necessary, and a word-break will also occur if needed. |
- by admin
JsFiddle is a playground for web developers, a tool which may be used in many ways. One can use it as an online editor for snippets build from HTML, CSS and JavaScript. The code can then be shared with others, embedded on a blog, etc. Using this approach, JavaScript developers can very easily isolate bugs.- by admin
$('#select').val('the_value');