简体   繁体   English

没有属性的 div 标签中的引用有什么作用?

[英]What does a reference inside a div tag without an attribute do?

I would like to start using Attribute Selectors in my css. I am seeing div tags that contain a reference WITHOUT any attribute statement like:我想在我的 css 中开始使用属性选择器。我看到包含引用但没有任何属性语句的 div 标签,例如:

<div class="container" data-footer>

All my searches (for the last hour) to find out how "data-footer" can be listed without the use of an attribute= (eg, id= or class= or etc.) have resulted in no information.我所有的搜索(最后一个小时)都没有找到任何信息,以了解如何在不使用 attribute=(例如,id= 或 class= 等)的情况下列出“data-footer”。 Dozens of SO and Google links without a single example of a reference inside a div tag without the use of an attribute.数十个 SO 和 Google 链接没有一个没有使用属性的 div 标记内的引用示例。 Because I do not know what this is (or what to call it) I'm probably not searching with the right keywords.因为我不知道这是什么(或如何称呼它),所以我可能没有使用正确的关键字进行搜索。 Is this a short-form way to pass an id or???这是传递 id 的简短方式还是???

Data- attributes without a value can be used as Boolean. For example:没有值的data-属性可以作为Boolean。例如:

if(div.hasAttribute('data-footer')) {
   // then do something
}

In css you can access it like:在 css 中,您可以像这样访问它:

div[data-footer] {

}

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

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