如何在<div>@media查询中禁用

  • 本文关键字:查询 @media div php html css
  • 更新时间 :
  • 英文 :


我制作了一个二进制计算器网站,我希望计算器在灰色背景中,但主体应该是黑色的。所以我做了一个黑色的身体和一个潜水所有的元素,我想做的是在这个灰色的背景。桌面上一切都很好,但现在我开始为移动设备进行优化,我意识到我必须";禁用";导致灰色背景的div有一个干净的黑色ui,没有灰色的大背景线。当我在chromes模拟手机上测试@media查询时,所有东西都定位正确,甚至div背景也消失了。尽管当我在手机上测试它时,它看起来就像照片中一样。提前谢谢。

模拟电话

电话

桌面1920x1080

@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@600&display=swap');
/*Desktop*/
@media only screen and (max-width: 2560px) {
body{
background-color:black;
}
h1{
font-family:Sans-serif; 
font-size:60px; 
text-decoration: underline black;
}
.background-box{
height:100vh; 
width:60vw;
background-color: rgb(42, 42, 42);
margin:auto;
text-align:center;
}
.Dezi{
width:500px;
height:40px;
font-size:25px;
}
.rechnen{
font-family: 'Source Sans Pro', sans-serif;
font-size:20px;
height:70px;
width:400px;
background-color:white;
border-width:2px;
border-color:black;
border:solid;
border-width:2px;
box-shadow: inset 0 0 0 0 white;
transition:ease-out 0.8s;
}
.rechnen:hover{
cursor:pointer;
box-shadow:inset 700px 0 0 0 #000000;
color:white;
border-color:white;
}
#operator{
position:relative;
top:30px;
left:290px
}
.result{
font-family: 'Source Sans Pro', sans-serif;
font-size:25px;
}
.homebutton{
font-family: 'Source Sans Pro', sans-serif;
font-size:22px;
width:350px;
height:70px;
letter-spacing:2px;
color:black;
transition: ease-out 0.4s;
background-color:white;
float:right;
position:relative;
box-shadow:black;
border-color:rgb(0, 0, 0);
top:-935px;
box-shadow:inset 0 0 0 0 white;
border:solid;

}
.homebutton:hover {
cursor:pointer;
box-shadow:inset 350px 0 0 0 black;
color:white;
border-color:white;
border-width:2px;
}
.DzBR{
font-family: 'Source Sans Pro', sans-serif;
font-size:22px;
width:350px;
height:70px;
letter-spacing:2px;
color:black;
transition: ease-out 0.4s;
background-color:white;
float:right;
position:relative;
box-shadow:black;
border-color:rgb(0, 0, 0);
top:-870px;
left:350px;
box-shadow:inset 0 0 0 0 white;
border:solid;
}
.DzBR:hover{
cursor:pointer;
box-shadow:inset 350px 0 0 0 black;
color:white;
border-color:white;
border-width:2px;
}
}
/*MOBILE*/
@media only screen and (max-width: 850px) {
body{
all:unset;
background-color:white;
text-align:center;
}   
h1{
font-family: 'Source Sans Pro', sans-serif; 
font-size:60px; 
text-decoration: underline black;
}
.background-box{
background-color: unset;
background-color: white;
}


.Dezi{
width:500px;
height:40px;
font-size:25px;
}

.rechnen{
font-family: 'Source Sans Pro', sans-serif;
font-size:20px;
height:70px;
width:400px;
background-color:white;
border-width:2px;
border-color:black;
border:solid;
border-width:2px;
box-shadow: inset 0 0 0 0 white;
transition:ease-out 0.8s;
}

.rechnen:hover{
cursor:pointer;
box-shadow:inset 700px 0 0 0 #000000;
color:white;
border-color:white;
}

#operator{

}

.result{
font-family: 'Source Sans Pro', sans-serif;
font-size:25px;
}

.homebutton{
all:unset;
all:revert;
font-family: 'Source Sans Pro', sans-serif;
font-size:22px;
width:350px;
height:70px;
letter-spacing:2px;
color:black;
transition: ease-out 0.4s;
background-color:white;
float:;
position:relative;
box-shadow:black;
border-color:rgb(0, 0, 0);
top:;
box-shadow:inset 0 0 0 0 white;
border:solid;

}

.homebutton:hover {
cursor:pointer;
box-shadow:inset 350px 0 0 0 black;
color:white;
border-color:white;
border-width:2px;
}

.DzBR{
all:unset;
font-family: 'Source Sans Pro', sans-serif;
font-size:22px;
width:350px;
height:70px;
letter-spacing:2px;
color:black;
transition: ease-out 0.4s;
background-color:white;
float:;
position:relative;
box-shadow:black;
border-color:rgb(0, 0, 0);
top:;
left:;
box-shadow:inset 0 0 0 0 white;
border:solid;
}

.DzBR:hover{
cursor:pointer;
box-shadow:inset 350px 0 0 0 black;
color:white;
border-color:white;
border-width:2px;
}

}
<html>
<head>
<link href="DzBRstyle.css" rel="stylesheet" type="text/css">
<title>Dezimal zu Binär Rechner</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<div class="background-box">
<body>
<h1>Dezimal zu Binär Rechner</h1>
<br>
<br>
<br>
<br>
<br>
<br>

<form action="DzBR.php" method="post">
<select id="operator" name="operator">
<option>Dual</option>
<option>Oktal</option>
<option>Hexal</option>
</select>
<br>

<input class="Dezi" name="Dezi" type="number">

<br>
<br>

<button name="rechnen" class="rechnen">Rechnen</button>
</form>
</div>
<form action="../hub.php">
<button class="homebutton">Home</button>
</form>
<form action="../Binaer-Dezimal/kayedrechner.php">
<button class="DzBR">Binär zu Dezimal Rechner</button>
</form>
</body>
</html>

background-boxdiv放入body(而不是之前(并正确关闭它(使用</div>标记(,然后在需要时(即在媒体查询中(将display: none;应用于它。

您可以使用css中的display:none;来"禁用";div,但也会使div中的所有内容都不可见。

另一种方法是visibility: hidden;,它使div不可见,但它仍然占用网站上的空间

以这种方式设置@media。

/* start with common css for desktop and smartphone */
....
/* high resolution (only desktop) */
@media only screen and (min-width: 850px) and (max-width: 2560px) {
....
}
/* low resolution (only smartphone) */
@media only screen and (max-width: 849.98px) {
....
}

对于非常高分辨率的屏幕来说,使用(最大宽度:2560px(并不是未来的证明。

任何div都可以用display: none;从流中移除。请注意,其中的所有内容也不会显示。

最新更新