html - 如何在 bootstrap 3 中居中对齐照片下方的文本?

标签 html css twitter-bootstrap

我希望用户名文本在页面中间的用户照片下方居中。这是我的 html 代码,但它不起作用:

<div class="row">
    <div class="col-sm-4 col-sm-push-4">

            <ul class="list-unstyled">
                <li class="text-center">
                    <img class="img-responsive img-circle" :src="BASE_URL +'/media/avatars/' + photo">
                </li>   
                <li class="text-center">
                    <h5><strong>{{$route.params.username}}</strong></h5>
                </li>
            </ul>          
    </div> 
</div>

我也尝试过其他技巧,例如不使用 class="text-center"li,但它们没有按预期工作。我该如何解决?

P.S 这是我使用的完整 custom.css:

body {
    background: #fdca15;
direction: rtl;
text-align: rtl;

}



.bala{
    text-align: center;
}



.mylogo  {
    width: 150px;
    text-align: left !important;
}

.results {
    font-family: sans-serif, arial, parastoo, tahoma, sans;
}


.search-bar {
    font-family: sahel, tahoma, sans;
}

.large-text{
    padding: 20px;
}



.share-links {      
 float: left;
}

.single-joke , .profile {
    padding: 10px;
    background: #fff;
    border-radius: 5px;

}


.btn-round-lg{
border-radius: 22.5px;

}
.btn-round{
border-radius: 17px;
}
.btn-round-sm{
border-radius: 15px;
}


 a:hover{
    color: red;
     text-decoration: none;
 }

 .grey {
    color: #aeadad;
 }

 .green {
    color: #9fde86;
 }

  .red {
    color: #ff7761;
 }

 .white {
    color: #fff;
 }

 .img-circle {
    height: 50px;
    width: 50px;
 }

 .avatar-comment {
    height: 32px;
    width: 32px;
 }

.img-responsive {
  margin: auto !important;
}


 .profile-photo {
        height: 128px;
    width: 128px;

 }
 .vertical-align {
    display: flex;
    align-items: center;
}

.username {
    text-align: right;
}

/* Dropdown Button */
.dropbtn {
    background-color: #ff8e15;
    color: white;
    padding: 16px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
    position: relative;
    display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
    display: block;
}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
    background-color: #3e8e41;
}

.joke-photo {
    max-width: "900px";
}

 .submenu:hover {
    cursor: pointer;
 }

 .photo-image {

    max-width: 800px;
 }

 .img-avatar {
    max-width: 64px;
    max-height: 64px;
 }

.img-small {

    max-width: 512px;
    max-height: 512px;

}

 ul li img {
    vertical-align: middle;
}


a {

    color: #852f01 !important;

}


a:hover {

    color: #E65100 !important;
}

最佳答案

img-responsive 是 bootstrap 3 中的 block 元素,因此您必须添加 ma​​ring:auto(text-center 不会对其产生影响) :

.img-responsive {
  margin: auto;
}

完整代码:

body {
  background: #fdca15;
  direction: rtl;
  text-align: rtl;
}

.bala {
  text-align: center;
}

.mylogo {
  width: 150px;
  text-align: left !important;
}

.results {
  font-family: sans-serif, arial, parastoo, tahoma, sans;
}

.search-bar {
  font-family: sahel, tahoma, sans;
}

.large-text {
  padding: 20px;
}

.share-links {
  float: left;
}

.single-joke,
.profile {
  padding: 10px;
  background: #fff;
  border-radius: 5px;
}

.btn-round-lg {
  border-radius: 22.5px;
}

.btn-round {
  border-radius: 17px;
}

.btn-round-sm {
  border-radius: 15px;
}

a:hover {
  color: red;
  text-decoration: none;
}

.grey {
  color: #aeadad;
}

.green {
  color: #9fde86;
}

.red {
  color: #ff7761;
}

.white {
  color: #fff;
}

.img-circle {
  height: 50px;
  width: 50px;
}

.avatar-comment {
  height: 32px;
  width: 32px;
}

.img-responsive {
  margin: auto;
}

.profile-photo {
  height: 128px;
  width: 128px;
}

.vertical-align {
  display: flex;
  align-items: center;
}

.username {
  text-align: right;
}


/* Dropdown Button */

.dropbtn {
  background-color: #ff8e15;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
  cursor: pointer;
}


/* The container <div> - needed to position the dropdown content */

.dropdown {
  position: relative;
  display: inline-block;
}


/* Dropdown Content (Hidden by Default) */

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}


/* Links inside the dropdown */

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}


/* Change color of dropdown links on hover */

.dropdown-content a:hover {
  background-color: #f1f1f1
}


/* Show the dropdown menu on hover */

.dropdown:hover .dropdown-content {
  display: block;
}


/* Change the background color of the dropdown button when the dropdown content is shown */

.dropdown:hover .dropbtn {
  background-color: #3e8e41;
}

.joke-photo {
  max-width: "900px";
}

.submenu:hover {
  cursor: pointer;
}

.photo-image {
  max-width: 800px;
}

.img-avatar {
  max-width: 64px;
  max-height: 64px;
}

.img-small {
  max-width: 512px;
  max-height: 512px;
}

ul li img {
  vertical-align: middle;
}

a {
  color: #852f01 !important;
}

a:hover {
  color: #E65100 !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
  <div class="col-sm-4 col-sm-push-4">

    <ul class="list-unstyled">
      <li>
        <img class="img-responsive img-circle" src="https://lorempixel.com/50/50/">
      </li>
      <li class="text-center">
        <h5><strong>text</strong></h5>
      </li>
    </ul>
  </div>
</div>

关于html - 如何在 bootstrap 3 中居中对齐照片下方的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47451120/

相关文章:

html - 如何正确渲染离屏 Canvas

javascript - 谷歌新工作表格式上的 XmlHttpRequest 状态 0

html - 当 div 具有动态高度内容时,如何将 div 粘贴在其他粘性 div 下方?

css - Twitter Bootstrap 导航栏不响应小屏幕

html - 构建 HTML 电子邮件时,我可以将样式放在 header 部分还是必须使用内联样式?

css - 如何获得网站的高度以适应各种大小的 iframe 页面?

html - 在 div 中居中垂直列表

html - TH 不覆盖表格边框 (CSS+HTML)

html - 为什么右浮动会影响其下方元素的布局?

html - 使用 bootstrap 在一行中定位 2 个元素