通过css设置标签的大小属性?

时间:2022-11-19 15:30:12

Normally you can do this:

通常你可以这样做:

<select size="3">
    <option>blah</option>
    <option>blah</option>
    <option>blah</option>
</select>

And it would render as a selectionbox where all three options are visible (without dropping down)
I'm looking for a way to set this size attribute from css.

并且它将呈现为一个选择框,其中所有三个选项都是可见的(没有下降)我正在寻找一种从css设置此大小属性的方法。

7 个解决方案

#1


8  

There ins't an option for setting the size, but if you do set the size some browsers will let you set the width/height properties to whatever you want via CSS.

没有设置大小的选项,但如果你设置了大小,一些浏览器会让你通过CSS将宽度/高度属性设置为你想要的任何东西。

Some = Firefox, Chrome, Safari, Opera.

有些= Firefox,Chrome,Safari,Opera。

Not much works in IE though (no surprise)

在IE中没有多少作品(毫不奇怪)

You could though, if you wanted, use CSS expressions in IE, to check if the size attribute is set, and if so, run JS to (re)set it to the size you want... e.g.

但是,如果你愿意,你可以在IE中使用CSS表达式来检查是否设置了size属性,如果是,则运行JS以(重新)将其设置为你想要的大小......例如

size = options.length;

#2


6  

I don't think that this is possible.

我不认为这是可能的。

CSS properties are very generic (applicable to any element) and are unable to alter the functionality of an element in any ways (only the looks).

CSS属性非常通用(适用于任何元素),并且无法以任何方式(仅外观)更改元素的功能。

The size attribute is changing the functionality of the element at least in the case of size = 1 / size != 1.

size属性正在改变元素的功能,至少在size = 1 / size!= 1的情况下。

#3


2  

Try this:

尝试这个:

select[attr=size] {
    width:auto;
    height:auto;
}

#4


2  

I disagree, I have been able to set select width and height using CSS with something like this:

我不同意,我已经能够使用CSS设置选择宽度和高度,如下所示:

select { width: 5em; height: 5em; }

Works in IE(7) as well as I just tested it.

在IE(7)中工作以及我刚刚测试过它。

#5


0  

In general you can't add attributes set within html via CSS. You can add to the html using the pseudo selectors :before and :after, but that's about it, plus they still aren't compatible across all browsers. If you really need to do this, I think you'd have to resort to Javascript.

通常,您无法通过CSS添加html中设置的属性。您可以使用伪选择器添加到html:before和:after,但这是关于它的,加上它们仍然不兼容所有浏览器。如果你真的需要这样做,我认为你不得不求助于Javascript。

#6


0  

You can use following CSS selector to style select items with the size attribute:

您可以使用以下CSS选择器来设置具有size属性的选项:

select[size]{
/*your style here */
}

#7


-2  

I do not believe this is possible no

我不相信这是不可能的

#1


8  

There ins't an option for setting the size, but if you do set the size some browsers will let you set the width/height properties to whatever you want via CSS.

没有设置大小的选项,但如果你设置了大小,一些浏览器会让你通过CSS将宽度/高度属性设置为你想要的任何东西。

Some = Firefox, Chrome, Safari, Opera.

有些= Firefox,Chrome,Safari,Opera。

Not much works in IE though (no surprise)

在IE中没有多少作品(毫不奇怪)

You could though, if you wanted, use CSS expressions in IE, to check if the size attribute is set, and if so, run JS to (re)set it to the size you want... e.g.

但是,如果你愿意,你可以在IE中使用CSS表达式来检查是否设置了size属性,如果是,则运行JS以(重新)将其设置为你想要的大小......例如

size = options.length;

#2


6  

I don't think that this is possible.

我不认为这是可能的。

CSS properties are very generic (applicable to any element) and are unable to alter the functionality of an element in any ways (only the looks).

CSS属性非常通用(适用于任何元素),并且无法以任何方式(仅外观)更改元素的功能。

The size attribute is changing the functionality of the element at least in the case of size = 1 / size != 1.

size属性正在改变元素的功能,至少在size = 1 / size!= 1的情况下。

#3


2  

Try this:

尝试这个:

select[attr=size] {
    width:auto;
    height:auto;
}

#4


2  

I disagree, I have been able to set select width and height using CSS with something like this:

我不同意,我已经能够使用CSS设置选择宽度和高度,如下所示:

select { width: 5em; height: 5em; }

Works in IE(7) as well as I just tested it.

在IE(7)中工作以及我刚刚测试过它。

#5


0  

In general you can't add attributes set within html via CSS. You can add to the html using the pseudo selectors :before and :after, but that's about it, plus they still aren't compatible across all browsers. If you really need to do this, I think you'd have to resort to Javascript.

通常,您无法通过CSS添加html中设置的属性。您可以使用伪选择器添加到html:before和:after,但这是关于它的,加上它们仍然不兼容所有浏览器。如果你真的需要这样做,我认为你不得不求助于Javascript。

#6


0  

You can use following CSS selector to style select items with the size attribute:

您可以使用以下CSS选择器来设置具有size属性的选项:

select[size]{
/*your style here */
}

#7


-2  

I do not believe this is possible no

我不相信这是不可能的