我希望用户名文本位于页面中间的用户照片下方。这是我的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>
我还尝试了其他技巧,例如li
而没有class="text-center"
,但它们没有按预期工作。我该如何解决?
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;
}
答案 0 :(得分:2)
img-responsive
是bootstrap 3中的一个块元素,所以你必须添加 maring:auto (文本中心不会对它产生影响):
.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>