简体   繁体   English

如何使用Bootstrap将按钮居中?

[英]How to Center a button using Bootstrap?

friend! 朋友! I am create a video list. 我正在创建一个视频列表。 I use bootstrap grid system create it. 我使用引导网格系统创建它。 This is my code I want to play button vertically and horizontally centere in the middle thumbnail. 这是我的代码,我想在中间的缩略图中垂直和水平居中播放按钮。 How to modify the code? 如何修改代码?

 .test { width: 100%; background: #f5f5f5; border: 1px solid #e5e5e5; position: relative; } .quick-img { display: block; width: 100%; height: auto; max-width: 100%; } .kkk { position: absolute; z-index: 1; top: 25%; left: 45%; font-size: 60px; opacity: 0.6; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); } 
 <script src="//cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <div class="container"> <div class="row"> <div class="col-lg-6 col-sm-12 "> <div class="test"> <a href="//google.com"> <img class="quick-img" src="http://imgs.aixifan.com/content/2017_10_02/1509609180.png" /> <button class="kkk glyphicon glyphicon-play"></button> </a> <h2 style=" word-break: break-all; word-wrap: break-word;">title test</h2> </div> </div> <div class="col-lg-6 col-sm-12 "> <div class="test"> <a href="//google.com"> <img class="quick-img" src="http://imgs.aixifan.com/content/2017_10_02/1509609180.png" /> <button class="kkk glyphicon glyphicon-play"></button> </a> <h2 style=" word-break: break-all; word-wrap: break-word;">title test</h2> </div> </div> <div class="col-lg-6 col-sm-12 "> <div class="test"> <a href="//google.com"> <img class="quick-img" src="http://imgs.aixifan.com/content/2017_10_02/1509609180.png" /> <button class="kkk glyphicon glyphicon-play"></button> </a> <h2 style=" word-break: break-all; word-wrap: break-word;">title test</h2> </div> </div> </div> </div> 

HI friend! 你好,朋友! I am create a video list. 我正在创建一个视频列表。 I use bootstrap grid system create it. 我使用引导网格系统创建它。 This is my code I want to play button vertically and horizontally centere in the middle thumbnail. 这是我的代码,我想在中间的缩略图中垂直和水平居中播放按钮。 How to modify the code? 如何修改代码?

Try adding to your css: 尝试添加到CSS中:

.kkk  
{
    padding-top:50px;
}

Try adding this to your CSS: 尝试将其添加到您的CSS中:

.test a { display: block; position: relative; }

button.kkk { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM