gpt4 book ai didi

css - HTML/CSS 如何让div与h1、p、图片等4个文本框对齐

转载 作者:太空宇宙 更新时间:2023-11-03 22:26:46 24 4
gpt4 key购买 nike

我是 HTML 和 CSS 的新手。目前,我正在尝试找出如何安排一个带有四个文本框的 div,其中包括一个标题、一个段落和一个位于左侧的 img。整个事情应该是这样的:

enter image description here

首先选择一个 div 底部 Pane ,因为它位于页面的底部。给它一个宽度和高度,它们将被继承到下面的 div。

如您所见,这看起来与预期相去甚远。现在,我不知道如何进一步处理这一步。我在 CSS 的语法和知识上苦苦挣扎。

谁能帮我解决这个问题?代码如下:

.bottompane {
width: 100%; /* defines overall width of bottompane */
height: 300px; /* defines overall height of bottompane */
background-color: silver;
position: relative;
}

.row {
text-align: center;
}

.features-text {
width: 50%; /* 50% width of the parent directory bottompane */
height: 120px;
display: inline-block;
}

.text-upperright {
width: 50%;
}

.text-upperleft {
width: 50%;
}

.text-bottomleft {
width: 50%;
}

.text-bottomright {
width: 50%;
}

#cat {
float: right;
}

#world {
float: left;
}

#swim {
float: right;
}

#columns {
float: left;
}

h1 {
}

p {
}
<div class="bottompane">
<div class="row">
<div class="features-text">
<div class="text-upperleft">
<h1>Best-in-class Features</h1>
<p>Nobody likes this stuff better than us, you can bet your life on that.</p>
</div>
<img src="cat.svg" alt="Cat Picture">
</div>
<div class="features-text">
<div class="text-upperright">
<h1>Reliable Service</h1>
<p>You can count on us to help you whenever you need it. We're talking round the clock service.</p>
</div>
<img src="world.svg" alt="World Map">
</div>
</div>
<div class="row">
<div class="features-text">
<div class="text-bottomleft">
<h1>An Acquired Taste</h1>
<p>It may take a little while for you to warm up to us but once you do you will never want to switch.</p>
</div>
<img src="swim.svg" alt="Person swimming">
</div>
<div class="features-text">
<div class="text-bottomright">
<h1>No Limits</h1>
<p>There are absolutely no limits. We do not throttle. We do not cap.</p>
</div>
<img src="columns.svg" alt="Greek/Roman columns">
</div>
</div>
</div>

最佳答案

希望对您有所帮助!

  <html>
<style>
.bottompane {
width: 100%; /* defines overall width of bottompane */
height: 300px; /* defines overall height of bottompane */
background-color: silver;
position: relative;

}

.row {
text-align: center;
}

.features-text {
width: 50%; /* 50% width of the parent directory bottompane */
height: 120px;
display: inline-block;
position:relative;
float:left;
}

.text-upperright {
width: 50%;
}

.text-upperleft {
width: 50%;
}

.text-bottomleft {
width: 50%;
}

.text-bottomright {
width: 50%;
}

.imageClass{
float:left;
width: 50px;
}
#cat {
float: right;
}

#world {
float: left;
}

#swim {
float: right;
}

#columns {
float: left;
}

h2 {
}

p {
margin-left:35%;
text-align:left;
}
</style>
<div class="bottompane">
<div class="row">
<div class="features-text">

<div class="text-upperleft">
<img src="cat.svg" alt="Cat Picture" class="imageClass">
<h2>Best-in-class Features</h2>
<p>Nobody likes this stuff better than us, you can bet your life on that.</p>
</div>

</div>
<div class="features-text">
<div class="text-upperright">
<img src="world.svg" alt="World Map" class="imageClass">
<h2>Reliable Service</h2>
<p>You can count on us to help you whenever you need it. We're talking round the clock service.</p>
</div>

</div>
</div>
<div class="row">
<div class="features-text">
<div class="text-bottomleft">
<img src="swim.svg" alt="Person swimming" class="imageClass">
<h2>An Acquired Taste</h2>
<p>It may take a little while for you to warm up to us but once you do you will never want to switch.</p>
</div>

</div>
<div class="features-text">
<div class="text-bottomright">
<img src="columns.svg" alt="Greek/Roman columns" class="imageClass">
<h2>No Limits</h2>
<p>There are absolutely no limits. We do not throttle. We do not cap.</p>
</div>

</div>
</div>
</div>
</html>

关于css - HTML/CSS 如何让div与h1、p、图片等4个文本框对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50670296/

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