在<div> </div> </div> </div>旁边的另一个<div>内的<div>的完整大小

时间:2013-03-20 20:34:46

标签: css

这是我的小游戏的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">
            <p>When you are ready, click on <strong>Fight</strong>.</p>
            <button id="resulot" onClick="resulte()">Fight!</button>
        </div>
        <div id="clear"></div>
    </div>

这是我的CSS

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;
}


#rock {
    width: 100px;
    height: 100px;
    background-color: white;
    background-image: url(img/rock.png);
    background-repeat: no-repeat;
    background-size: 80px 80px;
    background-position: center center;
}
#paper {
    width: 100px;
    height: 100px;
    background-color: white;
    background-image: url(img/paper.png);
    background-repeat: no-repeat;
    background-size: 80px 80px;
    background-position: center center;
}
#scissors {
    width: 100px;
    height: 100px;
    background-color: white;
    background-image: url(img/scissors.png);
    background-repeat: no-repeat;
    background-size: 80px 80px;
    background-position: center center;
}

#result {
    background-color: #ECECEC;
    border:2px solid gray;
    border-radius:25px;
    width: 200px;
    height: 100px;
}

#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;
    display: block;
    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: 100%;
    float: right;
}
#clear {
    clear: both;
}

您可以在http://jsfiddle.net/RWfhQ/上查看。我想让蓝色div与红色div相同。我想让它们大小相同。蓝色div可能比红色div大,所以我需要让它们具有相同的大小。

非常感谢。

2 个答案:

答案 0 :(得分:1)

显而易见的解决方案是在position: relative容器上使用#game,在position: absolute上使用#confirm

#confirm {
    ...
    position: absolute;  // <-- stretch the div
    top: 0;
    bottom: 0;
    right: 0;
}

在这种情况下,您不再需要height: 100%float: right

http://jsfiddle.net/RWfhQ/1/

答案 1 :(得分:0)

由于这是固定宽度,您可以使用faux-columns trick。用<div>包裹以处理背景,并使用半蓝半红的背景图像。