【发布时间】:2020-08-31 08:08:20
【问题描述】:
在我尝试为大型桌面显示器创建媒体查询之前,我没有遇到任何媒体查询问题。由于某种原因,大型设备媒体查询中只有一些样式有效,而有些则无效。似乎一般样式只覆盖了一些大型媒体查询,我只是不知道为什么。
我认为它的顺序错误并且被覆盖了,但是无论我把它放在哪里(高于一般样式、低于最小查询、高于大查询),都没有任何变化。然后我看到一个建议,它需要更多的特异性,所以我尝试这样做以及!important。仍然没有任何变化。我检查了错位的; 和{ },但都是正确的。
这些是我按顺序排列的媒体查询:
General styles not in media query
/* styles that work */
@media only screen and (min-width: 2560px){ /* styles that HALF work */ }
@media only screen and (max-width: 1275px){ /* styles that work */ }
@media only screen and (max-width: 750px) { /* styles that work */ }
@media only screen and (max-width: 600px) { /* styles that work */ }
@media only screen and (max-width: 375px) { /* styles that work */ }
更新:代码示例
PS:Idk 对所有事情都投了反对票,但不是我。
/* General styles that all work */
body {
font-size: 1.8rem;
}
h2{
font-size: 4rem;
}
h3{
font-size: 3rem;
}
.profilePic {
width: 30rem;
height: 30rem;
text-align: center;
border-radius: 50%;
border: var(--primary) 5px solid;
padding: 1%;
}
.typingEffect h1, .typingEffect p {
font-size: 4.5rem;
padding: 0.5rem;
font-weight: bold;
letter-spacing: 0.1rem;
text-align: center;
overflow: hidden;
}
/* Large device media query where some work */
@media only screen and (min-width: 2560px){
body{
font-size: 4rem; /* Works */
}
h2{
font-size: 9rem; /* Works */
}
h3{
font-size: 5rem; /* Works */
}
.profilePic {
width: 100rem; /* Doesn't work */
height: 100rem; /* Doesn't work */
}
.typingEffect h1, .typingEffect p {
font-size: 10.5rem; /* WORKS FOR h1, NOT FOR p */
padding: 5rem; /* WORKS FOR h1, NOT FOR p */
}
}
<header>
<img class="profilePic" src= "./images/orange-Avatar3.svg" alt="Avatar of me"/>
<div class="typingEffect">
<h1 class="name"> Hey, I'm Me</h1>
<p class="tagline"><span className="typed-text"></span><span class="cursor"> </span></p>
</div>
</header>
【问题讨论】:
-
媒体查询似乎很好,可能你有一些特异性问题。
-
也许在第一个媒体查询中显示规则集可能对接收有效答案很有用。
-
xD 他不会显示任何代码,而是会否决每个答案。无论如何,这是一个 CSS 特异性问题。添加您的代码,以便我们告诉您问题出在哪里。
-
将最小宽度:2560px 改为 1276px
标签: css media-queries