如何在中心水平对齐这些div?

时间:2016-04-12 11:18:22

标签: html css

我有一个图像,ul列表和另一个图像全部在div中排成一行,我希望它们全部水平和垂直居中,我希望它们在屏幕变小时移动到友好之下。有谁知道这个解决方案?这是一张图片供参考:

enter image description here

HTML:

<div class="more">

  <div id="social-logo">
    <a href="https://drinkaware.co.uk"><img src="" alt="" width="200" height="200"></a>
  </div>

    <ul class="about">
      <li class="a-links">
        <div id="about-links" class="site-content">
          <ul class="aboutli">
            <li><a target="_blank" href="#">About Us</a></li>
            <li><a target="_blank" href="#">FAQ's</a></li>
            <li><a target="_blank" href="#">Contact Us</a></li>
            <li><a target="_blank" href="#">Work With Us</a></li>
            <li><a target="_blank" href="#">Terms and Conditions</a></li>
            <li><a target="_blank" href="#">Privacy Policy</a></li>
          </ul>
        </div>
      </li>
    </ul>

    <div id="drinkaware" class="site-content">
      <a href="https://drinkaware.co.uk"><img src="/Applications/MAMP/htdocs/D0.1/images/drinkawarered.png" width="200" height="auto"></a>
    </div>

</div>

CSS:

.more {
  height: 300px;
  background-color: #e6e6e6;
  border-top: 1px solid #000000;
}
#social-logo {
  display: inline-block;
  margin-left: 200px
}
ul.about {
  width: 160px;
  height: 184px;
  display: inline-block;
  border: 1px solid #000000;
  list-style-type: none !important;
  list-style-position: inside;
  text-align: center;
  text-decoration: none;
  line-height: 0.8cm;
  padding: 0px;
}
ul.aboutli {
  color: #000000;
  font-size: 12px;
  border: 1px solid yellow;
  padding: 0px;
  text-decoration: none;
  list-style-type: none !important;
}

#drinkaware {
  display: inline-block;
  top: 100px;
}

2 个答案:

答案 0 :(得分:2)

使用bootstrap,这是一个很小的例子来获得你想要的响应式布局:http://jsfiddle.net/jb0Ly020/

HTML

<div class="row">
  <div class="col-sm-4 col-xs-12">
    123
  </div>
  <div class="col-sm-4 col-xs-12">
    456
  </div>
  <div class="col-sm-4 col-xs-12">
    789
  </div>
</div>

CSS

@import url('http://getbootstrap.com/dist/css/bootstrap.css');

要将所有元素设置为相同的高度,我将其高度设置为包含外部div的100%,其高度可以手动设置。

答案 1 :(得分:1)

通过添加包装器来应用此html:

<div class="wrapper">
<div class="more">

  <div id="social-logo">
    <a href="https://drinkaware.co.uk"><img src="" alt="" width="200" height="200"></a>
  </div>

    <ul class="about">
      <li class="a-links">
        <div id="about-links" class="site-content">
          <ul class="aboutli">
            <li><a target="_blank" href="#">About Us</a></li>
            <li><a target="_blank" href="#">FAQ's</a></li>
            <li><a target="_blank" href="#">Contact Us</a></li>
            <li><a target="_blank" href="#">Work With Us</a></li>
            <li><a target="_blank" href="#">Terms and Conditions</a></li>
            <li><a target="_blank" href="#">Privacy Policy</a></li>
          </ul>
        </div>
      </li>
    </ul>

    <div id="drinkaware" class="site-content">
      <a href="https://drinkaware.co.uk"><img src="/Applications/MAMP/htdocs/D0.1/images/drinkawarered.png" width="200" height="auto"></a>
    </div>

</div>
</div>

这个css:

.more {
  height: auto;
  background-color: #e6e6e6;
  border-top: 1px solid #000000;
  margin: 0 auto;
  width: 80%;
}
#social-logo {
  display: inline-block;

}
ul.about {
  width: 160px;
  height: 184px;
  display: inline-block;
  border: 1px solid #000000;
  list-style-type: none !important;
  list-style-position: inside;
  text-align: center;
  text-decoration: none;
  line-height: 0.8cm;
  padding: 0px;
}
ul.aboutli {
  color: #000000;
  font-size: 12px;
  border: 1px solid yellow;
  padding: 0px;
  text-decoration: none;
  list-style-type: none !important;
}

#drinkaware {
  display: inline-block;
  top: 100px;
}

.wrapper
{
    width: 100%;
    text-align: center;
    background-color: #e6e6e6;
}

如果您希望响应height: auto,则必须将divmore class中的%用于docker run -d hello sleep infinity