gpt4 book ai didi

html - 将要显示的部分文章与第三个元素居中对齐

转载 作者:行者123 更新时间:2023-11-28 04:19:30 25 4
gpt4 key购买 nike

我试图让我的部分的文章完全像这样显示(当扩展到更宽的浏览器宽度时,第三篇文章居中):https://www.screencast.com/t/vGdpZ91l

我探索了 CSS 的所有显示选项。当前 CSS 设置为 display: inline-flex;

这是我的 CSS/HTML。非常感谢您的帮助。

.places h1 {
align-content: top-left;
font-size: 30px;
}

.places article {
display: inline-flex;
width: 390px;
border: #FF5A5F 1px solid;
border-radius: 4px;
padding: 20px;
margin: 20px;
}

.places article h2 {
font-size: 30px;
text-align: center;
}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="7-places.css" media="all">
</head>
<body>
<header>
</header>

<div class="container">
<section class="places">
<h1>Places</h1>
<article class="home">
<h2>Home</h2>
</article>
<article class="apartment">
<h2>Apartment</h2>
</article>
<article class="dorm">
<h2>Dorm</h2>
</article>
</section>
</div>

</body>
</html>

最佳答案

在父级上使用 flex,并将其设置为 flex-wrap: wrap;证明内容:居中;

.places {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.places h1 {
align-content: top-left;
font-size: 30px;
width: 100%;
}

.places article {
width: 390px;
border: #FF5A5F 1px solid;
border-radius: 4px;
padding: 20px;
margin: 20px;
}

.places article h2 {
font-size: 30px;
text-align: center;
}
<div class="container">
<section class="places">
<h1>Places</h1>
<article class="home">
<h2>Home</h2>
</article>
<article class="apartment">
<h2>Apartment</h2>
</article>
<article class="dorm">
<h2>Dorm</h2>
</article>
</section>
</div>

关于html - 将要显示的部分文章与第三个元素居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42287260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com