【问题标题】:Two Div's next to each other with "text-overflow: ellipsis; overflow: hidden; white-space: nowrap;"两个 Div 彼此相邻,带有“文本溢出:省略号;溢出:隐藏;空白:nowrap;”
【发布时间】:2011-12-06 01:07:40
【问题描述】:

我深入研究了这个问题,在我周围的所有树木中都看不到森林......但也许有一个快速的解决方案。我使用 CSS 3,不能在一行中添加 2 个 div,条件如下: 1.DIV动态宽度和剪切文本。 2. DIV 旁边 1. DIV (inline) with fixed with。

所以如果容器(环绕 DIV)是 300px。而 2. DIV 是 100px。我希望 1. DIV 的大小为 200px(动态)并在需要时剪切其文本。

到目前为止,这是我这边的代码:

<!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>

不幸的是,2. DIV 始终低于 1. DIV。

感谢您的提示。

【问题讨论】:

    标签: html ellipsis


    【解决方案1】:

    好的,我找到了合适的解决方案:

        <!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>
    

    【讨论】:

      【解决方案2】:

      有两个问题:

      【讨论】:

        猜你喜欢
        • 2016-01-31
        • 1970-01-01
        • 1970-01-01
        • 2013-04-01
        • 2018-02-28
        • 2020-09-15
        • 1970-01-01
        • 2018-07-22
        • 1970-01-01
        相关资源
        最近更新 更多