Html 如何设置“的高度”;“家长”号;类别div等于;主动lg";不带JS的类div

Html 如何设置“的高度”;“家长”号;类别div等于;主动lg";不带JS的类div,html,css,Html,Css,问题:-如何使用“数字父类”设置div的高度,等于使用“活动lg”类而不使用css的div(不要设置px高度) 我创建了一个JSFIDLE, 链接:- 如果无法访问该链接, HTML:- <!DOCTYPE html> <html> <head> <title>Accordion Number Layout</title> <link rel="stylesheet" type="text/css" href="

问题:-如何使用“数字父类”设置div的高度,等于使用“活动lg”类而不使用css的div(不要设置px高度)

我创建了一个JSFIDLE, 链接:-

如果无法访问该链接, HTML:-

<!DOCTYPE html>
<html>
<head>
    <title>Accordion Number Layout</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class = "active-lg">
    <div class = "header">
        <div class = "number-parent">
            <div class = "number">1</div>
        </div>
        <h3>Header</h3>
    </div>
  <div class = "body">
        <div>
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
        </div>
</div>
</body>
</html>
.header{
  border : 1px solid red;
  height: 40px;
  margin-left: 40px;
}
.body{
  border : 1px solid green;
  height: 260px ;
  margin-left: 40px
}
.number-parent{
  display : inline-block;
  border: 1px solid blue;
  position: absolute;
  float: left;
  margin-left: -42px;

}
.number{
  width : 40px;
  height: 40px;
  border-radius: 50%;
  text-align : center;
  background-color:red;
}
h3{
  display: inline;
}

在您的情况下,设置最外层分区的位置:

.active-lg{
    position: relative;
}
然后,您可以将高度(以%为单位)用于您的.number父项

.number-parent {
  display: inline-block;
  border: 1px solid blue;
  position: absolute;
  float: left;
  margin-left: -42px;
  height:100%;
}

设置最外层div的位置,在您的情况下为活动lg:

.active-lg{
    position: relative;
}
然后,您可以将高度(以%为单位)用于您的.number父项

.number-parent {
  display: inline-block;
  border: 1px solid blue;
  position: absolute;
  float: left;
  margin-left: -42px;
  height:100%;
}

您可以尝试使用
height:inherit更多信息

:)

您可以尝试使用
height:inherit更多信息

:)

是的,它正在工作。谢谢。有没有其他方法可以让我只将css应用于数字父元素和数字类div?这并不是因为当您以%表示高度时,必须设置父元素。如果没有父元素,您的div将是页面的100%,而不是父div。是的,它正在工作。谢谢。是否有其他方法可以将css仅应用于数字父元素和数字类div?这不是真的,因为当您以%表示高度时,您必须设置父元素。如果没有父元素,您的div将是页面的100%,而不是父div。