html - 并排显示两个 div 元素的文本溢出

标签 html css element

我做了这个jsfiddle展示一些接近我目前拥有的东西。

我正在寻找的是位于右侧 div 旁边的行的左侧 div 上的省略号,这样它就不会重叠(我意识到 position 在这里可能不起作用)。两者都有动态文本。如有必要,我愿意更改所述元素。

编辑: 我需要第一行的第一部分只在一行上,当它与第二部分重叠时溢出。到目前为止,答案尚未提供执行此操作的方法。如果 div 的内容是静态的,我会设置静态宽度。我可能能够为第二个 div 设置静态宽度,因为其中内容的可能性是有限的。

注意:列宽的大小根据浏览器尺寸而变化。此外,由于页面上存在的其他容器/元素,它是绝对定位的。 (可能不理想)

另一个注意事项:该列可能有很多,所以我只显示几个作为示例。

下面是一些示例代码:

.col {
    background-color: pink;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 400px;
}

.row {
    background-color: #9595E4;
    border-bottom: 1px solid black;
    padding: 3px 8px;
}
p {
    margin: 0;
    padding: 0;
}

.row-top {
    position: relative;
    height: 19px;
    line-height: 19px;
}

.row-top .one {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: auto;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    font-weight: bold;
}

.row-top .two {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: auto;
    height: auto;
    font-size: 0.8em;
    color: #ccc;
}
<div class="col">
    <div class="row">
        <div class="row-top">
            <div class="one">
                This is the first line, part one, which overlaps
            </div>
            <div class="two">
                1st line, part two
            </div>
        </div>
        <p>This is the second line</p>
    </div>
    <div class="row">
        <div class="row-top">
            <div class="one">
                This content could be really really really really long
            </div>
            <div class="two">
                1st line, part two
            </div>
        </div>
        <p>This is the second line</p>
    </div>
    <div class="row">
        <div class="row-top">
            <div class="one">
                Or it could be short
            </div>
            <div class="two">
                1st line, part two
            </div>
        </div>
        <p>This is the second line</p>
    </div>
</div>

最佳答案

CSS 解决方案:https://css-tricks.com/line-clampin/

使用 jquery 插件的解决方案:http://dotdotdot.frebsite.nl/

关于html - 并排显示两个 div 元素的文本溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33284809/

相关文章:

html - IE8 阻止具有宽度/高度的元素在悬停内部文本之前不检测鼠标悬停

javascript - 是否可以在不接管整个样式的情况下使用 Bootstrap?

Java AWT 将元素添加到现有框架

element - cvc-complex-type.2.4.c : The matching wildcard is strict, 但找不到元素 'oxm:jaxb2-marshaller' 的声明

html - 另一个带有干净代码的粘性页脚/100% 高度 div

python - Django 1.8 CSS 加载不完全

jquery - 使用 Jquery 更改 INACTIVE div 类

css - 不同的 Css3 边框样式

visual-studio-2010 - 如何在一个 web.config 元素上应用两种不同的转换?

javascript - jquery调整大小后元素高度不更新