table cell in div is not working

Deadly 提交于 2019-12-14 03:26:53

问题


I am using a table and table cell in my website. The left most column needs to start from the top. Instead it goes to the bottom. Below is a link to that issue where the grey div starts from the very bottom.

http://jsfiddle.net/HtAJw/9/


回答1:


It's not clear what end result you're looking to achieve. However, by adding a pixel width to every element, where it adds up to something less than or equal to the container width, will prevent the wrapping you see.

http://jsfiddle.net/HtAJw/10/

HTML:

<div class="parent">
    <div class="child">
        <fieldset>
                a
        </fieldset>
    </div>
    <div class="child" >
        <div class= "newChildLeft">
                a <br/> b<br/> b<br/> b<br/>
        </div>
        <div class= "newChildRight">
                b<br/> b<br/> b
        </div>
   </div>
</div>

CSS:

.parent {
    width: 100px;
    display: table;
    border: 1px solid green;
    height: 100%
}
.child {
    background: blue;
    display: table-cell;
    height: inherit;
    width: 50px;
}
.newChildLeft {
    float: left;
    width: 25px;
}
.newChildRight {
    float: right
    width: 25px;
}
.child + .child {
    background: red;
    width: 50px;
}
fieldset {
    height: 100%;
    background-color: #666;  
    width: 50px;
}


来源:https://stackoverflow.com/questions/9121034/table-cell-in-div-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!