简体   繁体   English

CSS-是否有一个div html(在页面中)而没有页面的CSS规则

[英]CSS - Is it possible to have a div html (in a page) without css rules of the page

I'm facing an issue on my Liferay portal. 我在Liferay门户网站上遇到问题。

I have a web content with a text part saved as html. 我有一个网页内容,其文本部分另存为html。 In my jsp, i have : 在我的jsp中,我有:

 <div>${aWebContent.content}</div>

But the page include a css that is applied on all page (liferay theme) and i don't want this to be applied on my div. 但是该页面包含一个应用于所有页面(liferay主题)的css,我不希望将此应用于我的div。 Does a solution exist to do this ? 是否存在解决方案?

Thnaks ! na!

You can unset all style of an element by setting all property of CSS. 您可以通过设置CSS的all属性来取消设置元素的all样式。

.someDivClass{
  all: initial;
}

This will remove all applied CSS on this element either by its own or by its parent and will reset to initial value. 这将删除该元素本身或父元素对该元素应用的所有CSS,并将重置为初始值。

For more detail you can refer to - https://developer.mozilla.org/en-US/docs/Web/CSS/all 有关更多详细信息,请参阅-https://developer.mozilla.org/en-US/docs/Web/CSS/all

This property is not support in all browser, in order to find out the browser support you can follow this link - https://caniuse.com/#search=all 并非所有浏览器都支持此属性,要了解对浏览器的支持,您可以点击以下链接-https://caniuse.com/#search=all

One option is to embed your widget inside an iframe; 一种选择是将您的窗口小部件嵌入iframe中; as such, no styles from the surrounding document get inherited. 这样,周围文档中的样式都不会被继承。 This is the method used by many social widgets, such as share buttons, so that there isn't any style interference. 这是许多社交小部件(例如共享按钮)使用的方法,因此不会出现任何样式干扰。

There are CSS-only options beginning to be rolled out. 有仅CSS选项开始推出。 Safari supports: Safari支持:

.widget { all: revert; )

which does exactly what you're after. 这正是您所追求的。 There's greater support for: 对以下内容的支持更大:

.widget { all: initial; )

which is supported by all modern browsers (not Internet Explorer) but strips styles back beyond the browser defaults (eg <div> s will become inline), so you will have to add those back in - for example: 这是由所有现代浏览器(不是Internet Explorer)的支持,但剔除风格回超越浏览器的默认值(例如<div>旨意成为内联),所以你必须要添加这些回-例如:

.widget block { display: block; }

But at least you won't get style clash. 但是至少您不会遇到样式冲突。

https://developer.mozilla.org/en-US/docs/Web/CSS/initial https://developer.mozilla.org/en-US/docs/Web/CSS/initial
https://developer.mozilla.org/en-US/docs/Web/CSS/revert https://developer.mozilla.org/en-US/docs/Web/CSS/revert

While the other answers (all:initial) are good, here's another aspect : you might want to have some style, so you might as well have a more specific style in your theme. 尽管其他答案(全部:首字母缩写)都不错,但这是另一方面:您可能想要某种风格,因此您也可以在主题中使用更具体的风格。 Some browsers default to black on Grey, some black on white. 某些浏览器默认将灰色设为黑色,而某些则将白色设为黑色。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM