简体   繁体   中英

How can I accomplish this layout using proper markup and CSS?

I want to have a block on the left and a box which contains text to its right, but I don't want the text that wraps to drop under the block. It should stay with the confines of a rectangle that is adjacent the block. This is how a table would behave, but I'm not sure what the best way to accomplish this outside of one is.

I hope this fiddle will clarify: http://jsfiddle.net/bernk/Ck7cj/

<div class="container">
<div class="block">BLOCK</div>
<div class="text">This is a text box that wraps onto at least two lines</div>
</div>

Instead of floating you can use display:table-cell :

jsFiddle example

* {
    box-sizing: border-box;
}
.container {
    width: 200px;
    border: 1px solid black;
    overflow: auto;
}
.block {
    display:table-cell;
    width: 70px;
    height: 20px;
    background: red;
    color: white;
    text-align: center;
}
.text {
    border: 1px solid red;
    display:table-cell;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM