简体   繁体   English

嵌入样式是否覆盖内联样式?

[英]Embedded style overriding inline styles?

So I have a button with embedded style and a function that changes the button's style via inline style to display:none. 因此,我有一个具有嵌入式样式的按钮,以及一个通过嵌入式样式将按钮的样式更改为display:none的函数。 Problem is the embedded style seems to be overriding the inline style. 问题是嵌入式样式似乎覆盖了嵌入式样式。 So, the questions are: 因此,问题是:

  • Aren't inline styles supposed to take precedence over embedded? 内联样式不是应该优先于嵌入式样式吗? Is there something wrong with my code?? 我的代码有问题吗?

If there isn't anything wrong with my code: 如果我的代码没有任何问题:

  • How do I get my inline code to override the embedded style? 如何获取内联代码以覆盖嵌入式样式?

HTML HTML

<div id="buttonDiv1" style="float:left;"><button id="btn1">Change units</button></div>
<div id="buttonDiv1" style="float:left; display:none;"><button id="btn2">Change units</button></div>
<div id="buttonDiv1" style="float:left; display:none;"><button id="btn3">Change units</button></div>
<input id="text" style="float:left;"></input>

<div onChange="jsfunction()">
<div style="float: left">Type: <select id="typeSelector">
  <option value="" disabled selected style="display:none;"></option>
  <option value="1">Instrumental Cables</option>
  <option value="2">Erected Piping Materials</option>
  <option value="3">Electric Cables</option>
</select>
    </div></div>

<div id="container" class="cont" style="min-width: 310px; height: 400px; max-width: 800px; margin: 0 auto"></div>

JS JS

    function jsfunction(){
//Get from user which chart to display
var val = document.getElementById("typeSelector");

if(val.value==1){
document.getElementById("btn1").style.display="block";
document.getElementById("btn2").style.display="none";
document.getElementById("btn3").style.display="none";
}
else if(val.value==2){
document.getElementById("btn1").style.display="none";
document.getElementById("btn2").style.display="block";
document.getElementById("btn3").style.display="none";
}
else{
document.getElementById("btn1").style.display="none";
document.getElementById("btn2").style.display="none";
document.getElementById("btn3").style.display="block";
}
}

JSfiddle to demonstrate the problem: http://jsfiddle.net/4T4pb/1/ JSfiddle演示该问题: http : //jsfiddle.net/4T4pb/1/

Edit: It appears there was a problem with my demo code so I affixed the actual code 编辑:看来我的演示代码有问题,所以我加了实际代码

function func(){
    document.getElementById("change").stlye.display="none !important";
}

I removed the excess div's and their float layout and used display: inline; 我删除了多余的div及其浮动布局,并使用display:inline; on your buttons, so they don't break the line: 在您的按钮上,这样它们就不会破线:

Sorry, have to paste html here, otherwise i can't link a fiddle: 抱歉,必须在此处粘贴html,否则我无法链接小提琴:

<button id="btn1">Change units</button>
<button id="btn2" style="display: none;">Change units</button>
<button id="btn3" style="display: none;">Change units</button>
<input id="text"></input>

http://jsfiddle.net/4T4pb/2/ http://jsfiddle.net/4T4pb/2/

That should be what you are looking for. 那应该是您要寻找的。

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

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