【问题标题】:Prevent line break in this case在这种情况下防止换行
【发布时间】:2012-05-22 14:59:03
【问题描述】:

我试图防止这个 Html 中的换行

http://jsfiddle.net/DD3v8/

当我调整窗口大小时,图标和文本都会换行。我已经尝试过使用空白 CSS 属性。我也尝试过,一种表格方法,但行为是一样的

谁能弄清楚发生了什么?

提前致谢

【问题讨论】:

  • 尝试使用 nowrap 标签/属性吗?
  • @Dmitry 你的意思是 whitespace: nowrap 属性?是的,我做到了
  • 不,我的意思是 nowrap 标签:一些文本
  • 请在此处添加来自 jsfiddle.net 的代码。

标签: html css whitespace nowrap


【解决方案1】:

试试这个:

.line {
            height: 44px; 
            width: 100%; 
            display: inline-block; 
            background-color: #6c7987;
            white-space: nowrap;
            position: relative;
        }

        .icon {
            position: absolute;
            left: 0;
            height: 44px; 
            width: 90px; 
            background-color: 
            #FF0080; 
            color: white;
            text-align: center;
            line-height: 44px;
            font-family: Arial;
            float: left;
            font-size: 12px;
            font-weight: bold;
            padding: 0;
        }

        .title {
            position: absolute;
            left: 90px;
            color: white;
            line-height: 44px;
            text-align: left;
            padding: 0 0 0 10px;
            font-family: Arial;
            float: left;
            font-size: 12px;
            display: inline;
            white-space:nowrap;
        }

        .botoes {

            position: absolute;
            width: 300px;
            right: 0
        }

        .botao {
            width: 46px;
            height: 45px;
            float: right;
            line-height: 44px;
            text-align: center;
            display: block;
            white-space:nowrap;
            cursor: pointer;
        }

        .botaoVerRecurso {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoVerRecurso:hover {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoEditarRecurso {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoEditarRecurso:hover {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoFavRecurso {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoFavRecurso:hover {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoPartRecurso {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoPartRecurso:hover {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoApagarRecurso {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .botaoApagarRecurso:hover {
            background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
        }

        .clear {
            clear: both;
        }

解释很简单:用浮动,你不能给一个持有人更多的宽度,超过持有人的高度,浮动会自动下降,并断线。

如果你使用位置,这样使用它:

CONTAINER(位置:相对)
子元素(位置:绝对,顶部:0,左侧:0) 子元素(位置:绝对,底部:0,右侧:0)

在 W3C 中:http://www.w3schools.com/css/css_positioning.asp

【讨论】:

  • 感谢您的回答。不过要小心,w3schools 与 W3C 没有任何关系。阅读更多w3fools.com
【解决方案2】:

如果我正确理解您的问题,您需要能够调整窗口宽度,而不会出现文本和“x”图标跳下,是这样的:

.title删除CSS

min-width: 500px;

看到这个Fiddle Example

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 2020-04-29
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 2015-08-07
    相关资源
    最近更新 更多