html - 如何将 ap 标签放在两个 div 下?
问题描述
所以我有两个相邻的 div,通过左 div 向左浮动和右 div 向右浮动。我希望我的 p 出现在这两个 div 下面。然而,它只是拒绝这样做。它总是出现在页面顶部或两个 div 之间。我已经尝试将两个 div 设置为显示内联块,但是它们不会彼此相邻,而是进行换行。我对 HTML 和 CSS 比较陌生,所以这可能只是一个简单的初学者错误,但如果有人能帮助我,我将不胜感激。
.p {
background: red;
width: 100%;
}
.tippsboxright {
color: rgb(238, 238, 238);
max-width: 45%;
margin: 0 0 0 5%;
float: right;
font-size: 1.7vw;
padding: 0;
}
.boxleft {
max-width: 50%;
}
<main>
<header>
<h1>My header</h1>
</header>
<div class="content">
<div class="boxleft">
<img src="../images/questionguy.png" alt="Typ mit fragen" class="imgkauftipps">
</div>
<div class="tippsboxright">
<p>
This is the right box with text inside of it.
</p>
</div>
<p class="p">This is the p tag that I want to be at the bottom of the page.</p>
</div>
</main>
解决方案
您需要为此使用 CSS flexbox 而不是 float。将顶部 div 放入 wrapper/container 并提供 wrapper display: flex
。基本上就是这样,但你可以像我在这个例子中所做的那样巧妙地处理它:
.wrap {
display: flex;
justify-content: space-between;
}
.wrap div {
width: 100%;
outline: 1px solid red;
}
<div class="wrap">
<div>left</div>
<div>right</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Me non paenitet nullum festiviorem excogitasse ad hoc. Quis aute iure reprehenderit in voluptate velit esse. Quam temere in vitiis, legem sancimus haerentia. Inmensae subtilitatis, obscuris et malesuada fames. Fictum, deserunt mollit anim laborum astutumque!</p>
或者,使用您示例中的 html,除非我已将<p>
标签移出包装器。是否<p>
必须在包装器div中?
.content {
display: flex;
}
<main>
<header>
<h1>My header</h1>
</header>
<div class="content">
<div class="boxleft">
<img src="../images/questionguy.png" alt="Typ mit fragen" class="imgkauftipps">
</div>
<div class="tippsboxright">
<p>
This is the right box with text inside of it.
</p>
</div>
</div>
<p class="p">This is the p tag that I want to be at the bottom of the page.</p>
</main>
推荐阅读
- c# - 我们可以在 .NET Core (3.1) 项目中使用 Win2D 吗?
- swift - SwiftUI:初始列表元素的位置错误
- r - R如何进行分配和引用从字符串转换的变量名
- python - 如何迭代行并删除列匹配的所有其他行?
- reactjs - 从 ReactNative 上的 API(jsonplaceholder) 删除数据
- pdf - 为什么此 PDF 中的纯青色图像未显示为纯青色?
- php - PHP - 我需要在一个循环中启动一个优化图像的类,以便在上传每个图像时对其进行优化?
- powershell - 为什么我的变量在 Powershell 中中断?(从文件中获取变量)
- computer-vision - 使用 opencv [计算机视觉] 从实时网络摄像头进行眼睛注视跟踪
- performance - 为什么在重新创建 neo4j DB 后 Cypher 查询性能会提高?