How to allign DIV one next to each other?!

Discussion in 'CSS' started by redhits, Feb 26, 2008.

  1. #1
    I am having 2 divs , and i don't like how they allign , how i can make <div> Hello </div> <div> WORLD </div> , how i can make this 2 words to stay one to each other?!
     
    redhits, Feb 26, 2008 IP
  2. kreativi

    kreativi Peon

    Messages:
    89
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can do this by using CSS file, Here is the simple example;

     
    kreativi, Feb 26, 2008 IP
  3. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As far as I know, "inherit" is not an allowed value of "float". Is this a CSS3 thing?
    Float can only be left, right, and none (none does prevent inheritance, but inheritance cannot be set with the word "inherit" as it's automatic).

    I'd be curious to see what the above looks like (I'm too lazy to build it myself).

    I would think the that clear: left in div one would prevent div2 from riding up alongside.
     
    Stomme poes, Feb 27, 2008 IP
  4. St. Anger

    St. Anger Banned

    Messages:
    211
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Use float, the 2 divs will align on the same line...
     
    St. Anger, Feb 27, 2008 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Uhm... avoid the headache of floats and set both to display:inline; (assuming you don't need to set width or height on them) or display:inline-block; (and it's -moz equivalents if you do need to set dimensions)???

    Though at that point the question becomes why are you using DIV and not SPAN? (It's wierd - I've been seeing a LOT of code lately of people reversing the two)
     
    deathshadow, Feb 27, 2008 IP
  6. qube99

    qube99 Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Real men code with divs, no matter how hard and complicated it makes a job.

    :D
     
    qube99, Feb 27, 2008 IP
  7. kreativi

    kreativi Peon

    Messages:
    89
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Inherit is valid attribute for float, you can check it at
    http://www.css3.com/css-float/
     
    kreativi, Feb 27, 2008 IP
  8. deques

    deques Peon

    Messages:
    206
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    div {display: inline;}
    Code (markup):
    this code makes divs into inline elements instead of block elements
     
    deques, Feb 28, 2008 IP
  9. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks, I found that it's even a CSS2 attribute... for some reason my guide doesn't list it.
     
    Stomme poes, Feb 28, 2008 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #10
    Not that the inherit in that particular example would DO anything... since it's not nested in the first one, all it's going to set is float:none; - since that's the default behavior for body...

    Which is why I suggested other angles of attack.
     
    deathshadow, Feb 28, 2008 IP
  11. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #11
    My guide/cheat sheet simply doesn't mention it... which makes me trust it (the guide) less. I've never used "inherit" for anything so if it makes a difference somewhere with some code I should learn it.

    When would float: inherit be used? I assumed in the above example that he was trying to undo the clear for some reason (why there's a clear right after a float when you WANT the following div to ride up, I dunno...)
     
    Stomme poes, Feb 28, 2008 IP