Div显示问题

时间:2016-03-30 03:50:54

标签: html css3

我的div在我的字段下显示错误,如果form中有一个错误

问题是如果我使用inline-block,我在div区域所做的事情将以错误颜色

显示

当字段不再为空时,我只想要background: red;



div#alert-block {
    height:15px; 
    clear:both;
}

.alert-error {    
    display: inline-block;
    color: #fff;
    background-color: #ff0000;
    height:20px;
    width: 100%;
    clear:both; 

} 

<div id="alert-block">
    <span class="alert-error">{email_error}</span> 
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

尝试使用:代码后清空。

.alert-error:empty {   
  background-color: green;
}

了解更多信息和浏览器兼容性检查: https://css-tricks.com/almanac/selectors/e/empty/

或进一步改进(不确定浏览器兼容性)

.alert-error:not(:empty) {    
    display: inline-block;
    color: #fff;
    background-color: #ff0000;
    height:20px;
    width: 100%;
    clear:both; 
} 

答案 1 :(得分:0)

更改了Level1 level = new Level1(); level1.levelMethod(); //Prints "Level1 method" Level1 level = new Level2(); level.levelMethod(); //Prints "Level2 method" Level1 level = new Level3(); level.levelMethod(); //Prints "Level3 method" &#34; alert-error&#34; 中的width: auto。试试吧。如果没有错误消息,那么您现在不会获得class。希望,这是你的要求!

&#13;
&#13;
background: red;
&#13;
div#alert-block {
    height:15px; 
    clear:both;
}

.alert-error {    
    display: inline-block;
    color: #fff;
    background-color: #ff0000;
    height:20px;
    width: auto;
    clear:both; 

} 
&#13;
&#13;
&#13;