【问题标题】:css don't display text between html elements [duplicate]css不显示html元素之间的文本[重复]
【发布时间】:2019-01-10 10:37:38
【问题描述】:

设置

我有一段 HTML,看起来像,

<label for="offeringID_0">
        <input type="checkbox" name="offeringID[]" id="offeringID_0" class="active" value="4268" checked="checked">
        <span class="product-name">
            This product: JSDA JD6500                         
        </span>
        "-"
        <span class="price">
            <del>
                <span class="woocommerce-Price-amount amount">
                    # irrelevant span content
                </span>
            </del>
        </span>
    </label>

渲染得很好。


问题

是否可以使用 CSS 删除 "-"?我不知道该怎么做。

我已经在&lt;label for="offeringID_0"&gt; 元素上尝试了display:none;,但是没有显示元素内的任何内容。

【问题讨论】:

  • 谁在代码中添加了“-”?
  • 您可以将颜色设置为不同的标签和跨度以获得解决方案,但在 CSS 的帮助下无法删除代码
  • @Hkachhia,这个 WooCommerce 插件的开发者。

标签: html css


【解决方案1】:

font-size:0pxlabel 一起使用,如下所示

label {  
  font-size: 0;  
}
label>* {  
  font-size: 16px;  
}
label del{
  text-decoration:none;
}
<label for="offeringID_0">
    <input type="checkbox" name="offeringID[]" id="offeringID_0" class="active" value="4268" checked="checked">
    <span class="product-name">
        This product: JSDA JD6500                         
    </span>
    "-"
    <span class="price">
        <del>
            <span class="woocommerce-Price-amount amount">
                # irrelevant span content
            </span>
        </del>
    </span>
</label>

【讨论】:

  • 这似乎在某个地方!谢谢。尽管如此,我确实需要显示# irrelevant span content(我认为它与问题无关,我的错)。您知道如何调整代码以使其显示吗?如果有,是否需要知道无关内容的html?
  • 你想在没有换行的情况下显示“#无关跨度内容”吗?
  • 是的,没有直通
  • @LucSpan 检查更新的答案
【解决方案2】:

您不能使用 CSS 删除 "-",因为它不属于任何单独的元素。在标签{当前所在的位置}内,还有更多元素都会受到 css 的影响。 将"-" 放入span

<span class="removeThis">"-"</span>


.removeThis
{
display:none;
}



 or



label > .removeThis
{
display:none;
}

【讨论】:

  • 我认为他不想更改 html 中的任何内容,因为如果他这样做了,为什么不完全删除 "-",拥有它有什么意义?
  • CSS 以整个元素或其子元素为目标。我认为没有其他方法可以做到这一点。 CSS 用于样式而不是用于编辑内容。
【解决方案3】:

你不能单独管理“-”,因为它不是单独用 html 标签包裹的。也许您可以使用与背景匹配的颜色或其他一些技巧在视觉上隐藏它。但是你必须再次将反向 css 应用于跨度、输入等兄弟元素。

【讨论】:

    【解决方案4】:

    您可以通过将 - 放入跨度并添加此 css!

    希望这会有所帮助!

    span:nth-of-type(2) {
      display: none;
    }
    <label for="offeringID_0">
        <input type="checkbox" name="offeringID[]" id="offeringID_0" class="active" value="4268" checked="checked">
        <span class="product-name">
            This product: JSDA JD6500                         
        </span>
        <span>"-"</span>
        <span class="price">
            <del>
                <span class="woocommerce-Price-amount amount">
                    # irrelevant span content
                </span>
            </del>
        </span>
    </label>

    【讨论】:

    • 这不是他能改变的,他正在寻找替代方案。
    【解决方案5】:

    你不能真正删除它,但你可以隐藏它。 如果你将它的颜色与背景相同,并将 proice 稍微向左移动,它应该看起来像是被移除了。

    label{
      color: #FFFFFF;  /* make all label text white, hiding everything, including the dash */
    }
    
    label>*{
      color: #000000; /* revealing all elements except the dash */
    }
    
    label .price{
      margin-left: -20px; /* move the price slightly to the left, to accomodate for the hidden dash */
    }
    <label for="offeringID_0">
        <input type="checkbox" name="offeringID[]" id="offeringID_0" class="active" value="4268" checked="checked">
        <span class="product-name">
            This product: JSDA JD6500                         
        </span>
        "-"
        <span class="price">
            <del>
                <span class="woocommerce-Price-amount amount">
                    # irrelevant span content
                </span>
            </del>
        </span>
    </label>

    【讨论】:

      【解决方案6】:

      你不能删除它,但你可以破解它,如果你可以将它包装在一个跨度中,那么它很简单,请参见第二部分,或者 hacki 解决方案将字体大小更改为 0,然后恢复其他所有内容的字体大小。

      label {
        display: block;
        font-size: 0;
      }
      
      label * {
        font-size: 15px;
      }
      
      
      
      
      
      label .hide {
        display: none;
      }
      <label for="offeringID_0">
          <input type="checkbox" name="offeringID[]" id="offeringID_0" class="active" value="4268" checked="checked">
          <span class="product-name">
              This product: JSDA JD6500                         
          </span>
          <span class="hide">"-"</span>
          <span class="price">
              <del>
                  <span class="woocommerce-Price-amount amount">
                      # irrelevant span content
                  </span>
              </del>
          </span>
      </label>
      
      
      <label for="offeringID_0">
          <input type="checkbox" name="offeringID[]" id="offeringID_0" class="active" value="4268" checked="checked">
          <span class="product-name">
              This product: JSDA JD6500                         
          </span>
          "-"
          <span class="price">
              <del>
                  <span class="woocommerce-Price-amount amount">
                      # irrelevant span content
                  </span>
              </del>
          </span>
      </label>

      【讨论】:

      • 我认为,您应该在回答之前阅读 cmets 和其他答案
      • @JoykalInfotech 如果您提到我的答案是在我之前 1 分钟发布的其他答案的组合,那么抱歉我没有强制检查是否有人在我之前回答了
      • 不是你的答案是组合,而是你没有像其他人一样正确理解问题
      猜你喜欢
      • 1970-01-01
      • 2021-04-12
      • 2021-06-21
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多