我有一個div.innerDiv
,它已被分配一個height: 300px !important;
在CSS文件中。我既不能更改現有的CSS文件,也不能添加新的類來覆蓋。由於樣式是!important
,所以它可以作爲inline
樣式被覆蓋,只有!important
。但它不會產生預期的效果。無法用!重要使用javascript覆蓋高度
參照演示here。
UPDATE: 我只需要內嵌風格。
HTML:
<div>
<div class="innerDiv">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
CSS:
.innerDiv {
height: 300px !important;
width: 150px;
border: 1px solid;
}
JS:
function overrideHeight() {
document.getElementsByClassName('innerDiv')[0].style.height = 400 + 'px !important';
}
overrideHeight();
可能重複[Overriding!important style](http://stackoverflow.com/questions/462537/overriding-important-style) – CBroe
@CBroe,Thankyou標記爲重複。但我想告訴你,在發佈這個問題之前,我做了一個徹底的研究。我之前瀏覽過指定的鏈接,在那裏它並沒有幫助我,它創建了一個新的樣式,我已經提到,我需要使用'內聯CSS'來解決。希望你讀過它。 – Shashank