Css 我如何定位这个div?
我有5个div,其中4个有:Css 我如何定位这个div?,css,html,position,css-float,Css,Html,Position,Css Float,我有5个div,其中4个有: 4divs{width:150px; height:100px; float:left;} 及中分区: midDiv{width:200px; height:200px; float:left;} 和容器: container{width:500px; height:200px;} 我想要的是: 假设名称为:div1、div2、div3、div4和div-mid。 试着这样安排 那你会的 将div3放置在容器最左侧 将div4放置在容器的最右侧
4divs{width:150px; height:100px; float:left;}
及中分区:
midDiv{width:200px; height:200px; float:left;}
和容器:
container{width:500px; height:200px;}
我想要的是:
假设名称为:div1、div2、div3、div4和div-mid。 试着这样安排
那你会的
- 将div3放置在容器最左侧
- 将div4放置在容器的最右侧
- 然后将它们都放在容器底部
float:left
和float:right
。
尝试对div3和div4执行position:relative
如果您没有,请获取Firebug:
您无法从div的CSS的给定状态中实现所需。无论您做什么,都必须修改指定的CSS才能实现这一点 有两种可能的方法可以做到这一点
<div class="container">
<div class="left">
<div class="upper">
</div>
<div class="lower">
</div>
</div>
<div class="middle">
</div>
<div class="right">
<div class="upper">
</div>
<div class="lower">
</div>
</div>
位置:绝对
看到这个鉴于您当前的html结构,您将无法仅使用css创建该布局 你真的需要有下面的html结构,这意味着一个容器中有三个浮动的DIC,其中有你自己的块
<div class="container">
<div class="container-2">
<div class="div1">
</div>
<div class="div1">
</div>
</div>
<div class="container-2">
<div class="div2"></div>
</div>
<div class="container-2">
<div class="div1">
</div>
<div class="div1">
</div>
</div>
</div><!-- / .container -->
.container {
overflow: hidden;
}
.container-2 {
float: left;
margin-right: 10px;
display: inline-block;
}
.div1 {
width: 150px;
height: 100px;
margin-bottom: 10px;
}
.div2 {
width: 150px;
height: 210px;
margin-bottom: 10px;
}
.container-2 .div1:last-child {
margin-bottom: 0;
}
.集装箱{
溢出:隐藏;
}
.货柜-2{
浮动:左;
右边距:10px;
显示:内联块;
}
.1分部{
宽度:150px;
高度:100px;
边缘底部:10px;
}
.第2分部{
宽度:150px;
高度:210px;
边缘底部:10px;
}
.container-2.div1:最后一个孩子{
页边距底部:0;
}
给出您的#容器{position:relative;}
然后为每个div给出绝对位置:
div:nth-child(1){position:absolute; top:0; left:0;}
div:nth-child(2){position:absolute; top:100px; left:0;}
div:nth-child(3){position:absolute; top:0; left:100px;}
div:nth-child(4){position:absolute; top:0; right:0;}
div:nth-child(5){position:absolute; top:100px; right:0;}
你能修改html结构吗?还是只使用css?你知道css吗?只需检查你的浮动,这些div实际上是帖子,所以我不能随意修改htmland你是如何发布它们的?也许是一个序列。。顺便说一句,我没有使用这些代码,所以我不得不用这种奇怪的方式来写。