当为子 <div>
设置了 float: left;
后,父 <div>
的高度可能会缩小或小于子 <div>
的高度。这是因为设置了浮动后,子元素从文档流中脱离,不再撑开父元素的高度。
要解决这个问题,你可以在父 <div>
上添加一个 clearfix 清除浮动。可以使用以下 CSS 样式:
<div :style="{ position: 'relative', top: '42px', background: 'red', minHeight: minheight ,width: '100%'}" class="clearfix">
<!-- <router-view/>-->
<div style="width: 100%;">
<div style="opacity: 0.1;width: 60%;float: left" ><Blog/></div>
</div>
</div>
然后,在你的 CSS 文件中定义 clearfix 类:
.clearfix::after {
content: "";
display: table;
clear: both;
}
通过给父 <div>
添加 .clearfix
类,并使用 ::after
伪元素来清除浮动。这样就可以确保父 <div>
根据子 <div>
的高度自适应,不会发生高度缩小的情况。