简体   繁体   English

您如何分别设置两个都需要jquery-ui.css的jQuery小部件的样式?

[英]How do you separately style two jQuery widgets that both require jquery-ui.css?

I have a page that I've designed which uses two commercial widgets both of which require the jquery-ui.css. 我有一个设计好的页面,它使用两个商业小部件,而这两个都需要jquery-ui.css。 When both widgets are on the page, one shows the .ui-slider .ui-slider-range correctly while the other one is absent. 当两个小部件都在页面上时,一个小部件会正确显示.ui-slider .ui-slider-range范围,而另一个小部件则不存在。 One widget uses the jquery-ui without modification while the other widget makes specific changes to the styling of .ui-slider .ui-slider-range. 一个小部件使用jquery-ui而不进行修改,而另一个小部件对.ui-slider .ui-slider-range的样式进行特定更改。 I assume I need to make one a separate class/id/element. 我假设我需要将一个单独的类/ ID /元素。 How do I do that when it is based on a specific library/template? 如果它基于特定的库/模板,该怎么办? I tried using !important but that just created other issues. 我尝试使用!important,但这只是造成了其他问题。

You are on the right track, you can use the console to try your styles. 您处在正确的轨道上,可以使用控制台尝试样式。

What im guessing is that you made changes in a class used by other widgets like .ui-widget, try to not mess with classes like .left, .container, or anything that looks like a generic name. 我的猜测是,您对其他控件(如.ui-widget)使用的类进行了更改,请尽量避免与.left,.container或类似通用名称的类混淆。

What you can do to specify the element you want to change is add a container with a different class, and then use it to access the widget classes: 您可以指定要更改的元素的方法是添加一个具有不同类的容器,然后使用它来访问小部件类:

<div class="myFirstContainer">
    // Here comes widget 1
</div>

<div class="mySecondContainer">
    // Here comes widget 2
</div>

Styles: 样式:

.myFirstContainer .ui-slider{
    background: red !important;
}

.mySecondContainer .ui-slider{
    background: blue !important;
}

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

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