如何垂直对齐这些图片?

时间:2016-11-25 02:03:37

标签: html css alignment vertical-alignment

我正在创建一个页脚,我想垂直对齐社交网络的图像,并自动 。随着触点源尺寸的增加,图像也会增加。我不知道该怎么办。

我在jsfiddle的代码:Demo Code

HTML

repair

CSS

<!DOCTYPE html>
<title>Teste</title>

<body>
  <footer class="footer">
    <div class="content">
      <div class="footer-right">
        <p><b>(43)3333-3333</b></p>
        <p>contact@contact.com</p>
      </div>
      <div class="footer-left">
        <ul>
          <li>
            <a href="#"><img src="http://imgur.com/RVvPQt9.png" alt="Twitter"></a>
          </li>
          <li>
            <a href="#"><img src="http://imgur.com/LsqUBIh.png" alt="Facebook"></a>
          </li>
          <li>
            <a href="#"><img src="http://imgur.com/8PhKmDe.png" alt="Instagram"></a>
          </li>
          <li>
            <a href="#"><img src="http://imgur.com/hDSPEMm.png" alt="Linkedin"></a>
          </li>
        </ul>
      </div>
    </div>
  </footer>
</body>

2 个答案:

答案 0 :(得分:0)

使用表格显示css - table-cell导致浮动工作,table-header-group和table-footer-group导致重新排序。

&#13;
&#13;
* {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Source Sans Pro', sans-serif;
}

.content {
    margin: 0 auto;
    max-width: 1100px;
    padding: 0 4% 0 4%;
    min-width:92%;
    display:table;
}

li {
    list-style: none;
}

.footer {
    background-color: rgba(158, 158, 158, 0.42);
    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    width: 100%;
    text-align: left;
    padding: 15px 0;
    overflow: hidden;
}

.footer .footer-right {
    display:table-cell;
    width:50%;
}

.footer .footer-right {
    font-size: 18px;
    text-align: right;
    width:50%;
}

.footer .content .footer-left {
    display:table-cell;
    vertical-align:middle;
}

.footer .content .footer-left > ul > li {
    display: inline-block;
}

.footer > .content > .footer-left > ul > li > a {
    display: block;
}

.footer > .content > .footer-left > ul > li > a > img {
    height: 30px;
    width: 30px;
}


/*MEDIA QUERIES*/

@media screen and (max-width: 400px) {
    .footer > .content > .footer-left {
        display:table-footer-group;
        width:100%;
        float:none;
        text-align: center;
    }
    .footer > .content > .footer-right {
        display:table-header-group;
        margin-bottom: 10px;
        float:none;
        width:100%;
    }
    .footer > .content > .footer-right p {
        width:100%;
        display:block;
        text-align: center;
    }
}
&#13;
<!DOCTYPE html>
    <title>Teste</title>
<body>
    <footer class="footer">
        <div class="content">
            <div class="footer-left">
                <ul>
                    <li>
                        <a href="#"><img src="http://imgur.com/RVvPQt9.png"
                                alt="Twitter"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/LsqUBIh.png"
                                alt="Facebook"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/8PhKmDe.png"
                                alt="Instagram"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/hDSPEMm.png"
                                alt="Linkedin"></a>
                    </li>
                </ul>
            </div>
            <div class="footer-right">
                <p><b>(43)3333-3333</b></p>
                <p>contact@contact.coma</p>
                <p><b>(43)3333-3333</b></p>
                <p>contact@contact.coma</p>
            </div>
        </div>
    </footer>
</body>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

请尝试此代码 这是一种对齐垂直

的简单方法

如果您想添加垂直中间框,可以使用以下样式作为父div。

"display:table;"

并为儿童添加以下属性

 "display:table-cell"

CSS

* {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Source Sans Pro', sans-serif;
}

.content {
    margin: 0 auto;
    max-width: 1100px;
    width: 100%;
    padding: 0 4% 0 4%;
    display: table;
}

li {
    list-style: none;
}

.footer {
    background-color: rgba(158, 158, 158, 0.42);
    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
    box-sizing: border-box;
    width: 100%;
    text-align: left;
    padding: 15px 0;
    overflow: hidden;
}

.footer .footer-right {
    float: none;
    vertical-align: middle;
    text-align: right;
    display: table-cell;
}

.footer .footer-right {
    font-size: 18px;
    text-align: right;
}

.footer .content .footer-left {
    display: table-cell;
    float: none;
    vertical-align: middle;
    text-align:left;
}

.footer .content .footer-left > ul > li {
    display: inline-block;
}

.footer > .content > .footer-left > ul > li > a {
    display: block;
}

.footer > .content > .footer-left > ul > li > a > img {
    height: 30px;
    width: 30px;
}


/*MEDIA QUERIES*/

@media screen and (max-width: 400px) {
    .footer > .content > .footer-right, .footer-left {
        float: none !important;
        text-align: center;
    }
    .footer > .content > .footer-right {
        margin-bottom: 10px;
    }
}

HTML

<!DOCTYPE html>
    <title>Teste</title>
<body>
    <footer class="footer">
        <div class="content">

            <div class="footer-left">
                <ul>
                    <li>
                        <a href="#"><img src="http://imgur.com/RVvPQt9.png"
                                alt="Twitter"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/LsqUBIh.png"
                                alt="Facebook"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/8PhKmDe.png"
                                alt="Instagram"></a>
                    </li>
                    <li>
                        <a href="#"><img src="http://imgur.com/hDSPEMm.png"
                                alt="Linkedin"></a>
                    </li>
                </ul>
            </div>

            <div class="footer-right">
                <p><b>(43)3333-3333</b></p>

                <p><b>(43)3333-3333</b></p>
                <p>contact@contact.com</p>
            </div>
        </div>
    </footer>
</body>

JSFIDDLE