是不好使用!重要在css属性 [英] Is it bad to use !important in css property

查看:90
本文介绍了是不好使用!重要在css属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不太了解css和纯粹的 Java / J2EE 开发人员,但一些如何在一些 css 我无法解决

Not know much about css and purely a Java/J2EE developer but some how got strucked in some css puzzle which i am unable to solve

我使用一个带有一些Jquery灯箱效果的表单,它有一个 div id class

i was using a form with some Jquery light box effect which has a div with id and class

<div id="contact-container"
     class="myclass"
     style="z-index: 1002; height: 386px; width: 450px; position: fixed; left: 406.5px; top: 15%; ">

在我的css文件中,我看到以下条目

in my css file i saw the following entry

#contact-container {
    font: 16px/22px 'Trebuchet MS', Verdana, Arial;
    text-align:left;
    width:450px;
}

但是当此表单显示为jquery弹出窗口时, Mozilla,但在谷歌chrome和IE的盒子没有正确来到只有一些部分,并休息为滚动条。

but when this form was displayed as jquery pop-up it getting displayed properly in Mozilla but on Google chrome and IE the box was not coming properly like only some part of it and rest as a scroll bar.

当我看到它通过firebug时间:))它显示我像

when i saw it through firebug (used first time :)) it showing me something like

<div id="contact-container"
     class="myclass" 
     style="position: fixed; z-index: 1002; height: 67px; width: 450px; left: 406.5px; top: 15%;">

并且对于相同的设置它没有正确的IE和Mozilla,所以后大量的Goggling我做更改为 css

and for same settings it was not coming properly for IE and Mozilla so after lots of Goggling i did following changes to css

#contact-container {
    font: 16px/22px 'Trebuchet MS', Verdana, Arial;
    text-align:left;
    width:450px;
    height:380px !important;
}

我固定高度 height:380px!important ;

虽然这固定了我的问题,但不知道CSS我不知道这是否正确的方法,

though this fixed my issue but being no idea about CSS i am not sure if this was the right approach as i searched about height but it was not defined anywhere.

请建议我是否采用错误的方法

Please suggest if i have adopted a wrong approach

推荐答案

!important 是一个有用的工具,但缺点是它是一种最后的工具。所以你不想过度使用它,因为你会导致头痛的任何人维护网站的道路。

!important is a useful tool, but the drawback is that it's kind of a tool of last resort. So you don't want to over-use it as you'll end up causing headaches down the road for anyone that's maintaining the site.

但是,你的例子是一个典型使用。发生的是,JS正在注入内联样式属性。因此,这是超越的级联在你的CSS。 !important 可让您超越。

However, your example is a typical use. What is happening is that the JS is injecting inline style attributes on the fly. As such, that's over-riding the cascade in your CSS. !important allows you to over-ride that.

这篇关于是不好使用!重要在css属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆