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,386
  • 16
  • 69
  • 103

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
  • 326,646
  • 82
  • 467
  • 441
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,594
  • 33
  • 29
  • 34