gpt4 book ai didi

html - 为什么 100vh 不适用于 p 元素?

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

我有一个侧边栏,我希望它适合浏览器高度。所以我使用了 100vh。

如果我删除了 p 元素(带有 background-text 类),它确实有效。

	* {
margin:0;
padding:0;
}

body{
overflow:hidden;
}

.wrapper>div{
display:inline-block;
}

.sidebar{
background-color:#4e4e4e;
height:100vh;
width:25%;
}
.picproperties{
padding:30px 0px 0px 30px;
}
.background-text{
display:block;
}

.returnbar{
height:25px;
background-color:#5a5a5a;
}


.workspace{
height:100vh;
width:75%;
background-color:red;

}
<body>
<div class="wrapper">
<div class="sidebar">
<div class="returnbar">
<div class="returnbtn"></div>
</div>
<div class="picproperties">
<div class="pp-background">

</div>
<div class="pp-ratio">
</div>
<div class="pp-patterns">
</div>
</div>
<div class="imgproperties">
<div class="ip-layers">
</div>
<div class="ip-image">
</div>
</div>
</div><!--
--><div class="workspace">

</div>
</div>
</body>

但是当我保留 p 元素时它不起作用

	* {
margin:0;
padding:0;
}

body{
overflow:hidden;
}

.wrapper>div{
display:inline-block;
}

.sidebar{
background-color:#4e4e4e;
height:100vh;
width:25%;
}
.picproperties{
padding:30px 0px 0px 30px;
}
.background-text{
display:block;
}

.returnbar{
height:25px;
background-color:#5a5a5a;
}


.workspace{
height:100vh;
width:75%;
background-color:red;

}
<body>
<div class="wrapper">
<div class="sidebar">
<div class="returnbar">
<div class="returnbtn"></div>
</div>
<div class="picproperties">
<div class="pp-background">
<p class="background-text">Background :</p>
</div>
<div class="pp-ratio">
</div>
<div class="pp-patterns">
</div>
</div>
<div class="imgproperties">
<div class="ip-layers">
</div>
<div class="ip-image">
</div>
</div>
</div><!--
--><div class="workspace">

</div>
</div>
</body>

我怎样才能保留 p 元素并仍然使侧边栏适合浏览器屏幕高度(抱歉我的英语不好)。

最佳答案

如果您将 float:left 添加到侧边栏,它会起作用:

	* {
margin:0;
padding:0;
}

body{
overflow:hidden;
}

.wrapper>div{
display:inline-block;
}

.sidebar{
background-color:#4e4e4e;
height:100vh;
width:25%;

float:left;
}
.picproperties{
padding:30px 0px 0px 30px;
}
.background-text{
display:block;
}

.returnbar{
height:25px;
background-color:#5a5a5a;
}


.workspace{
height:100vh;
width:75%;
background-color:red;

}
<body>
<div class="wrapper">
<div class="sidebar">
<div class="returnbar">
<div class="returnbtn"></div>
</div>
<div class="picproperties">
<div class="pp-background">
<p class="background-text">Background :</p>
</div>
<div class="pp-ratio">
</div>
<div class="pp-patterns">
</div>
</div>
<div class="imgproperties">
<div class="ip-layers">
</div>
<div class="ip-image">
</div>
</div>
</div><!--
--><div class="workspace">

</div>
</div>
</body>

有关 css 设计原则的概述,请查看 this !!

关于html - 为什么 100vh 不适用于 p 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30798110/

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