【问题标题】:Create custom tags html创建自定义标签 html
【发布时间】:2021-10-14 23:47:29
【问题描述】:

我想在 html 中创建自定义标签来做一些事情,比如有没有办法将 html 和 css div 转换为标签?

.me {
  width: 100px;
  height: 100px;
  background-color: red;
}
<div class="me"></div><br>
<p>Make the above div a "redbox" tag or something</p>

【问题讨论】:

标签: html css


【解决方案1】:

你可以这样:

redbox {
  display: block;
  width: 100px;
  height: 100px;
  background-color: red;
}
<redbox></redbox>
<!-- OR -->
<redbox />

你可以像这样传递属性:

redbox {
  display: block;
  width: 100px;
  height: 100px;
  background-color: red;
}

redbox[center] {
  margin: auto;
}
&lt;redbox center/&gt;

redbox {
  display: block;
  width: 100px;
  height: 100px;
  background-color: red;
}

redbox[align="center"] {
  margin: auto;
}
&lt;redbox align="center" /&gt;

【讨论】:

  • 有什么办法可以传递参数,所以看起来像&lt;redbox center/&gt;
  • @CrimsonX 我已经更新了答案,这是你想要的吗?
  • 是的,这确实有帮助。
猜你喜欢
  • 2011-03-14
  • 2012-02-29
  • 1970-01-01
  • 2011-08-06
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-09
相关资源
最近更新 更多