gpt4 book ai didi

css - 使用css隐藏html中的部分文本

转载 作者:太空宇宙 更新时间:2023-11-04 04:16:38 26 4
gpt4 key购买 nike

当我有以下代码时,如何使用 css 隐藏 5000 和 5001 文本?

<div id="field-dishe" class="readonly_label">
5000&nbsp;&nbsp;&nbsp;家乡猪脚醋 或 秘制黄酒鸡 Pork Trotters in Sweetened Vinegar Or Chicken Stewed in Rice Wine<br>
5001&nbsp;&nbsp;&nbsp;椰香冷当雞 Rendang Chicken<br>
</div>

编辑:很难用 span 包装它,因为它们是由框架生成的。

最佳答案

仅使用 CSS,不使用 JavaScript,也不更改 HTML,如果没有像这样的丑陋技巧,很难做到这一点:

#field-dishe{
position: relative;
}
#field-dishe:before {
position: absolute;
width: 35px;
top:0;
bottom:0;
z-index:2;
background: white;
content:" "
}

Demonstration

我建议通过添加一些跨度或使用 JavaScript 来更改您的 HTML。这是一个 jQuery 示例:

$('#field-dishe').html(function(_,h){
return h.replace(/\d+/g,'');
});

Demonstration

关于css - 使用css隐藏html中的部分文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19834795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com