Responsively change div size keeping aspect ratio [duplicate]

You can do this using pure CSS; no JavaScript needed. This utilizes the (somewhat counterintuitive) fact that padding-top percentages are relative to the containing block’s width. Here’s an example: .wrapper { width: 50%; /* whatever width you want */ display: inline-block; position: relative; } .wrapper:after { padding-top: 56.25%; /* 16:9 ratio */ display: block; content: … Read more

Change bootstrap navbar collapse breakpoint without using LESS

2018 UPDATE Bootstrap 4 Changing the navbar breakpoint is easier in Bootstrap 4 using the navbar-expand-* classes: <nav class=”navbar fixed-top navbar-expand-sm”>..</nav> navbar-expand-sm = mobile menu on xs screens <576px navbar-expand-md = mobile menu on sm screens <768px navbar-expand-lg = mobile menu on md screens <992px navbar-expand-xl = mobile menu on lg screens <1200px navbar-expand = … Read more

Responsive css background images

If you want the same image to scale based on the size of the browser window: background-image:url(‘../images/bg.png’); background-repeat:no-repeat; background-size:contain; background-position:center; Do not set width, height, or margins. EDIT: The previous line about not setting width, height or margin refers to OP’s original question about scaling with the window size. In other use cases, you may … Read more