简体   繁体   English

两个Div相邻,并带有“文本溢出:省略号; 溢出:隐藏; 空白:nowrap;”

[英]Two Div's next to each other with “text-overflow: ellipsis; overflow: hidden; white-space: nowrap;”

I got to deep in this problem and can not see the forest out of all the trees around me... but maybe there is a quick solution for this. 我深陷这个问题,无法从我周围的所有树木中看到森林……但是也许有一个快速的解决方案。 I work with CSS 3 and cannot add 2 div's in one line with the following condition: 1. DIV dynamic width and cutting text. 我使用CSS 3,在以下情况下无法在一行中添加2 div:1. DIV动态宽度和剪切文本。 2. DIV next to 1. DIV (inline) with fixed with. 2. DIV旁边的1. DIV(内联)带有固定用。

So if the container (sourounding DIV) is 300px. 因此,如果容器(环绕声DIV)为300px。 And the 2. DIV is 100px. 而2. DIV为100px。 I expect that the 1. DIV gets a size of 200px (dynamic) and cutting its text if needed. 我期望1. DIV的大小为200px(动态),并在需要时剪切其文本。

So this is the code from my side so far: 所以这是到目前为止我的代码:

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        .container {
            width: 200px;
            border: 1px solid black;
        }
        .info {
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }
        .dynamicWidth {

        }
        .staticWidth {
            width: 60px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="dynamicWidth">
            <div>Title element</div>
            <div class="info">Text: This is a text which should be break with 3 dots when it is bigger then its parent div</div>
        </div>
        <div class="staticWidth">BUT</div>
    </div>
</body>

Unfortunately, all the time the 2. DIV is below the 1. DIV. 不幸的是,一直以来2. DIV都低于1. DIV。

Thx for your hints. 谢谢你的提示。

There are two problems: 有两个问题:

Ok, I found a fitting solution: 好的,我找到了合适的解决方案:

    <!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        .container {
            border: 1px solid black;
            position: relative;
        }
        .info {
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }
        .dynamicWidth {
            margin-right: 30px;
        }
        .staticWidth {
            position: absolute;
            top: 0;
            right: 0;
            width: 30px;
            top: 25%; /*centers the content of this div in middle of height*/
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="dynamicWidth">
            <div>Title element</div>
            <div class="info">Text: This is a text which should be break with 3 dots when it is bigger then its parent div</div>
        </div>
        <div class="staticWidth">BUT</div>
    </div>
</body>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在移动设备中,空白:nowrap; 溢出:隐藏 文字溢出:省略号; 有点不起作用 - in mobile devices, white-space:nowrap; overflow:hidden; text-overflow:ellipsis; kinda do not work 溢出:隐藏; 文字溢出:省略号; 空白:nowrap; 在fieldset内不工作? - overflow: hidden; text-overflow: ellipsis; white-space: nowrap; not working inside fieldset? CSS Transition 不适用于空白:nowrap 和文本溢出:悬停时省略号 - CSS Transition not working with white-space: nowrap and text-overflow: ellipsis when hover 文本溢出:省略号无法在 IE 和 Edge 中对所有行进行预标记或空白预文本 - text-overflow: ellipsis is not working to pre tag or white-space pre text all lines in IE & Edge 溢出问题:隐藏和文本溢出:省略号 - Problems with overflow: hidden and text-overflow: ellipsis 我如何通过溢出自动获取绝对定位的div以将其内容的宽度设置为nowrap增长到其内容的宽度? - How do I get an absolutely positioned div with overflow auto to grow to the width of it's contents with white-space set to nowrap? 空格nowrap不适用于div以下的div,以及如何获取溢出实际宽度 - white-space nowrap don't work with div below div,and how to get overflow real width 文字溢出省略号 - text-overflow ellipsis 表格单元格中的水平滚动div:空格:nowrap +溢出:滚动=不起作用 - Horizontally scrollable div in table cell: white-space: nowrap + overflow:scroll = not working 在内部div上应用“文字溢出:省略号” - Apply “text-overflow: ellipsis;” to inner div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM