簡體   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