gpt4 book ai didi

html - 我试图将文本居中放置在我的页面 HTML 中间

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:59 30 4
gpt4 key购买 nike

我有三个不同的 div 标签(不在彼此内部)和代码,所以它有一个把单词放在左边、中间或右边,但中心非常偏离中心。这是 HTML 代码:

.desc {
float: right;
color: skyblue;
}

.desc1 {
float: left;
color: skyblue;
}

.desc2 {
text-align: center;
color: skyblue;
}
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>

最佳答案

你可以使用 flexbox 来解决这个问题,

HTML:

<div class="container">
<div class="desc1">
<h2>What we are here to do!</h2>
<p>Example</p>
</div>
<div class="desc2">
<h2>What we have completed</h2>
<p>Recent work (can include pictures)</p>
</div>
<div class="desc">
<h2>Company Description</h2>
<p>EXAMPLE!</p>
</div>
</div>

CSS:

.container{
display: flex;
align-items: center;
justify-content: space-between;
}

关于html - 我试图将文本居中放置在我的页面 HTML 中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45374464/

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