简体   繁体   English

如何并排对齐三个背景图像

[英]How to align three background images side by side

I'm trying to align three background images side by side, ideally with fluidity so that they re-position when my browser window resizes.我正在尝试并排对齐三个背景图像,理想情况下具有流动性,以便在我的浏览器窗口调整大小时重新定位。

I've tried searching for an answer to this problem and thought using CSS properties suited to aligning regular 'img src' elements would work, however they haven't.我试过寻找这个问题的答案,并认为使用适合对齐常规 'img src' 元素的 CSS 属性会起作用,但它们没有。

Essentially, I have a page with a gallery.本质上,我有一个带有画廊的页面。 Each image has a city name in it's center.每个图像的中心都有一个城市名称。 Through research, I've decided to assign a background-image property to three separate divs and used the line-height property matching the height of each image so that the city name aligns itself in the center.通过研究,我决定将 background-image 属性分配给三个单独的 div,并使用 line-height 属性匹配每个图像的高度,以便城市名称在中心对齐。 The background-image technique assists in the alignment of the city name.背景图像技术有助于城市名称的对齐。

Where am I going wrong?我哪里错了?

 #jumbotron2 { height: 500px; width: 100%; } #city-container { width: 100%; height: 100%; } .london-square { height: 400px; width: 400px; background-image: url("tombnb-images/london-400px.jpg") } .newyork-square { height: 400px; width: 400px; background-image: url("tombnb-images/newyork-400px.jpg") } .sydney-square { height: 400px; width: 400px; background-image: url("tombnb-images/sydney-400px.jpg") } .square p { font-family: 'Slabo 27px', serif; font-size: 32px; color: #FFFFFF; line-height: 400px; text-align: center; text-shadow: 0px 0px 10px black; }
 <div id="jumbotron2"> <div id="city-container"> <div class="london-square square"> <p id="text">London</p> </div> <div class="newyork-square square"> <p id="text">New York</p> </div> <div class="sydney-square square"> <p id="text">Sydney</p> </div> </div> </div>

if you use a percentage width of your divs you have to float them too.如果您使用 div 的百分比宽度,您也必须浮动它们。 I recommand using this:我建议使用这个:

#city-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    flex-warp: wrap;
}

You can use bootstrap.您可以使用引导程序。 you put your images inside divs.你把你的图像放在 div 中。

 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class="col-sm-4"> <img class="img-thumbnail" src="http://www.nature.org/cs/groups/webcontent/@web/@giftplanning/documents/media/sample-cga-rates-splash-1.jpg"> </div> <div class="col-sm-4"> <img class="img-thumbnail" src="http://sharedforfree.com/wp-content/uploads/2013/07/cropped-harrimanToday.jpg"> </div> <div class="col-sm-4"> <img class="img-thumbnail" src="http://pre02.deviantart.net/f34e/th/pre/f/2015/182/4/f/croatia_nature_pack___sample__2___proref_org_by_proref-d8zgrc2.jpg"> </div> </div>

Check out this fiddle: jsfiddle example看看这个小提琴: jsfiddle example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM