Reputation:
I'm using this now,
@media (max-width: 1024px) { #icons { border-radius: 0px } }
@media ( width: 1025px) { #icons { border-radius: 1px 1px 0px 0px } }
@media ( width: 1026px) { #icons { border-radius: 2px 2px 0px 0px } }
@media ( width: 1027px) { #icons { border-radius: 3px 3px 0px 0px } }
@media ( width: 1028px) { #icons { border-radius: 4px 4px 0px 0px } }
@media ( width: 1029px) { #icons { border-radius: 5px 5px 0px 0px } }
@media ( width: 1030px) { #icons { border-radius: 6px 6px 0px 0px } }
@media ( width: 1031px) { #icons { border-radius: 7px 7px 0px 0px } }
@media ( width: 1032px) { #icons { border-radius: 8px 8px 0px 0px } }
@media ( width: 1033px) { #icons { border-radius: 9px 9px 0px 0px } }
To generate a flexible border-radius, proportional to the client's window width. Though, this looks ridiculous.
How else can this be achieved? Thanks!
Upvotes: 5
Views: 6641
Reputation: 1020
Between December 2019 and April 2020 the browsers all added support for a new method in CSS called clamp( ).
Replace media queries with clamp()
Upvotes: 0
Reputation: 24541
Media queries are not ridiculous... Using JS to replace them is ridiculuos especially when it's 2016.
@media (max-width: 1024px) { #icons { border-radius: 0px } }
@media (min-width: 1025px and max-width: 1033px) {
#icons {
border-radius: calc(100vw - 1024px) calc(100vw - 1024px) 0px 0px;
}
}
@media (min-width: 1034px) {
#icons {
border-radius: 10px;
}
}
This should do the job.
Upvotes: 4
Reputation:
Using % instead of px. You may specify the value of border-radius in percentages.
Also you can use Javascript:
bordervalue = window.innerWidth.toString().split('').pop();
/*here you can modify border value as you wish*/
document.getElementById("icons").style.borderRadius=bordervalue + "px " + bordervalue + "px 0px 0px";
Upvotes: 0
Reputation: 17351
Perhaps use a little dynamic, DRY (Don't Repeat Yourself) coding with JS?
The following uses jQuery for convenience.
var win = $(window);
win.resize(function() {
if(win.width() >= 1024) {
var padding = win.width()-1024;
$("#icons").css("border-radius", padding + "px " + padding + "px 0px 0px");
}
}).resize();
#icons {
height: 100px;
width: 100px;
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="icons">Try resizing the window to widths greater than 1024px.</div>
What it does:
$(window)
to avoid multiple DOM queries (which are slow).border-radius
string by calculating the necessary padding.resize()
on load.Upvotes: 4