【问题标题】:Show bottom of an overflow string in a div with fixed height/width?在具有固定高度/宽度的 div 中显示溢出字符串的底部?
【发布时间】:2023-04-08 02:10:01
【问题描述】:

背景

我有一个固定宽度和高度的不可滚动的 div。 这是一个 JSFiddle:https://jsfiddle.net/Naibaf/47fm4pvf/2/

目标

如果不是前面的字符串,我想尽可能多地显示底部字符串。

推理和问题

你应该问自己:为什么?我正在尝试显示news-alert-like-bar,但我将我的 div 的内容与setInterval() 连接起来,这将使其快速溢出。

在我看来,jQuery 的 .scrollTop() 像这里:http://jsfiddle.net/2WpQf/1/ 是不合适的,因为我希望我的 div 不能滚动。 CSS overflow 也是如此。

有人知道怎么做吗?

HTML

<p>How to make the bottom of a string visible within the boundaries of a div and NOT show or hide the top part?</p>
<p>The opposite of what I want:
</p>
<div class="hidden">You can use the overflow property when you want to have better control of the layout. The default value is visible.</div>

CSS

div.hidden {
background-color: #00FF00;
width: 100px;
height: 100px;
overflow: hidden;
}

【问题讨论】:

  • 我不清楚...您想要固定尺寸,但显示所有内容并且不使用滚动?
  • 固定尺寸​​,无滚动,但仅显示适合 div 的底部内容。
  • 喜欢这个jsfiddle.net/47fm4pvf/3 ?
  • 就是这样!非常感谢。我现在怎么给你信用?
  • 一般我们使用 div.hidden { background-color: #00FF00;宽度:100px;高度:100px;溢出-y:滚动; }

标签: jquery html css overflow


【解决方案1】:

您可以做的是使用额外的容器和底部的position:absolute,这样当您添加更多文本时,块似乎从底部到顶部增加:

div.hidden {
  position:relative;
    background-color: #00FF00;
    width: 100px;
    height: 100px;
    overflow: hidden;
}
/*Position extrawrap*/
div.hidden span {
  position:absolute;
  width:100%;
  bottom:0;
  left:0;
}
<div class="hidden">
  <! -- Extra Wrapper Here -->
  <span>
    You can use the overflow property when you want to have better control of the layout. The default value is visible.
  </span>
</div>

Demo Fiddle

【讨论】:

    猜你喜欢
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多