繁体   English   中英

HTML 居中标题,图像左对齐

[英]HTML Centered Title with Image Left Aligned

如何使图像与页面左角对齐且标题居中?

我尝试了什么:

<div style="display: flex; height: 100px;">
    <img style="max-width: 100%; max-height: 100%;" src="static/totally_original_logo.jpg" alt="totally original logo">
    <div style="text-align: center; margin: 0 auto;">
        <a href="foo.com">Return to home</a>
        <h1>My Title</h1>
    </div>
</div>

截屏


<div style="display: flex; height: 100px; justify-content: center;">
    <img style="max-width: 100%; max-height: 100%;" src="static/totally_original_logo.jpg" alt="totally original logo">
    <div style="text-align: center;">
        <a href="foo.com">Return to home</a>
        <h1>My Title</h1>
    </div>
</div>

在此处输入图像描述

我想要的是: 在此处输入图像描述

保持justify-content: center并给 img 一个justify-self: start属性。 您可能还需要为 div 提供 100% 的宽度。

img {
justify-self: start;
}
div {
width: 100%;
}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM