简体   繁体   English

如何在使用GWT-Bootstrap的GWT项目中应用自定义样式

[英]How Do I apply custom styles in a GWT project that uses GWT-Bootstrap

I am using a GWTBootstrap Modal for my project, the problem is that it's width is too narrow for my liking. 我正在为我的项目使用GWTBootstrap模式,问题是它的宽度太窄,不符合我的喜好。

I inspected the styles that it gets with firebug and saw this 我检查了它与firebug得到的样式,并看到了这一点

.modal {
background-clip: padding-box;
background-color: #FFFFFF;
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 6px 6px 6px 6px;
box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
left: 50%;
margin: -250px 0 0 -280px;
outline: medium none;
position: fixed;
top: 50%;
width: 560px;
z-index: 1050;
}

I went to the Webapp/css directory and made the following changes to the bootstrap.min.css 我转到Webapp / css目录并对bootstrap.min.css进行了以下更改

.modal {
width : 960px;
max-height : 960px;
}

But it gets overwritten by the gwt compiler. 但它会被gwt编译器覆盖。

Next I referred to this Created a css file custom-overrides.css 接下来我提到了这个创建了一个css文件custom-overrides.css

.modal {
    width : 960px;
    max-height : 960px;
}

and imported it like <stylesheet src="/custom-overrides.css" /> in my gwt.xml That doesn't work either, eclipse warns me that the file got changed or deleted upon compilation. 并且像我的gwt.xml <stylesheet src="/custom-overrides.css" />那样导入它。这也不起作用,eclipse警告我文件在编译时被更改或删除。

I have also tried making the same change in the UIBinder file where I create the modal. 我也尝试在创建模态的UIBinder文件中进行相同的更改。

<ui:style>
    .modal{
        width : 960px;
    max-height : 960px;
    }
</ui:style>

That doesn't work either. 这也行不通。 I'm baffled, what should I do to get my styles to be applied? 我很困惑,我该怎样做才能让我的风格得到应用?

It's a twitter bootstrap issue: the modal is not responsive. 这是一个Twitter引导问题:模态没有响应。

This should be fixed in Bootstrap 3.0. 这应该在Bootstrap 3.0中修复。

About solutions, as @mit said, it will work, but I have to warn you: it's not a good practice unless you know exactly what you're doing. 关于解决方案,正如@mit所说,它会起作用,但我必须警告你:除非你确切知道你在做什么,否则这不是一个好习惯。

I'll suggest you to add an ID to your modal, and write the CSS specific for it. 我建议你为你的模态添加一个ID,并为它编写特定的CSS。 This will evict mess with other modals. 这将驱逐其他模态的混乱。 As ID is more specific, you will not need to use !important also. 由于ID更具体,您也不需要使用!important

All 3 solutions should work. 所有3种解决方案都可行

  1. You can override the bootstrap.min.css but you have to do this in the gwt-bootstrap library itself because as you found out it get's overwritten when you compile your app. 您可以覆盖bootstrap.min.css但是您必须在gwt-bootstrap库本身中执行此操作,因为您发现它在编译应用程序时会被覆盖。
  2. You can also include a custom-override.css stylesheet but you have to make sure that it also overrides the .modal styles from the original bootstrap file. 您还可以包含custom-override.css stylesheet但必须确保它还覆盖原始引导程序文件中的.modal样式。 You can ensure that by adding !important to the overwritten css styles (i..e width : 960px !important; ) 你可以通过添加!important来覆盖css样式(i..e width : 960px !important;
  3. If you want to override the .modal class in your UiBinder file you have to use the @external annotation: 如果要覆盖UiBinder文件中的.modal类,则必须使用@external批注:

Something like this: 像这样的东西:

<ui:style>
    @external .modal;
    .modal{
        width : 960px;
        max-height : 960px;
    }
</ui:style>

But you might also have to add the !important rule to the styles 但您可能还需要将!important规则添加到样式中

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

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