HTML List element : Sharing the parent width into equal parts

后端 未结 5 1892
無奈伤痛
無奈伤痛 2020-12-01 06:39

I have a parent

    and couple of
  1. items in that.

      &
5条回答
  •  庸人自扰
    2020-12-01 07:30

    I think this is what you're asking for. It required jQuery though.

    http://jsfiddle.net/sKPLQ/3/

    CSS:

    ul {
        width: 800px;
    }
    
    li {
        display: inline-block;
        float:left;
    }
    

    JS:

    var evenWidth = $(".list").width()/$(".list li").size();
    $(".list li").css("width", evenWidth);
    

    HTML:

    • Item 1
    • Item 2
    • Item 3
    • Item 4

提交回复
热议问题