1

I have this css:

.test {
    background-color:#00ff00;
    display: inline;    
    width: 200px;
}

<div class="test">test1</div>
<div class="test">test2</div>

But it seems that the width is not read. How to change the css? Thanks

Dail
  • 4,622
  • 16
  • 74
  • 109

2 Answers2

3

inline items cannot have an explicitly set width. Use inline-block instead.

.test {
    background-color:#00ff00;
    display: inline-block;
    width: 200px;
}

Note, though, that IE 6/7 have compatibility issues with inline-block, it doesn't apply properly to elements that are block-level by default. These issues can be resolved.

Community
  • 1
  • 1
Andy E
  • 338,112
  • 86
  • 474
  • 445
0

We cannot set width for inline. But if we use inline-block we cannot place child elements in one row So please use inline-table. This is style that I have tested

.test {
    background-color:#00ff00;
    display: inline-table;
    width: 200px;
}

I have checked this. Use display:inline-table. It works well.

David Buck
  • 3,752
  • 35
  • 31
  • 35