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

override css style by another css style in gwt

我需要用 gwt 中另一个 css 文件的样式覆盖特定元素的 css 样式。

我试过下面的代码

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

警报来了。但风格并没有被覆盖。 css 代码是 .发送按钮{ 显示:块; 字体大小:16pt; color:red; } 。屁股{ 字体大小:32pt; visible:false; color:green; } 按钮字体为红色,但未更改为绿色。我也将此 css 包含在 html 文件中。

所以请告诉我如何在 gwt 中用另一个 css 文件的样式覆盖一个 css 样式。

提前致谢

如果这是您想要应用于所有按钮的样式,您可以覆盖 GWT 应用于所有按钮的样式:gwt-Button.

或者,尝试:

color: red !important;

或者更具体地使用您的 CSS 选择器,这样其他 CSS 规则就不会优先。

我假设 .gwt-button 和 .gwt-Button-selected 是您按钮的默认样式名称(由 GWT 提供)。

你可以像下面那样做。在这里我删除了一些 css 属性(所有属性在这里都是随机的)。您应该在 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;
    }

试试这个

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

setStyleName 清除对象的所有样式名称并将其设置为给定样式。