Reputation: 1587
How can I set a dynamic left margin of a div depending on $(window).width()
?
For example, for a width of 1886px
the margin should be 20%
, but for a width of 1280px
the margin should change to 10%
.
Upvotes: 1
Views: 419
Reputation: 8246
div {
margin-left: 20%; /* Default */
}
@media (max-width: 1280px) { /* Apply these styles to 1280px width and under */
div {
margin-left: 10%;
}
}
Upvotes: 2
Reputation: 28434
CSS media queries is a way to go:
@media (max-width:1280px) {
margin-left: 10%;
}
@media (min-width:1281px) {
margin-left: 20%;
}
Upvotes: 1