html - 如何在图像旁边正确放置几行文本并正确缩进
问题描述
所以,我刚刚开始学习 HTML 和 CSS,并且正在从事一个私人项目。我想要实现的是:https ://imgur.com/a/kg1rE9U
我挣扎的是第一个蓝色“盒子”。更准确地说,我只是不知道如何像上图那样正确格式化它(到框边界的距离,图像和 text2 / text 3 之间的距离,...)。不仅我的代码没有按预期工作(例如 text2 和 text3 之间的距离太大),我还觉得我做的比实际更复杂。
到目前为止的 HTML 代码是
<div class="standardfield", style="width: 100%;">
<p class ="standardfield", style="float:left;">
<span style="display:block; height: 20px;"></span>
<img src="image.png">
</p>
<p class ="standardfield", style="font-size: 40px; text-indent:20px;">
<span style="display:block; height: 20px;"></span>
<b>text2</b>
</p>
<div class="standardfield", style="font-size:20px; text-indent: 20px;">
text3
</div>
而 CSS 是
.standardfield {
text-align:left;
background-color: #D0DEED;
color: #548DD1;
}
解决方案
你应该使用display:flex
.
.wrapper {
display: flex;
flex-direction: row;
width: 100%;
}
.bluebox {
display: flex;
flex-direction: row;
align-items: center;
flex-grow: 1;
background-color: #D0DEED;
color: #548DD1;
padding: 10px;
margin: 10px;
}
.text {
padding-left: 10px;
text-align: left;
}
<div class="wrapper">
<div class="bluebox">
<img src="https://www.gravatar.com/avatar/8679b0fa062922b9826d58315e6f0324?s=64&d=identicon&r=PG&f=1">
<div class="text">
<p><strong>text2</strong></p>
<p>text3</p>
</div>
</div>
</div>
<div class="wrapper">
<div class="bluebox">
<img src="https://www.gravatar.com/avatar/8679b0fa062922b9826d25315e6f0324?s=64&d=identicon&r=PG&f=1">
<div class="text">
<p><strong>text2</strong></p>
<p>text3</p>
</div>
</div>
<div class="bluebox">
<img src="https://www.gravatar.com/avatar/8679b0fa062955b9826d25315e6f0324?s=64&d=identicon&r=PG">
<div class="text">
<p><strong>some more text</strong></p>
<p>text1</p>
<p>text2</p>
<p>text3</p>
</div>
</div>
</div>
推荐阅读
- javascript - 使用 Javascript 在 Django 中处理公式
- spring-data-r2dbc - 如何使用 Reactor 和 Spring 创建 PostgreSQL savePoint
- c# - 从主 AppDomain 订阅 DomainUnload 事件
- symfony - CSS 没有应用于 Symfony 中的页面?
- java - 来自 println 的奇怪行为
- r - 为什么 R Shiny 的文档处理程序不会将我的反应式弹性表导出到 PowerPoint?
- php - amp-list index.js:59 Uncaught (in promise) 错误:获取 JSON 数据失败:HTTP 错误 406
- python - 字典中某些键的平均值
- swiftui - 在 SwiftUI 中使用 Multiarray 进行 onMove
- python - 如何更改加载逻辑回归模型的决策阈值