GWT - TabLayoutPanel 样式问题

发布于 2024-10-24 12:18:48 字数 917 浏览 1 评论 0原文

我想使用 TabLayoutPanel 实现水平导航栏,并使用自定义样式来满足我的需求。

但我不知道如何覆盖 default 样式。这是 UiBinder 模板:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
  xmlns:g="urn:import:com.google.gwt.user.client.ui">
  <ui:style>
    .gwt-TabLayoutPanel .gwt-TabLayoutPanelHeader {
      background-color: red;
      padding: 0;
      margin: 0;
    }
  </ui:style>
  <g:TabLayoutPanel barHeight="3.75" barUnit="EM">
    <g:tab>
      <g:header>Latest</g:header>
      <g:Label>Latest Activities</g:Label>
    </g:tab>
    <g:tab>
      <g:header>Patients</g:header>
      <g:Label>Patients</g:Label>
    </g:tab>
  </g:TabLayoutPanel>
</ui:UiBinder>

这不起作用。但是我如何引用默认样式呢?

I want to implement a horizontal navbar using a TabLayoutPanel, using custom styling to fit my needs.

But I don't know how to override the default styling. Here's the UiBinder template:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
  xmlns:g="urn:import:com.google.gwt.user.client.ui">
  <ui:style>
    .gwt-TabLayoutPanel .gwt-TabLayoutPanelHeader {
      background-color: red;
      padding: 0;
      margin: 0;
    }
  </ui:style>
  <g:TabLayoutPanel barHeight="3.75" barUnit="EM">
    <g:tab>
      <g:header>Latest</g:header>
      <g:Label>Latest Activities</g:Label>
    </g:tab>
    <g:tab>
      <g:header>Patients</g:header>
      <g:Label>Patients</g:Label>
    </g:tab>
  </g:TabLayoutPanel>
</ui:UiBinder>

This doesn't work. But how can I reference the default styles?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

月竹挽风 2024-10-31 12:18:48

为了详细说明 atamur 的答案,他建议的第二个选项实际上是两个选项中更好的一个,特别是如果您所有其他样式都是使用 UiBinder 或客户端捆绑包设置的。基本上,您可以在初始 标记下方添加以下行:

@external .gwt-TabLayoutPanel .gwt-TabLayoutPanelHeader

问题是 GWT 混淆了您在 UiBinder 模板中定义的样式规则。因此,当您编写“gwt-TabLayoutPanel”时,它会被混淆为“GMDW0RHDH”之类的内容,然后它永远不会应用于 TabLayoutPanel 的元素。添加“@external”会禁用这种混淆,并允许按照您的预期应用 UiBinder 中的样式。

To elaborate on atamur's answer, the second option he suggests is really the better of the two, especially if all your other styles are set using UiBinder or client bundles. Basically, you add the following line below your initial <ui:style> tag:

@external .gwt-TabLayoutPanel .gwt-TabLayoutPanelHeader

The problem is that GWT is obfuscating the style rules you define in your UiBinder template. So when you write "gwt-TabLayoutPanel", that gets obfuscated to something like "GMDW0RHDH", which is then never applied to the elements of your TabLayoutPanel. Adding "@external" disables this obfuscation, and allows the styles in UiBinder to be applied as you'd expect.

新一帅帅 2024-10-31 12:18:48

附加一个单独的CSS,我认为 - 内联样式可与同一模板中的 {style.xyz} 一起使用。其实还有第二种解决方案。如果您坚持将其放在 ui.xml 中 - 使用外部作用域:http ://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#External_and_legacy_scopes

attach a separate css i think - inline styles are for use with {style.xyz} in the same template. Actually there's a second solution. If you insist on having it in the ui.xml - use external scope: http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#External_and_legacy_scopes

执手闯天涯 2024-10-31 12:18:48

或者您可以简单地将 !important 添加到您的样式定义中...

Or you could simply add !important to your style definitions...

GRAY°灰色天空 2024-10-31 12:18:48

经过一番研究后,我使用了下面的方法并且它有效...我正在使用 GWT 2.5

/**the panel itself**/
.gwt-TabLayoutPanel {
    border: none;
    margin: 0px;
    padding: 0px;
}
/**the tab bar element**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTabs {
    background-color: #F4F4F4 !important;
}
/**an individual tab**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTab {
    background-color: #6F6F6E !important;
}

.gwt-TabLayoutPanel .gwt-TabLayoutPanelTab-selected {
    background-color: white !important;
}
/**an element nested in each tab (useful for styling)**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTabInner {
    font-family: Arial !important;
}

/**applied to all child content widgets**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelContent {
    border: none;
    margin: 0px;
    overflow: hidden;
    padding: 15px;
}

after some research i used the below approach and it worked...i am using GWT 2.5

/**the panel itself**/
.gwt-TabLayoutPanel {
    border: none;
    margin: 0px;
    padding: 0px;
}
/**the tab bar element**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTabs {
    background-color: #F4F4F4 !important;
}
/**an individual tab**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTab {
    background-color: #6F6F6E !important;
}

.gwt-TabLayoutPanel .gwt-TabLayoutPanelTab-selected {
    background-color: white !important;
}
/**an element nested in each tab (useful for styling)**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTabInner {
    font-family: Arial !important;
}

/**applied to all child content widgets**/
.gwt-TabLayoutPanel .gwt-TabLayoutPanelContent {
    border: none;
    margin: 0px;
    overflow: hidden;
    padding: 15px;
}
別甾虛僞 2024-10-31 12:18:48

如果你想查看 GWT css 文件是如何声明的:

  1. 打开 gwt-user.jar
  2. 找到主题包,即:Clean Theme 的 com.google.gwt.user.theme.clean,以及打开 public/gwt/clean/clean.css。
  3. 查找 .gwt-TabLayoutPanel 并了解其声明方式。
  4. 制作您自己的 css 文件并在 your_module.gwt.xml 中声明它。

如果需要,您可以更改主题。

If you want to see how GWT css file is declare:

  1. Open gwt-user.jar
  2. Find the package of the theme, ie: com.google.gwt.user.theme.clean for Clean Theme, and open public/gwt/clean/clean.css.
  3. Find how .gwt-TabLayoutPanel and see how it's declared.
  4. Make your own css file and declare it in the your_module.gwt.xml

You can change the theme if you want.

那小子欠揍 2024-10-31 12:18:48
<ui:style>
    @external onMouseOverBorderColor onMouseOutBorderColor;
    .onMouseOverBorderColor {border-color: red; border-style: outset}
    .onMouseOutBorderColor {border-color: black; border-style: outset}
</ui:style>
<ui:style>
    @external onMouseOverBorderColor onMouseOutBorderColor;
    .onMouseOverBorderColor {border-color: red; border-style: outset}
    .onMouseOutBorderColor {border-color: black; border-style: outset}
</ui:style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文