gpt4 book ai didi

css - 当我将一个 DIV 放入另一个 DIV 时,它不会复制其宽度和高度

转载 作者:太空宇宙 更新时间:2023-11-04 13:30:13 25 4
gpt4 key购买 nike

HTML代码:

<div id="container>

<div id="wrapper">Some text
</div>

</div>

CSS 代码:

div {

position:fixed;
display:block;
}

#container {
max-width:1500px;
height:10%;
}

#wrapper {
width:50%;
height:10%;
}

现在,我的 wrapper 和容器的大小相同,尽管您会认为 wrapper 是容器高度的一半,是容器高度的十分之一。不幸的是,它们现在都一样大。有人可以帮帮我吗?

最佳答案

您需要在 #container 上将 max-width 更改为 width 以获得正确的宽度:

#container {
width: 1500px;
height: 10%;
}

并且您需要删除 position: fixed 并在 html, body 上设置高度以使百分比高度起作用:

html, body {
height: 100%;
}
div {
position: fixed;
display: block;
}

JSFiddle

(您还缺少容器 div 中的结尾 ",但我认为这是一个错字)

关于css - 当我将一个 DIV 放入另一个 DIV 时,它不会复制其宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23414526/

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