html span显示后消失,html – 当span元素为空时,如何不显示css填充

如果您不需要

support for IE8,则可以使用伪状态:空(

here for more examples)来重置无内容的.myClassDie实例的填充,使用以下代码.

.myClassDie:empty

{

padding:0;

}

更新您的工作示例,它变为:

.myClassDer

{

font-size: 34px;

color:white;

background: blue;

color: white;

border-radius: 25px;

padding: 7px;

width: auto;

height: auto;

}

.myClassDie

{

font-size: 34px;

color:black;

background: red;

color: white;

border-radius: 25px;

padding: 7px;

width: auto;

height: auto;

}

.myClassDie:empty

{

padding:0;

}

here

ClassDie but with content

我在其中插入了两个< span class =“myClassDie”>向您展示有和没有内容的行为.

由于“空”案例的有效隐形,如果您想要一个更紧凑的解决方案,您可以将两个单独的规则折叠成一个,只需设置:

.myClassDie:not(:empty)

{

font-size: 34px;

color:black;

background: red;

color: white;

border-radius: 25px;

padding: 7px;

width: auto;

height: auto;

}

在这种情况下,仅当.myClassDie不为空时,您才会应用所有属性.

这对于这种特定情况是等效的,但是如果你想看到这个DIV也是空的,只限于重置填充(例如因为它有固定的大小或边框),你必须使用第一个解决方案,而不是更紧凑的解决方案.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值