简体   繁体   English

内联时保证金正常工作,但在CSS规则中不起作用

[英]Margin works normally when inline but doesn't work in css rules

When I write something like: 当我写类似的东西时:

<table style="margin-left: 30px;" >
</table>

or: 要么:

<div style="margin-left: 30px;">
            <h:commandButton value="add" action="a"></h:commandButton>
            <h:commandButton value="cancel" action="b" immediate="true"></h:commandButton>
</div>

The margin shows up properly. 边距显示正确。

But when I write: 但是当我写:

<table class="marg" >
</table>

or: 要么:

<div class="marg">
    <h:commandButton value="add" action="a"></h:commandButton>
    <h:commandButton value="cancel" action="b" immediate="true"></h:commandButton>
</div>

With this rule: 使用此规则:

.marg {
    margin-left: 50px;
    margin-top: 30px; 
}

HTML generated code: HTML生成的代码:

<table class="marg">
</table>
<div class="marg">
<input id="j_id1109917403_4227fec1:j_id1109917403_4227feb3" type="submit" value="add" name="j_id1109917403_4227fec1:j_id1109917403_4227feb3">
<input id="j_id1109917403_4227fec1:j_id1109917403_4227feae" type="submit" value="cancel" name="j_id1109917403_4227fec1:j_id1109917403_4227feae">
</div>

The table and button display without margin. 表格和按钮显示为无边距。 Why ? 为什么呢

  1. Test if the CSS rule is applied by adding a background-color : 通过添加background-color测试是否应用了CSS规则:

     .marg { margin-left: 50px; margin-top: 30px; background-color: pink; } 
  2. If yes, then add !important to your existing instruction for testing purpose: 如果是,则在您现有的说明中添加!important以进行测试:

     .marg { margin-left: 50px !important; margin-top: 30px !important; background-color: pink; } 
    1. Look in Firebug/Inspector which rules are applied; 查看Firebug / Inspector中适用的规则; if there are many declarations, which one has an !important modifier or has more specificity than others or comes last and is finally applied. 如果有很多声明,则其中一个具有!important修饰符,或者具有比其他声明更具体的声明,或者最后声明并最终应用。

Is your CSS applied? CSS是否适用? Does !important change something? !important更改吗? What do you see in Firebug? 您在Firebug中看到了什么? Come back with a fiddle (without CSS reset!) if you still have a problem: HTML and CSS code can help us to understand your problem; 如果您仍然有问题,请来个小提琴(无需重置CSS!):HTML和CSS代码可以帮助我们了解您的问题; back-end code that generates HTML doesn't 生成HTML的后端代码不会

Oh, please sorry, it was my very stupid mistake. 哦,对不起,这是我非常愚蠢的错误。 I forget to add in HTML : 我忘了添加HTML:

<link rel="stylesheet" type="text/css" href="style/myCSS.css"   media="all" />

I thought that I added it. 我以为我添加了它。

.marg css类的左边距设置为50px,这与属性内部的设置为30px不同。

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

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