gpt4 book ai didi

html - 在屏幕中央的两个图像之间居中文本

转载 作者:行者123 更新时间:2023-11-28 06:05:20 25 4
gpt4 key购买 nike

我在尝试获取一段文本、将其置于页面中央并在其左侧和右侧放置图像时遇到问题。

请记住,我只能更改用于定位的 CSS 代码。 HTML 完全正确。

这里是html代码:

<div id="container">
<div>
<img src="../logo.png" id="header">
</div>
<div>
<img src="../barbecue01.jpg" id="pic_1">
<div id="aboutus">
<h1>About Us</h1>
<p>
Our restaurant has the best barbecue that you can find at Philadelphia.
We have an amazing team just to serve you, your family, and your friends.
</p>
<h1>Try It Now!</h1>
</div>
<img src="../barbecue02.jpg" id="pic_2">
</div>
</div>

这是我的 CSS

#container {
width: 75%;
margin: 15px auto 15px auto;
}

* {
background-color: tan;
}

#pic_1 {
position: absolute;
display: inline-block;
float: left;
}

#pic_2 {
position: absolute;
display: inline-block;
float: right;
}

#aboutus {
position: relative;
text-align: center;
height: 275px;
width: 200px;
color: white;
display: inline-block;
left: 275px;
}

div {
border: solid 2px black;
}

我遇到的问题是第一张图片位于正确的位置,我只是想让第二张图片位于右侧。出于某种原因,它只是没有它。文本应该居中。

任何帮助将不胜感激

最佳答案

我建议您使用 flex 而不是 float,因为 float 实际上并不适合布局。

堆栈片段

#container {
width: 75%;
margin: 15px auto;
}

* {
background-color: tan;
}

#container > div:nth-child(2) {
display: flex;
}

#pic_1 {
flex: 1;
}

#pic_2 {
flex: 1;
}

#aboutus {
flex: 1 1 200px;
text-align: center;
height: 275px;
color: white;
}

div {
border: solid 2px black;
}
<div id="container">
<!-- ADD NEW CODE HERE... -->

<div>
<img src="../logo.png" id="header">
</div>


<div>
<img src="../barbecue01.jpg" id="pic_1">
<div id="aboutus">
<h1>About Us</h1>
<p>Our restaurant has the best barbecue that you can find at Philadelphia. We have an amazing team just to serve you, your family, and your friends. </p>
<h1>Try It Now!</h1>
</div>
<img src="../barbecue02.jpg" id="pic_2">
</div>
</div>

关于html - 在屏幕中央的两个图像之间居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36491811/

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