html - 是否可以在 Flexbox 中作为基线时拉伸项目?
问题描述
请看下面我的代码;
<html>
<head>
<style>
.Window__caption {
display: flex;
align-items: baseline;
background-color: #fff;
border: 1px solid black;
}
.Window__title {
margin: auto auto auto 5px;
cursor: move;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.Window__buttons {
cursor: pointer;
background-color: #fff;
border: 0;
}
.Window__maximize-button:hover {
background-color: #ddd;
}
.Window__minimize-button:hover {
background-color: #ddd;
}
.Window__close-button:hover {
color: #fff;
background-color: #f00;
}
</style>
</head>
<body>
<div class="Window__caption">
<span class="Window__title">My First Window</span>
<button class="Window__buttons Window__minimize-button">−</button>
<button class="Window__buttons Window__maximize-button">☐</button>
<button class="Window__buttons Window__close-button">⨉</button>
</div>
</body>
</html>
这是我的代码的截图;
如您所见,我有一个标题和三个不同高度的控制按钮。我想要的是在它们是基线时垂直拉伸所有 flexbox 项目。是否有可能做到这一点?
更新:
下图是align-item为“baseline”时;
下一个是当 align-item 为“拉伸”时;
字形似乎是对齐的,但它们不是。只需在浏览器中播放即可查看差异。
解决方案
我不知道“伸展”到底是什么意思,但我试过了;
<html>
<head>
<style>
.Window__caption {
display: flex;
height: 20rem;
align-items: baseline;
background-color: #fff;
border: 1px solid black;
}
.Window__title {
margin: 0 auto auto 5px;
cursor: move;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.Window__buttons {
cursor: pointer;
background-color: #fff;
border: 0;
}
.Window__maximize-button:hover {
background-color: #ddd;
}
.Window__minimize-button:hover {
background-color: #ddd;
}
.Window__close-button:hover {
color: #fff;
background-color: #f00;
}
</style>
</head>
<body>
<div class="Window__caption">
<span class="Window__title">My First Window</span>
<button class="Window__buttons Window__minimize-button">−</button>
<button class="Window__buttons Window__maximize-button">☐</button>
<button class="Window__buttons Window__close-button">⨉</button>
</div>
</body>
</html>
告诉我这是否不是你想要的。
- 更新 -
我认为这是您真正想要的:>
看起来字形没有在中心对齐,但我认为这是字形本身的问题。
如果你想检查字形的对齐,删除justify-content: center;
`.btn'里面。你可以看到它会略有变化。
<html>
<head>
<style>
* {
margin: 0;
}
.container {
width: 100%; height: 10rem;
display: flex;
border: 1px solid black;
}
.title, .filter, .button-wrap {
display:flex; flex-flow: column; justify-content: center;
}
.filter {
flex-grow: 1.1;
}
ul, ul li {
list-style: none; list-style-type: none;
display: flex; flex-flow: row;
}
.btn {
display: flex; flex-flow: column; justify-content: center;
}
</style>
</head>
<body>
<div class="container">
<span class="title">My First Window</span>
<div class="filter"></div>
<div class="button-wrap">
<ul>
<li><button class="btn">−</button></li>
<li><button class="btn">☐</button></li>
<li><button class="btn">⨉</button></li>
</ul>
</div>
</div>
</body>
</html>
推荐阅读
- python - 将csv文件存储在redis数据库中
- php - 如何将android应用令牌从应用传递到php页面?拉拉维尔
- javascript - 在 React-Native 视图中根据纬度和经度定位对象而不显示实际地图
- flutter - 如何在颤动中将深色主题更改为所有页面
- state - 高级关联规则挖掘
- python-3.x - 使用 Selenium 刮玻璃门
- javascript - 如何在 WebRTC 流中显示每个接收到的帧?
- redis - redis,设置一个值为3,但它的类型是字符串
- spring-boot - 高 CPU 使用率和 ActiveMQ Artemis 中许多队列和会话的负载
- vim - 在 Vim 中的每一行末尾添加一个反斜杠