代码之家  ›  专栏  ›  技术社区  ›  elbrant

我看到很多`<open></close>`标记集不包含任何数据,这不是否定了标记吗?

  •  -2
  • elbrant  · 技术社区  · 7 年前

    在回答问题的过程中,我注意到很多代码示例都显示了如下标记 <span></span>

    我意识到其中许多只是示例,但似乎也有很多人认为这样编写代码“没问题”。这是一件“事情”吗?

    1 回复  |  直到 7 年前
        1
  •  4
  •   Maarti    7 年前

    标签为人们在Web上看到的视觉内容提供方向或配方,它们可以通过CSS进行样式化、定向、修改、通过Javascript注入,因此即使它们是空的,也可以拥有一个实用程序,这取决于上下文。

    由于您没有提供任何特定的上下文,下面是一个只显示空文本和彩色形状的示例 <span> 标签:

    span{
      display:block;
      width:50px;
      height:50px;
      background-color:yellow;
      border-radius: 100%;
    }
    
    span:first-child{
      margin-top:20px;
      background-color:red;
    }
    
    span:last-of-type{
      background-color:green;
    }
    
    span:first-child::after{
      content: "Dare to say to this cute traffic light that he is pointless 😦";
      position:absolute;
      top:0;
    }
    span:first-child::before{
      position:absolute;  
      background-color:black;
      height:150px;
      width:50px;
      z-index:-1;
      content:"";
    }
    
    span:last-of-type::before{
      position:absolute;  
      background-color:black;
      height:150px;
      width:20px;
      z-index:-1;
      left:22px;
      top:150px;
      content:"";
    }
    <span></span>
    <span></span>
    <span></span>
    推荐文章