简体   繁体   English

在div内水平和垂直居中对齐图像

[英]Center align image inside div horizontally and vertically

I currently have a header div and inside of it, I have header-top and header-bottom . 我目前有一个header div,在它的里面,我有header-topheader-bottom I am trying to place my logo on the top-header and align it vertically and horizontally. 我正在尝试将徽标放在top-header并使其在垂直和水平方向上对齐。 The logo aligns horizontally but vertically, it pushes aligns according to the body it seems and it brings the header down 20px. 标志水平对齐,但垂直,它根据推对齐body似乎和它带来的头部向下20像素。 Here is my code. 这是我的代码。

HTML: HTML:

<body>
    <div id="big-wrapper">
        <div id="header">
            <div id="header-top">
                <img src="img/main-logo.png" />
            </div>
            <div id="header-bottom">
            </div>
        </div>
    </div>
</body>

CSS: CSS:

#header {
    width: 100%;
    height: 160px;
    box-shadow: 0 1px 4px 1px rgba(237, 237, 237, 1);
}

#header-top {
    height: 130px;
    border-bottom: 1px solid rgba(200, 200, 200, 0.7);
    background-color: rgba(255, 255, 255, 1);
}

#header-top img {
    height: 90px;
    width: 255px;
    display: block;
    margin: 20px auto;
}

#header-bottom {
    height: 30px;
    border-bottom: 1px solid rgba(200, 200, 200, 0.7);
    background-color: rgba(255, 255, 255, 1);
}

This is what I get 这就是我得到的

在此处输入图片说明

Suggestion. 建议。 Could be wrong. 可能是错误的。

    <div id="header-top">
        <center>
            <img src="img/main-logo.png" />
        </center>
    </div>

If wrong, try aligning the div as so. 如果错误,请尝试将div对齐。

Edit: If all else fails, edit image, and offset it to desired alignment 编辑:如果其他所有方法均失败,则编辑图像并将其偏移到所需的对齐方式

对齐内部的图像和文本<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中水平和垂直对齐图像 - Align image inside DIV horizontally and vertically 对齐内部的图像和文本<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 在div中垂直和水平对齐图像 - Vertically and horizontally align an image in a div 在div中水平和垂直对齐图像 - Horizontally and vertically align image in div 将图像垂直和水平居中 - center an image in div vertically and horizontally 如何在div内水平和垂直居中放置图像和文本? - How can I center an image and text horizontally and vertically inside a div? 如何在较小的 div 内制作图像中心(垂直和水平) - How to make an image center (vertically & horizontally) inside a smaller div DIV中垂直和水平居中的图像浮动:左? - Center image vertically and horizontally inside of DIV with float:left? 在div垂直居中对齐图像 - align image in a div vertically center 垂直和水平对齐图像到中心 - Align image to the center both vertically and horizontally
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM