javascript - 除非使用 !important,否则 CSS 规则不起作用
问题描述
除非使用 CSS,否则 CSS 不适用于其他代码(宽度等)!important
,但其他代码有效。这是为什么/是什么原因?除了使用还有什么解决方案!important
吗?
我已经@media
在其他像素上使用过,但它在除此之外的所有代码上都可以正常工作。
媒体查询中的宽度不会更改,其余属性会更改。
@media screen and (min-width= 1200px) and (max-width= 1440px)
.slideshow
{
width: 50% !important;
overflow: hidden;
position: absolute;
z-index: -1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.slides
{
width: 300%;
height: auto;
display: flex;
}
.slide
{
width: 20%;
transition: 0.6s;
}
.slide img
{
width: 50%;
height: auto;
border: 5px solid maroon;
}
.about
{
position: absolute;
top: 50px;
width: 500px;
height: 100px;
display: flex;
flex-wrap: wrap;
font-family: arial;
color: black;
}
.about h2
{
padding: 10px 30px 10px;
}
.about p
{
padding: 10px 30px 20px;
text-align: justify;
}
.about p i
{
opacity: 50%;
font-size: 22px;
}
.content
{
position: absolute;
z-index: -1;
top: 110px;
right: 2px;
width: 280px;
height: 100px;
display: flex;
flex-wrap: wrap;
font-family: arial;
}
.content h2
{
padding: 10px 30px 10px;
}
.content p
{
padding: 10px 30px 20px;
text-align: justify;
}
}
解决方案
This is a really low effort question, as it shows you didn't do your research on the question at all.
A very basic concept of CSS is the Cascade, it's literally right in the name.
This means that rules defined lower in the document overwrite rules earlier in the document.
Instead of using !important, which is very bad practice, simply move the @media rule all the way down your document so it doesn't get overridden.
推荐阅读
- linux - 在bash中删除具有条件的类似目录
- opengl - GLSL 阴影映射:shadow2DProj 导致渲染伪影
- azure - 无法使用 Azure CLI 模板创建 SendGrid 资源 - “提供的订阅标识符无效”
- actionscript-3 - actionscript "var myObjectInst:myObject = new myObject(params);" 在 createJS 中
- prime-factoring - 在函数 FACTOR 的 PARI/GP 中,-1 是错误还是意味着其他?
- java - 如何使用观察者模式通过线程进行文件监控?
- spring-data - 根据文档,Spring Data Rest 不支持发布项目资源,但它支持吗?
- protractor - 量角器元素定位器是否需要 getter 函数
- parallel-processing - Fortran MPI_Isend 和 MPI_Irecv
- c++ - 在 C++ OOP 中,谁负责删除传递给构造函数的对象