css - 面板的对齐问题

标签 css twitter-bootstrap

您好,请查看此链接。我怎样才能使图像居中,因为现在它似乎太向右了

http://jsbin.com/yenade

最佳答案

演示 - http://jsbin.com/xacikizuhe/

使用 left: 50%;transform: translateX(-50%);

.panel-profile .panel-heading img {
  position: absolute;
  margin: 0;
  left: 50%;
  transform: translateX(-50%);
  bottom: -25px;
}

/*demo */

body {
  padding: 5%;
}
.panel {
  max-width: 500px;
  margin: 0 auto
}
/* end demo */

.panel-profile .panel-heading {
  position: relative;
}
.panel-profile .panel-heading h4 {
  margin: 10px 0 20px;
  font-weight: normal;
}
.panel-profile .panel-heading img {
  margin: 0 auto 10px;
  display: block;
  border: 1px solid #ddd;
  background: #fff;
}
@media (min-width: 400px) {
  .panel-profile .panel-heading a {
    font-size: .75em;
    float: right;
  }
  .panel-profile .panel-heading {
    margin-bottom: 30px;
  }
  .panel-profile .panel-heading img {
    position: absolute;
    margin: 0;
    left: 50%;
    transform: translateX(-50%);
    bottom: -25px;
  }
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="panel panel-default panel-profile">
  <div class="panel-heading text-center clearfix">
    <h4>Name of Person</h4>
    <img src="http://placepic.me/profiles/50-50" class="img-circle">

    <a href="#">Edit Profile</a> 
  </div>
  <div class="panel-body">
    Panel content
  </div>
</div>

关于css - 面板的对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26946180/

相关文章:

css - 从 Rails 图像标记中调整图像大小

javascript - 使用模态 Bootstrap 确认将不起作用

javascript - Bootstrap 4 最新版本轮播按钮不工作

javascript - Jquery 验证不适用于折叠的 Bootstrap 面板

javascript - 如何附加文本和 Bootstrap 日期选择器

Javascript/JQuery : Is there a way to append an image or text to an image that is downloaded?

css - 页面标题CSS样式

html - CSS属性是否适用于相同类型的连续嵌套标签?

html - 如何在联系表 7 中设置接受标签的样式?

html - 变换时平移 Y 未在中间垂直对齐