I am using HTML, CSS, mediaQuery, Javascript, jQuery and PrimeFaces, and I want to use the css property
calc(100% - 100px)
I've implement a javascript work around for old browsers, which do not support this property.
After reading several related questions, such as:
An excerpt from my code:
1.) my JavaScript function in my facelet:
<ui:define name="search_results">
<h:outputStylesheet name="primeicons/primeicons.css" library="primefaces"/>
<h:outputStylesheet library="css" name="results.css" />
<h:outputScript library="primefaces" name="jquery/jquery.js"/>
<h:outputScript library="js" name="results.js"/>
<script>
// we need to execute the js function after the page load:
// @see https://stackoverflow.com/questions/8996316/how-to-execute-javascript-after-page-load
jQuery(document).ready(function() {
jQuery(document).ready(function() {
// twice in document.ready to execute after Primefaces callbacks
document.getElementById("homeDetailsPanelId").setAttribute("style","width:583px !important;");
var width = document.getElementById("homeDetailsPanelId").style.width;
alert (width);
});
});
</script>
2.) My HTML and CSS code for the element in question:
<div id="homeDetailsPanelId" class="col-7">
<!-- more code here -->
</div>
3.) My css file:
@media only screen and (min-width: 1200px) {
.col-7 {
width:calc(100% - 395px);
}
/* more styles here */
}
Minimal working example:
https://github.com/alexmivonwien/pf.css
When I load my page in any browser, I see that the javascript gets executed and the width of the element is set properly. However, after the javascript alert()
shows up and I confirm it, the browser applies the css from the media query and the width of the element set with javascript is overwritten.
How can I make my JavaScript take precedence over the media query in the CSS?
Current result: