简体   繁体   中英

CSS table and list-style-position bug? Workaround?

I have an unordered list with display: table; and list-style-position: inside; . The problem is on Google Chrome, the list items don't take up full width, but instead wrap to the next line.

http://jsfiddle.net/ntbq5/

Funny enough this doesn't always happen, so if you don't see what I'm talking about try clicking the "Run" button - here's what I'm seeing:

在此处输入图片说明

If I refresh the fiddle, somehow it appears normal again... http://i40.tinypic.com/30hr4gl.gif . Firefox and IE it appears normal as well. But on a real website, refreshing doesn't change anything for me. What's the solution?

EDIT: My bad, I forgot to say I need to center my table as well so I can't use 100% width http://jsfiddle.net/ntbq5/10/ What else can be done?

Use White-space:nowrap; to overcome this issue.

WORKING DEMO

The Code Change:

ul {
    display: table;
    list-style-position: inside;
    white-space:nowrap;
}

Hope this helps.

Maybe just define a width for the li elements:

li {
    width: 150px;
}

Here a screen of the fiddle where i added this:

http://jsfiddle.net/ntbq5/embedded/result/

You can add width 100% to your <ul> elements.

CSS:

ul {
   display: table;
   width: 100%;
   list-style-position: inside;
}

You are displaying the ul as table and table's width should be defined for fine looking. So you need to set width for that ul. So use this:

ul {
    display: table;
    list-style-position: inside;
    width: 100%;
}

As you mentioned your ul tag is having margin auto in the comment, you could assign text-align to center

demo

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