Systematically resolve conflicting styles in css

后端 未结 4 1100
长情又很酷
长情又很酷 2021-02-20 04:31

I have some stylesheets from different sources in my web project. I want to harmonize them. Some styles I need from the one, some from the other. Is there a tool or method how

相关标签:
4条回答
  • 2021-02-20 04:47

    If you view the site in FireFox, and use the Firebug extension, you can then look at each element in your rendered page, and by using the "CSS" tab in firefox, you can see the cascade of style rules that are being applied to that element, and from what CSS source file each came from. It will show you what rules are being overridden, too.

    This is helpful in determining just where each particular rule is coming from, and what is being overridden.

    You still have the task of "rationalizing" your style sheets, and there may be other tools that can help in that.

    0 讨论(0)
  • 2021-02-20 04:50

    I threw together a quick script that can be helpful for detecting overlap of CSS rules from multiple sources: https://github.com/mgsloan/css-overlap

    As written it only works for stylesheets referenced by URL, but can very easily be adapted to handle inline stylesheets. It uses two regexes to split the stylesheets into two sets, and then scans every DOM node in your page looking for cases where some rules from both sets of stylesheets match.

    0 讨论(0)
  • 2021-02-20 04:57

    CSS doesn't have conflicts, it has cascades. The idea is that you CAN define multiple rules that apply to the same elements and the order in which you place the styles reflects an importance - i.e. if it appears last, it will override previous rules where there is something you describe as a conflict.

    You should either...

    1) Decide which style sheet is the most important and put it second

    OR

    2) Re-write your styles to avoid the mess

    OR

    3) Mark important rules as !IMPORTANT

    0 讨论(0)
  • 2021-02-20 04:59

    Have you tried this Firefox extension? Dust Me Selector http://www.brothercake.com/dustmeselectors/ It makes removing redundant styles much easier.

    Otherwise, I'd probably pop all the styles into one file, trying to group together similar rules, and then use Dust-Me to remove the unused ones.

    0 讨论(0)
提交回复
热议问题