javascript - 两个内联块 div 的垂直对齐
问题描述
我在父 div 中有两个 div,两个子 div 都是 display: inline-block。我想让它左边的第一个 div 是垂直对齐:顶部,而第二个 div 是垂直对齐:底部,但我也想限制第二个 div,所以它的第一行文本行与第一个 div 的最后一行文本并向下延伸,增加了父 div 的高度,而不是向上。我怎么能做到这一点?
例如,如果我有这样的事情:
<html>
<body>
<div>
<div id="d1" style="width: 50px;display:inline-block;vertical-align:top;">
Here is some text
</div>
<div id="d2" style="width: 50px;display:inline-block;vertical-align:bottom;">
Here is some other text
</div>
</div>
</body>
</html>
我希望 d2 的第一行与 d1 的最后一行一致。所以它看起来像这样:
Here
is
some
text Here
is
some
other
text
解决方案
这是我使用的grid
布局
.container {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: 55px 20px 55px;
width: 65px;
}
#d2 {
grid-row: 2;
grid-column: 2;
}
<div class="container">
<div id="d1">
Here is some text
</div>
<div id="d2">
Here is some other text
</div>
</div>
推荐阅读
- typescript - How to change a bitmap drawn on a canvas with vue-nativescript on android?
- python - 将列表中的字符串值拆分为单个值,Python
- jasmine - 有没有办法为多个测试定义提供者、声明、导入
- python - 如何从 json 文件中加载对象
- php - 根据用户角色验证用户输入
- c - 我怎样才能打印一个结构和memcpy呢?
- html - 如何在锚点处渲染 EJS
- c - 为什么在有 readdir 内核函数的情况下将 readdir 函数添加到 POSIX 库接口?
- c++ - 使用 Windows API 获取黑色屏幕截图
- floating-point - 1 如何在 C/C++ 中编码为浮点数(假设 IEEE 754 单精度表示)?