0

我有一个 div 元素,其中有两个 div 元素,内部 div 是浮动的。但我想要具有自动高度的主 div。不固定。并且背景必须正确显示。当我将高度设置250px为背景时,仅显示 250px 区域。但是当我将高度设置auto为背景时没有显示。如何使背景以自动高度显示?

我的 HTML 代码:-

<div class="ejz_wc" id="ejz_wc">
    <div class="ejz_wc_main" id="ejz_wc_main">
        <div class="ejz_wcm_txt">
            <h2 class="ejz_wc_1_h2">Welcome</h2>
            <p class="ejz_wc_msg">
            If you are new to us then Register a free account today .<br />
            We are here to give you entertainment
            </p>
            <div class="wclinks">
            <a href="<? echo $url; ?>/info/about.php">Learn moare about us</a><br />
            <a href="<? echo $url; ?>/info/payment.php">Learn more about Payment</a><br /><br />
            <a href="ez-register.php#free">Register</a> for a free Account<br />
            <a href="ez-register.php#performer">Register</a> for a Premium Account<br />
            </div>
        </div>
        <div class="ejz_wc_box">
            <div class="ejz_wcbox">
                <h3>Sign In</h3>
                <p>Sign in to us

                <center><a class="lnksnrg" href="ez-login.php"><div class="signin_ejz">Login</div></a></center>
                <h3>Not registered yet?</h3>
                Register now and get access to all items.</p>
                <br />
                <center><a class="lnksnrg" href="ez-login.php"><div class="register_ejz">Register</div></a></center>
            </div>
        </div>
    </div>
</div>

我的 CSS 代码是:-

.ejz_wc
{
width:900px;
margin:auto;
height:250px;
}
.ejz_wc_main
{
font-family: 'Segoe UI','Tahoma Bold','Arial Bold','Helvetica Bold',sans-serif;
height:100%;
border-radius:10px;
-moz-border-radius:10px;
width:100%;
background:#f4f4f4;
}
.ejz_wcm_txt a
{
text-decoration:none;
}
.ejz_wcm_txt a:hover
{
text-decoration:underline;
}
.ejz_wcm_txt
{
float:left;height:auto;
width:450px;
padding:10px 20px;
font-family: 'Segoe UI','Tahoma Bold','Arial Bold','Helvetica Bold',sans-serif;
}
.ejz_wc_box
{
float:right;height:auto;
width:320px;
padding:10px;
font-family: 'Segoe UI','Tahoma Bold','Arial Bold','Helvetica Bold',sans-serif;
}
.ejz_wc_1_h2
{
font-family: 'Segoe UI','Tahoma Bold','Arial Bold','Helvetica Bold',sans-serif;
font-size:x-large;
color:#38939b;height:auto;
}
h1, h2, h3, h4, h5, h6
{
font-family: 'Segoe UI','Tahoma Bold','Arial Bold','Helvetica Bold',sans-serif;
}
.signin_ejz , .register_ejz
{
background:#019be1;
background: -moz-linear-gradient(019be1, #1a75d6); 
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #1a75d6),color-stop(1, #019be1));    
background: -webkit-linear-gradient(#019be1, #1a75d6);  
background: -o-linear-gradient(#019be1, #1a75d6);
background: -ms-linear-gradient(#019be1, #1a75d6);
background: linear-gradient(#019be1, #1a75d6);
padding:5px;
border-radius:10px;
-moz-border-radius:10px;
color:white;
text-decoration:none;
width:100px;
margin:auto;
border:2px solid #019be1;
}

.lnksnrg
{
text-decoration:none;
color:white;
}
.lnksnrg:hover
{
text-decoration:none;
}
.signin_ejz:hover , .register_ejz:hover
{
background:#019be1;
border:2px solid #019be1;
background: -moz-linear-gradient(1a75d6, #019be1); 
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #019be1),color-stop(1, #1a75d6));    
background: -webkit-linear-gradient(#1a75d6, #019be1);  
background: -o-linear-gradient(#1a75d6, #019be1);
background: -ms-linear-gradient(#1a75d6, #019be1);
background: linear-gradient(#1a75d6, #019be1Fwc);
}
4

3 回答 3

3

overflow:hidden在“.ejz_wc_main”中提及将解决您的问题。

.ejz_wc_main {
    background: none repeat scroll 0 0 green;
    border-radius: 10px 10px 10px 10px;
    font-family: 'Segoe UI','Tahoma Bold','Arial Bold','Helvetica Bold',sans-serif;
    height: 100%;
    overflow: hidden;
    width: 100%;
}

这是工作代码jsFiddle文件

于 2013-06-15T05:06:19.677 回答
1

将此 CSS 代码用于前两个类...

.ejz_wc
{
    宽度:900px;
    边距:自动;
    高度:自动;
}

.ejz_wc_main
{
    font-family: 'Segoe UI','Tahoma Bold','Arial Bold','Helvetica Bold',sans-serif;
    高度:100%;
    边框半径:10px;
    -moz-边界半径:10px;
    宽度:100%;
    背景:#f4f4f4;
    向左飘浮;
}

哈哈哈

于 2013-06-15T05:23:02.700 回答
1

很酷的事情是 clearfix 方法。我在你的代码中使用它,这个类有一个 css

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

在具有浮动子元素的父元素上添加 .clearfix。

<div class="ejz_wc_main clearfix" id="ejz_wc_main"></div>

这是给你的演示

http://jsfiddle.net/ppqCD/1/

于 2013-06-15T09:56:46.110 回答