CSS表达式设置div的高度 [英] CSS expression to set height of div

查看:152
本文介绍了CSS表达式设置div的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据CSS表达式设置div的高度。

I want to set the height of a div based on CSS expression.

基本上应该设置为视口的一些%(比如90%) width
我尝试了以下操作,但是不工作;

Basically it should be set as some % (say 90%) of the viewport width I tried the following, but is not working;

height:expression(document.documentElement.clientWidth ? document.documentElement.clientWidth : window.innerWidth );

我正在寻找一个跨浏览器的方式(IE7 +,FF4 +,Safari) p>

I am looking at a cross-browser way of doing this (IE7+, FF4+, Safari)

推荐答案

除了IE之外,CSS表达式不支持任何地方(即使存在,也被认为是一个坏主意)。

CSS expressions are not supported anywhere except IE (and are considered a bad idea even there).

但是,没有真正的另一种方式来做你所要求的,至少不使用CSS。

However, there isn't really another way of doing what you're asking, at least not using just CSS.

唯一的选择是

事实上,IE的CSS表达式本身就是Javascript,它允许使用相当强大的表达式,但也具有消除布局和脚本抽象的负面影响。这是为什么他们皱眉,但有一些用例,如你的纯布局需要某种形式的表达。

In fact, IE's CSS expressions are themselves Javascript, which allows quite powerful expressions, but also has the negative effect of removing the abstraction of layout and script. This is why they're frowned on, but there are use cases such as yours where pure layout requires some form of expression.

正如我说的,真的不是

未来可能有一些希望,因为Google目前正在试验一些包含变量的CSS增强功能。文章: http://johanbrook.com/design/css/webkit-css- variable-mixins-nesting / 。但是,我不确定这是否会允许你需要的表达式。

There might be some hope for the future, as Google are currently experimenting with some enhancements to CSS which include variables. Article about it here: http://johanbrook.com/design/css/webkit-css-variables-mixins-nesting/. However, I'm not sure whether even this would allow the kind of expressions you're needing.

这可能是继续需要Javascript的未来。这无论如何,现在,无论如何。

So possibly this is something that might continue needing needing Javascript into the future. It certainly does for now, either way.

这篇关于CSS表达式设置div的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆