2

I have a div #login_container and within that I have another div #login, and they both are within another div #block_2. With the border around the #login_container everything works as I wanted, but, when I removed its border, its child div (i.e. #login) lose its margin and all its text and other contents touch the #login_container. I am just learning html and css, please correct me if I am wrong and please help me how to let the #login div retain its margin. Thank you.

Without border around #login_container div:

Without border in the login container

With border around #login_container div:

With border in the #login_container

Snippet of .html:

        <div id="block_2">
            <div id="login_container" class="div">
                <div id="login">
                    <p>Email Address</p>
                    <input type="text">
                    <p>Password</p>
                    <input type="password">
                    <p>Password</p>
                    <input type="password">
                    <p><input type="checkbox" name="agreement">I have read and agree to the terms of service</input></p>
                </div>
            </div>
        </div>

Snippet of .css:

#block_2 {
    width: 1120px;
    margin: 0px auto;
}

#login_container {
    width: 400px;
    height: 400px;
    margin: 0px 600px;
    border-radius: 30px;
}

.div {
    background:rgb(0,0,0);
    background: transparent\9;
    background:rgba(0,0,0,0.3);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#4c000000,endColorstr=#4c00    0000);
    zoom: 1;
}
.div:nth-child(n) {
    filter: none;
}

#login {
    width: 350px;
    margin: 20px auto;
}

#login_container p, input{
    font-weight: bold;
    font-style: italic;
    margin: 10px;
    color: white;
    font-size: 20px;
}
4

1 回答 1

0

http://jsbin.com/azudAzO/1/edit

#block_2 {
    width: 1120px;
    margin: 0px auto;
}

#login_container {
    position:relative; 
    left:600px;  
    width: 400px;
    height: 400px;
    border-radius: 30px;
    padding:20px 35px;
}

.div {
    background:rgb(0,0,0);
    background: transparent\9;
    background:rgba(0,0,0,0.3);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#4c000000,endColorstr=#4c00    0000);
    zoom: 1;
}
.div:nth-child(n) {
    filter: none;
}

#login {
    width: 350px;
}

#login_container p, input{
    font-weight: bold;
    font-style: italic;
    color: white;
    font-size: 20px;
}
于 2013-09-16T12:05:22.753 回答