簡體   English   中英

如何在div內水平居中放置網格塊?

[英]How can I center horizontally a Grid-block inside of a div?

我正在嘗試將div內的Block網格居中,但是當我應用CSS類時,Block網格不會受到影響。

我在視覺上有此功能(輪廓由Firefox擴展程序制成): 阻止網格分配

我想看起來像這樣: 方塊網格

如您所見,我還需要對齊Block網格內容和div內容,但是我不知道該怎么做。

這是我當前的代碼:

<div class="sitios-amigos">


<div class="wrap row small-up-1 medium-up-4">

    <div class="column column-block tarjeta-material">
        <a src="http://www.conacyt.gob.mx/" target="_blank"><img alt="Página web Conacyt" src="img/conacyt.png"/></a>
    </div>
    <div class="column column-block tarjeta-material">
        <a href="http://www.concytep.pue.gob.mx/" target="_blank">
        <img alt="Página web de Concytep" src="img/concytep.png"></a>
    </div>
    <div class="column column-block tarjeta-material">
    <a href="http://www.viep.buap.mx/" target="_blank">
        <img alt="Página web VIEP BUAP" src="img/VIEP.png"></a>
    </div>           
</div>

</div>

CSS:

.sitios-amigos{

background: red;
max-width:11000px;
width: 100%;
margin: 0 auto; 
}
.wrap{
width:90%;
max-width:11000px;
margin: 0 auto;
}
.tarjeta-material {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
margin: 15px 10px;
text-align:center;
}

.tarjeta-material:hover {
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
}




.tarjeta-material {
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
margin: 15px 10px;
text-align:center;
}

.tarjeta-material:hover {
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
}

如果要對齊的div是另一個div的子級。 這是您可以做的。

.parent-div {
    text-align: center;

.child-div {
    display: inline-block;
}

您也可以嘗試不引用父div。

.child-div {
    margin-left: auto;
    margin-right: auto;
}

將其居中在絕對中間位置:

.parent-div {
        position: relative;

    .child-div {
        position: absolute;
        top: 50%;
        /* this will put the left edge at 50%. not the image */
        left: 50%;
        /* do a negative margin-left of half the width of your block so you have to find that.*/
        margin-left: -halfthewidth;
        margin-top: -halfthelength;
    }

您是否嘗試過使用引導網格系統 他們有這么多的樣本,更容易使用..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM