W3C home > Mailing lists > Public > www-style@w3.org > November 2008

Re: [css3] "keep aspect ratio" feature

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Fri, 21 Nov 2008 08:51:32 -0600
Message-ID: <dd0fbad0811210651w745508e2x8ac59808a7063b3a@mail.gmail.com>
To: "Andrew Fedoniouk" <news@terrainformatica.com>
Cc: www-style <www-style@w3.org>
On Thu, Nov 20, 2008 at 11:28 PM, Andrew Fedoniouk <
news@terrainformatica.com> wrote:

>
> Time to time I am getting feature request to provide
> "keep aspect ratio" functionality in CSS.
>
> Here is a simple idea of how aspect ratio could be done
> without changing too much in CSS:
>
> To declare function 'width(NN%)' that can be used as a value of
> height, min-height, max-height CSS attributes. Thus it would
> be possible to define element that keeps its aspect ratio simply as:
>
> #my-golden-ratio
> {
>  width: 30%;
>  height: width(62%);
> }
>
> where width takes 30% of content box of #my-golden-ratio parent
> and height of the element will be set to 62% of its computed width.
>
> Optional part:
>
> In principle use of this width() can be expanded on other vertical
> length attributes of the element: margin-top/bottom, border-top/bottom and
> padding-top/bottom. And list of functions similar to the width()
> can be expanded to:
>  margin-left(), margin-right()
>  border-left(), border-right()
>  padding-left(), padding-right()
>

I like the idea, and think it could be a valuable addition.  As well, in
this simple form it avoid the circular-dependency issues that plague more
general solutions.

There's no reason for the margin/border/padding versions of the properties,
though.  Margin and padding % values depend on the width of the containing
block no matter what, so you can maintain an aspect ratio on them simply by
setting % values with the ratio you want.  Border doesn't allow % at all (it
only takes length values), and so there's no way to vary the border width
and thus any aspect ratios are hardcoded.  If it *did* allow %s, though, it
would certainly work the same as margin and padding.

~TJ
Received on Friday, 21 November 2008 14:52:09 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:55:17 GMT