简体   繁体   中英

HTML Centered Title with Image Left Aligned

How can I get an image aligned to the left corner of the page with a centered title?

What I tried:

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

在此处输入图像描述

What I want: 在此处输入图像描述

Keep justify-content: center on the div tag and give the img a justify-self: start property. You may need to give the div a width of 100% as well.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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