!Important的使用及测试

CSS的原理:

我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义 < 元素style>中的属性,但是如果使用!important,优先级会变得不一样。

使用!important的css定义是拥有最高的优先级的。但是在ie6下出了一点小的bug,注意书写方式一般可以轻松避开的。

测试用例:

<!DOCTYPE HTML>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>测试!Important在ie6中区别</title> 
</head> 
<style type="text/css">
.testClass1{ 
color:blue !important;
}
.testClass2{ 
color:blue !important;
color: green;
}
.testClass3{ 
color: green;
color:blue !important;
}
.testClass4{ 
color:blue !important;
}
.testClass4{ 
color: green;
}
.testClass5{ 
color: green !important;
}
</style>
<body>
    <div class="testClass1" style="color:red;">
        测试Css1中的Important
    </div>
    <div class="testClass2" style="color:red;">
        测试Css2中的Important
    </div>
    <div class="testClass3" style="color:red;">
        测试Css3中的Important
    </div>
    <div class="testClass4" style="color:red;">
        测试Css4中的Important
    </div>
        <div class="testClass5" style="color:red !important;">
        测试Css5中的Important
    </div>
</body>

</html>

虽然元素的style中有testClass类的定义,但是在上面的css定义中的用!important限定的定义却是优先级最高的,无论是在ie6-10或者Firefox和Chrome表现都是一致的,都显示蓝色。

在testClass1可以说明ie6是可以识别!important的。如果写成testClass2,ie6是识别不出来的,这是ie6的小缺陷。

不过这个问题可以通过testClass4的方式解决


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里是一个简单的 Python 代码,用于实现MBTI性格测试: ```python questions = [ "1. You find it takes effort to introduce yourself to other people.", "2. You often get lost in your thoughts and ignore or forget your surroundings.", "3. You try to respond to your emails as soon as possible and cannot stand a messy inbox.", "4. You find it easy to stay relaxed and focused even when there is some pressure.", "5. You do not usually initiate conversations.", "6. You rarely do something just out of sheer curiosity.", "7. You feel superior to other people.", "8. Being organized is more important to you than being adaptable.", "9. You are usually highly motivated and energetic.", "10. Winning a debate matters less to you than making sure no one gets upset.", ] results = { "ISTJ": 0, "ISFJ": 0, "INFJ": 0, "INTJ": 0, "ISTP": 0, "ISFP": 0, "INFP": 0, "INTP": 0, "ESTP": 0, "ESFP": 0, "ENFP": 0, "ENTP": 0, "ESTJ": 0, "ESFJ": 0, "ENFJ": 0, "ENTJ": 0, } print("Please answer the following questions with 'yes' or 'no':\n") for q in questions: response = input(q + " (yes/no) ") while response.lower() not in ["yes", "no"]: response = input("Please enter 'yes' or 'no': ") if response.lower() == "yes": results["ISTJ"] += 1 results["ISFJ"] += 1 results["INFJ"] += 1 results["INTJ"] += 1 results["ISTP"] += 1 results["ISFP"] += 1 results["INFP"] += 1 results["INTP"] += 1 results["ESTP"] += 1 results["ESFP"] += 1 results["ENFP"] += 1 results["ENTP"] += 1 results["ESTJ"] += 1 results["ESFJ"] += 1 results["ENFJ"] += 1 results["ENTJ"] += 1 else: results["ISTJ"] -= 1 results["ISFJ"] -= 1 results["INFJ"] -= 1 results["INTJ"] -= 1 results["ISTP"] -= 1 results["ISFP"] -= 1 results["INFP"] -= 1 results["INTP"] -= 1 results["ESTP"] -= 1 results["ESFP"] -= 1 results["ENFP"] -= 1 results["ENTP"] -= 1 results["ESTJ"] -= 1 results["ESFJ"] -= 1 results["ENFJ"] -= 1 results["ENTJ"] -= 1 type_result = max(results, key=results.get) print(f"\nYour MBTI personality type is: {type_result}") ``` 此代码将问用户一些问题,并根据他们的回答计算MBTI测试结果。每个回答都会将16种可能的MBTI性格类型中的几个得分增加或减少1分。完成问答后,代码将输出用户的MBTI性格类型。 请注意,此代码仅用于示例和学习目的。实际的MBTI测试使用更复杂和全面的问卷和算法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值