在 HTML 和 CSS 中,“双行夹批效果” 通常指的是:
✅ 第一行文字
✅ 第二行文字
👉 右边有一个“批注”或“操作按钮”等元素,垂直居中或两行夹中间
✅ 实现效果预览(Flex 实现双行夹批):
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>双行夹批效果</title>
<style>
.wrapper {
display: flex;
justify-content: space-between;
align-items: center;
width: 600px;
padding: 16px;
border: 1px solid #ccc;
margin: 20px auto;
font-family: sans-serif;
}
.text-box {
display: flex;
flex-direction: column;
}
.text-box .line {
font-size: 16px;
margin: 2px 0;
}
.action {
margin-left: 20px;
background-color: #4caf50;
color: white;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
white-space: nowrap;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="text-box">
<div class="line">这是第一行内容</div>
<div class="line">这是第二行内容</div>
</div>
<div class="action">批注</div>
</div>
</body>
</html>
✅ 说明:
元素 | 作用 |
---|---|
.wrapper | 主容器,横向 flex 布局 |
.text-box | 纵向排列两行文字 |
.action | 位于右侧,自动与两行文字“夹中” |
✅ 如果你想要“操作按钮在两行文字中间垂直对齐”:
- 默认
align-items: center
已做到这一点。 - 也可以通过设置
.action { align-self: center; }
精细控制。
✅ 可选增强:
- 多个按钮或图标(如“编辑”“删除”)
- 响应式布局
- 支持换行或长文本截断
是否需要我帮你加上响应式缩放效果或图标?比如按钮变成小图标?欢迎继续提问。
发表回复