You're code looks fine, so I think the problem is browser compatibility. According to Mozilla Documentation, this feature works in Chrome, Firefox, and IE (the newer versions), but is nonexistent in Opera and is buggy in Safari. this question for more compatibility information. A much safer fallback/alternative would be to do your calculations in Javascript:
if ($(document).width() >= 750){
$("#yourElementsID").css("width",$("#yourElementsID").width()*0.5-20)
} else if ($(document).width() >= 400){
// do something here for smaller values
}
You can use the jQuery .width()
function to detect the width of the document, then set the width of your elements accordingly. But just warning you, try to keep as many of your styles outside of your scripts and inside your stylesheets because otherwise it will be unmaintainable.
If it still doesn't work in some browsers, use Modernizr to detect the browser/version/OS and then redirect them to a different version of the page.
Edit 1: Added responsiveness
Edit 2: Removed Interval
Edit 3: Added mention of Modernizr