gpt4 book ai didi

html - 为分辨率应用不同的 css 类

转载 作者:行者123 更新时间:2023-11-28 10:08:22 25 4
gpt4 key购买 nike

我的 UL 中有一个跨度类 user-name。我想在不同的分辨率下删除应用不同的类。

<link href="media-queries.css" rel="stylesheet">
<span class="user-name">Shane</span>

当我在不同的分辨率上重新定义我的类时,它不会pickup

@media only screen and (max-device-width:480px) {
.user-name {
min-width:10px;
display:inline-block;
margin-right:20px;
color:red;
}
}
/* default iPad screens */;
@media only screen and (device-width:768px) {
.user-name {
min-width:10px;
display:inline-block;
margin-right:20px;
color:green;
}
}

它总是选择基定义的类。

.user-name {
min-width:10px;
display:inline-block;
margin-right:20px;
color:red;
}

最佳答案

正确使用媒体查询,确保这段代码在底部

.user-name {
min-width:10px;
display:inline-block;
margin-right:20px;
color:red;
}

@media (max-width: 768px){
.user-name {
color:green;
}
}

@media (max-width: 480px){
.user-name {
color:red; /* use can use different color here */
}
}

关于html - 为分辨率应用不同的 css 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24468746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com