Kyrbi
Kyrbi

Reputation: 2260

CSS positioning divs next to each other

I have got problem with positioning 2 divs inside a div. I want to have 2 divs next to each other but I dont know how. Here is my html

<div id="game">
    <div id="choice" onmouseover="npcRoll()">
        <p>Chosse your weapon!</p>
        <button id="rock" onClick="choose(1)">Rock</button>
        <button id="paper" onClick="choose(2)">Paper</button>
        <button id="scissors" onClick="choose(3)">Scissors</button>
        <p>You chose <span id="userChoice">none</span>!</p>
    </div>
    <div id="confirm">    
    </div>
</div>

And this is my CSS:

#choice {
    border: 2px solid #87231C;
    border-radius: 12px;
    border-top-right-radius: 0px;
    border-bottom-right-radius: 0px;
    background-color: #FF5A51;
    width: 350px;
}
#game {
    border: 2px solid #fff;
    border-radius: 15px;
    background-color: white;
    width: 500px;
    margin: 0 auto;
}
#confirm {
    border: 2px solid #00008B;
    border-radius: 12px;
    border-top-left-radius: 0px;
    border-bottom-left-radius: 0px;
    background-color: #1E90FF;
    width: 142px;
    height: 100px;
}
body {
    background-color: #DFEFF0;
    text-align: center;
}

button {
    font-size: 22px;
    border: 2px solid #87231C;
    border-radius: 100px;
    width: 100px;
    height: 100px;
    color: #FF5A51;
    text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
    padding-top: 36px;
}

button:active {
    font-size: 22px;
    border: 2px solid #328505;
    color: #32A505;
    border-radius: 100px;
    width: 100px;
    height: 100px;
    padding-top: 36px;
}

You can check it out here how it looks. http://jsfiddle.net/VcU7J/

Thank you for any help!

EDIT: I also tried to add float elements into to the CSS but it screwed it more. :/

Upvotes: 0

Views: 3151

Answers (2)

kqlambert
kqlambert

Reputation: 2711

Use css floats to position divs next to each other, but do not forget to clear the floats after your done.

#game {
    float:left;
}
#confirm {
    float: right;
}
.clear {
    clear: both;
}

and then the html would look like:

<div id="game">
    <div id="choice" onmouseover="npcRoll()">
        <p>Chosse your weapon!</p>
        <button id="rock" onClick="choose(1)">Rock</button>
        <button id="paper" onClick="choose(2)">Paper</button>
        <button id="scissors" onClick="choose(3)">Scissors</button>
        <p>You chose <span id="userChoice">none</span>!</p>
    </div>
    <div id="confirm">    
    </div>
    <div class="clear"></div>
</div>

Upvotes: 1

Nick Tomlin
Nick Tomlin

Reputation: 29261

There are several ways to do this. The most traditional being to use CSS' float property your two divs:

CSS

#choice {
    border: 2px solid #87231C;
    border-radius: 12px;
    border-top-right-radius: 0px;
    border-bottom-right-radius: 0px;
    background-color: #FF5A51;
    width: 350px;

     float:left; 
}
#game {
    border: 2px solid #fff;
    border-radius: 15px;
    background-color: white;
    width: 500px;
    margin: 0 auto;

    /* this is needed to make sure your container background 
      "contains" your floated divs */ 
    overflow:auto; 

}
#confirm {
    border: 2px solid #00008B;
    border-radius: 12px;
    border-top-left-radius: 0px;
    border-bottom-left-radius: 0px;
    background-color: #1E90FF;
    width: 142px;
    height: 100px;

    float:left      
}

fiddle

More on floats here

Upvotes: 2

Related Questions