html - 将图像与文本块对齐
问题描述
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.css" rel="stylesheet"/>
<div class="center" style="margin: auto;">
<img src="./Resources/document.png" style="vertical-align: middle;" />
<p style="display: inline-block">Never lose an email again</p>
<p style="font-size: 0.8em">Second paragrah the wants to have indentation</p>
</div>
请注意,图像与第一个文本块垂直对齐,第二个文本块具有正确的缩进。我想用带有灵活填充的容器来包含整个元素,比如width:50%
目前我的代码是
<div class="center" style="margin: auto;">
<img src="./Resources/document.png" style="vertical-align: middle;" />
<p style="display: inline-block">Never lose an email again</p>
</div>
但是,第二个文本块没有正确缩进。
解决方案
我建议您使用FontAwesome
图标或类似的东西而不是使用图像来实现最终结果。
更新的片段复制了您附加的屏幕截图 -
.small {
font-size: 0.8em;
margin-top: 20px;
}
.box {
width: 30%;
margin-left: 35%;
margin-right: 35%;
margin-top: 30px;
}
.box:before {
font-family: FontAwesome;
color: green;
font-size: 25px;
position: absolute;
margin-left: -33px;
margin-top: -5px;
}
.magnify:before {
content: "\f002";
}
.book:before {
content: "\f02d";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="box magnify">
<p>Never lose an email again</p>
<p class="small">Second paragrah the wants to have indentation Second paragrah the wants to have indentation Second paragrah the wants to have indentation</p>
</div>
<div class="box book">
<p>Never lose an email again</p>
<p class="small">Second paragrah the wants to have indentation Second paragrah the wants to have indentation Second paragrah the wants to have indentation</p>
</div>
推荐阅读
- groovy - 使用 Terraform 地图变量的 Jenkins 参数化作业
- javascript - 在 Windows 任务栏中(纯 JavaScript)等元素上交换位置
- windows - 如何将记事本的默认unicode设置为UTF8?
- javascript - 在 Amcharts4 range.contents.fill 不适用于 Lineseries.propertiesField.fill
- node.js - 如何防止我的图书馆的消费者安装我的 devDependencies?
- javascript - React.js,在 useEffect 挂钩中,window.location.href 不会停止中断进一步的代码执行
- python - xclip 没有从 pexpect 获取标准输入,或者 pexpect 没有发送?
- c# - 使用 MailboxAddress(String) 构造函数发送带有 mailKit 过时警告的电子邮件
- bash - VSCode 打开工作区时如何运行 bash 命令或设置环境变量
- spring-cloud-gateway - Retry GatewayFilter 在 Spring Cloud Gateway 上无法按预期工作