html - 如何在没有JS的情况下将 "number-parent"类div的高度设置为等于 "active-lg"类div

标签 html css

问题:- 如何使用“number-parent”类设置 div 的高度,等于使用“active-lg”的 div没有JS的类只使用css(不想设置px高度)

我创建了一个 JSFiddle, 链接 :- http://jsfiddle.net/thakv1/s4v6tLne/

如果链接不可访问, 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>

CSS :-

.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;
}

最佳答案

设置最外层 div 的位置,在您的例子中是 active-lg:

.active-lg{
    position: relative;
}

然后你可以为你的 .number-parent 使用 % 的高度

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

Here is working example

关于html - 如何在没有JS的情况下将 "number-parent"类div的高度设置为等于 "active-lg"类div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53752364/

相关文章:

php - 如何在提交按钮中显示不同颜色的文本

C# 和 JS 函数的链接

php - 我如何在提交时显示错误并在页面上保留 DIV(特殊框)

html - 显示值中的星号

html - calc() 中忽略了第二个数字

asp.net - 自动文本框宽度

html/css定位三个文本框

javascript - 使网页背景的一部分变亮

html - 如何向下添加元素以便能够滚动?

html - 为什么 float 元素在使用宽度时不能并排对齐?