html - 为什么附加文本的字体系列在可编辑的 div 中会发生变化?
问题描述
* {
font-family: sans-serif;
}
.sample {
font-family: monospace !important;
}
.sample>* {
font-family: monospace !important;
}
<div class="sample" contenteditable>
This is not inside span. <span>Go to the next line and append some text to see inconsistent effects.</span>
</div>
玩弄更多的编辑只会暴露更多的不一致。如何解决?如何将monospace
字体设置为里面的所有文本div
?我尝试删除!important
,但无济于事。
删除<span>
是一个选项,但我不能在我正在处理的原始项目中这样做,因为这些元素具有某些格式。我也不能删除*
规则声明,因为我想要sans-serif
div 之外的字体。很烦人,两者都解决了问题。还有什么办法吗?
解决方案
>
选择直系子女。创建新行时,您会注意到span
标签被包裹在div
.
相反,您可以尝试选择所有span
子元素.sample
:
* {
font-family: sans-serif;
}
.sample {
font-family: monospace !important;
}
.sample span {
font-family: monospace !important;
}
<div class="sample" contenteditable>
This is not inside span. <span>Go to the next line and append some text to see inconsistent effects.</span>
</div>
推荐阅读
- c# - 无法使用 System.Management 获取 azure vm 机器的已安装软件详细信息
- android - Android资源链接失败(未找到任何解决方案)
- sql - 在gridview中生成下拉字段,其中选项作为另一列中具有相同ID的列中的值
- c# - 使用 c# 将受密码保护的 Zip 文件转换为 Enc 文件
- azure - 使用 Azure SQLDW Polybase 使用 vnet 服务终结点从 ADLS Gen 1 引入数据
- c# - 在过滤器属性中使用 Autofac 进行属性/方法注入
- pentaho-spoon - 在 pentaho PDI V7 中未选中表输出中的“指定数据库字段”时,“列名无效”
- android - 在 Kotlin 中使 Android Lifecycle Observer 接收器不可为空
- php - PHP - 使用 dns_get_record() 验证 NS / DNS 服务器 Ip
- r - RSelenium 和网页抓取