【问题标题】:How to access CSS Style Rules of MenuBar from Code - GWT如何从代码中访问 MenuBar 的 CSS 样式规则 - GWT
【发布时间】:2014-07-04 15:15:32
【问题描述】:

有没有办法编辑自定义的 css 类来启用这些 css 样式规则 http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/MenuBar.html

我目前通过以下代码创建了我的 MenuBar:

        MenuBar menuButton = new MenuBar();         
        menuButton.addStyleName(masterPanel.getmenuBar());

使用接口获取css类:

interface Style extends CssResource {
        String menuBar();
        String action();
    }

我有一个只能编辑我的菜单栏的 css 类:

.menuBar {
cursor: default; 
text-align: center;
background: transparent;
border: none;
color: white;
text-shadow: none;
font-size: 16px;    
}

有没有办法我可以访问如下样式:

.gwt-MenuBar-horizontal
.gwt-MenuBar-vertical
.gwt-MenuBar .gwt-MenuItem
.gwt-MenuBar .gwt-MenuItem-selected
.gwt-MenuBar .gwt-MenuItemSeparator
.gwt-MenuBar .gwt-MenuItemSeparator .menuSeparatorInner
.gwt-MenuBarPopup .menuPopupTopLeft

【问题讨论】:

    标签: java html css gwt


    【解决方案1】:

    首先,我将您的 css sn-p 添加到项目的 .css 中,并使用 menuButton.setStyleName("menuBar") 将其添加到菜单栏中。然后我将以下内容添加到项目 css 类中(作为示例):

    .gwt-MenuItem-selected 
    {
    color:red !important; 
    }
    

    现在第一个 menuBar 样式已启用,并且附加样式也已设置。必须使用 !important 来覆盖默认属性。

    【讨论】:

    • 如果我的 css 位于 UiBiner xml 文件中,它还能工作吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 2021-11-24
    • 2011-05-15
    • 2020-08-06
    • 2014-11-23
    • 1970-01-01
    相关资源
    最近更新 更多