我需要一个div在另一个div中浮动。尝试使用位置:已修复,但div现在浮动在父div之外。
下面是示例代码。我需要“Div to Float”浮动在“Div 1”内部。现在它浮动在“Div 1”外部并位于“Div 2”后面。
下面是代码。
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style id="compiled-css" type="text/css">
.wrapper {<!--from www .j av a2s.c o m-->
width:100%;
height: 200px;
overflow-y: scroll;
}
.container {
width: 301px;
margin: 0px auto;
height: 1501px;
background: green;
position: relative;
}
.element {
background:yellow;
position:fixed;
width:101px;
height:71px;
top:51px;
right:0px;
left:769px;
border:2px solid blue;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container"> Div 1
<div class="element">
Div to float
</div>
</div>
</div>
<div class="container" style="margin-top: 30px;background: purple;">
Div 2
</div>
</body>
</html>
"我尝试过的一切"
https://codepen.io/vrnreg/pen/poKdvBJ
"我所期待的“
我需要“Div-to-Float”在“Div 1”中浮动。
"现在的结果是什么"
现在,它漂浮在'分区1'外面,并在'分区2'后面
1条答案
按热度按时间whlutmcx1#
我不完全理解“float”是什么意思,但是这段代码会把你的
div.element
放在div.container
里面