Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table Cell image and text alignment

I have a three column layout where sometimes I want to have text in one column adjacent to an image in another column. My issue is that when I insert an image into one of the columns, the text in the adjacent column(s) positions itself adjacent to the bottom of the image in the adjacent column rather than at the top of the column as one would expect.

My basic structure:

<div class="fwcol">
    <div class="col">
        <div class="ttl">
        <img src="images/placeholder.png" width="571" height="540">
        <p>Bla Bla Bla </p>
        </div><!--ttl-->
        <div class="otr">Column 2 Content
        </div><!--otr-->
    </div><!--col-->
</div><!--fwcol-->

CSS:

.fwcol {
    float: left;
    width: 966px;
}        
.ttl {
    display: table-cell;
    padding: 20px;
    width: 571px;
    background: #FFF;
}
.col {
    width: 966px;
    display: table;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 20px;
}
like image 220
Welly Avatar asked Jul 15 '26 08:07

Welly


2 Answers

You did not use vertical-align to the div where you're applying table-cell:

.ttl {
    display: table-cell;
    vertical-align: top;
    padding: 20px;
    width: 571px;
    background: #FFF;
}

Also, in image itself you need to use vertical align:

.ttl img {
    display: inline-block;
    vertical-align: top;
}
like image 158
Bhojendra Rauniyar Avatar answered Jul 17 '26 22:07

Bhojendra Rauniyar


It's doing that because .ttl's display is set to table-cell. You could add vertical-align: top to the element in order to correct this behavior:

.ttl {
    display: table-cell;
    vertical-align: top;
    padding:20px;
    width: 571px;
    background: #FFF;
}
like image 29
Josh Crozier Avatar answered Jul 17 '26 21:07

Josh Crozier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!