List html li width

Full width li elements

I am trying to make the list elements of this list full width. They had padding on them and when you hover on them the padding is coloured yellow. The padding isn’t filling up the whole ul block which is what I want it to do. I have tried using different displays and making the width of the list element 100% but this doesn’t work.

.footer-navigation < list-style: none; padding-left: 0px; display: inline-block; width: 100%; >.footer-navigation li < padding: 10px; width: 100%; >.footer-navigation a < padding: 10px; color: #000000; >.footer-navigation a:hover

5 Answers 5

Make your anchors block level instead of inline. You can also add box-sizing so that they don’t poke out and extend beyond the right edge:

.footer-navigation < list-style: none; padding-left: 0px; display: inline-block; width: 100%; >.footer-navigation li < padding: 10px; width: 100%; box-sizing: border-box; >.footer-navigation a < padding: 10px; color: #000000; display: block; >.footer-navigation a:hover

actualy you padding isn’t changing color to yellow on hovw.it is anchor tag. Change it to li:hover to change color of full li item. Here is fiddle

.footer-navigation < list-style: none; padding-left: 0px; display: inline-block; width: 100%; >.footer-navigation li < padding: 10px; width: 100%; >.footer-navigation a < padding: 10px; color: #000000; >.footer-navigation li:hover

The issue here is that you’re yellow background is showing on the a element. Your ‘li element **is** 100% width, but the highlight is showing on the a` element, which is not 100% width.

    , the problem here is that you’re applying the hover effect on the links inside the
  • s not the
  • s themselves. s are inline elements they occupy the width of their text only.

you can solve this by applying display: inline-block; to the s.

.footer-navigation < list-style: none; padding-left: 0px; display: inline-block; width: 100%; >.footer-navigation li < padding: 10px; width: 100%; >.footer-navigation a < padding: 10px; color: #000000; width: 100%; display: inline-block; >.footer-navigation a:hover

Источник

UL/LI list item full-width

enter image description here

How can create full-width ul/li with that. Like: Note:

  • The code should work in IE8
  • we don’t know number of li item because they are dynamically created
.record-top-btns < width:100%; display:table; >.record-top-btns a < padding:2px; color:#5c5c5c; display:block; margin-top:2px; margin-bottom:2px; text-align:center; width:100%; >.record-top-btns li < display:table-cell; /* will not work in IE8 */ background:#e3ffca; text-align:center; background:white; >

i doubt you can handle dynamic things with css , if old IE versions are to be considered. u have to opt for jquery.

@Radian For a non JS solution that works in IE8, how about using table and you dynamically create td instead of li — JSFiddle?

Just count the number of elements using the server-side script of your choice and generate the needed «dynamic css»

5 Answers 5

In IE8 you can use text-align-last:justify on the container and display:inline-block on the elements to achieve the evenly spaced effect — it just won’t work in stable Chrome, so you’ll need to make it a fallback with conditional comments so only older IEs use the text-align approach. For some reason IE also requires you to set text-align when setting text-align-last — keep that in mind.

i try your code but not working in IE8 , here is fiddle: jsfiddle.net/LqXH5/2 «please check that in IE8 »

Источник

List html li width

Find centralized, trusted content and collaborate around the technologies you use most.

Connect and share knowledge within a single location that is structured and easy to search.

    but even with width:auto it doesn’t work at all, and I don’t know why. I tried to use display:inline-block but this is the same. I don’t know how many tabs I will have so this is why I am not using a percentage directly. I would like to display the list inline when I display the page on a desktop and display one li per line when I am on a smartphone (with media queries). I have this:
ul#menu < margin:0; padding:0; list-style-type:none; width:100%; position:relative; display:block; height:30px; font-size:12px; font-weight:bold; font-family:Arial, Helvetica, sans-serif; /*border-bottom:1px solid #000000; border-top:1px solid #000000;*/ >li.button < background:transparent url(../images/nav_bg.png) repeat-x top left; height:30px; width:auto; >ul#menu li < display:inline-block; margin:0; padding:0; width:auto; >ul#menu li a < display:inline-block; color:#999999; text-decoration:none; font-weight:bold; padding:8px 20px 0 20px; width:auto; >ul#menu li a:hover < color:#FFFFFF; height:22px; background:transparent url(../images/nav_bg.png) 0px -30px no-repeat; >ul#menu li a.current < display:inline-block; height:22px; background:transparent url(images/nav_bg.png) 0px -30px no-repeat; margin:0; >

Two thoughts: 1) Why are you using inline-block ? Why not just use block if you want the full width? 2) Have you tried width:100% instead of width:auto

putting width:auto will end up with li which have same width like ul. so it will overwrite the inline-block or block

7 Answers 7

I’ve found this way to deal with single-line full-width ul where an undefined number of li elements need to be spaced out evenly:

Basically, it emulates a table. Works in Gecko, Webkit, IE8+. For IE7 and downwards you should use some inline-block hackery 🙂

If you need to make each cell change its size adaptive to its content, the table-layout can be set to «auto»

Since the li count can change, I can only think of accomplishing this with javascript/jquery as you suggested. Just divide 100 by the # of li’s and set the width on each one.

var width = Math.floor(100 / $("ul#menu li").size()); $("ul#menu li").css('width', width + "%"); 

You will probably have to play with the width depending on padding and what not.

As a side note, If you haven’t already, I recommend getting a tool like firebug, which will let you edit css and execute js on the fly. It is infinitely useful for fine tuning appearances.

Оцените статью