【问题标题】:HTML CSS: Is there a Useless tag which does nothing?HTML CSS:是否有无用的标签?
【发布时间】:2019-07-12 03:37:56
【问题描述】:

有没有办法创建一个无用的Html Tag,它什么都不做(不影响格式、内容、间距,更像是一个空标签?是span还是div?

我想在以下项目周围放置一个无用的标签。如果我在前后添加 span 或 div,它会在 Codepen 中向上移动项目。只寻找一个标签容器,而不是两个。

https://codepen.io/WebTesting41/pen/YoBmye

 <i class="material-icons" style="font-size:48px;">notifications</i>
 <i class="material-icons" style="font-size:48px;">delete</i>

代码:

.grid-container 
{
 display: grid;
 grid-template-columns: repeat(1, 50px);
 grid-template-rows: repeat(2, 50px);
 grid-gap: 1px;
 padding: 0px;
 align-items: center;
}
  
.material-icons
{
   text-align:center;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<div class="grid-container" id="gridid1556351f5ece4ee3a7dce6962be48e39" >
   <i class="material-icons" style="font-size:48px;">notifications</i>
   <i class="material-icons" style="font-size:48px;">delete</i>
</div>

【问题讨论】:

  • 你命名它们,span 和 div 是中性标签,一个是 inline 保存文本,另一个是 block 保存任何标签。您可能正在寻找跨度,但在屏幕上会看到 html 中的空白,否则单词会相互粘连。
  • span 和 div 在 codepen 中不断移动所有项目
  • 向上是什么意思?
  • 语义中立,但没有用处。如果您想添加额外的包装器,我不明白您所说的无用是什么意思,一定有某种用途吗?如果你包装 标签,那么它们不再是网格子元素,span 是单行,而不是两行。

标签: html css twitter-bootstrap


【解决方案1】:

分别用于两个元素。您对 codepen 中的两个元素都使用了一个跨度。我已经编辑了 html 文件。核实。希望对你有帮助。

.grid-container.toolsetbutton
{
 display: grid;
 grid-template-columns: repeat(1, 50px);
/*  grid-template-rows: repeat(2, 50px); */
 grid-gap: 1px;
 padding: 0px;
 align-items: center;
}
  
.material-icons.toolsetbutton
{
   text-align:center;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<div class="grid-container toolsetbutton" id="gridid1556351f5ece4ee3a7dce6962be48e39" >
   <span><i class="material-icons toolsetbutton" style="font-size:48px;">notifications</i>
   <i class="material-icons toolsetbutton" style="font-size:48px;">delete</i></span>
</div>

【讨论】:

  • 只寻找一个容器,而不是两个
  • @jerrythomas 我已经编辑了代码。我只是在 css 中注释掉“grid-template-rows: repeat(2, 50px);”属性。检查一下。
  • 不想影响css编辑,只找简单的html标签,好像html标签不支持无用标签,总是要编辑css
  • 如果我对跨度使用 css 属性可以吗? @jerrythomas
  • 如果没问题,那么在你的 CSS 中添加“span { margin-top: 50px; }”。 @jerrythomas
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-09
  • 1970-01-01
相关资源
最近更新 更多