孩子 div 是不是继承父母的身高?
Posted
技术标签:
【中文标题】孩子 div 是不是继承父母的身高?【英文标题】:Does a child div inherit parent's height?孩子 div 是否继承父母的身高? 【发布时间】:2019-10-16 15:36:49 【问题描述】:据我所知,子 div 通常会继承父级的样式。但是,当我尝试复制父母的身高时,情况并非如此。任何有关其工作原理的说明将不胜感激
父分区
子区
我已尝试切换到 position:relative
和 display:inline
,但我还没有找到任何可以修改子 div 相对于父级的高度的东西。
// Plot our graphs
var data = [
z: [[1, 20, 30], [20, 1, 60], [30, 60, 1]],
type: 'heatmap'
];
Plotly.newPlot('chart_div', data);
/*//////////////////////////////////////////////////////////////////
[ FONT ]*/
@font-face
font-family: Ubuntu-Regular;
src: url('../fonts/ubuntu_regular-webfont.woff') format('woff');
@font-face
font-family: Ubuntu-Bold;
src: url('../fonts/ubuntu-bold-webfont.woff') format('woff');
@font-face
font-family: Montserrat-Regular;
src: url('../fonts/montserrat-regular-webfont.woff') format('woff');
@font-face
font-family: FontAwesome;
src: url('../fonts/fontawesome-webfont.woff') format('woff');
@font-face
font-family: Material-Design-Iconic-Font;
src: url('../fonts/Material-Design-Iconic-Font.woff') format('woff');
fontawesome-webfont.woff
/*//////////////////////////////////////////////////////////////////
[ RESTYLE TAG ]*/
*
margin: 0px;
padding: 0px;
box-sizing: border-box;
body, html
height: 100%;
font-family: Ubuntu-Regular, sans-serif;
/*---------------------------------------------*/
a
font-family: Ubuntu-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
transition: all 0.4s;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
a:focus
outline: none !important;
a:hover
text-decoration: none;
color: #403866;
/*---------------------------------------------*/
h1,h2,h3,h4,h5,h6
margin: 0px;
p
font-family: Ubuntu-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
ul, li
margin: 0px;
list-style-type: none;
/*---------------------------------------------*/
input
outline: none;
border: none;
textarea
outline: none;
border: none;
textarea:focus, input:focus
border-color: transparent !important;
input::-webkit-input-placeholder color: #8f8fa1;
input:-moz-placeholder color: #8f8fa1;
input::-moz-placeholder color: #8f8fa1;
input:-ms-input-placeholder color: #8f8fa1;
textarea::-webkit-input-placeholder color: #8f8fa1;
textarea:-moz-placeholder color: #8f8fa1;
textarea::-moz-placeholder color: #8f8fa1;
textarea:-ms-input-placeholder color: #8f8fa1;
label
display: block;
margin: 0;
/*---------------------------------------------*/
button
outline: none !important;
border: none;
background: transparent;
button:hover
cursor: pointer;
iframe
border: none !important;
/*//////////////////////////////////////////////////////////////////
[ Utility ]*/
.txt1
font-family: Ubuntu-Regular;
font-size: 16px;
color: #827ffe;
line-height: 1.4;
.app-explanation
font-family: Ubuntu-Regular;
font-size: 13px;
color: #403866;
line-height: 1.4;
text-align: center;
font-style: italic;
width: 100%;
/*//////////////////////////////////////////////////////////////////
[ login ]*/
.limiter
width: 100%;
margin: 0 auto;
.container-login100
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 15px;
position: relative;
background-position: center;
background-size: cover;
background-repeat: no-repeat;;
.wrap-login100
width: 390px;;
background: #fff;
border-radius: 10px;
position: relative;
.wrap-data100
width: 90%;
background: #fff;
border-radius: 10px;
position: relative;
/*==================================================================
[ Form ]*/
.login100-form
width: 100%;
.login100-form-title
font-family: Ubuntu-Bold;
font-size: 30px;
color: #403866;
line-height: 1.2;
text-transform: uppercase;
text-align: center;
width: 100%;
display: block;
/*------------------------------------------------------------------
[ Input ]*/
.wrap-input100
width: 100%;
position: relative;
background-color: #e6e6e6;
border: 1px solid transparent;
border-radius: 3px;
/*---------------------------------------------*/
.input100
font-family: Ubuntu-Bold;
color: #403866;
line-height: 1.2;
font-size: 18px;
display: block;
width: 100%;
background: transparent;
height: 62px;
padding: 0 20px 0 38px;
/*------------------------------------------------------------------
[ Focus Input ]*/
.focus-input100
position: absolute;
display: block;
width: calc(100% + 2px);
height: calc(100% + 2px);
top: -1px;
left: -1px;
pointer-events: none;
border: 1px solid #827ffe;
border-radius: 3px;
visibility: hidden;
opacity: 0;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
transition: all 0.4s;
-webkit-transform: scaleX(1.1) scaleY(1.3);
-moz-transform: scaleX(1.1) scaleY(1.3);
-ms-transform: scaleX(1.1) scaleY(1.3);
-o-transform: scaleX(1.1) scaleY(1.3);
transform: scaleX(1.1) scaleY(1.3);
.input100:focus + .focus-input100
visibility: visible;
opacity: 1;
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
.eff-focus-selection
visibility: visible;
opacity: 1;
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
/*==================================================================
[ Restyle Checkbox ]*/
.input-checkbox100
display: none;
.label-checkbox100
font-family: Ubuntu-Regular;
font-size: 16px;
color: #999999;
line-height: 1.2;
display: block;
position: relative;
padding-left: 26px;
cursor: pointer;
.label-checkbox100::before
content: "\f00c";
font-family: FontAwesome;
font-size: 13px;
color: transparent;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
width: 18px;
height: 18px;
border-radius: 3px;
background: #fff;
border: 2px solid #827ffe;
left: 0;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
.input-checkbox100:checked + .label-checkbox100::before
color: #827ffe;
/*------------------------------------------------------------------
[ Button ]*/
.container-login100-form-btn
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
.login100-form-btn
font-family: Ubuntu-Bold;
font-size: 16px;
color: #fff;
line-height: 1.2;
text-transform: uppercase;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
justify-content: center;
align-items: center;
padding: 0 20px;
width: 100%;
height: 62px;
background-color: #827ffe;
border-radius: 3px;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
transition: all 0.4s;
.login100-form-btn:hover
background-color: #403866;
/*------------------------------------------------------------------
[ Alert validate ]*/
.validate-input
position: relative;
.alert-validate::before
content: attr(data-validate);
position: absolute;
max-width: 70%;
background-color: #fff;
border: 1px solid #c80000;
border-radius: 3px;
padding: 4px 25px 5px 10px;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
right: 12px;
pointer-events: none;
font-family: Ubuntu-Regular;
color: #c80000;
font-size: 14px;
line-height: 1.4;
text-align: left;
visibility: hidden;
opacity: 0;
-webkit-transition: opacity 0.4s;
-o-transition: opacity 0.4s;
-moz-transition: opacity 0.4s;
transition: opacity 0.4s;
.alert-validate::after
content: "\f12a";
font-family: FontAwesome;
display: block;
position: absolute;
color: #c80000;
font-size: 18px;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
right: 18px;
.alert-validate:hover:before
visibility: visible;
opacity: 1;
@media (max-width: 992px)
.alert-validate::before
visibility: visible;
opacity: 1;
/*==================================================================
[ Restyle Select2 ]*/
.select2-container
display: block;
max-width: 100% !important;
width: auto !important;
.select2-container .select2-selection--single
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
align-items: center;
background-color: rgba(171, 171, 189, 0.233);
border: none;
height: 40px;
outline: none;
position: relative;
left: -40px;
/*------------------------------------------------------------------
[ in select ]*/
.select2-container .select2-selection--single .select2-selection__rendered
font-family: Ubuntu-Bold;
font-size: 18px;
color: #555555;
line-height: 1.2;
padding-left: 0px ;
background-color: transparent;
.select2-container--default .select2-selection--single .select2-selection__arrow
height: 100%;
top: 50%;
transform: translateY(-50%);
right: 0px;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
align-items: center;
justify-content: flex-end;
.select2-selection__arrow b
display: none;
font-family: Material-Design-Iconic-Font !important;
font-size: 18px;
color: #555555;
.select2-selection__arrow
content: '\f312';
font-family: Material-Design-Iconic-Font !important;
font-size: 18px;
color: #555555;
/*------------------------------------------------------------------
[ Dropdown option ]*/
.select2-container--open .select2-dropdown
z-index: 1251;
width: calc(100% + 2px);
border: 0px solid transparent;
border-radius: 10px;
overflow: hidden;
background-color: rgba(171, 171, 189, 0.233);
left: -40px;
box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-o-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-ms-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
@media (max-width: 576px)
.select2-container--open .select2-dropdown
left: -12px;
.select2-dropdown--above top: -38px;
.select2-dropdown--below top: 10px;
.select2-container .select2-results__option[aria-selected]
padding-top: 10px;
padding-bottom: 10px;
padding-left: 24px;
@media (max-width: 576px)
.select2-container .select2-results__option[aria-selected]
padding-left: 12px;
.select2-container .select2-results__option[aria-selected="true"]
background: #403866;
color: white;
.select2-container .select2-results__option--highlighted[aria-selected]
background: #827ffe;
color: white;
.select2-results__options
font-family: Ubuntu-Bold;
font-size: 14px;
color: #555555;
line-height: 1.2;
.select2-search--dropdown .select2-search__field
border: 1px solid #aaa;
outline: none;
font-family: Ubuntu-Bold;
font-size: 15px;
color: #333333;
line-height: 1.2;
.wrap-input100 .dropDownSelect2 .select2-container--open
width: 100% !important;
.wrap-input100 .dropDownSelect2 .select2-dropdown
width: calc(100% + 2px) !important;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blackfynn Exporter</title>
<meta charset="UTF-8">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico" />
<!--===============================================================================================-->
<script src="build/build.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id='half-height' style="height: 40% !important">
<div id='blackfynn-panel' style="position: relative">
<div class="container-login100 datasetUI" id="dataset_div">
<div class="wrap-data100 p-t-50 p-b-90 datasetUI">
<form class="contact100-form validate-form">
<span class="login100-form-title p-b-51">
Data Viewer
</span>
<div class=" input100 wrap-input100 input100-select bg1 datasetUI">
<span class="label-input100"></span>
<div id="channel_div">
<select class="js-select2" name="service" id="select_channel">
<option>Channel Selection</option>
</select>
<div class="dropDownSelect2"></div>
</div>
</div>
</form>
<div class="datasetUI" id="chart_div"></div>
<br>
<div id="exportURL">
</div>
</div>
</div>
</div>
</div>
<!--===============================================================================================-->
<!--===============================================================================================-->
</body>
</html>
【问题讨论】:
高度不被继承。在这里,您正在限制父母的高度,因此孩子会溢出 谢谢@TemaniAfif 如何限制孩子的身高以便继承? 为所需元素添加高度限制,所以你应该为孩子做 height:100% 例如,它需要 100% 的父高度,即它的父(主体)的 40%是其父级 (html) 的 100%,依此类推 【参考方案1】:子元素不会继承其父元素的高度。
Reference: MDN
但是,您可以将其值设置为 height:inherit;
CodePen Example
您也可以使用height: 100%
或max-height: 100%
在任何情况下,如果内容太多而无法适应设定的高度,您必须考虑要如何处理内容:overflow: hidden
; overflow-y:hidden
; overflow-y: scroll
.
【讨论】:
以上是关于孩子 div 是不是继承父母的身高?的主要内容,如果未能解决你的问题,请参考以下文章