Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Min/Max height vs JS / jQuery / MooTools resize for website

Posted on 2011-02-16
4
866 Views
Last Modified: 2012-05-11
Hey guys!

I am creating a website, and would like to make the website resize depending on the user's browser window size (realtime if possible). It will be a E-Commerce shopping cart, so there will be a lot of different size images, content, and buttons to consider also.

The question is, what it be feasible to make the ENTIRE website resizable depending on the user's browser window?

If so, would it be better / easier to use JS for this or CSS (min-height,max-height)? Everything will be dependent on the height of the browser, not the width of it.

The images will be dependent on ratios (2/3). The website currently has a mixture of MooTools and jQuery, where some pages either contain one or the other.

Please let me know what you think.

Thanks!
0
Comment
Question by:areyouamac
  • 3
4 Comments
 
LVL 8

Accepted Solution

by:
imantas earned 500 total points
ID: 34912847
CSS won't help you here enough. Use javascript, something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <title>Blank page</title>
 <meta name="viewport" content="width=device-width,user-scalable=no"/>
</head>
<body>
Window width: <input id="width" type="text" size="10" /><br/>
Window height: <input id="height" type="text" size="10" />

<script type="text/javascript">
<!--
    window.size = function () {
      var windowWidth, windowHeight;
      if (typeof window.innerWidth != 'undefined') {
        windowWidth = window.innerWidth;
        windowHeight = window.innerHeight;
      }
      else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight
      }
      else if (document.getElementsByTagName && document.getElementsByTagName('body').length > 0) {
        windowWidth = document.getElementsByTagName('body')[0].clientWidth;
        windowHeight = document.getElementsByTagName('body')[0].clientHeight;
      }
      window.width = window.w = windowWidth;
      window.height = window.h = windowHeight;
      
      return { w: windowWidth, h: windowHeight, width: windowWidth, height: windowHeight };
    };
    window.onresize = function() {
      document.getElementById('width').value = window.size().width + 'px';
      document.getElementById('height').value = window.size().height + 'px';
    };
//-->
</script>

</body></html>

Open in new window


This is a complete page, no frameworks needed. Try resizing this window. You can do whatever you like with window.size().[width/height]. Please note that there's no default methods for getting window size that would be supported by all major browsers, so you have to use a function similar to the one you can find in the code.
0
 

Author Comment

by:areyouamac
ID: 34913380
Hey imantas!

Thank  you. This resizes the website size perfectly.

Have a great day!
0
 

Author Closing Comment

by:areyouamac
ID: 34913385
Straight to the point. Explains what to do. Thanks!
0
 

Author Comment

by:areyouamac
ID: 34913405
Hey imantas,

I have one more question,

Can this JS script also be used for ratio purposes? If, for example. the webpage has a 3/4 (height/width) ratio, how would I implement it in the coding above?

Or is it an entirely different code?

Thanks!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question