【问题标题】:one :before psuedo element before four h1..?一:在四个h1之前的伪元素之前..?
【发布时间】:2014-11-25 22:25:24
【问题描述】:

对于我的生活无法让他工作 - 我尝试在 div 中的一组 h1 标签之前插入一个图标字体。我可以在每个 H1 标签之前获得一个图标字体,但这不是我想要的。重新迭代,在 div 之前有一个图标字体,而不是每个 h1。任何帮助将不胜感激。仅供参考 - H1 中的文本由 animate.css 淡入和延迟组成,因此有单独的 ID 和标签。

.container{
  position:;
  margin:0px auto;
  background-color:pink;
  width:100%;
  height:100%;
  overflow: hidden;
}

.motto-text {
  position:absolute;
  display: ;
  bottom:;
  left:;
}

#hero-text .motto-text:before {
  font-family: icomoon;
  content: "\e600"; 
  display:block;
  height:25px;
  width:25px;
  padding-right:3px;
  text-align: center;
  font-size: 3em;
  float: left;
  position: relative;
  color: white;
}​
<div class="container">
  <div id="hero-text" class="motto-text"><!-- Hero text to start-->
    <h1 id="delayedText1" class="animated fadeIn delay-1">Line 1</h1>
    <h1 id="delayedText2" class="animated fadeIn delay-2">Line 2</h1>
    <h1 id="delayedText3" class="animated fadeIn delay-3">Line 3</h1>
    <h1 id="delayedText4" class="animated fadeIn delay-4">Line</h1>
  </div>
</div>

【问题讨论】:

    标签: html css pseudo-element pseudo-class


    【解决方案1】:

    您有一个错误的选择器:#hero-text .motto-text:before 与您的标记中的任何元素都不匹配,因为它是一个子选择器。请改用#hero-text.motto-text:before 或只使用#hero-text:before。

    【讨论】:

    • 这也不起作用 - 我认为您的意思是删除类之间的空间,因为您的选择器是相同的..?
    • 选择器不一样。代码中的空格使选择器成为子选择器。因此有必要将其删除。如果这不能解决问题,那么您有 another 错误,从发布的代码中看不到。它可以是你的图标字体;您的代码实际上确实定义了它。首先用包含普通字符的content 属性进行测试,看看它确实显示出来了。
    • Icon 字体肯定可以工作 - 我可以在#hero-text 上方显示它,但之前不能。我还可以将 h1 添加到选择器,它会在每个 h1 选择器之前添加图标字体。我只是无法让它显示在#hero-text div 的前面
    • 问题中的代码在我的答案中修复后有效,并提供图标字体有效。如果事情对您不起作用,那么您有一些其他代码会导致问题,因此会出现另一个问题,您可能会将其作为新问题发布,并且有足够的代码来实际重现它。如果您这样测试此代码,您可以看到这一点。我还描述了如何更好地看到效果;您也可以考虑将颜色设置为红色而不是白色,以进行测试。
    • 新问题发布在这里:stackoverflow.com/questions/27144141/…
    猜你喜欢
    • 2016-08-14
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 1970-01-01
    相关资源
    最近更新 更多