我可以将CSS样式应用于元素名称吗

我可以将CSS样式应用于元素名称吗

本文介绍了我可以将CSS样式应用于元素名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个项目,我无法控制我应用CSS样式的HTML。和HTML没有很好地标记,在一个意义上没有足够的id和类声明来区分元素。



所以,我在寻找方式可以对没有id或类属性的对象应用样式。



有时,表单项有一个name或value属性:

 < input type =submitvalue =Goname =goButton>有没有一种方法,我可以应用基于name =goButton的样式?。



value是什么?



这是一种很难找到的东西,因为Google搜索会找到各种各样的实例,其中包含诸如name value将出现在网页中。



我怀疑答案是不是...但是有人有一个聪明的黑客?

$

解决方案

您可以使用属性选择器, code> input [name =goButton] {} 。请注意,它不支持在IE6。



更新:在2016年,你可以使用他们,因为IE6已经死了。




I'm currently working on a project where I have no control over the HTML that I am applying CSS styles to. And the HTML is not very well labelled, in the sense that there are not enough id and class declarations to differentiate between elements.

So, I'm looking for ways I can apply styles to objects that don't have an id or class attribute.

Sometimes, form items have a "name" or "value" attribute:

<input type="submit" value="Go" name="goButton">

Is there a way I can apply a style based on name="goButton"? What about "value"?

It's the kind of thing that's hard to find out because a Google search will find all sorts of instances in which broad terms like "name" and "value" will appear in web pages.

I'm kind of suspecting the answer is no... but perhaps someone has a clever hack?

Any advice would be greatly appreciated.

解决方案

You can use the attribute selector, input[name="goButton"] { }. Be aware that it isn't supported in IE6.

Update: In 2016 you can pretty much use them as you want, since IE6 is dead. http://quirksmode.org/css/selectors/

http://reference.sitepoint.com/css/attributeselector

这篇关于我可以将CSS样式应用于元素名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:33