我的网页上有一张载有2张图片的网页.我希望一个图像左对齐,另一个图像右边对齐.
这是我的HTML:
<div class="header">
<img id ="ttl" src="Home_files/images/ttl.png">
<img id ="se" src="Home_files/images/se.png">
</div>
Run Code Online (Sandbox Code Playgroud)
和CSS:
.header {
position: relative;
top: 0%;
height: 20%;
}
/*Header CSS*/
img#ttl {
position: relative;
top:50%;
height: 50%;
left: 0px;
}
img#se {
position: relative;
top:60%;
height:30%;
vertical-align:right;
margin-right: 2%;
}
Run Code Online (Sandbox Code Playgroud)
PS:我试过了float:right;.它适用于Chrome和FF,但不适用于IE.当然这个div有一个父div.但我不认为这将是一个问题.
您可以将图像包装在相对容器的位置内,并使用position: absolute;它们将它们放置在左下角和右下角
<div class="wrap">
<img src="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" />
<img src="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" />
</div>
div.wrap {
width: 600px;
border: 1px solid #f00;
height: 300px;
position: relative;
}
.wrap img {
border: 1px solid blue;
position: absolute;
bottom: 0;
}
.wrap img:nth-of-type(1) {
left: 0;
}
.wrap img:nth-of-type(2) {
right: 0;
}
Run Code Online (Sandbox Code Playgroud)
注意:
nth-of-type用于选择图像以便我不必为每个图像声明类,如果要支持旧版浏览器,则需要为每个图像添加类并替换:nth-of-type为这些类
| 归档时间: |
|
| 查看次数: |
26141 次 |
| 最近记录: |