gpt4 book ai didi

html - 溢出的 Div :

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:55 24 4
gpt4 key购买 nike

我想在一个 div 中有 2 个元素,但只有一个应该是可见的,而且我想要一个垂直滚动条。不幸的是,第二个元素是可见的,没有滚动条。

   #visu {
top:10px;
height:180px;
width:50%;
overflow:auto;
background-color:yellow;
}
#element1 {
position:absolute;
top:15px;
left:80px;
}

#element2 {
position:absolute;
top:200px;
left:80px;
}

.element {
margin-right:-50px;
}

.namecontainer {
display:flex;
border:4px solid #000033; border-radius:10px;
padding:10px; box-sizing:border-box;
background-color:white;
width:280px;
height:150px;
margin-left:0px;
align-items: center;
justify-content:center:
color:#1a1a1a;
}

.namecontainer p {
font-size:35px;
font-family: 'Arial';
font-weight:bold;
color:#1a1a1a;
text-align:center;
width:380px;
}

 <div id="visu">
<div id="element1" class="element">
<div class="namecontainer">
<p class= "name" id="name1" >element 1</p>
</div>
</div>

<div id="element2" class="element">
<div class="namecontainer">
<p class= "name" id="name3" >element 2</p>
</div>
</div>

</div>

最佳答案

您需要使用 margin 和 drop absolute positionnong,因为它会从流中移除元素,这里不需要 https://jsfiddle.net/vpdc5L4m/13/

   #visu {
top: 10px;
height: 180px;
width: 50%;
overflow: auto;
background-color: yellow;
}

#element1 {}

#element2 {}

.element {
margin: 15px auto ;
}

.namecontainer {
display: flex;
border: 4px solid #000033;
border-radius: 10px;
padding: 10px;
box-sizing: border-box;
background-color: white;
width: 280px;
height: 150px;
margin:auto;
align-items: center;
justify-content: center: color: #1a1a1a;
}

.namecontainer p {
font-size: 35px;
font-family: 'Arial';
font-weight: bold;
color: #1a1a1a;
text-align: center;
width: 380px;
}
<div id="visu">
<div id="element1" class="element">
<div class="namecontainer">
<p class="name" id="name1">element 1</p>
</div>
</div>

<div id="element2" class="element">
<div class="namecontainer">
<p class="name" id="name2">element 2</p>
</div>
</div>

<div id="element3" class="element">
<div class="namecontainer">
<p class="name" id="name3">a third one ?</p>
</div>
</div>

</div>

关于html - 溢出的 Div :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37839035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com