Maison > Questions et réponses > le corps du texte
@media screen and (min-width: 360px) and (max-width: 375px){
.ejiao_description .form form p{
margin-bottom: 11px;
}
}
La requête média en CSS s'écrit comme ceci
js
var screen1 = window.matchMedia('@media (min-width: 360px) and (max-width: 375px)');
if (screen1.matches){
XXXXXX.....
}
else{
XXXX....
}
Mais ça ne marche pas maintenant.
滿天的星座2017-07-05 10:40:16
https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
Veuillez consulter la documentation
我想大声告诉你2017-07-05 10:40:16
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
@media screen and (min-width: 360px) and (max-width: 375px){
.aa .form form p{
margin-bottom: 11px;
}
}
</style>
</head>
<body>
<!-- 想通过js判断css的媒体查询 出错 -->
<p class="aa">
<p class="form">
<form>
<p>123123</p>
</form>
</p>
</p>
</body>
<script>
var screen1 = window.matchMedia('(min-width: 360px) and (max-width: 375px)');
console.log( screen1 );
if (screen1.matches){
console.log( 1 );
}
else{
console.log( 2 );
}
</script>
</html>
pourwindow.matchMedia('(min-width: 360px) and (max-width: 375px)');
,没@media