gpt4 book ai didi

右侧带有控件的 CSS 栏

转载 作者:太空宇宙 更新时间:2023-11-04 12:43:45 26 4
gpt4 key购买 nike

Here's a nice jsFiddle illustrating the problem

我正在尝试创建一个标题栏元素...

  • 永远只有 1 行高
  • 在右上角有始终存在的控件
  • 在左上角有一个标题,如果太长会被截断为“...”

有谁知道我将如何解决这个问题?我有点难过。

.item {
border: 1px solid grey;
display: inline-block;
margin-right: 1em;
width: 25%;
}

.titlebar {
background: red;
overflow: hidden;
padding: 0.5em;
text-overflow: ellipsis;
}

.title {
overflow: hidden;
white-space: nowrap;
}

i {
font-style: normal;
float: right;
}

.content {
min-height: 15em;
}
<div class="item">
<div class="titlebar">
<span class="title">My title</span>
<span class="controls">
<i>-</i><i>+</i><i>X</i>
</span>
</div>
<div class="content">
This is the most simple use-case - a nice short title, everything works tickety-boo.
</div>
</div>

<div class="item">
<div class="titlebar">
<span class="title">My title which is just right...</span>
<span class="controls">
<i>-</i><i>+</i><i>X</i>
</span>
</div>
<div class="content">
This is how it should look if the title is too long (obviously this title is just the right length, but pretend there are other words after it).
</div>
</div>

<div class="item">
<div class="titlebar">
<span class="title">My title which is really far too long for a sensible title to be</span>
<span class="controls">
<i>-</i><i>+</i><i>X</i>
</span>
</div>
<div class="content">
This is the problem: the title is way longer than can fit, and it pushes the buttons down on to a second line.
</div>
</div>

最佳答案

对于没有固定大小的解决方案,更改 html 中 .title.controls 的顺序。这可确保当您在 .controls 上设置 float: right 时,控件将首先呈现并出现在第一行。在此之后你需要有 overflow: hidden, text-overflow: ellipsis, white-space: nowrapdisplay: block.title

我已经更新了您的示例以反射(reflect)这一点。

.item {
border: 1px solid grey;
display: inline-block;
margin-right: 1em;
width: 25%;
}

.titlebar {
background: red;
overflow: hidden;
padding: 0.5em;
}

.title {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: block;
}

i {
font-style: normal;
float: right;
}

.content {
min-height: 15em;
}

.controls {
float: right;
}
<div class="item">
<div class="titlebar">
<span class="controls">
<i>-</i><i>+</i><i>X</i>
</span>
<span class="title">My title</span>
</div>
<div class="content">
This is the most simple use-case - a nice short title, everything works tickety-boo.
</div>
</div>

<div class="item">
<div class="titlebar">
<span class="controls">
<i>-</i><i>+</i><i>X</i>
</span>
<span class="title">My title which is just right...</span>
</div>
<div class="content">
This is how it should look if the title is too long (obviously this title is just the right length, but pretend there are other words after it).
</div>
</div>

<div class="item">
<div class="titlebar">
<span class="controls">
<i>-</i><i>+</i><i>X</i>
</span>
<span class="title">My title which is really far too long for a sensible title to be</span>
</div>
<div class="content">
This is the problem: the title is way longer than can fit, and it pushes the buttons down on to a second line.
</div>
</div>

关于右侧带有控件的 CSS 栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26671609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com