jumbotron的元素没有正确对齐

时间:2016-06-19 05:18:35

标签: html css twitter-bootstrap

美好的一天!我正在努力将jumbtron与我的日历图标对齐。并且jumbtron的元素不在其中。有人可以帮我解决这个问题吗?想法?我刚开始学习bootstrap和css。

这是图片。

enter image description here

这是我的HTML代码。

 <div class="events">
   <div class="container">
     <div class="row">
       <div class= "col-sm-4 col-xs-25">
         <h4 id="event"><i class="fa fa-calendar" aria-hidden="true"></i> Upcoming Events</h4>
         <hr class="carved">
         <div class="date">
           <span class="month">August</span>
           <h1 class="day">28</h1>
         </div>
         <div class="container">
           <div class="jumbotron">
             <h4>Sample Title</h4>
             <p>IT Thesis defense</p>
             <h6>7:00 AM - 8:00 PM</h6>
           </div>
         </div>
         <hr class="divider">
         <div class="date">
           <span class="month">August</span>
           <h1 class="day">28</h1>
         </div>
         <hr class="divider">
         <div class="date">
           <span class="month">August</span>
           <h1 class="day">28</h1>
         </div>
       </div>
       <div class= "col-sm-8 col-xs-25">
         <h4 id="event"><i class="fa fa-newspaper-o" aria-hidden="true"></i> Latest News</h4>
         <hr class="carved">
       </div>
     </div>
   </div>
 </div>

这是我的css

#event {
  color: #a92419;
}
hr.carved {
  clear: both;
  float: none;
  width: 100%;
  height: 2px;
  border: none;
  background: #ddd;
  background-image: -webkit-gradient(
      linear,
      left top,
      left bottom,
      color-stop(0.5, rgb(126,27,18)),
      color-stop(0.5, rgb(211,45,31))
  );
  background-image: -moz-linear-gradient(
      center top,
      rgb(126,27,18) 50%,
      rgb(211,45,31) 50%
  );
}
.date {
  display: block;
  width: 60px;
  height: 60px;
  margin-bottom: 20px;
  background: #fff;
  text-align: center;
  font-family: 'Helvetica', sans-serif;
  position: relative;
}
.date .month {
  background: #a92419;
  display: block;
  padding-bottom: 5px;
  padding-top: 5px;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  border-bottom: 2px solid #a92419;
  box-shadow: inset 0 -1px 0 0 #a92419;
}

.date .day {
  display: block;
  margin: 0;
  padding-bottom: 10px;
  padding-top: 5px;
  text-align: center;
  font-size: 20px;
  color:#a92419;
  box-shadow: 0 0 3px #ccc;
  position: relative;
}

.date .day::after {
  content: '';
  display: block;
  height: 95%;
  width: 96%;
  position: absolute;
  top: 3px;
  left: 2%;
  z-index: -1;
  box-shadow: 0 0 3px #ccc;
}

.date .day::before {
  content: '';
  display: block;
  height: 90%;
  width: 90%;
  position: absolute;
  top: 6px;
  left: 5%;
  z-index: -1;
}
.jumbotron {
  width: 300px;
  height: 100px;
  margin:none;
}
.jumbotron p {
  font-size:12px;
}

2 个答案:

答案 0 :(得分:1)

<div class="container">
    <div class="row">
         <div class="col-md-2">
         <h4 id="event"><i class="fa fa-calendar" aria-hidden="true"></i> Upcoming Events</h4>
         <hr class="carved">
        <div class="date">
        <span class="month">August</span>
        <h1 class="day">28</h1>
    </div><!-- date -->
</div><!-- md2 --> 

<div class="col-md-10">
<h4 id="event"><i class="fa fa-newspaper-o" aria-hidden="true"></i> Latest News</h4>
<hr class="carved">
    <div class="jumbotron">
    <h4>Sample Title</h4>
    <p>IT Thesis defense</p>
    <h6>7:00 AM - 8:00 PM</h6>
    </div><!-- jumbo -->
</div><!-- md10 -->

</div><!-row>
</div><!-- container -->

+

#event {
  color: #a92419;
}
hr.carved {
  clear: both;
  float: none;
  width: 100%;
  height: 2px;
  border: none;
  background: #ddd;
  background-image: -webkit-gradient(
      linear,
      left top,
      left bottom,
      color-stop(0.5, rgb(126,27,18)),
      color-stop(0.5, rgb(211,45,31))
  );
  background-image: -moz-linear-gradient(
      center top,
      rgb(126,27,18) 50%,
      rgb(211,45,31) 50%
  );
}
.date {
  display: block;
  width: 60px;
  height: 60px;
  margin-bottom: 20px;
  background: #fff;
  text-align: center;
  font-family: 'Helvetica', sans-serif;
  position: relative;
}
.date .month {
  background: #a92419;
  display: block;
  padding-bottom: 5px;
  padding-top: 5px;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  border-bottom: 2px solid #a92419;
  box-shadow: inset 0 -1px 0 0 #a92419;
}

.date .day {
  display: block;
  margin: 0;
  padding-bottom: 10px;
  padding-top: 5px;
  text-align: center;
  font-size: 20px;
  color:#a92419;
  box-shadow: 0 0 3px #ccc;
  position: relative;
}

.date .day::after {
  content: '';
  display: block;
  height: 95%;
  width: 96%;
  position: absolute;
  top: 3px;
  left: 2%;
  z-index: -1;
  box-shadow: 0 0 3px #ccc;
}

.date .day::before {
  content: '';
  display: block;
  height: 90%;
  width: 90%;
  position: absolute;
  top: 6px;
  left: 5%;
  z-index: -1;
}

Result

答案 1 :(得分:1)

.container类具有自己的宽度,旨在用作布局的外部包装。因此,它们不容易嵌套。你作为.date分类元素的兄弟姐妹的那个正在打破布局。

至于.jumbotron内容的间距,默认情况下,Bootstrap会为该类分配一些非常引人注目的填充。考虑使用.jumbotron规则中的您自己的值覆盖该值。另一个问题 - .jumbotron内容从容器中流失 - 这是您设置的height: 100px的结果。您可以通过添加/修改其overflow属性来阻止内容占用超出.jumbotron边界的空间。 这可能是一个意见问题,但我认为通常最好避免在CSS中设置height并让内容定义容器的大小 - 尤其是在内容为CMS /客户端驱动的情况下

如果您移除.container,则仍会遇到.date.jumbotron垂直堆叠的问题。要解决这个问题,您可以考虑将Date元素视为.row,其中包含.date元素的列,以及该Date的事件列。

<hr class="carved">

<div class=“row”><!-- the Date wrapper -->

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

    <div class="date">
      <span class="month">August</span>
      <h1 class="day">28</h1>
    </div>

  </div>

  <div class="col-sm-8"><!-- this column holds all the Events for this Date -->

    <div class="jumbotron">
        <h4>Sample Title</h4>
        <p>IT Thesis defense</p>
        <h6>7:00 AM - 8:00 PM</h6>
    </div>

  </div>

</div>

注意:新结构需要对您的某些CSS width属性以及我在日期和事件中添加的col-设备/尺寸进行一些调整列只是示例 - 根据需要大小。