Putting Two Div Blocks Side By Side? - CSS woes

Pages: 1, 2
free web hosting
Free Web Hosting > Computers & Tech > Designing > Web Design and HTML

Putting Two Div Blocks Side By Side? - CSS woes

chiiyo
Hi all~ Need some help with CSS.

I'm trying to get two divs to reside side by side. Each div has a few lines of words and I need the two div blocks to be just next to each other if possible. I went through many methods and this is what I've come up with so far that works pretty well...

The trial page is here.

CODE

<html><head>
<style type="text/css">
#commentforma { margin-top: 2em; margin-bottom: 2em; margin-left: 2em; margin-right: 1em; text-align: center; float: left }
#commentformb { margin-top: 2em; margin-bottom: 2em; margin-left: 2em; margin-right: 2em; text-align: center; float: left }
input { font-size: 11px; line-height: 16px; letter-spacing: 1px; font-family: tahoma, helvetica, arial, sans-serif; color : #000; text-align: center }
label { font-size: 11px; line-height: 16px; letter-spacing: 1px; font-family: tahoma, helvetica, arial, sans-serif; color : #CCC; text-align: center }
textarea { font-size: 11px; line-height: 16px; letter-spacing: 1px; font-family: tahoma, helvetica, arial, sans-serif; color : #000; text-align: center }
</style>
</head><body>
<form method="post" action="$tmp[php_self]?show_id=$tmp[post_id]#$tmp[post_id]">
<input type=hidden name='fields[post_id]' value='$tmp[post_id]' />
<div id="commentforma"><label for="name">name</label><br /><input type="text" name="fields[name]" tabindex="1" size="20" maxlength="50" class='pc_input' id="name" /><br /><label for="email">email</label><br /><input type="text" name="fields[email]" tabindex="2" size="20" class='pc_input' id="email" /><br /><label for="url">url</label><br /><input type="text" name="fields[homepage]"  size="20" tabindex="3" class='pc_input' id="url" /></div>
<div id="commentformb"><label for="comments">comments</label><br /><textarea name="fields[comments]" rows="6" cols="25" tabindex="4" class='pc_input' wrap="soft" id="comments"></textarea><br /><input type="submit"  name="doit" value="submit" tabindex="5" class='pc_submit'></div>
</form>
</body></html>


(I'm trying to customise Poster Child by the way...)

Problem is, this code doesn't work in IE 5.2 for Mac! It looks like IE:mac doesn't recognise the float command in CSS (which has existed since Netscape 4.0, for goodness sakes, but apparently IE:mac is ridiculously buggy and has been horribly ported to OS X, so it doesn't even recognise something as simple as float) and thus the div blocks end up one after the other, placed vertically.

I'm literally pulling my hair out over this, I need the information to be in two div blocks because the elements have to centralised within their own div block but it would be really good if I could get them to be side by side.

Does anyone know how to do this with CSS without having to resort to position: relative or absolute? I'm not sure whether position: relative or absolute would work because I'm nesting this bunch of div blocks within another div tag. Using another div to "contain" the two div tags doesn't work in IE:mac too, plus it's really buggy, once the browser window size changes, it will switch back to being one above the other.

For now I'm resigned to having it work on Safari and not have it work on IE:mac. Problem is I'm also scared it won't work on Windows browsers (spent too much time on IE:mac haven't tested it with other browsers yet), so if the above code doesn't work in your browser, tell me please...

 

 

 


Reply

miCRoSCoPiC^eaRthLinG
Hey,
That's how I'd created my NOTE tag, by nesting 5 other divs inside a main container div. The header div has 3 of these divs nested inside it, and placed side-by-side using the float attribute. However, I used float: left, right & center to place them. Take a look at this tutorial: http://www.astahost.com/howto-3-custom-bbc...note-t4009.html
It might just help you.

However, for some strange reason, I'd to draw the right-most floated div first and then the left & center. Or else these div's would turn up at random places. Even I'm struggling with CSS so I couldn't come up with a valid explanation as to why it was working this way. But hey, IT WORKS !! lol.. See if that NOTE tag dissertation helps you.. smile.gif

Reply

jipman
Or you just could use the <SPAN> tag instead of the <DIV> tag

the span one doesn't add a linefeed to the output so you can have to <span>'s on one line.

If that is what you mean.

here for more info : http://www.w3schools.com/tags/tag_span.asp

Reply

chiiyo
Thanks jipman and m^e, but unfortunately, still doesn't solve the problem... >_< The Span tag works literally the same as the div, as in it still doesn't work, and the note example isn't so much talking about two div blocks placed next to each other.

To put my question baldly: is there some way I can make two div blocks next to each other without
1. Using the float attribute
2. Using position: absolute or position: relative <-- or if these two are needed, would the code still work if it's nested within another div tag.

Reply

jipman
THen chiiyo you are doing something wrong here.

Here's an example of the difference of DiV and Span that I created just for you wink.gif

CODE

<html>
<head>
<style type="text/css">
.a {background-color: #ffff00;border:1px solid black;}
.b {background-color: #0000ff;border:1px solid black;}

.c {background-color: #ff0000;border:3px solid black;}
.d {background-color: #00ff00;border:1px dashed black;}
</style>
</head>
<span class="a">These are two different spans</span>
<span class="b">so it's clearly that the two are side by side</span>
<p>
<p>
<div class="c">This is a div example</div>
<div class="d">so you see the difference</div>
</html>


So I'm sure it should work for you smile.gif

 

 

 


Reply

chiiyo
Hmm, I understand what you mean, jipman, about how spans are inline and divs are not, but the problem is I have is that I have several LINES of information that I need to be in a block, and the span tag isn't able to "contain" the information in one ordered block. I need two blocks of information, each containing several lines, to be inline. Span can't help me there.

To use your example to illustrate what I mean, I added a second line to each of the span and div tags.

CODE

<html>
<head>
<style type="text/css">
.a {background-color: #ffff00;border:1px solid black;}
.b {background-color: #0000ff;border:1px solid black;}

.c {background-color: #ff0000;border:3px solid black;}
.d {background-color: #00ff00;border:1px dashed black;}
</style>
</head>
<span class="a">These are two different spans<br />(A second line for the yellow span)</span>
<span class="b">so it's clearly that the two are side by side<br />(A second line for the blue span)</span>
<p>
<p>
<div class="c">This is a div example<br />(A second line for this div, this is what i mean by having several lines of information)</div>
<div class="d">so you see the difference<br />(Do you see once I add a second line the effect is changed?)</div>
</html>


The only way I can contain the lines of information is by using div tags, so my problem is still unsolved...

Reply

jipman
Hmm yes i see,

howabout using a table?

CODE

<html>
<head>
<style type="text/css">
.a {background-color: #ffff00;border:1px solid black;}
.b {background-color: #0000ff;border:1px solid black;}

.c {background-color: #ff0000;border:3px solid black;}
.d {background-color: #00ff00;border:1px dashed black;}
</style>
</head>
<table>
<tr><td><div class="a">These are two different divs<br>(A second line for the yellow div)</div></td>
   <td><idv class="b">so it's clearly that the two are side by side<br>(A second line for the blue div)</div></td>
</table>
</html>


This would be better than using postion stuff...

Reply

chiiyo
Yeah, I'm a big table lover, my brain still works the table way, I don't know how many times I've thought, I could just put that in a cell, colspan that, rowspan that, width that....

BUT

I'm trying to make my site XHTML 1.0 compliant, and that means trying as hard as possible not to use tables for layout purposes.

Which goes back to the question, is there, or isn't there a way to place two div blocks next to each other without using float or position?

Reply

Tobias
Maybe instead of using float for both divs, try absolute positioning one. Then instead of floating the second one, use margins to move it side to side. If you're trying to get the divs closer together then just change the margins of the boxes. Hope this is what you wanted.

[CODE]
<html>
<head>
<title>CSS</title>
<style type="text/css">
#leftbox {
position: absolute;
margin: 0 0 0 50px;
padding: 0;
width: 150px;
height: 150px;
}

#centerbox {
margin: 0 0 0 225px;
padding: 0;
width: 150px;
height: 150px;
}
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<div id="leftbox">
<span>This should work the way you want it to.</span>
</div>
<div id="centerbox">
<span>Then you can put your form in here.</span>
</div>
</BODY>
</HTML>

Reply

chiiyo
Thank you very much Tobias, that solved my problem! I used ems instead of px to change the margins, because IE:mac seems to respond better to ems than to pxs, but either than that, the code worked perfectly, even when nested within other divs. Exactly what I was looking for, thank you!

Took me a while to actually try it out, what with exams and other stuff, but thanks~

Someone can close this post if you want, problem solved~

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. div side by side - 0.73 hr back. (1)
  2. css float div side by side - 2.82 hr back. (1)
  3. place div side by side - 3.40 hr back. (1)
  4. side by div - 3.93 hr back. (1)
  5. css
    side-by-side - 3.99 hr back. (1)
  6. css menu side block - 4.26 hr back. (1)
  7. css position div side by side - 4.74 hr back. (1)
  8. put div side by side - 5.88 hr back. (1)
  9. problem putting two divs side by side - 6.20 hr back. (1)
  10. two divs side by side - 6.21 hr back. (1)
  11. how to place 2 divs side by side - 6.74 hr back. (1)
  12. two side by side divs - 7.29 hr back. (1)
  13. div side by side html - 9.15 hr back. (1)
  14. tables side by side using div - 9.17 hr back. (1)
Similar Topics

Keywords : putting, div, blocks, side, side, css, woes

  1. Almost 3d Blocks
    Using CSS borders (6)
  2. putting a background color makes a slight problem
    (7)
    take a look at this code Test 1 Test2 Test3
    when the tag for the background color of the page is put in, it makes the top cell for the table
    appear slightly off. however when it's not in, the cell inside the table appears fine....

    1. Looking for putting, div, blocks, side, side, css, woes






*SIMILAR VIDEOS*
Searching Video's for putting, div, blocks, side, side, css, woes
advertisement




Putting Two Div Blocks Side By Side? - CSS woes



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE