CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 4th, 2004, 06:31 PM
(sic)master's Avatar
(sic)master (sic)master is offline
I'm your master now!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Somewhere between screaming and crying
Posts: 370 (sic)master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 1 m 56 sec
Reputation Power: 0
How to make this simple example with divs/css?

Hi,
Take a look at this page: http://nazgulled.home.sapo.pt/table.html

This is easly done with tables as you can see, now, I want reproduce the same effect with divs but I don't know how.

My exact problem is, how can I center more than 1 div tag in the same "line". And for any div tag I use the float option, I can't align the text to anywhere, how can I do this too?
__________________

HomepageBlogFotologGFXartist
nzFotolog
My own PHP script to manage photoblogs.

Reply With Quote
  #2  
Old September 4th, 2004, 07:44 PM
1beb's Avatar
1beb 1beb is offline
This tagline is not long enoug
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: Toronto, ON Canada! I AM CANADIAN
Posts: 861 1beb User rank is Corporal (100 - 500 Reputation Level)1beb User rank is Corporal (100 - 500 Reputation Level)1beb User rank is Corporal (100 - 500 Reputation Level)1beb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 h 32 m 12 sec
Reputation Power: 10
Send a message via ICQ to 1beb Send a message via AIM to 1beb Send a message via MSN to 1beb Send a message via Yahoo to 1beb
Code:
<style>
#contain{text-align:center; margin: 0px auto; /* Centre's container in viewport */}
#left{text-align:left; float:left; width: X%}
#centre{text-align:center;/* Damned American spelling */ float:left; width: X%}
#right{text-align:right; float:left; width: X%}
</style>
<body>
<div id="contain">
<div id="left">LEFT DIV</div>
<div id="centre">CENTRE DIV</div>
<div id="right">RIGHT DIV</div>
</div>


Where X% represents a an equal width for each div. The sum of all X should be < 100%

Reply With Quote
  #3  
Old September 4th, 2004, 09:07 PM
(sic)master's Avatar
(sic)master (sic)master is offline
I'm your master now!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Somewhere between screaming and crying
Posts: 370 (sic)master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 1 m 56 sec
Reputation Power: 0
well... that doesn't do exactly what I want and does not reproduce the same effect as the tables...

first because I don't want the 3 divs to have the total width of the viewport, I want the 3 divs to have (for instance) 300px (not 300px to each but 100px to each) and to be centered on the screen.

Reply With Quote
  #4  
Old September 4th, 2004, 09:32 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 23rd Plane (16000 - 16499 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 16,008 Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 3 Weeks 6 Days 3 h 36 m 48 sec
Reputation Power: 1544
So set them to "width: 100px;".

Reply With Quote
  #5  
Old September 4th, 2004, 10:05 PM
(sic)master's Avatar
(sic)master (sic)master is offline
I'm your master now!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Somewhere between screaming and crying
Posts: 370 (sic)master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 1 m 56 sec
Reputation Power: 0
if it was that easy...

that is an option and almost works at 100% but the prolbme is, if I set them all to 100px, they will all be aligned in the left and I want the 3 divs to be aligned in the center...

Reply With Quote
  #6  
Old September 4th, 2004, 10:13 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 23rd Plane (16000 - 16499 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 16,008 Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 3 Weeks 6 Days 3 h 36 m 48 sec
Reputation Power: 1544
Use 1beb's code, but change the widths from "width: X%" to "width: 100px;".

Reply With Quote
  #7  
Old September 4th, 2004, 10:47 PM
(sic)master's Avatar
(sic)master (sic)master is offline
I'm your master now!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Somewhere between screaming and crying
Posts: 370 (sic)master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 1 m 56 sec
Reputation Power: 0
doesn't quite work...

http://nazgulled.home.sapo.pt/divs.html - it's not centered, I need to center this on the screen.

Reply With Quote
  #8  
Old September 5th, 2004, 01:59 AM
1beb's Avatar
1beb 1beb is offline
This tagline is not long enoug
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: Toronto, ON Canada! I AM CANADIAN
Posts: 861 1beb User rank is Corporal (100 - 500 Reputation Level)1beb User rank is Corporal (100 - 500 Reputation Level)1beb User rank is Corporal (100 - 500 Reputation Level)1beb User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 h 32 m 12 sec
Reputation Power: 10
Send a message via ICQ to 1beb Send a message via AIM to 1beb Send a message via MSN to 1beb Send a message via Yahoo to 1beb
Quote:
Originally Posted by (sic)master
doesn't quite work...

http://nazgulled.home.sapo.pt/divs.html - it's not centered, I need to center this on the screen.


You need to set a width. Because other wise you have three floated elements inside of a 100% wide container, meaning that there are no boundaries for the margin.

Sorry, that's my fault... in the style selection for #contain add something like:

Code:
width:600px;


The reason I did it in percentage is so that you would understand that the three widths of the floating divs should be slightly less ( cumulatively speaking ) than that of the container.

Reply With Quote
  #9  
Old September 5th, 2004, 04:18 AM
kk5st's Avatar
kk5st kk5st is offline
Thanks Johnny Hart (BC) R.I.P.
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: May 2003
Location: Dallas
Posts: 4,674 kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level)kk5st User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 15 h 15 m 50 sec
Reputation Power: 687
This can only be considered an exercise. Neither Brandon's nor my solution is a real world example. Brandon creates a constraining block element that is centered in the window. Mine simply displays the elements as inline, using text-align to center them.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="generator"
    content="HTML Tidy for Linux/x86 (vers 1st March 2002), see www.w3.org" />
    <meta name="editor" content="Emacs 21" />
    <meta name="author" content="Gary Turner" />
    <meta http-equiv="content-type"
    content="text/html; charset=ISO-8859-1" />

    <title></title>
<style type="text/css">
/*<![CDATA[*/
body {
    margin: 0;
    padding: 0;
    text-align: center;
    }

.inline {
    display: inline;
    margin: 5px;
    background-color: yellow;
    color: black;
    }

/*]]>*/

</style>
  </head>

  <body>
    <p class="inline">some text</p>

    <p class="inline">some text</p>

    <p class="inline">some text</p>

    <br />

    <div class="inline">
      some text
    </div>

    <div class="inline">
      some text
    </div>

    <div class="inline">
      some text
    </div>
  </body>
</html>

cheers,

gary
__________________
There are those who manage to build a web site without knowing what they're doing; thereby proving to themselves they do, indeed, know what they're doing.

My html and css workshop, demos and tutorials.
Ask a better question, get a better answer.

Reply With Quote
  #10  
Old September 5th, 2004, 10:07 AM
(sic)master's Avatar
(sic)master (sic)master is offline
I'm your master now!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Somewhere between screaming and crying
Posts: 370 (sic)master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 1 m 56 sec
Reputation Power: 0
thank you all... I finally worked it out with your help

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > How to make this simple example with divs/css?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |