aaa
  • aaa
  • aaa.more { background-color: r...">

    Vertical alignment in UL LI?

    <ul> <li class="more">aaa</li> <li class="moretwo">aaa</li> <li class="more">aaa</li> </ul> .more { background-color: red; height: 50px; vertical-align:middle; } .moretwo { background-color: green; height: 50px; vertical-align:sub; } 

    Why does vertical alignment not work in this example? Can I do it? If so, how can I do this?

    DIRECT EXAMPLE: http://jsfiddle.net/gQM68/ with your answers

    +4
    source share
    4 answers

    the text is aligned with its line height so that you either increase the line height and then apply vertical alignment

    or

    using padding-top

    you can check this link for reference

    http://jsfiddle.net/gQM68/2/

    or

    http://www.w3schools.com/cssref/pr_pos_vertical-align.asp

    +8
    source

    you can use vertical-align with display:table-cell

     .more { background-color: red; height: 50px; display:table-cell; vertical-align:middle; } .moretwo { background-color: green; height: 50px; display:table-cell; vertical-align:sub; } 
    +5
    source

    If you surround the text with a span and set its style as shown below, it should work:

     <ul> <li class="more"><span>aaa</span></li> ... </ul> li span { display: inline-block; vertical-align: middle; } .more { ... } .moretwo { ... } 
    0
    source

    Source: https://habr.com/ru/post/1389042/


    All Articles