I have a div with some styles and a fixed width for big screens :
.div {
width: 1600px;
transition: width 0.5s
}
And I am using media query with smaller fixed width for smaller screens :
@media only screen and (max-width: 1000px) {
.div {
width: 400px;
}
}
My problem is when I enter to the website (not refresh), if the browser width is bigger than 1000px, the animation will fire up (the div get from 400px to 1600px) !
I tried to add the transition to the media query, but the transition will not work when I resize the browser (less than 400px to over 400px) which is normal.
I can't understand why the browser use styles inside the media query when it doesn't match the browser with !
Please check this URL with a very basic example :
https://octamerous-hunts.000webhostapp.com/
Update I just tested in Mozilla and Chrome and it work without problem, actually the problem occur only when I use IE and Edge !
The code :
<head>
<style>
.div1 {
position: relative;
width: 1400px;
height: 200px;
left: 50%;
margin-left: -700px;
background-color: royalblue;
transition: width 0.5s, margin-left 0.5s;
}
@media only screen and (max-width: 1399px) {
.div1 {
width: 1000px;
margin-left: -500px;
}
}
</style>
</head>
<body>
<div class="div1">
</div>
</body>
Update 2
I found a similar question :
IE/Edge - CSS3 transitions firing on navigate
But the solution provided doesn't work !
Update 3
I found the solution :
IE11 triggers css transition on page load when non-applied media query exists
That fix the problem with IE and Edge !