简体   繁体   中英

Display: inline-block and center aligning

#words { width: 600px; height: 450px; overflow-x: hidden; overflow-y: auto; border: 1px solid black; }
#words li { display: inline-block; width: auto; padding: 10px; height: auto; background-color: #c4c4c4; margin: 2px; text-align: center; }

So that's my CSS code for my mark-up:

<ul id="words">
  <li>blah</li>
  <li>blah</li>
  <li>blah</li>
  <li>blah</li>
  <li>blah</li>
  <li>blah</li>
  <li>blah</li>
  <li>blah</li>
  <li>blah</li>
</ul>

But, I cannot seem to have width:auto; on the <li> without floating them left (in FireFox).

Any ideas?

If you want it stacked up vertically (as I understand) then you just need to remove "inline-" from your words li selector:

#words li 
{ 
    display: block;
...
}

Example here .

Nevermind, I sorted it.

#words now has text-align: center;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM