css-specificity

CSS specificity, Media Queries and min-width

早过忘川 提交于 2019-11-27 12:39:32
I'm redesigning my blog with responsive web design in mind, and the "mobile first" method - In short I'm trying to use min-width to avoid any kind of replication or css.. no display:none's etc.. My problem is that when I do need to over-write a CSS value, the lower min-width takes precedence. Example: @media only screen and (min-width: 600px) { h2 { font-size: 2.2em; } } @media only screen and (min-width: 320px) { h2 { font: normal 1.7em/2.1em Helvetica, sans-serif; } } I'd expect when I'm in resolutions of 600px and above to get a 2.2em h2, but instead I get 1.7em.. In my Dev tools I see that

Change icon-bar (☰) color in bootstrap

故事扮演 提交于 2019-11-27 11:06:54
问题 I want to change ☰ color. HTML: <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#menu"> <span class="sr-only">Toggle menu navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> I tried various things (look bellow) but nothing works. CSS: .icon-bar { color: black; border-color: black; background-color: black; } 回答1: The reason your CSS isn't working is because of specificity. The Bootstrap

How do I give a CSS class priority over an id?

穿精又带淫゛_ 提交于 2019-11-27 09:21:42
I have a element like this: #idname{ border: 2px solid black; } .classname{ border: 2px solid gray; } <div id = "idname" class="classname">it is a test</div> I want to give a bigger priority to its CSS class instead of its CSS id. Is it possible? (In other word I want to set gray -color as its border ) Do not use !important because it is the worst solution, if you want to switch the styling then do it that way. #idname{ border: 2px solid black; } #idname.classname { border: 2px solid gray; } <div id = "idname" class="classname">it is a test</div> If you want to target also other elements with

Can type selectors be repeated to increase specificity?

喜欢而已 提交于 2019-11-27 09:17:22
The spec states regarding calculating CSS specificity: (bold mine) Note: Repeated occurrences of the same simple selector are allowed and do increase specificity. So for example .class.class {} has twice the specificity than .class {} - DEMO However, regarding the term ' simple selector ' the spec has this to say: (bold mine) A simple selector is either a type selector or universal selector followed immediately by zero or more attribute selectors, ID selectors, or pseudo-classes, in any order. So since the spec says that repeated occurrences of the same simple selector are allowed - this would

Is an attribute selector for the ID attribute less specific than an ID selector?

拟墨画扇 提交于 2019-11-27 08:19:35
问题 What do I need to do to give the [id^=value] selector the same specificity as a regular ID, and why isn't it equal or greater already? (considering that I gave it html as well) html div[id^="blue"] { background-color: blue } #blue4 { background-color: red } jsfiddle: http://jsfiddle.net/bjwe6yr0/1/ 回答1: An attribute selector will always be less specific than an ID selector; its specificity value does not change based on the attribute name. Selectors only maps specific attribute names to class

Why is the use of `!important` discouraged?

喜欢而已 提交于 2019-11-27 08:04:30
问题 Several answers tagged css discourage the use of !important in favor of specificity. Why? 回答1: There is actual math you can use to predict, control, and reverse-engineer the impact of CSS rules. By using !important you're breaking that. Look at this JS fiddle for example, which doesn't use !important : http://jsfiddle.net/hXPk7/ If you use Firebug or Chrome dev tools to inspect the title element where it says "Richard", you should see these rules, in this order: /**************************/ /

Overriding CSS properties for a specific html element

99封情书 提交于 2019-11-27 05:22:16
I have the following: <section class="main_section"> <article> ... </article> </section> In my stylesheet I have: .main_section article { background-color:#fff; /* ... */ } The article is styled, and I am happy about it. Now, for a single instance of article , I want to do the following: <section class="main_section"> <article class="special-bg"> ... </article> </section> Which I have defined: .special-bg { background-color: #276a7f; } But the class is not setting the background-color. It seems that the styling of the html tag article takes precedence, no matter the order of the CSS rules in

CSS specificity or inheritance?

醉酒当歌 提交于 2019-11-26 22:08:35
问题 I've looked at similar questions here but I haven't found one particular to my case. If I read this article correctly: http://css-tricks.com/specifics-on-css-specificity/ then what is happening doesn't make sense to me. Can someone explain if this is due to locality, inheritance or specificity please? I've stripped out all the unrelated css. CSS a:link {font-size:0.875em;color:#005984} .button {color:#fff} HTML <a class="button">Awesome call to action</a> I end up with a button that has blue

CSS :hover effect not working when I set an ID to the paragraph

只谈情不闲聊 提交于 2019-11-26 22:05:29
问题 I have the following css3 transition with ease effect: HTML <div class="button"> <a href="#" onMouseOver="clicksound.playclip()"></a> <p id="myId" class="top"></p> </div> CSS * { padding: 0; margin: 0; } .button { width: 180px; margin-top: 45px; } .button a { display: block; height: 40px; width: 180px; /*TYPE*/ color: black; font: 17px/50px Helvetica, Verdana, sans-serif; text-decoration: none; text-align: center; text-transform: uppercase; } .button a { background:url(http://imageshack.com/a

Can I override inline !important?

冷暖自知 提交于 2019-11-26 18:57:14
If you have <div style="display: none !important;"></div> Is there a way to override that in the style sheet to make it displayed? Preferably using something similar to this: div { display: block !important; } o.v. Let me begin by saying that generally inline styles can be overridden : .override {color:red !important;}​ <p style="color:blue;">I will be blue</p> <p style="color:blue;" class="override">But I will be red</p> Fiddled This behavior is described in W3 specs , where it is stated that !important declarations do not alter the specificity, but rather take precedence over "normal"