Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
center of the screen with CSS
Old 12-22-2006, 03:28 AM center of the screen with CSS
Average Talker

Posts: 22
Name: Momo
Trades: 0
Hi all,
I'm trying to put a text in the middle of the page using CSS. this is what I've done:

<divstyle="width: 100%; height: 100%; text-align: center; vertical-align: middle;">
jgjgjgj
</div>

what happens is that the text is in the aligned to the center, but it's not in the middle vertically. what am I doing wrong?
ophir.oren is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-22-2006, 04:00 AM Re: center of the screen with CSS
Novice Talker

Posts: 13
Name: Romell
Trades: 0
If you are using the doctype declaration at the beginning of your file, you can't assign a percentage height to your elements. Try removing the doctype declaration and seeing if it displays how you want it then.

Let me know.
mellymell is offline
Reply With Quote
View Public Profile
 
Old 12-22-2006, 04:14 AM Re: center of the screen with CSS
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
vertical-align does not work as you are expecting.

It is only applicable to inline-elements and will align elements relative to the height of the content of the parent container

here is some demo code so you can see how it actually works;
HTML Code:
<div style="border:1px solid orange;font-size:5em;height: 300px; text-align: center;">
Some text
<span style="border:1px solid orange;font-size:20px; text-align: center; vertical-align: middle;">
Some text in the middle
</span>
<span style="border:1px solid orange;font-size:10px; text-align: center; vertical-align: top;">
Some more text at the top
</span>
<br>
<span style="border:1px solid orange;font-size:20px; vertical-align: middle;">
Some text in the middle
</span>
</div>
BTW you don't need width:100% on divs they are a block element and are 100% wide by default.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-22-2006, 04:16 AM Re: center of the screen with CSS
Average Talker

Posts: 22
Name: Momo
Trades: 0
if I remove it it indeed works.

the doc type I have is for xhtml:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

but I want to write w3 propper html code, and still it should look good on all resolutions in the center of the screen. what should I do?
ophir.oren is offline
Reply With Quote
View Public Profile
 
Old 12-22-2006, 04:20 AM Re: center of the screen with CSS
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by mellymell View Post
If you are using the doctype declaration at the beginning of your file, you can't assign a percentage height to your elements.
Huh?

you can assign percentage heights to elements regardless of doctype.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-22-2006, 09:37 AM Re: center of the screen with CSS
blackhawkpowers's Avatar
Ultra Talker

Posts: 313
Name: Dustin
Location: GA
Trades: 0
you can refrence this post for vertical centering with CSS
http://www.webmaster-talk.com/html-f...v-div-css.html
__________________
A patch is a piece of software which replaces old bugs with new bugs.

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
blackhawkpowers is offline
Reply With Quote
View Public Profile Visit blackhawkpowers's homepage!
 
Old 12-22-2006, 12:08 PM Re: center of the screen with CSS
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
To center horizontally, you need to do 2 things.

body{
text-align: center; /* for IE 6 and below */
}

Then on the div you want centered, a wrapper div if you want the whole thing centered, you add:

#wrapper{
width: xxxx;
margin: 0 auto; /* top-bottom, left/right values*/
}
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 12-22-2006, 01:52 PM Re: center of the screen with CSS
Average Talker

Posts: 22
Name: Momo
Trades: 0
Quote:
Originally Posted by LadynRed View Post
To center horizontally, you need to do 2 things.

body{
text-align: center; /* for IE 6 and below */
}

Then on the div you want centered, a wrapper div if you want the whole thing centered, you add:

#wrapper{
width: xxxx;
margin: 0 auto; /* top-bottom, left/right values*/
}
the problem is I don't know the width - it changes between different screens resolutions
ophir.oren is offline
Reply With Quote
View Public Profile
 
Old 12-22-2006, 03:12 PM Re: center of the screen with CSS
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
So, you use a percentage.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 12-23-2006, 08:00 PM Re: center of the screen with CSS
Experienced Talker

Posts: 37
Trades: 0
Quote:
Originally Posted by LadynRed View Post
To center horizontally, you need to do 2 things.

body{
text-align: center; /* for IE 6 and below */
}

Then on the div you want centered, a wrapper div if you want the whole thing centered, you add:

#wrapper{
width: xxxx;
margin: 0 auto; /* top-bottom, left/right values*/
}
so what u actually want is

#wrapper {
height: 400px;
margin: auto 0px;
}
gaz545 is offline
Reply With Quote
View Public Profile
 
Old 12-24-2006, 03:23 AM Re: center of the screen with CSS
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Nope, Because using auto for top and bottom does not affect the container position vertically.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-24-2006, 09:35 AM Re: center of the screen with CSS
Experienced Talker

Posts: 37
Trades: 0
so then that won't actually work, as it will just center horizontaly and not verticaly
gaz545 is offline
Reply With Quote
View Public Profile
 
Old 12-25-2006, 09:04 AM Re: center of the screen with CSS
Matthew.'s Avatar
Experienced Talker

Posts: 37
Name: Matt or Matthew
Location: UK
Trades: 0
I am not fantastic with CSS, however to align something vertically you will need these two properties:

Code:
display:table;
vertical-align:middle;
Add that to a layer acting as a 'wrapper' around the content and it should be aligned vertically.
Matthew. is offline
Reply With Quote
View Public Profile Visit Matthew.'s homepage!
 
Reply     « Reply to center of the screen with CSS
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38918 seconds with 12 queries