Reputation: 1985
I have following structure of an HTML document:
<body>
<div class="main">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
<div>
</body>
Is it possible to define different width for the main
, left
, center
and right
depending on the screen resulation. For example if the screen resulution is 1280 or higher, main width should be 1140px. If it is 1280 or lower, the width should 960px?
Thanks.
PS. I understand we can define the width in %, but I am interested to know if we can define 2 different fixed widths.
Upvotes: 0
Views: 862
Reputation: 2363
this can be achieved using javascript:
<script language="javascript">
if ((screen.width>=1024) && (screen.height>=768)) {
alert('High resolution');
} else {
alert('Low resolution');
}
</script>
Upvotes: 1
Reputation: 3065
this is the javascript you can use to check the screen width and height.
<script type="text/javascript">
document.write(screen.width+'x'+screen.height);
</script>
reference.. http://andylangton.co.uk/articles/javascript/browser-screen-resolution/
Upvotes: 1
Reputation: 908
Using only CSS, you can use media queries. Here's the spec, and some examples. Note that not all browsers support this feature.
Upvotes: 3
Reputation: 5605
Use JavaScript for this. Jquery can can give better syntax. Use screen.width
to get the width of user screen and then resize your content accordingly.
Upvotes: 1