2015-02-24 63 views
0

我正在rails上開發一個ruby表單,並以這種形式使用滑塊(http://seiyria.github.io/bootstrap-slider/)。停止element.style來覆蓋我的css風格

的問題是,我有這個element.style覆寫我css這樣的:

對於存儲領域: enter image description here

當我添加動態的一個新領域: enter image description here

這是什麼element.style

爲什麼這個element.style覆蓋width

這個element.style width在第一種情況下的值爲0px,第二種情況下的值爲152px,我沒有意識到爲什麼。

任何幫助?

+3

你應該閱讀[CSS特異性](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)。 style屬性很可能是由javascript小部件添加的。你可能只能用不受歡迎的['!important'規則](http://www.w3.org/TR/CSS2/cascade.html#important-rules) – 2015-02-24 19:20:20

回答

1

!important添加到您不想覆蓋的規則。例如。 .slider.slider-horizontal {width: 210px}

(使用!重要的東西通常是不被接受的,因爲它最初可以啓用結構不良的CSS,然後繼續使您的樣式變得雜亂無章,因爲您開始必須使用更多!肯定有時候你只需要使用它)

+1

來覆蓋style屬性,參見http://stackoverflow.com/questions/7369216/how-do-you-read-important-in-css,http://stackoverflow.com/questions/3706819/what-are-the-implications-of-using-important-in-css,http ://stackoverflow.com/questions/5701149/when-to-use-important-property-in-css,http://stackoverflow.com/questions/2042497/when-to-use-important-to-save-the通過@cody通過@cody-as-working-with-css灰色評論http://stackoverflow.com/questions/9245353/what-does-important-in-css-mean – henry 2015-02-24 19:47:10