• All geek questions in one place

    How to vertically align elements in a horizontal ul list with images?

    I have the following html code:

    <div id="footer"> <ul id="yw1"> <li><a href="/index.php/site/login">About</a></li> <li><a href="/index.php/site/login">FAQ</a></li> <li><a href="http://twitter.com"><img src="/images/twitter_icon.png" /></a></li> <li><a href="http://twitter.com"><img src="/images/facebook_icon.png" /></a></li> </ul> </div> 

    And the following CSS styles:

     #footer { margin-top: 25px; background: #000000 url(images/background.png) repeat; padding: 25px; box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, .2); } #footer ul { margin: 0; padding: 0px 0px 0px 0px; list-style: none; line-height: normal; } #footer li { padding-left: 20px; display: inline; list-style-type: none; } #footer a { color:white; letter-spacing: 1px; text-decoration: none; text-align: center; font-size: 14px; font-weight: 300; } 

    Now the result:

    screenshot

    But I need to align the images and text links vertically. How can i do this?

    +6
    html css vertical-alignment
    user2218845 Apr 25 '13 at 7:59
    source share
    4 answers

    As the img tag is embedded by default, it is vertically aligned to the baseline and therefore you need to use vertical-align: middle; for img tag

    Demo

    CSS

     #footer img { vertical-align: middle; } 
    +9
    Mr. Alien Apr 25 '13 at 8:06
    source share

    You just need vertical-align: middle on #footer li and #footer a + display: inline-block on images:

     #footer li { /* ... */ display: inline; vertical-align: middle; } #footer a { /* ... */ vertical-align: middle; display: inline-block; } 

    http://jsfiddle.net/dfsq/7kssu/

    0
    dfsq Apr 25 '13 at 8:17
    source share

    The user following the CSS.

     li { display:inline-block; vertical-align:middle } 
    0
    Asim nadeem Jul 17 '14 at 14:03
    source share

    Just change your css

    of

     line-height:normal 

    to

     line-height:30px 
    -1
    I am legend Apr 25 '13 at 8:10
    source share

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

    More articles:

    • Error connecting to the web using socket.io on an ec2 instance? - javascript
    • jQuery matches div height with dynamic image height - javascript
    • iOS sorts NSString's NSArray time - sorting
    • How to convert Int while in C #? - c #
    • What does "2e4" mean in code - javascript
    • https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/943600/what-is-the-fastest-way-to-notify-another-thread-that-data-is-available-any-alternativies-to-spinning&usg=ALkJrhgFGa_PBlTGdzX-kXiDxoyYYeLiQQ
    • Make centered DIV inside wide DIV expand with content width - html
    • avoiding collisions while collapsing an infinite blocking buffer into a circular buffer - c ++
    • Ruby array for javascript - Rails - javascript
    • Rotate google map marker image - javascript

    All Articles

    Geek Questions | 2019