如何将嵌套的css类设置为CssResources

时间:2013-11-16 00:57:56

标签: css gwt

例如我有这个html div结构

<div class="parent">
   <div class="child1">
      <div class="child21"></div>
      <div class="child22"></div>
   </div>
</div>

和这些相应的类

.parent{ /*stuff*/}
.parent .child1{/*stuff*/}
.parent .child1 .child21{/*stuff*/}
.parent .child1 .child22{/*stuff*/}

那么如何在CssResource中为这些嵌套的div设置类名。我尝试了不同的组合,但没有人工作。我将展示一些不起作用的组合。

public interface CssStuff extends CssResource{
      public String parent();  // works

      Classname("parent child1")
      public String child1();   // dont work

      Classname("parent .child1 .child21")
      public String child21();   // dont work

      Classname("parent.child1.child22")
      public String child22();   // dont work
 }

我收到以下错误消息:

  

替换CSS类名     CSS文件中缺少以下混淆样式类:     parent .child1:通过添加.parent .child1 {}

进行修复

等等。

我的意思是这些类存在于CSS文件中。 那么什么是错的以及如何在CssResource中设置这些类?

2 个答案:

答案 0 :(得分:2)

嵌套的类名只是类名,所以只需将代码更改为:

public interface CssStuff extends CssResource{
  public String parent();
  public String child1();
  public String child21();
  public String child22();
}

您将获得这些类的模糊名称,以便在您的小部件中使用。

答案 1 :(得分:1)

我不确定如何使用GWT,但我确实知道每个例子中的“parent”都没有被称为类,因为它缺少“。”

要定位css选择器子项,它将是

.parent .child1
.parent .child1 .child21

如果您在DOM元素上有多个类,例如

<div class="parent child1">

结果选择器将是

.parent.child1

你的css示例中有正确的,但正如我之前所说,我不熟悉GWT。

相关问题