简体   繁体   English

垂直对齐Div内的图像和文本

[英]Vertically Align Image and Text Inside a Div

I would like to position the image and the navigation links so that they are vertically aligned with the HeadContainer and each other. 我想定位图像和导航链接,使它们与HeadContainer和彼此垂直对齐。

HTML HTML

<header>
<div id="HeadContainer">
  <img src="favicon.png" id="title"/>
  <nav>
    <p>Home</p>
    <p>About</p>
    <p>Portfolio</p>
    <p>Contact</p>
  </nav>
</div>
</header>

CSS: CSS:

#HeadContainer {
width:70%;
margin: 0 auto;
display: block;
}

header {
height: 60px;
}

nav {
    float: right;
}

nav p {
    display: inline;
    margin-left: 10px;
    font-size: 1.2em;
}

#title {
    float: left;
    width: 40px;
}

At the moment they are not aligned. 目前他们没有对齐。 How would I align the paragraph tags in the nav with the image? 如何将导航中的段落标记与图像对齐?

You should know that inside a navigation you'll hardly have <p> elements. 你应该知道在导航中你几乎没有<p>元素。 I don't see any reason Google also. 我也没有看到谷歌的任何原因。 So go with: http://jsbin.com/melag/2/edit 所以请访问: http//jsbin.com/melag/2/edit

<nav>
  <ul>
    <li><a href="">Home</a></li>
    <li><a href="">About</a></li>
    <li><a href="">Portfolio</a></li>
    <li><a href="">Contact</a></li>
  </ul>
</nav>

nav {
    float: right;
}
nav ul{
    list-style:none;
}
nav ul li{
    display:inline-block;
    vertical-align:middle;
}

Roko's answer is the tried and true method. Roko的答案是经过验证的真实方法。 I recommend it too. 我也推荐它。 I want to point out that, in HTML 5, the <nav> tag is intended to replace a modified unordered list for navigation menus. 我想指出,在HTML 5中, <nav>标签旨在替换导航菜单的修改无序列表。

W3 Schools <nav> tag page W3 Schools <nav>标签页

对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将文字与图片中的图片垂直对齐<div> - How to align text vertically with an image inside a <div> 将文本与div中的图像垂直对齐 - Vertically align a text with an image inside a div 对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically <a>在div中</a>垂直对齐<a>文本</a> - Vertically Align <a> text inside a div 如何在DIV内垂直对齐文本和图像? - How do I align text and an image vertically inside a DIV? 使div和图像在div内垂直对齐 - make div and image vertically align inside a div 在DIV中水平和垂直对齐图像 - Align image inside DIV horizontally and vertically 将跨度与 div 内的图像垂直对齐 - Vertically align span with image inside div 垂直对齐div内的图像和响应高度 - Vertically align an image inside a div with responsive height 在粘性 div 内垂直对齐图像 - Vertically align image inside a sticky div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM