我试图通过简单地定义min-height css属性来将div框的高度调整到文本高度。但是,这不起作用。 div似乎总是遵循边距定义,并且不适应文本高度。有人可以帮忙吗?
<!DOCTYPE html>
<html>
<head>
<style type="text/css" >
body {
margin:0;
}
.parallax-group {
position:relative;
height:100vh;
}
.sectiontext {
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
content: "";
margin-bottom:20%;
margin-top:15%;
margin-left:0px;
min-height: 1px;
box-shadow: 0 0 8px rgba(0, 0, 0, .7);
}
</style>
</head>
<body>
<section class = "parallax-group">
<div class = "sectiontext ">
blablablablablablablablablablablablablablabla
</div>
</section>
</body>
</html>
答案 0 :(得分:0)
解决方案非常简单:必须删除“bottom:0”约束:
<!DOCTYPE html>
<html>
<head>
<style type="text/css" >
body {
margin:0;
}
.parallax-group {
position:relative;
height:100vh;
}
.sectiontext {
position:absolute;
left:0;
right:0;
top:0;
content: "";
margin-bottom:20%;
margin-top:15%;
margin-left:0px;
min-height: 1px;
box-shadow: 0 0 8px rgba(0, 0, 0, .7);
}
</style>
</head>
<body>
<section class = "parallax-group">
<div class = "sectiontext ">
blablablablablablablablablablablablablablabla
</div>
</section>
</body>
</html>