Basic HTML: place images in one row with same distance from each other

醉酒当歌 提交于 2019-12-23 00:47:38

问题


My aim is to place 3 images in one row with the same distance from each other, as it is shown in the picture below (assuming the 2 arrows have the same length).

By now my solution is a very ugly one, which breaks, if the window size is too small:

<h1>
    <div style="width:105px; height:30px; float:left; margin-top:25px;">
        <img src="image1.png"/>
    </div>
    <div style="width:190px; height:30px; float:left; margin-top:25px; margin-left:30%; margin-right:30%;">
        <img src="image2.png"/>
    </div>
    <div style="width:102px; height:30px; float:right; margin-top:25px;">
        <img src="image3.png"/>
    </div>
    <div style="clear: both;">
    </div>
</h1>

I would really prefer a "clean" solution, but my HTML knowledge about positioning is too limited so far. Any help would be appreciated.


回答1:


Use text-align: justify:

<div class="outer">
  <img src="http://placehold.it/50x100" />
  <img src="http://placehold.it/150x100" />
  <img src="http://placehold.it/50x100" />
  <span class="fix"></span>
</div>
.outer {
    text-align: justify;
}
.outer img {
    display: inline-block;
    vertical-align: center;
}
.outer .fix {
    width: 100%;
    height: 0;
    display: inline-block;
}

In most browsers, you can remove that .fix span, and add:

.outer::after {
    width: 100%;
    height: 0;
    display: inline-block;
    content: "";
}


来源:https://stackoverflow.com/questions/13290085/basic-html-place-images-in-one-row-with-same-distance-from-each-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!