CSS list item width/height does not work

前端 未结 6 559
谎友^
谎友^ 2020-12-02 22:35

I tried to make a navigation inline list. You can find it here: http://www.luukratief-design.nl/dump/parallax/para.html

For some reason it does not display the widt

相关标签:
6条回答
  • 2020-12-02 23:11

    Inline items cannot have a width. You have to use display: block or display:inline-block, but the latter is not supported everywhere.

    0 讨论(0)
  • 2020-12-02 23:13

    Remove the <br> from the .navcontainer-top li styles.

    0 讨论(0)
  • 2020-12-02 23:18

    I think the problem is, that you're trying to set width to an inline element which I'm not sure is possible. In general Li is block and this would work.

    0 讨论(0)
  • 2020-12-02 23:22

    Using width/height on inline elements is not always a good idea. You can use display: inline-block instead

    0 讨论(0)
  • 2020-12-02 23:24

    Declare the a element as display: inline-block and drop the width and height from the li element.

    Alternatively, apply a float: left to the li element and use display: block on the a element. This is a bit more cross browser compatible, as display: inline-block is not supported in Firefox <= 2 for example.

    The first method allows you to have a dynamically centered list if you give the ul element a width of 100% (so that it spans from left to right edge) and then apply text-align: center.

    Use line-height to control the text's Y-position inside the element.

    0 讨论(0)
  • 2020-12-02 23:26

    I had a similar issue trying to fix the item size to fit the background image width. This worked (at least with Firefox 35) for me :

    .navcontainer-top li
    {
      display: inline-block;
      background: url("../images/nav-button.png") no-repeat;
      width: 117px;
      height: 26px;
    }
    
    0 讨论(0)
提交回复
热议问题