2016-10-18 37 views
1

我正在做一个网页,需要中心对齐3个格作宣传的内容,这样的:中心文字与图片Flexbox的

enter image description here

为了得到这个间距和对齐方式,我加隐形图像搞得那么隐藏在移动,所以他们得到响应,这样的:

<div id="promocontent"> 
    <img class="img-responsive" src="img/iconenope.png"> 
    <img class="img-responsive hidden hide-on-med-and-down" src="img/iconehidden.png"> 
    <img class="img-responsive" src="img/iconenope.png"> 
    <img class="img-responsive hidden hide-on-med-and-down" src="img/iconehidden.png"> 
    <img class="img-responsive" src="img/iconenope.png"><br><br> 
</div> 

CSS:

#promocontent { 
display: flex;     /* establish flex container */ 
flex-direction: row;   /* default value; can be omitted */ 
flex-wrap: nowrap;    /* default value; can be omitted */ 
justify-content: space-between; /* switched from default (flex-start, see below) */ 
padding: 5px; 
} 

现在,我需要对这些图像的中心底部添加文本,是这样的:

enter image description here

所以,我怎么能做到这一点(响应工作)?对齐2行文字(可能是1,但2会更好)。

谢谢。

回答

0

我会避免使用间隔一个额外的形象,仅仅依靠justify-content: space-between

随时检查出我codepen(基本相同迈克尔斯) 。

http://codepen.io/anon/pen/zKmaVJ

+0

有什么优势吗?像我的额外img有什么问题? – MucaP

+0

没有什么,除了你迫使用户下载不必要的重量。我们希望尽可能少 - 这是设计的完美。你也可以尝试用''''''''来试验间距。 – ilrein

+0

谢谢。顺便说一句,它的工作! – MucaP

1

#promocontent { 
 
    display: flex; 
 
    justify-content: space-between; 
 
    padding: 5px; 
 
} 
 
#promocontent > div { 
 
    display: flex; 
 
    flex-direction: column; 
 
    align-items: center;  /* horizontally center child elements */ 
 
    text-align: center;  /* horizontally center text on narrow screens; 
 
           see http://stackoverflow.com/q/39678610/3597276 */ 
 
}
<div id="promocontent"> 
 
    <div> 
 
    <img class="img-responsive" src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""> 
 
    <h2>header text</h2> 
 
    <span>text text text text text</span> 
 
    </div> 
 
    <div> 
 
    <img class="img-responsive" src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""> 
 
    <h2>header text</h2> 
 
    <span>text text text text text</span> 
 
    </div> 
 
    <div> 
 
    <img class="img-responsive" src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt=""> 
 
    <h2>header text</h2> 
 
    <span>text text text text text</span> 
 
    </div> 
 
</div>

https://jsfiddle.net/x2rzj1cu/2/

+0

不起作用。为每行添加一个空格。 – MucaP

+0

你可以发布更多信息或演示你想要它吗? –

+0

我已经发布了,这是关于第二个img的问题。 – MucaP