【问题标题】:How to exclude specific the form from the css applied to body [duplicate]如何从应用于正文的css中排除特定的形式[重复]
【发布时间】:2016-05-08 09:14:36
【问题描述】:

如果我在正文中有一个具有特定样式的form,并且我想将此form 从该样式(正文样式)中排除。

<body>
    <form id="form1" runat="server">
        <div class="demo-containers">
            <div class="demo-container" id="decorationZone">
                <h4>Student Schedule</h4>

                <fieldset>
                    <legend>Registeration Number</legend>
                    <label for="<%= UsernameBox.ClientID %>" runat="server">RegNum:&nbsp;</label>
                    <asp:TextBox runat="server" ID="UsernameBox" Width="150px" TabIndex="7"></asp:TextBox>
                </fieldset>
            </div>
        </div>
    </form>
......
</body>

问题是:正文有一个css,我希望这种样式不应用于我的表单,

【问题讨论】:

    标签: javascript html asp.net css


    【解决方案1】:

    你可以覆盖你不想要的样式。假设您的身体有红色背景,所以在您的表单中只需将背景颜色覆盖为白色。我在下面创建了一个像这样的小演示。

    Demo

    body{
      background-color:red;
    }
    form{
      background-color:white;
    }
    

    在 CSS3 继承模块中有一个名为 all 的属性。它的工作原理是这样的:

    form {
      all: default;
    }
    

    【讨论】:

    • 我想覆盖一切,我是否应该为身体存在的每个人创建一个规则!
    • 是的,您必须为表单标签覆盖所有这些样式,或者您可以从正文标签中删除这些样式。
    • 我只是想从正文样式中排除表单!
    • 是的,您必须覆盖表单中的所有正文样式。
    • 这个问题回答了你的问题stackoverflow.com/questions/5080365/…
    【解决方案2】:

    您可以使用 CSS 否定并省略您不想从 body 继承的内容:

    body :not(form) { 
      background-color: red;
    }
    

    【讨论】:

      【解决方案3】:

      不幸的是,如果您在页面上应用正文样式,它将影响页面的所有元素。 我认为您只能在表单样式中重新定义身体的属性。 在 css 中,您应该恢复要从样式中排除的表单

      #form1
      

      你将不得不覆盖你不想要的 css 属性。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-17
        • 2013-02-22
        • 2016-10-16
        • 2020-04-07
        • 2011-12-28
        • 1970-01-01
        相关资源
        最近更新 更多