简体   繁体   English

主体部分上的CSS选择器

[英]css selector on the body section

Is it possible to add CSS selector inside the body section? 是否可以在主体部分内添加CSS选择器? Here is my code for example (but it doesn't work): 这是我的示例代码(但不起作用):

 <html> <head> </head> <body> <div style= "a[target=_blank] {background-color: yellow;}"> **css selector on this section <a href="http://test.com">test</a> <a href="http://test1.com" target="_blank">test1</a> <a href="http://test2.com" target="_top">test2</a> </div> </body> </html> 

No, you can not use selectors inside inline style. 不,您不能在内联样式中使用选择器。 the inline style will effect only on element that style tag located in. 内联样式仅会影响样式标签所在的元素。

It seems to work fine when using css in a style sheet. 在样式表中使用css时,似乎工作正常。

As far as I know inline styles only effect the element the style is on and so cannot be used to change another. 据我所知,内联样式仅影响样式处于启用状态的元素,因此不能用于更改其他样式。

 a[target=_blank] { background-color: yellow; } 
 <html> <head> </head> <body> <div> <a href="http://test.com">test</a> <a href="http://test1.com" target="_blank">test1</a> <a href="http://test2.com" target="_top">test2</a> </div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM