简体   繁体   English

在css中有没有办法清除所有font-family + font-size样式声明?

[英]Is there a way in css to clear all font-family + font-size style declarations?

I have a page which is a cms/wysiwyg/ms word nightmare. 我有一个页面,这是一个cms / wysiwyg / ms字噩梦。

It pulls many paragraphs of text from a database, some of which have retained ms word's bizarre html tags - including font declarations!!! 它从数据库中提取了许多段落的文本,其中一些保留了ms word的奇怪的html标签 - 包括字体声明! ahh! 啊!

In one sentence I can have things like: 在一句话中我可以有这样的事情:

<span style="font-family:Verdana">this is some</span>
<span style="font-family:arial">ugly text!</span>

I was wondering if there is a way of removing all font-family and font-size styles so they will adapt the master stylesheet css? 我想知道是否有一种方法可以删除所有font-family和font-size样式,以便它们适应主样式表css?

I'd prefer to not get into massive preg_replace conditions if I can avoid it. 如果我可以避免它,我宁愿不进入大规模的preg_replace条件。 Thanks 谢谢

CSS: CSS:

span {
    font-family: initial !important;
    font-size: initial !important;
}

Well, if you're getting inline styles in many places, I would add this to the body CSS 好吧,如果你在许多地方获得内联样式,我会将它添加到body CSS中

body {
     font-family: Arial, Helvetica, sans-serif !important;
     font-size: 16px !important;
 }

If you notice that all of the inline font styling are going on span s, you could target spans instead of the body. 如果您注意到所有内联字体样式都在span s,那么您可以定位跨度而不是正文。

I chose these two fonts because they are the "default" fonts for Windows and Mac/iOS. 我选择了这两种字体,因为它们是Windows和Mac / iOS的“默认”字体。 Of course you can choose your own font size. 当然,您可以选择自己的字体大小。 The only unfortunate part about this is if you want a different font and font size in other places you'll have to use more !important s. 唯一不幸的是,如果你想在其他地方使用不同的字体和字体大小,你将不得不使用更多!important s。

You can use the !important rule for this. 您可以使用!important规则。 But you will have to explicitly define each element you want it to go on (or use the universal selector * ) 但是你必须明确定义你希望它继续运行的每个元素(或使用通用选择器*

http://jsfiddle.net/b8RKm/ http://jsfiddle.net/b8RKm/

* { font-family: Tahoma, sans-serif !important; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式从样式属性中删除除 php 中的 font-family 之外的所有属性 - RegEx to remove all properties from style attribute except font-family in php 如何通过AJAX发送字体系列样式 - How to send font-family style via AJAX 如何获取已安装字体的CSS字体系列? - How to obtain the CSS font-family of installed fonts? 从CSS文件中提取@ font-face的font-family和font-weight - Extract font-family and font-weight of @font-face from a CSS file PHP:解析CSS文件,查找带引号的字体系列值,复制没有该带引号的字体的规则/选择器,将类添加到具有该字体名称的所有选择器 - PHP: Parse CSS file, find quoted font-family value, copy rules/selectors without that quoted font, add class to all selectors with that font name Dompdf 并设置不同的字体系列 - Dompdf and set different font-family 如何使用preg_replace php删除字符串中的字体家族样式? - How to using preg_replace php for remove font-family style in string? Mpdf - 当字体系列不可用时如何禁用后备字体 - Mpdf - how to disable a fallback font when font-family is not available 使用HTML / CSS内容将字符串中的字体大小加倍 - Double the font-size in string with HTML/CSS content 如何在phpStorm 8中更改字体大小的代码? - How to change font-size code in phpStorm 8?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM