根据CSS的高度设置元素宽度 [英] Setting Element Width Based on Height Via CSS

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

问题描述

我有一组元素,并要求它们的最小宽度等于它们的高度,但是高度没有明确设置。目前我能够通过jQuery设置css min-width 属性来实现这一点:

I have a set of elements and require that their minimum width be equal to their height, but the height is not explicitly set. Currently I am able to achieve this by setting the css min-width property via jQuery:

$(document).ready
(
    function()
    {
        $('.myClass').each
         (
             function() {$(this).css('min-width', $(this).css('height'));}
         );
    }
);  

是否可以直接在css中指定此行为?

Is it possible to specify this behaviour directly in the css?

这里是一个jsfiddle演示我想实现什么: http://jsfiddle.net/p8PeW/

Here is a jsfiddle demonstrating what I am trying to achieve: http://jsfiddle.net/p8PeW/

推荐答案

我不相信这是没有JS,但也许有人可以证明我错了吗?

I don't believe this is possible without JS, but maybe someone can prove me wrong?

CSS不允许你使用动态变量,所以如果在页面加载之前没有设置高度,我不知道这是怎么做的。

CSS doesn't allow you to use dynamic variables, so if the height isn't set until the page loads, I'm not sure how this could be done.

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

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