图像不居中Bootstrap center-block

时间:2015-10-21 14:24:22

标签: html css twitter-bootstrap

我无法将我的图像放在bootstrap提供的面板中:

enter image description here

这是我的html代码:

          <div class="row">
              <div class="col-lg-12">

                    <div class="col-lg-4">
                        <div class="panel panel-default">
                            <a class="modals" data-toggle="modal" data-target="#PatientDiagnosisModal"  href="">
                        <div class="panel-body"><img class="img-responsive  center-block" src="../img/diagnosis.png"></img></div>
                        <div class="panel-footer"><center>Patient Diagnosis</center></div></a>
                        </div>
                  </div>

                    <div class="col-lg-4">
                        <div class="panel panel-default">
                            <a class="modals" data-toggle="modal" data-target="#PatientDiagnosisModal"  href="">
                        <div class="panel-body"><img class="img-responsive  center-block" src="../img/diagnosis.png"></img></div>
                        <div class="panel-footer"><center>Patient Diagnosis</center></div></a>
                        </div>
                  </div>

                    <div class="col-lg-4">
                        <div class="panel panel-default">
                            <a class="modals" data-toggle="modal" data-target="#PatientDiagnosisModal"  href="">
                        <div class="panel-body"><img class="img-responsive  center-block" src="../img/diagnosis.png"></img></div>
                        <div class="panel-footer"><center>Patient Diagnosis</center></div></a>
                        </div>
                  </div>
            </div>
          </div>

如何克服这个问题?

3 个答案:

答案 0 :(得分:0)

Bootstrap有辅助类来居中元素:http://getbootstrap.com/css/#helper-classes-center

将类center-block添加到您的图片中,应该可以解决问题:

<div class="panel-body"><img class="img-responsive center-block" src="../img/diagnosis.png"></img></div>

Working example

如果它没有使用boostrap类,请尝试在css文件中添加自己的center-block类,然后将其添加到图像中:

.center-block {
    display: block;
    margin: 0 auto;
}

JSFiddle for this solution

答案 1 :(得分:-1)

Instid您可以使用<center>标记来实现此目标。这是一个简单的例子。

<center><div class="row"><img src="your image"/></div></center>

希望这有帮助!

答案 2 :(得分:-1)

写入CSS:

.panel.panel-default { margin: 0 auto !important; }