【问题标题】:Two elements on two opposite sides两个相对侧的两个元素
【发布时间】:2017-10-14 14:41:40
【问题描述】:
【问题讨论】:
标签:
javascript
html
css
image
elements
【解决方案2】:
CSS 属性 Float 可以帮助您!
.parent {
width: 90%;
height: 100px;
background: #EFEFEF;
}
.left-child {
width: 80px;
height: 80px;
margin: 10px;
background: #DDDDDD;
float: left;
}
.right-child {
width: 80px;
height: 80px;
margin: 10px;
background: #DDDDDD;
float: right;
}
<div class="parent">
<div class="left-child"></div>
<div class="right-child"></div>
<div>
【解决方案3】:
你可以通过使用float来实现它,如下所示:
<!DOCTYPE html>
<html>
<head>
<style>
.left {
float:left;
}
.right {
float:right;
}
img {
margin:0.5em;
}
</style>
<body>
<div class="container">
<p class="left">Text will come here</p>
<img src="" width="" height="" class="right" />
</div>
</body>
</html>
请指定图像属性。
谢谢!
【解决方案4】:
有很多方法,包括边距、浮动甚至 position: absolute 在某些情况下,但值得注意的是有一组相当新的 css 属性 - flex:
.container {
display: flex;
justify-content: space-between;
}
<div class="container">
<div>a</div>
<div>b</div>
</div>