【发布时间】:2019-06-11 03:35:04
【问题描述】:
我正在使用 wp_editor 在我的 WordPress 网站上创建一个前端表单,用户可以使用该表单进行发布,而无需转到管理部分。它可以工作,但是因为他们可以剪切和粘贴到其中,所以他们可能会在其中复制内联样式,这将与网站的整体设计发生冲突。
为了解决这个问题,我用 clean 类将所有帖子封装在 div 中,这会去除任何潜在的内联样式:SCSS 代码如下:
.clean {
/*Stops inline styles overwriting when people cut and paste */
* {
font-color: inherit !important;
font-family: inherit !important;
font-size: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}
b, strong {
font-weight: bold !important;
}
p {
margin:0;
padding: .5em 0 !important;
-webkit-margin-before:0;
-webkit-margin-after:0;
}
}
但是,我知道在您的 css 中使用 !important 通常被认为是不好的做法,因此我正在寻找解决方法。这可以在 css 中完成吗?
【问题讨论】:
-
对于内联样式,不,没有其他办法,除了实际删除内联样式。或许你能找到一个去除内联样式的插件?
-
在用户发布垃圾 CSS 属性之前,是否很难去除内联样式?似乎最好在它们成为问题之前将其删除。