简体   繁体   English

GWT按钮背景不起作用

[英]GWT button background not working

I am new to GWT/uiBinder (latest version of GWT and testing under latest Eclipse) and really puzzled. 我是GWT / uiBinder的新手(GWT的最新版本,并在最新的Eclipse下进行测试),并感到非常困惑。 My CSS for buttons is ... 我的按钮CSS是...

/* --button-- */
.gwt-Button {
    font-size: 16px;
    font-weight: normal;
    color: #0F0;
    background: #F00;    /* this gets ignored */
}

The background does nothing, the rest works. 后台不执行任何操作,其余操作正常。

I have tested that this CSS entry does something by changing the color and seeing that it works. 我已经测试过此CSS条目通过更改颜色并看到其有效而起作用。 I have also tried "background-color" (I have seen both in various docs). 我也尝试过“ background-color”(在各种文档中都见过)。 The background never changes. 背景永远不会改变。

I also tested a gwt-TextBox as follows and it works just fine. 我还如下测试了gwt-TextBox,它工作得很好。

/* --text box-- */
.gwt-TextBox {
    font-size: 16px;
    font-weight: normal;
    color: #0F0;
    background: Beige;
}

Note: I know that sometimes while testing you have to refresh the web page to see your changes. 注意:我知道有时候测试时必须刷新网页才能看到所做的更改。

Note: I can set the button background by using a CSS entry called "myButton" and using styleName='myButton' it in the uiBinder entry. 注意:我可以通过使用名为“ myButton”的CSS条目并在uiBinder条目中使用styleName ='myButton'来设置按钮背景。

Note: The button is in a Layer in a LayoutPanel in a north:DockLayoutPanel in an east:DockLayoutPanel. 注意:该按钮位于东部:DockLayoutPanel的north:DockLayoutPanel的LayoutPanel的Layer中。

Help! 救命!

https://stackoverflow.com/a/7833358/635411 https://stackoverflow.com/a/7833358/635411

You can use a more specific selector like the other answer suggests: 您可以像其他答案一样使用更具体的选择器:

/* --button-- */
button.gwt-Button {
    font-size: 16px;
    font-weight: normal;
    color: #0F0;
    background: #F00;
}

Personally, I try to avoid overwriting the default styles because of the precedence issues. 就个人而言,由于优先级问题,我尝试避免覆盖默认样式。

I think this should solve your problem 我认为这应该可以解决您的问题

.gwt-Button {
         font-size: 16px;
         font-weight: normal;
         color: #0F0;
         background: #F00 !important; 
}

You need to include this line before you make any changes to the background of gwt-Button 在对gwt-Button的背景进行任何更改之前,需要包括此行

background-image:initial !important;

The problem you're having is that you're trying to set a background color, when gwt-Button uses a background image, so the image goes over your background color, making it seem like your css is being ignored. 您遇到的问题是,当gwt-Button使用背景图像时,您试图设置背景颜色,因此该图像超出了背景颜色,从而使您的css似乎被忽略了。

there is a simpler way you need to remove the gwt-Button style and then add whatever color you like ` 有一种更简单的方法,您需要删除gwt-Button样式,然后添加所需的任何颜色`

Button button=new Button();
button.removeStyleName("gwt-Button");
button.getElement().getStyle().setbackgroundColor("#F00");
//incase you need to remove the default border style aswell
button.getElement().getStyle().setBorderStyle(BorderStyle.NONE);

` `

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

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