HighDots Forums  

Keeping aspect ratio of <div>

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Keeping aspect ratio of <div> in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Martin Plotz
 
Posts: n/a

Default Keeping aspect ratio of <div> - 02-04-2008 , 07:45 AM






Hi all,
is it possible to say "I'd like a <div> with width:100% and an aspect
ratio of height/width=2/3" in a way that browsers understand?

Thanks for hints,
Martin

Reply With Quote
  #2  
Old   
Carolyn Marenger
 
Posts: n/a

Default Re: Keeping aspect ratio of <div> - 02-04-2008 , 08:41 AM






Martin Plotz wrote:
Quote:
Hi all,
is it possible to say "I'd like a <div> with width:100% and an aspect
ratio of height/width=2/3" in a way that browsers understand?

Thanks for hints,
Martin
Martin,

Using javascript, you could determine the size of the view port and then
set height and width to a computation based on those results.

Here is one of many links that may assist you with the javascript end of
things. Be warned however, some of us have javascript turned off, so
you need a fall back for us.

http://andylangton.co.uk/articles/ja...ze-javascript/

Carolyn


Reply With Quote
  #3  
Old   
Ben C
 
Posts: n/a

Default Re: Keeping aspect ratio of <div> - 02-04-2008 , 08:56 AM



On 2008-02-04, Martin Plotz <martinplotz (AT) yahoo (DOT) de> wrote:
Quote:
Hi all,
is it possible to say "I'd like a <div> with width:100% and an aspect
ratio of height/width=2/3" in a way that browsers understand?
The suggestion below should work in modern browsers, not tested in IE.

You first need to create a little transparent image called 23.png (or
whatever you like) that's 3px x 2px.

.aspect23
{
border: 1px solid black;
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
}

...

<div style="position: relative">
<img src="23.png" style="display: block; width: 100%">
<div class="aspect23">
Hello
</div>
</div>

I've put that relatively positioned div in-- but you just need to add
position: relative to whichever block you want this special 2/3 div in.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.