将容器水平对齐3个div

时间:2017-04-09 18:38:58

标签: html css containers

我尝试制作一个带有3个div的容器,使三个盒子水平排列。中心框的顶部和底部没有与左框对齐,第三个框远远低于前两个框。我对此进行了一些研究,但我试图做的改变并没有改变这一点。

非常感谢你!

Link that shows photo of final page and the issue that I am having

Html代码:

301

xhtml doc中的样式代码:

<div class="container">
<div class="left">
<p>
Tarata Community Engagement
</p>
<a href="http://www.onlythebridge.com/?page_id=28" class="tarata" target="_blank"><img src="tarata.jpg" width="400" height="267" alt="Tarata Community Engagement Project" /></a></div>
<div class="center">
<p>
Santa Rosa Community Engagement
</p>
<img src="santa-rosa.jpg" width="400" height="267" alt="Santa Rosa Community Engagement Project" />
</div>
<div class="right">
<p>
Our histories are unique. The places that we root ourselves, the communities that we are part of, and the ways those relationships change over time are both personal and shared experiences. 
<br><br>
What place/s are meaningful to you? Why? <br>
What are your roots? What do they mean to you in your life?<br>
How do you carry meaningful places and your roots with you? <br>
What is home to you? <br>
Have you left any places or communities behind, what's that like? 
</p></div>
</div> 

2 个答案:

答案 0 :(得分:1)

这有帮助吗?您可以使用flex来对齐三个列,就像您尝试做的那样。 Flex在IE中不起作用(http://caniuse.com/#feat=flexbox

.container {
  /* Important for columns */
  display: -webkit-flex;
  display: flex;
  flex-wrap:wrap; /*EDIT: will wrap into 1 column if screen small */
}

.item {
  /* Important for columns */
  flex: 1 1 0;
  border: 3px solid #808080;
  height: 52px;
  padding: 10px;
}


/* Remove duplicate borders */

.item-2 {
  border-left: none;
  border-right: none;
}
<div class="container">

  <div class="item item-1">
  Image or text here - 1
  </div>
  
  <div class="item item-2">
  Image or text here - 2 
  </div>
  
  <div class="item item-3">
  Image or text here - 3
  </div>
  
</div>

答案 1 :(得分:0)

不幸的是,没有浮动中心。

咨询this Stack Overflow question,因为它可能会让您更好地了解该怎么做。如果你可以使用flex,上面也可以工作!

相关问题