javascript-如何在响应式布局中的div中垂直对齐文本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-如何在响应式布局中的div中垂直对齐文本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1550字,纯文字阅读大概需要3分钟。
内容图文
![javascript-如何在响应式布局中的div中垂直对齐文本](/upload/InfoBanner/zyjiaocheng/682/4a53db263a63469886f9c990e93a0bc5.jpg)
我正在使用Bootstrap网格系统来构建网站
div中有一个文本,我想垂直对齐中间
当前的HTML是
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12 right">
<p>Hatha with Steve Smith</p>
<p>Pure Yoga is dedicated to serving the yoga community in Asia by offering diverse yoga practices - Vinyasa, Hatha, Hot, Wall Rope Yoga, Pre-Natal, & more...</p>
</div>
和CSS
@media (min-width: 1140px)
.col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
float: left;
}
.video_bar .right p:first-child {
font-size: 15px;
font-weight: bold;
margin-top: 30px;
}
因此,您可以注意到,现在文本正在使用margin-top来假装对齐中间,而最佳实践并非如此.如何解决?
演示站点:
http://internal001.zizsoft.com/yoga/section/beginners
感谢您的帮助.
解决方法:
尝试这个
的CSS
.video_bar .left {
border-right: 1px solid #e2e2e2;
display: table-cell;
float: none;
padding: 0;
position: relative;
vertical-align: middle;
}
.col-lg-9.col-md-9.col-sm-9.col-xs-12.right {
display: table-cell;
float: none;
vertical-align: middle;
}
.video_block a,
.video_bar a {
color: #666666;
display: table;
}
编辑
由于您的断点是sm,因此您需要垂直对齐:中间位置> 768px
因此您只能将此代码用于这样的代码
@media (min-width: 768px) {
.video_bar .left {
border-right: 1px solid #e2e2e2;
display: table-cell;
float: none;
padding: 0;
position: relative;
vertical-align: middle;
}
.col-lg-9.col-md-9.col-sm-9.col-xs-12.right {
display: table-cell;
float: none;
vertical-align: middle;
}
.video_block a,
.video_bar a {
color: #666666;
display: table;
}
}
并且在小宽度上,您将保留boostrap布局.
内容总结
以上是互联网集市为您收集整理的javascript-如何在响应式布局中的div中垂直对齐文本全部内容,希望文章能够帮你解决javascript-如何在响应式布局中的div中垂直对齐文本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。