html - 如何使父母与位置最高的孩子一样高:绝对和相对?
问题描述
我想main
和最大的孩子一样高,但我不知道如何使用 position: relative&absolute。
HTML
<main>
<div class="layout-content"></div>
<aside class="layout-sidebar-first"></aside>
</main>
因为我想把我的aside
左边和.layout-content
右边作为CSS:
main {
max-width: 1000px;
height: 100%;
position: relative;
}
.layout-sidebar-first {
width: 25%;
position: absolute;
left: 0;
}
.layout-content {
width: 75%;
position: absolute;
right: 0;
}
我正在使用 Drupal,所以我不能aside
在div
html 中使用 display:flex。
我试过main
CSS:
height:100% or auto;
box-sizing: border-box;
contain: content;
display:block
解决方案
正如所评论的,flex-direction
将允许您颠倒 tath 元素连续呈现的顺序。
main {
max-width: 1000px;
height: 100%;
display: flex;
flex-direction: row-reverse;
}
.layout-sidebar-first {
width: 25%;
}
.layout-content {
width: 75%;
}
作为替代方案,您还可以使用 CSSorder
属性来更改单个元素的位置,而无需反转整行的方向。
main {
max-width: 1000px;
height: 100%;
display: flex;
}
.layout-sidebar-first {
width: 25%;
order: 2;
}
.layout-content {
width: 75%;
}
另外值得注意的是,您可以为order
.
.layout-sidebar-first {
width: 25%;
order: -1;
}
推荐阅读
- daterangepicker - 如何在侧边栏的选择器中更改 Bootstrap daterangepicker 语言
- javascript - 构建后如何在 Vue.js 项目中存储 Firebase 凭据(env_var)
- docker - IBpy2 和 IBGateway 之间没有数据交换
- dart - 是否可以循环颤动卡?
- python - 如何有效地 blit 72 图像
- php - 无法使用 PHP 连接到 MS Access DB:SQLSTATE[IM002]
- python - 将包含转义字符和字节文字字符的 str 转换为字节文字
- solr - Solr:搜索所有字段
- automated-tests - 使用 testcafe 在 iPhone 中的 browserstack chrome 浏览器上运行测试
- java - 使用主题属性中的颜色无法按预期工作