Chrome中Bootstrap轮播的文本内容未与中心对齐

时间:2015-09-03 21:00:18

标签: css twitter-bootstrap-3 carousel

我需要将轮播内容放在页面的中心。在chrome中,无论我尝试什么,总是会保留对齐,包括text-align:center

<?php
$var = "sometext";
?>
<html>
<body>
<?php echo $var ?>
</body>
</html>

Safari的行为符合预期。没有检查IE。你能帮忙吗?

1 个答案:

答案 0 :(得分:1)

您需要执行的操作,而不是text-align: center div中div的carousel-content,而是使用margin: 0 auto

我认为以下代码是你想要的:)

<html lang="en">
<head>
<meta charset="UTF-8">
<title>caro homepage</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style type="text/css">
    .carousel-inner{
      width:auto;
      height:200px;
      max-height:200px !important;
    }
    .carousel-content {
        color:black;
        display:flex;
        text-align:center;
    }

</style>
</head>
<body>

<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="4000" data-pause="hover" >
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>

  </ol>
  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
        <div class="carousel-content">
           <div style="margin: 0 auto">
                <h3>#1</h3>
                <p>The first  Message.</p>
           </div>
        </div>
    </div>
    <div class="item">
        <div class="carousel-content">
           <div style="margin: 0 auto">
                <h3>#2</h3>
                <p>The 2nd Message.</p>
           </div>
        </div>
    </div>    
  </div>
  <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

</body>
</html>