How to use vertical alignment: medium; properly?

I want my list (nav) to coincide with the center of the image (logo). I tried to use vertical-align: middle;, but I could not get it to work when I placed the images on the left and right.

Here is my code:

HTML:

<div id="head">
    <img id="logo" src="logo.png" />
    <ul id="nav">
        <li><a href="#">Item 1</a></li>
        <li><a href="#">Item 2</a></li>
        <li><a href="#">Item 3</a></li>
    </ul>
</div>

CSS

#head {
    margin-top: 2px;
    width: 100%;
}
    #logo {
        float: left;
        }

    ul#nav {
        float: right;
        }

        ul#nav li {
            display: inline;
            list-style-type: none;
            }

I took everything vertical-align: middle;from the place where I placed them (I tested it in every element, although it should only apply to #logo, from what I read.)

In any case, any help would be appreciated.

+3
source share
2 answers

Vertical-align:middle . float:left, 0px , , .

, <br style='clear:both' /> , DIV, , .

+2

.

<div id="head">

<table>
<tr>

<td>
  <h1>Fluid Heading</h1>
</td>

<td style="width: 5%">
  <img id="logo" src="logo.png" />
</td>

<td style="width: 5%">
  <ul id="nav">
    <li><a href="#">Item 1</a></li>
    <li><a href="#">Item 2</a></li>
    <li><a href="#">Item 3</a></li>
  </ul>
</td>

</tr>
</table>

</div>

CSS

.head td { vertical-align: middle; }
0

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


All Articles