CSS questions

Reply

Join Date: Oct 2008
Posts: 35
Reputation: Modo is an unknown quantity at this point 
Solved Threads: 0
Modo Modo is offline Offline
Light Poster

CSS questions

 
0
  #1
Feb 7th, 2009
Hello guys, how are you doing?
I have a couple of questions please, I would appreciate any help.

1- I have three "relative <div>" I want to put them next to each other and making sure if someone has less resolution, there wont be a scroll bar. But instead the <div> will adjust and the text will go below.

I made sure all three have the following attributes:
position: relative;
float: left;

But the problem is that each one of these div's has a width according to the text in it, which means they are next to each other. I also added a <div> to wrap all three <div> it didnt work.
I tried giving them a width of 33% each and one 34% but one of them jumps down whenever I resize my browser.
here is my code:

HTML and CSS Syntax (Toggle Plain Text)
  1. .bassano1 { width: 33%; }
  2. .bassano2 { width: 33%; }
  3. .bassano3 { width: 33%; }
  4. .bassano1, .bassano2, .bassano3, .bassano4, .bassano5
  5. {
  6. position: relative;
  7. background-color: #008001;
  8. border: 2px solid #095E09;
  9. float: left;
  10. height: 50 %;
  11. }
I tried making the height the same, but it didnt work either.

2- How can I center a table or an image in a <div>?

Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: CSS questions

 
0
  #2
Feb 8th, 2009
Hey,

I notice that you apply 2px borders to the divs. With the box model, borders are added to the width of the container.

You therefore have 99% width across the three divs, + 12px for the borders (left and right).

I'd suggest making the widths something lower, e.g. 32% + a border.


And to centre an image within a div, I believe if you use text-align: center on the div, it should centre the image itself.

R.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 35
Reputation: Modo is an unknown quantity at this point 
Solved Threads: 0
Modo Modo is offline Offline
Light Poster

Re: CSS questions

 
0
  #3
Feb 8th, 2009
thanks for the reply ...
as for the images i tried using center align but it didnt work for the img .. i use center align for img in css and not for the whole div since it contains soms text.

and i will do what u told me but there is a problem of div jumping down if i dont use the width and put some value into it.

any idea's ?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,332
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 162
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: CSS questions

 
0
  #4
Feb 8th, 2009
  1. .bassano1 { width: 33%; }
  2. .bassano2 { width: 33%; }
  3. .bassano3 { width: 33%; }
  4. .bassano1, .bassano2, .bassano3, .bassano4, .bassano5
  5. { position: relative;
  6. background-color: #008001;
  7. border: 2px solid #095E09;
  8. float: left;
  9. height: 50 %; }
the css is buggy, the space between '50' & '%' makes a second parameter, not sure how much rendering difference it will make or what quirks it will throw at which browser height: 50%; and retry,
Last edited by almostbob; Feb 8th, 2009 at 4:47 pm.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 76
Reputation: ccube921 is an unknown quantity at this point 
Solved Threads: 6
ccube921 ccube921 is offline Offline
Junior Poster in Training

Re: CSS questions

 
0
  #5
Feb 8th, 2009
The problem seems to be your borders, without the borders everything was ok, but the borders didn't fit on the screen, when I set the divs to 32%, it went back.

About the text you complained wouldn't stay in the div, is it in a <P> or is it straight in the div? (it should be in a p) .

Concerning that p, did you set a font size for it?

To center objects, you can try using:
margin: 0 auto;
But, that will only work if you set a height for the centered object, for example:
height: 100%
If I have been helpful add to my reputation!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 35
Reputation: Modo is an unknown quantity at this point 
Solved Threads: 0
Modo Modo is offline Offline
Light Poster

Re: CSS questions

 
0
  #6
Feb 9th, 2009
Thanks for the reply

1- The text is indeed in a <p>, I did not set a font-size I just made the position relative. But the body has a font-size of 12px.

2- I tried centering using the margin but it didnt work.
3- I am also trying to make the heights of each div the same
but I dont seem to succeed in it. But the main problem is the divs for now. I have always used absolute positioning and relative positioning isnt my thing.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: CSS questions

 
0
  #7
Feb 11th, 2009
Several points:

Height can't see the browser window size in most browsers.

Most browsers correctly put the surrounding styles (margin, border, padding) OUTSIDE the size styles (width, height). Internet Explorer crams them INSIDE instead. The cure for this is to not use nonzero surrounding styles with size styles in the same style or tag.

Center text reliably using the following code:
In the stylesheet, place:
HTML and CSS Syntax (Toggle Plain Text)
  1. .cenx {text-align: center;}
Then, where you want to place the centered text, put this code:
HTML and CSS Syntax (Toggle Plain Text)
  1. <p class="bxfix cenx">Your Text to be Centered</p>
The p tag may be replaced by one of the h tags.

Center images reliably using the following code:
In the stylesheet, place:
HTML and CSS Syntax (Toggle Plain Text)
  1. .cenx {text-align: center;}
  2. .ceni {clear: both;}
  3. .bxfix {margin: 0; border: none; padding: 0;}
Then, where you want to place the centered image, put this code:
HTML and CSS Syntax (Toggle Plain Text)
  1. <div class="bxfix cenx">
  2. <img src="yourimag.jpg" alt="description" class="ceni" />
  3. </div>
There must be room for the image, or it won't work.

Center other objects reliably using the following code:
In the stylesheet, place:
HTML and CSS Syntax (Toggle Plain Text)
  1. .cenx {text-align: center;}
  2. .ceni {clear: both;}
  3. .bxcen {margin-left: auto; margin-right: auto; border: none; padding: 0;}
Then, where you want to place the centered object, put this code:
HTML and CSS Syntax (Toggle Plain Text)
  1. <div class="bxcen cenx">
  2. <tag>Your object</tag>
  3. </div>
Put the name of the tag for the object you have instead of the word "tag".
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 35
Reputation: Modo is an unknown quantity at this point 
Solved Threads: 0
Modo Modo is offline Offline
Light Poster

Re: CSS questions

 
0
  #8
Feb 11th, 2009
I think I get the point ..
but my main problem is now the following:
- The table is the only thing which is not getting centered
- The div's next to each other dont have the same height
- The border of the wrapper is not really adjusting automatically

any idea's ?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: CSS questions

 
0
  #9
Feb 17th, 2009
Divs next to each other never have the same height. They each expand downward just enough to hold their contents.

One way to force the height issue is to use the display style on div:

HTML and CSS Syntax (Toggle Plain Text)
  1. div {display: table-cell;}
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the HTML and CSS Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC