Square brackets in CSS [duplicate]

2019-09-18 20:38发布

This question already has an answer here:

What does it mean when something between square brackets in CSS? E.g.

input[type="radio"]

标签: html css forms
4条回答
Root(大扎)
2楼-- · 2019-09-18 20:44

Square brackets are attribute selector syntax.

Your (complete) example means "Select elements of type input which have a type attribute with the value radio" e.g. <input type="radio">

查看更多
我只想做你的唯一
3楼-- · 2019-09-18 20:51

It's a attribute selector in CSS

E[foo="warning"] Matches any E element whose "foo" attribute value is exactly equal to "warning".

more on http://www.w3.org/TR/CSS2/selector.html

查看更多
We Are One
4楼-- · 2019-09-18 20:56

This is a CSS attribute selector that will only select inputs with the type set to radio, that is, it will select all of the radio buttons. Here's an article explaining it a bit more.

查看更多
等我变得足够好
5楼-- · 2019-09-18 20:58

This is an attribute selector. It selects elements that have the specified attribute. You can find out more about them here: https://developer.mozilla.org/en-US/docs/CSS/Attribute_selectors

In your example: input[type="radio"]

This would match an element that looked like this:

<input type='radio'>

The selector you've given in the question means it would need all three words: The element name 'input', the attribute 'type' and the value for that attribute being 'radio'.

Browser compatibilty: This is a standard selector that is available in all browsers in common use. The only browser you may need to worry about that doesn't support it is IE6. See here for compatibility charts for this and other CSS selectors.

Hope that helps.

查看更多
登录 后发表回答