Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display: table and text-align right not working

I've got a html-structure like this:

<div class="campain">
    <div class="campainText">
        <a href="#"><h2>Ny app til iPhone og iPad</h2></a>
        <a href="#"><h2>Tips og vinn</h2></a>
    </div>
    <div class="campainPicture">
        Picture goes here
    </div><div class="clear"></div>
</div>

And I'd like the campainText to be right-align. The css for this element is this:

font-family: 'Spinnaker', sans-serif;
font-size: 17px;
color: #FFFFFF;
background-color: #A2AD00;
display: table;
padding: 4px;
margin: 4px 4px 4px 4px;
text-decoration: none;

I know that the rest of the css is working. The problem is that the text is left-aligned if I include the table-option in the display-field. As soon as I remove this, it works as expected. Are there any workarounds for this, or do I have to use display: inline and <br /> tags?

like image 613
OptimusCrime Avatar asked Oct 14 '11 09:10

OptimusCrime


People also ask

How do I align text right to a table?

HTML | <td> align Attribute left: It sets the text left-align. right: It sets the text right-align. center: It sets the text center-align.

Why text-Align Center doesn't work?

Short answer: your text isn't centered because the elements are floated, and floated elements "shrink" to the content, even if it's a block level element.

How do you align text in a table cell in HTML?

To place an item at the top or bottom of its cell, insert the "VALIGN=" attribute within the code for that cell. To vertically align an entire row (e.g., placing all data in that row at the tops of the cells), insert the "VALIGN=" attribute within the code for that row.


1 Answers

Fiddle: http://jsfiddle.net/xbNCZ/

"Table + text-align:right does not work", because a table element doesn't stretch to the full width by default. Add width:100% to get the desired result.

Before / After setting width:100%.

like image 187
Rob W Avatar answered Sep 27 '22 19:09

Rob W