Search / Log-In

HelpDesk:
HelpDesk
Contact me:
Contact Peter Buick
Don’t miss out… join the tribe today
Terms Of Use & Privacy Policy
Please see here for our Terms Of Use and Pricacy Policy.
There is much love for you here…
Add to Technorati Favorites

css: centreing text in a div tag

css: centreing text in a div tag

HTML design should be easier, with CSS. But sometimes it isn’t. So this is a reminder for me, and if you find it useful too, then that’s a bonus ;-)

They go and just depreciate old standards like right align.

CSS styles are easy and can be applied to any Tag. Thus;
(PS zero thanks to WordPress for rendering code inside code tags meaning I needed a screen grab picture instead)

But when it comes to centreing elements within elements, it goes a bit to pot.

The simple answer is you need a container FIRST which is somewhere


.pmast_outer {
postiion:relative;
width:100%;
text-align: left;
}

Then you can do what you expect to do


.pmast_insert {
background-color: #CCCCCC;
height: 60px;
width: 468px;
border: 1px solid #FFFF00;
color: #FFFF00;
text-align: right;
float:right;
}

and then you simply tie the two together in divs using classes. thus;

hello world....

I don’t know why no one else can seem to explain it that easily?
I had to read 12 different design tutorials and still try empirically.

float:right;
was the remaining missing piece of my alignment nightmare.

Anyway there we go…

If you don’t put the master container somewhere (ie relative) then it just doesn’t work.

Leave a Reply

You must be logged in to post a comment.