简体   繁体   English

用gwt中的另一个CSS样式覆盖CSS样式

[英]override css style by another css style in gwt

I need to override css style for a particular element with another css file's style in gwt. 我需要在gwt中用另一个CSS文件的样式覆盖特定元素的CSS样式。

I have tried by the following code 我已经尝试过以下代码

    sendButton.addStyleName("sendButton");
    Window.alert("test");
    sendButton.addStyleName("butt");

The alert is coming. 警报来了。 but the style has not been overridden. 但是样式尚未被覆盖。 the css code is .sendButton { display: block; CSS代码是.sendButton {display:block; font-size: 16pt; 字体大小:16pt; color:red; 红色; } .butt{ font-size:32pt; } .butt {font-size:32pt; visible:false; 可见:假; color:green; 颜色:绿色; } the button font is in red colour only it is not changed to green. }按钮字体只有红色,不会更改为绿色。 i have included this css in html file as well. 我在HTML文件中也包含了此CSS。

so please tell me how to override one css style by another css file's style in gwt. 所以请告诉我如何在gwt中用另一个css文件的样式覆盖一个css样式。

Thanks in advance 提前致谢

If this is the style that you want applied to all buttons, you can override the style the GWT applies to all buttons: gwt-Button . 如果这是要应用于所有按钮的样式,则可以覆盖GWT应用于所有按钮的样式: gwt-Button

Alternatively, try: 或者,尝试:

color: red !important;

or be more specific with your CSS selector so that other CSS rules do not take precedence. 或更具体地讲您的CSS选择器,以便其他CSS规则不优先。

I am assuming the .gwt-button and .gwt-Button-selected are the default style names(provided by GWT) of you button. 我假设.gwt-button和.gwt-Button-selected是您按钮的默认样式名称(由GWT提供)。

You can do sth like below. 您可以像下面那样做。 Here I have removed some css properties(all properties are random here). 在这里,我删除了一些css属性(所有属性在这里都是随机的)。 You should write these css properties in your UIBinder. 您应该在UIBinder中编写这些CSS属性。

@external .gwt-Button;
    .gwt-Button {
      cursor: pointer;
      cursor: hand;
      color: #3e3e3e;
      font-weight: bold;
      text-align: center;
      background: white;
      margin-top: -6px;
      margin-top: -33px;
      margin-left: -1px;
    }
    @external .gwt-Button-selected;
    .gwt-Button .gwt-Button-selected {
      cursor: default;
      background: white;
    }

Try this 尝试这个

 sendButton.addStyleName("sendButton");
 Window.alert("test");
 sendButton.setStyleName("butt");

setStyleName Clears all of the object's style names and sets it to the given style. setStyleName清除对象的所有样式名称,并将其设置为给定样式。

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

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