html - 没有换行的 CSS 水平元素?

标签 html css

我无法在 CSS 中构建以下内容。

enter image description here

问题是我没有将绿色框调整到黄色容器的全尺寸,如图所示。此外,如果标签太长,则不应破坏结构。

我试过:

<div id="c1">
    <div id="c2">test</div>
    <div id="c3">test</div>        
</div>

我的CSS:

#c1 {
    background-color: yellow;
    width: 400px;
    height: 50px;
}

#c2 {
   width: 30px;
   height: 30px;
   margin: 10px;
   background-color: blue;
   display: inline-block; 
}

#c3 {
   background-color: green;
   display: inline-block;  
   height: 30px;
}

这是我制作的 JsFiddle:http://jsfiddle.net/confile/32RGz/

最佳答案

您有几个选择 - 您必须为 c2 和 c3 指定特定宽度,或者使用 CSS 表格模型。

Example Fiddle

HTML

 <div class='table'>
    <div class='row'>
        <div class='cell'>Something quite long</div>  
        <div class='cell'>
            here is some moreSomething quite long that should exceed the table cell.Something quite long that should exceed the table cell.
        </div>          
    </div>
</div>

CSS

.table{
    margin:0;
    padding:0;
    display:table;
    table-layout: fixed;
    width:100%;
    max-width:100%;
}
.row{
    display:table-row;
}
.cell{
    display:table-cell;
    border:6px solid yellow;
}
.cell:first-child{
    width:30px;
    background:blue;
    overflow:hidden;
}
.cell:last-child{
    white-space: nowrap;
    overflow:hidden;
    text-overflow: ellipsis;
    background:green;    
}

关于html - 没有换行的 CSS 水平元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20637738/

相关文章:

php - 如何更改PDF文件

html - 着色表行 - 3 行,3 种不同的颜色?

javascript - 透明背景CSS绘制圆形边框动画

javascript - 改变颜色 <li>

javascript - 未捕获的 TypeError :Cannot read property indexOf. 也许是 .load() jquery 问题?

javascript - 如何将自定义控件添加到适用于 iOS 的全屏 Html5 视频?

jQuery Lightbox 2 在随机图像中显示边框

html - CSS 下拉菜单问题,垂直对齐

javascript - 您可以使 javascript 函数在页面上用自定义 html 替换自身吗?

javascript - 返回查询结果时加载包含mysql查询代码的页面到div