The reason you cannot set the width is because you are setting display:inline; .
When elements are displayed in a row, they cannot indicate their sizes, because the size of an element is determined by the length of the text inside it.
By default, <div> tags are set to display:block; . This mode may have the specified height and width, but by default they are displayed below the previous block.
There are two ways for you:
Use display:block; and float:left; - this will change the blocks to floating elements, which means that subsequent elements will wrap around them. When used with other blocks, this effectively allows you to build them. However, using a float may have other unexpected side effects due to the wrapping effect that I described.
Use display:inline-block; - This is my preferred solution to this issue. inline-block is an intermediate house mode between block and inline . It allows you to treat the element as built-in for workflow purposes, but still behaves like a block inside, since it will always be straight, and you can specify the height and width, etc. This has a few quirks (especially for poor support in IE6), but overall for what you're trying to achieve, this is a much cleaner solution and has no weird float side effects.
Hope this helps.
Spudley
source share