如何垂直对齐(证明)多个元素

时间:2015-03-21 00:15:11

标签: html css alignment vertical-alignment vertical-text

我不太确定如何说出我想要的但我会尝试。我想垂直对齐三个不同的元素,所有三个包裹在单独的div中。目前这是我的代码:



.service_info {
  margin-top: 45px;
  clear: both;
  background-color: #ffffff;
  font-family: "source-sans-pro", sans-serif;
}
.title_text_serviceinfo {
  margin-top: 85px;
  margin-left: 60px;
  padding-bottom: 20px;
  color: #333132;
  font-size: 24px;
  font-family: "source-sans-pro", sans-serif;
}
.service_info_times {
  margin-top: -110px;
  margin-left: 200px;
  font-size: 18px;
  line-height: 175%;
  border-left: 5px solid #0b496f;
  padding-left: 20px;
  color: #333132;
}
.service_info_events {
  postion: fixed;
  left: 300px;
  top: 20px;
  font-size: 18px;
  line-height: 175%;
  color: #333132;
}

<!--Service Information-->

<section class="service_info">
  <h2 class="secondary_header"> When We Gather </h2>

  <h3 class="title_text_serviceinfo"> Sunday </h3> 
  <div class="service_info_times">
    <ul>
      <li>7:00am</li>
      <li>8:30am</li>
      <li>9:00am</li>
      <li>10:15am</li>
      <li>4:00pm</li>
    </ul>
  </div>

  <div class="service_info_events">
    <ul>
      <li>Men's Prayer</li>
      <li>Fellowship Time</li>
      <li>Sunday School</li>
      <li>Worship Service</li>
      <li>Revolution Student Ministries</li>
    </ul>
  </div>

  <h3 class="title_text_serviceinfo"> Monday </h3>
  <div class="service_info_times">
    <ul>
      <li>6:00pm</li>
    </ul>
  </div>

  <div class="service_info_events">
    <ul>
      <li>Precept Bible Study</li>
    </ul>
  </div>

  <h3 class="title_text_serviceinfo"> Tuesday </h3>
  <div class="service_info_times">
    <ul>
      <li>9:15am</li>
    </ul>
  </div>

  <div class="service_info_events">
    <ul>
      <li>P.E.A.R.L.S. (Lady's Ministry</li>
    </ul>
  </div>

  <h3 class="title_text_serviceinfo"> Wednesday </h3>
  <div class="service_info_times">
    <ul>
      <li>7:00am</li>
      <li>7:00pm</li>
      <li>7:00pm</li>
      <li>7:00pm</li>
    </ul>
  </div>

  <div class="service_info_events">
    <ul>
      <li>Stronger Senior</li>
      <li>CLC</li>
      <li>Club 56</li>
      <li>House of Prayer</li>
    </ul>
  </div>
</section>
&#13;
&#13;
&#13;

随时帮助我纠正任何其他错误......我刚开始学习如何编写网站代码。

以下是我想要最终产品的图片:(我必须链接到它,因为我是这个网站的新手。)

fujifame.com/art260/

1 个答案:

答案 0 :(得分:0)

编辑: @GCyrillus有一个更清洁的codepen:http://codepen.io/gc-nomade/pen/raovxv

我设法将您的代码破解为提交。我希望这可以帮助你,但你的代码真的需要重写。根据您拥有的图像,您应该有2列div。一周中的哪一天应该在第一列div中,事件应该在第二列中。将css属性foat:left;添加到第二列div,如果它们没有向下移动到下一列,则使用CSS属性clear:清除它们。希望这能为您提供一个良好的开端!你走了。

.header{ clear:both; }
.service_info {
  margin-top: 45px;

  background-color: #ffffff;
  font-family: "source-sans-pro", sans-serif;
}
.title_text_serviceinfo {
  margin-top: 100px;
  margin-left: 60px;
  /*padding-bottom: 20px;*/
  color: #333132;
  font-size: 24px;
  font-family: "source-sans-pro", sans-serif;
  float:left;
  clear:left;
  width:140px;
}
.service_info_times {
  margin-top: 20px;
  /*margin-left: 200px;*/
  font-size: 18px;
  line-height: 175%;
  border-left: 5px solid #0b496f;
  padding-left: 20px;
  color: #333132;
  float:left;
  clear:right;
}
.service_info_events {
  font-size: 18px;
  line-height: 175%;
  color: #333132;
  clear:right;
}

.secondMargin{ margin-top:40px; }
.thirdMargin{ margin-top:80px; }
<section class="service_info">
  <div id = "header">
    <h2 class="secondary_header"> When We Gather </h2>
  </div>

  <h3 class="title_text_serviceinfo"> Sunday </h3> 
  <div class="service_info_times">
    <ul>
      <li>7:00am Men's Prayer</li>
      <li>8:30am Fellowship Time</li>
      <li>9:00am Sunday School</li>
      <li>10:15am Worship Service</li>
      <li>4:00pm Revolution Student Ministries</li>
    </ul>
  </div>



  <h3 class="title_text_serviceinfo secondMargin"> Monday </h3>
  <div class="service_info_times">
    <ul>
      <li>6:00pm Precept Bible Study</li>
    </ul>
  </div>

  <h3 class="title_text_serviceinfo secondMargin"> Tuesday </h3>
  <div class="service_info_times">
    <ul>
      <li>9:15am P.E.A.R.L.S. (Lady's Ministry)</li>
    </ul>
  </div>

  <h3 class="title_text_serviceinfo"> Wednesday </h3>
  <div class="service_info_times">
    <ul>
      <li>7:00am Stronger Senior</li>
      <li>7:00pm CLC</li>
      <li>7:00pm Club 56</li>
      <li>7:00pm House of Prayer</li>
    </ul>
  </div>
</section>