-1

My webpage has some CSS issues... in fact every time the user resizes the window, for some reason everything gets messed up.

For some reason, all browsers (Chrome, Firefox and IE) don't recalculate the CSS (or don't recalculate it correctly) after resizing of the browser's window.

Can I force reloading the page (by that I mean CSS recalculation) every time the user resizes his browser's window? However, I don't want to have to reprovide the content from the server every time.

Thanks all!

Emilio
  • 1,314
  • 2
  • 15
  • 39
  • It might be better to try and find the underlying problem. I'm not sure I understand what you mean by browsers not recalculating CSS after resizing - do you have a lot of styles applied by JS on page load? – ESR Apr 27 '17 at 01:43
  • You really need to provide a code example showing this behavior. Are you explicitly setting widths in pixels in your javascript somewhere? – jas7457 Apr 27 '17 at 01:45
  • @EdmundReed I know, but I'm looking for a quick fix... I thik the issue is because I have a header, with 3 parts which all have a different CSS transition to them – Emilio Apr 27 '17 at 02:31
  • Add media queries to your CSS and set the correct values for the various CSS selectors/properties for each situation/browser size you need. – Derek Apr 27 '17 at 02:51
  • @Derek Exactly what I've done! And it doesn't recalculate properly! – Emilio Apr 27 '17 at 02:59
  • you need to post your code – Derek Apr 27 '17 at 04:40

1 Answers1

0

According to your description, you need to recalculate the specific broken css when user resizes the window.

For jQuery, you could do

$(window).resize(function() {
  $('.someEle').css('width', $(window).width()/2)
})

And for vanilla javascript:

window.onresize = function() {
  // do sth here
}

Either way, you have to know specifically where and why your css broke down, and how to fix them in the resize handler.

Thanks for reading.

Chang
  • 1,658
  • 1
  • 17
  • 23
  • I mean, I want to recalculate the whole page when user resizes the window – Emilio Apr 27 '17 at 02:23
  • 1
    @Emilio maybe you could refer to this, but I don't think this is a good practice. http://stackoverflow.com/questions/13721183/reload-css-stylesheets-with-javascript – Chang Apr 27 '17 at 05:22