【问题标题】:a tag inside div-classdiv-class 中的标签
【发布时间】:2017-02-28 21:24:53
【问题描述】:

我可以把<a href="#">test</a>放在<div class="test">里面

我很清楚<div class="test"> <a href="#">test</a> </div> 我对该代码的问题是 a 标记为我在 css 中留下了一些样式,我很乐意尽可能地缩小我的代码。

【问题讨论】:

  • 你如何在 div 中放置锚点?
  • 好吧,我不会问我是否知道没有其他方法......
  • 不,差不多了。

标签: html css class tags


【解决方案1】:

绝对!锚点没有理由不能驻留在 div 中:

<div class="test">
  <a href="#">test</a>
</div>

是完全有效的语法。

<body>
  <a class="test2" href="#">test</a>
</body>

也是完全有效的语法。

这实际上取决于您希望如何应用您的样式。您可以使用:

.test a {
  // Style the whole DIV, which can contain multiple <a> tags
}

或者:

.test2 {
  // Style the <a> tags that match the class `test2`.
}

希望这会有所帮助! :)

【讨论】:

  • OP 已经知道这是有效的语法。他正在寻找一些更短的替代方法。
  • 嗯。我没想过把课程放在锚里面。会试试看。
  • 谢谢 Obsidian Age :) 我刚刚删除了我的 CSS 中的 8 行。我想我只是在工作上眨了眨眼。
猜你喜欢
  • 1970-01-01
  • 2016-07-13
  • 2020-08-11
  • 2023-03-20
  • 2017-08-26
  • 1970-01-01
  • 1970-01-01
  • 2014-02-28
  • 1970-01-01
相关资源
最近更新 更多