Web Design Web Design Forum
Registration is free! Here you can view your subscribed threads, work with private messages and edit your profile and preferences Calendar Find other members Frequently Asked Questions Search
Home Web Design

Convenient web based access to our favorite web design Usenet groups

web design reviews

This is Interesting: Free Magazines for Graphics designers and webmasters  





Pages (2): [1] 2 »   Last Thread  Next Thread
Author
Thread Post New Thread   

Vertical alignment of text within a DIV
 

~john




quote this post edit post

IP Loged report this post

Old Post  08-29-06 - 11:45 PM  
Sorry if this is a dumb question buy my CSS is pretty bad... but how do
I get text to center vertically within a div tag? Here's my code
below... the text is displaying on the far top-right. I would like it
far right centered vertically.

#test
{
width: 100%;
height: 55px;
margin: 0 0 0 0;
padding: 0 0 0 0;
border: solid #3366CC;
border-width: 1px 0 0 0;
text-align: right;
font-size: 14px;
font-weight: bold;
color: #ffffff;
}

<div id="test">would like this text centered vertically</div>



Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Els




quote this post edit post

IP Loged report this post

Old Post  08-29-06 - 11:45 PM  
~john wrote:

> Sorry if this is a dumb question buy my CSS is pretty bad... but how do
> I get text to center vertically within a div tag?

You don't really, at least not in the same way as in a table cell.

> Here's my code
> below... the text is displaying on the far top-right. I would like it
> far right centered vertically.
>
> #test
> {
> 	width: 100%;
> 	height: 55px;
> 	margin: 0 0 0 0;
> 	padding: 0 0 0 0;
> 	border: solid #3366CC;
> 	border-width: 1px 0 0 0;
> 	text-align: right;
> 	font-size: 14px;
> 	font-weight: bold;
> 	color: #ffffff;
> }
>
> <div id="test">would like this text centered vertically</div>

Add a <p> around the text inside that div, and give it a top margin.
It will always stay at that level though, regardless of the text
wrapping or font resizing. Yes, the text will be resizable, in any
other browser than IE - as it should. To give IE users the same
benefits, please don't set a font-size in px, but use % or em.

--
Els                           http://locusmeus.com/
accessible web design:     http://locusoptimus.com/

Now playing: Camel - Lady Fantasy (Bonus track)


Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

~john




quote this post edit post

IP Loged report this post

Old Post  08-29-06 - 11:45 PM  
thanks


Els wrote:
> ~john wrote:
> 
>
> You don't really, at least not in the same way as in a table cell.
> 
>
> Add a <p> around the text inside that div, and give it a top margin.
> It will always stay at that level though, regardless of the text
> wrapping or font resizing. Yes, the text will be resizable, in any
> other browser than IE - as it should. To give IE users the same
> benefits, please don't set a font-size in px, but use % or em.
>
> --
> Els                           http://locusmeus.com/
> accessible web design:     http://locusoptimus.com/
>
> Now playing: Camel - Lady Fantasy (Bonus track)



Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Wayne Poe




quote this post edit post

IP Loged report this post

Old Post  08-30-06 - 08:41 AM  
Els wrote:
> ~john wrote:
> 
>
> You don't really, at least not in the same way as in a table cell.
> 
>
> Add a <p> around the text inside that div, and give it a top margin.
> It will always stay at that level though, regardless of the text
> wrapping or font resizing. Yes, the text will be resizable, in any
> other browser than IE - as it should. To give IE users the same
> benefits, please don't set a font-size in px, but use % or em.

Actually this is a major short coming to CSS, as I jsut keep seeing more
and more cases of it jsut makes life difficult and painful for what
shoudl be basic things. Just like the "equal column height" and proper
multi column layout dilemas.

Seriously, I cannot fathum how the inventors of CSS (at least the
position part; the formating parts of CSS are not a prolbem at all and
work great) could not of made it straight foward. Would it really have
been so horrible to having something like align-vertical,
align-horizontal, and proper height control (notice how 100% heights on
DIVs inside DIVs sometimes push out of the confines of the outer div,
when the spec CLEARLY states the height % should of the CONTAINING DIV's
space. This strangeness happens is virtually any CSS supporting browser
I've tested (Moz, FF, IE, Opera...)

I'm sorry, but it really seems CSS has not yet come of age. don't get me
wrong, CSS is a triuth in many areas, but in the area of layouts,
anything advanced (or many things easily doable with, gasp, tables) it
just seems so lacking. At the very least, it makes many things easy
(having styles that can be easily reused) but at the same time it makes
many thing a heck of a lot harder than they should be, or even near
impossible without some wild or strange hackery. (Keep in mind I don't
mean cross browsers hacks.)




Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Gus Richter




quote this post edit post

IP Loged report this post

Old Post  08-30-06 - 08:41 AM  
~john wrote:
> Show do
> I get text to center vertically within a div tag?

Here is a page where someone has gone to the trouble to explain methods:

<http://www.student.oulu.fi/~laurirai/www/css/middle/>

--
Gus


Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Spartanicus




quote this post edit post

IP Loged report this post

Old Post  08-30-06 - 08:41 AM  
"Wayne Poe" <louis@h4h.com> wrote:

>Actually this is a major short coming to CSS, as I jsut keep seeing more
>and more cases of it jsut makes life difficult and painful for what
>shoudl be basic things. Just like the "equal column height" and proper
>multi column layout dilemas.

Equal "column" height is possible with CSS2 methods, but IE doesn't
support that part of CSS2.

Multi column layouts (text ends at the bottom of one column and
continues at the top of the adjacent right column) make no sense at all
on the web, the fact that this cannot be done with CSS2 is a good thing.
(Regrettably it looks like CSS3 may provide authors with a method to
create such monstrosities.)

>Seriously, I cannot fathum how the inventors of CSS (at least the
>position part; the formating parts of CSS are not a prolbem at all and
>work great) could not of made it straight foward. Would it really have
>been so horrible to having something like align-vertical,
>align-horizontal,

Although not implemented in a straight forward manner, again this is
possible using CSS2 methods, but again not supported by IE.

The fact that IE doesn't support these bits of CSS2 could be considered
as a blessing in disguise because the way that it is provided for in
CSS2 has all the drawbacks (minus one) of HTML tables: reflows, or
nothing being rendered until all content has been downloaded.

>and proper height control (notice how 100% heights on
>DIVs inside DIVs sometimes push out of the confines of the outer div,
>when the spec CLEARLY states the height % should of the CONTAINING DIV's
>space.

You misunderstood the phrase "containing block"
http://www.w3.org/TR/CSS21/visuren....ontaining-block

>This strangeness happens is virtually any CSS supporting browser
>I've tested (Moz, FF, IE, Opera...)

Moz, FF and Opera more than likely render such according to spec, your
understanding is flawed.

>I'm sorry, but it really seems CSS has not yet come of age. don't get me
>wrong, CSS is a triuth in many areas, but in the area of layouts,
>anything advanced (or many things easily doable with, gasp, tables) it
>just seems so lacking. At the very least, it makes many things easy
>(having styles that can be easily reused) but at the same time it makes
>many thing a heck of a lot harder than they should be, or even near
>impossible without some wild or strange hackery. (Keep in mind I don't
>mean cross browsers hacks.)

Sadly CSS2 does not offer a good method for creating layouts suitable
for the web, this is indeed a shortcoming. But layouts that work on the
web are a complex problem if the serious drawbacks of table layouts are
to be avoided

--
Spartanicus


Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Christian Kirsch




quote this post edit post

IP Loged report this post

Old Post  08-30-06 - 11:48 AM  
Spartanicus schrieb:
> "Wayne Poe" <louis@h4h.com> wrote:
>
 
>
> Although not implemented in a straight forward manner, again this is
> possible using CSS2 methods, but again not supported by IE.
>

Would you care to elaborate on that (or maybe just post a link?)

Thanks a lot



Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Spartanicus




quote this post edit post

IP Loged report this post

Old Post  08-30-06 - 11:49 AM  
Christian Kirsch <ck@bru6.de> wrote:
 
>
>Would you care to elaborate on that (or maybe just post a link?)

http://www.w3.org/TR/CSS21/visuren.html#display-prop
http://homepage.ntlworld.ie/spartanicus/css-table.htm should work in any
modern browser but IE

--
Spartanicus


Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Wayne Poe




quote this post edit post

IP Loged report this post

Old Post  08-30-06 - 11:41 PM  
Spartanicus wrote:
> "Wayne Poe" <louis@h4h.com> wrote:
> 
>
> Equal "column" height is possible with CSS2 methods, but IE doesn't
> support that part of CSS2.

Well, yes and no. Correct me if I'm wrong, but when IE6 first came out,
wasn't CSS2 not yet finalized?

> Multi column layouts (text ends at the bottom of one column and
> continues at the top of the adjacent right column) make no sense at
> all on the web,

I wasn't refering to that, but actually sidbar type setups, which are
incredibly easy with html <tables>. But saying it is no suitable, is
more of your opinion than stone carved fact I fret. NOthing wrong with
that, but it would be nice if you said so instead of pushing as what
everyone should be doing.

Actually have a two column news-paper style layout is rather well suited
for, well, news sites, as many seem to do just.
 
>
> Although not implemented in a straight forward manner, again this is
> possible using CSS2 methods, but again not supported by IE.
>
> The fact that IE doesn't support these bits of CSS2 could be
> considered as a blessing in disguise because the way that it is
> provided for in CSS2 has all the drawbacks (minus one) of HTML
> tables: reflows, or nothing being rendered until all content has been
> downloaded.

How about this one, going the other way:

Take this code:
#########################################################################
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
body { margin: 4px; }
#outter {
background: #66AAFF;
color: #007700;
height: 300px;
border: #000000 2px solid;
padding: 5px;
}
#outter .inner {
background: #BBBBBB;
height: 100%;
width: 90%;
border: #DD0000 2px solid;
padding: 50px 0px 50px 0px;
}
</style>
<title>um...</title>
</head>
<body>
<div id="outter" align="center">
<div class="inner">111</div>
</div>
</body>
</html>
#########################################################################

Notice how the bottom of the outer div gets pushed down properly in IE6,
but in Moz 1.7 and FF 1.5.0.6, NS 7, and Opera 8, the inner div's bottom
simply gets pushed out of the bounds of the outter div. If no pading and
borders are used on inner, then it's uniform in all those browsers.

Granted, according to O'Reilly CSS pocket ref, height "defines the
height of an element's content area, outside of which padding, borders,
and margins are added." But it doesn't say ANYTHING about pushing
OUTSIDE it's container (which seems rather undesirable for a
flow/non-positionsed layout. In fact, it only makes sense for absolute
positioning, where the container no longer matters in that respect.)

So you tell me, is this a design flaw of CSS (and the fact it doesn't
seem to give you very much control over weather content should "push"
it's container's height so that everything "fits" ? Other than overflow,
which DOES NOT solve this problem, but instead only allows to either
hide it and make the container scrollable.)
 
>
> You misunderstood the phrase "containing block"
> http://www.w3.org/TR/CSS21/visuren....ontaining-block
> 
>
> Moz, FF and Opera more than likely render such according to spec, your
> understanding is flawed.

Actually, with strict on, I've witnessed many anomalies on the Moz/FF/NS
side of things, just as much as I've seen on the IE side. Browser bias
is not something you want to get into here.
 
>
> Sadly CSS2 does not offer a good method for creating layouts suitable
> for the web, this is indeed a shortcoming. But layouts that work on
> the web are a complex problem if the serious drawbacks of table
> layouts are to be avoided

Yes, but if CSS actually made it even half as easy to do many layouts
you could easily hack out with <table> based layout, as frowned upon as
they may be, you wouldn't have half as many posts concerning how to do
such layouts in CSS only.

I just wish the CSS advocates here would simply admit CSS has not yet
arrived to the point where it completely replaces "old fashioned"
layouts, if you will. I too wish CSS would come of age, and I hope CSS3
resolves many the glaring issues. But I fear it will take some time
before it will be safe to broadly embrace the new spec when it comes
out, for fear of leaving previous gen browsers in the cold, just like
when CSS2 first arived. You can not expect the shift to CSS3 to change
over night.

This is why I find CSS2, which it's infinate potential to really be a
failure in that it should of come out a lot stronger and compatibility
among browsers should of been ensured.




Post Follow-Up to this message ]
Re: Vertical alignment of text within a DIV
 

Chris F.A. Johnson




quote this post edit post

IP Loged report this post

Old Post  08-30-06 - 11:41 PM  
On 2006-08-30, Wayne Poe wrote:
> Spartanicus wrote: 
> 
>
> I wasn't refering to that, but actually sidbar type setups, which are
> incredibly easy with html <tables>. But saying it is no suitable, is
> more of your opinion than stone carved fact I fret. NOthing wrong with
> that, but it would be nice if you said so instead of pushing as what
> everyone should be doing.
>
> Actually have a two column news-paper style layout is rather well suited
> for, well, news sites, as many seem to do just.

Spartanicus is right. A 2-column layout which flows from the bottom
of the first column to the top of the second column only makes
sense when you have a fixed column height that is entirely visible.
You can never be sure of having that in any browser window.

--
Chris F.A. Johnson                      <http://cfaj.freeshell.org>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


Post Follow-Up to this message ]
Sponsored Links
 





All times are GMT. The time now is 05:33 PM. Post New Thread   
Pages (2): [1] 2 »   Previous Last Thread   Next Thread next
Stylesheets archive | Show Printable Version | Email this Page | Subscribe to this Thread

Popular forums

Adobe Photoshop forum Macromedia Flash Web Site Design
Dreamweaver FrontPage forum
JavaScript Forum XML forum
Style Sheets VRML
Forum Jump:
Rate This Thread:

 

XML RSS Feed web design latest articles Syndicate our forum via XML or simple JavaScript

Web Design archive  Database administration help  


Top Home  -  Register  -  Control Panel   -  Memberlist  -  Calendar  -  Faq  -  Search Top