如何在GWT代码中将样式设置为重要?

时间:2011-04-10 10:34:52

标签: gwt coding-style

我需要在GWT代码中在运行时设置以下样式:

margin: 0 0 0 -6px !important;

我尝试过以下无效的方法:

Style style = htmlProductSearch.getElement().getStyle();
style.setProperty("margin", "0 0 0 -6px !important");

然而,当我从字符串中删除!important时,它可以工作..但我迫切需要使这种风格变得重要。

我也使用了setter方法setMarginxxxx,但也没有用。

感谢。

4 个答案:

答案 0 :(得分:4)

htmlProductSearch.getElement()。setAttribute(" style"," margin:0 0 0 -6px!important");
希望这应该有效。

答案 1 :(得分:1)

不是一个完美的解决方案,但您可以使用addStyleName添加css样式。

在此css样式中,您可以使用!important

我认为这将有效

答案 2 :(得分:0)

您可以使用elemental2

style.setProperty(propertyName, value, "important");

答案 3 :(得分:-1)

首先,我必须阻止你使用!important子句,因为它违背了相同的级联概念。

但是如果你没有其他选择,你可以让它去除速记风格。这应该适合你:

margin-left: -6px !important;
相关问题