Reputation: 1
my media breakpoints aren't applying as they should. I put together a simplified example to demonstrate.
In the below example, the div "myDiv" should read:
Instead, it's reading "normal width", when over max-width of 1200px, and "mw1200", when below.
.myContainer {
position: absolute;
top: 100px;
left: 100px;
color: #FFF;
background-color: #000;
padding: 10px;
width: auto;
height: auto;
}
.myDiv {
padding-left: 10px;
padding-right: 10px;
}
.myDiv:after {
content: 'normal width';
}
@media screen and (max-width:768px) {
.myDiv:after {
content: 'mw768';
}
}
@media screen and (max-width:992px) {
.myDiv:after {
content: 'mw992';
}
}
@media screen and (max-width:1200px) {
.myDiv:after {
content: 'mw1200';
}
}
<div class="myContainer">
<div class="myDiv">
myDiv inside myContainer
</div>
</div>
Upvotes: 0
Views: 34
Reputation: 981
I'd probably refactor this and go mobile-first. You could do something like:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
.myContainer {
position: absolute;
top: 100px;
left: 100px;
color: #FFF;
background-color: #000;
padding: 10px;
width: auto;
height: auto;
}
.myDiv {
padding-left:10px;
padding-right:10px;
}
.myDiv:after {
content: 'mw768';
}
@media screen and (min-width: 769px) {
.myDiv:after {
content: 'mw992';
}
}
@media screen and (min-width: 993px) and (max-width: 1200px) {
.myDiv:after {
content: 'mw1200';
}
}
</style>
</head>
<body>
<div class="myContainer">
<div class="myDiv">
myDiv inside myContainer
</div>
</div>
</body>
</html>
That way, you'd use less code to achieve basically the same thing.
Upvotes: 0