!important is not overriding inline CSS - css

I have some inline CSS I can't change
<span style = "color: #404040; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 17px;">
stuff
</span>
and it is overriding my external CSS. I tried putting !important
.product-description
{
font-family:wide latin !important;
}
but it had no effect
If I go to inspect element and delete the style attribute, my external CSS works

Update 1
OP mentioned they only have access to the CSS file.
In this case, you will need to change your CSS selector up a bit but is still doable. The example below has the class applied to the parent element of an element you'd like to change.
.change p {
color: pink !important;
}
<div class="change">
<p style="color: blue;">
This is some text.
</p>
</div>
You might have to get even more specific with your CSS selector if there are a lot of child elements to wade through when you hook into a CSS class selector. Try to hook into the CSS class selector that is the closest to the element you want to target.
.change div p:nth-child(2) {
color: pink !important;
}
<div class="change">
<p style="color: blue;">
This is some text.
</p>
<div>
<p style="color: green;">
This is some text.
</p>
<p style="color: orange;">
This is some text. (only change me)
</p>
</div>
</div>
Original Answer
My guess is that you're not applying the CSS class directly to the element you want changed as I do not see .product-description being applied to the example <span>.
Look at the two examples below.
I think you're attempting this one, class applied to outer element of the element you want changed. <p> would inherit the color of .change if <p> didn't have something with a higher specificity applied to it, like inline CSS or another CSS class.
Here we apply the class directly to the element we want changed, that way the specificity of !important can override the specificity of the inline CSS.
.change {
color: pink !important;
}
<!-- #1 -->
<div class="change">
<p style="color: green;">
This is some text.
</p>
</div>
<!-- #2 -->
<div>
<p class="change" style="color: green;">
This is some text.
</p>
</div>

Related

CSS - color direct text only/ do not inherit to other child - classes

I know similar questions have already been asked at least a dozens of times (at least I found a dozen of them), but none of the many answers I found solved my problem.
I just want to color the text which is directly(!) inside these <h3> tags:
<div class="page-header">
<h3> I want this green <div class="page-header-button-group">But not this</div></h3>
</div>
please note: I cannot change anything in the html. I tried this:
.page-header > h3:first-child{
color:green;
}
But it sadly is not doing what I need.
This should help you.
h3 {
color: green;
}
h3>* {
/* all children of h3 */
color: black;
}
<div class="page-header">
<h3> I want this green
<div class="page-header-button-group">But not this</div>
</h3>
</div>
The problem is, that the default value for color is not specified and its value is inherited from the parent (see w3schools). That means, since you specified a color for the <h3> and the <div> has no other color rules, it will inherit the color from its parent.
The only solution is to reset the color with an extra rule for each child. h3:first-child > * (any element which is a direct child of the h3).
.page-header > h3:first-child{
color:green;
}
.page-header > h3:first-child > * {
color: #000;
}
<div class="page-header">
<h3> I want this green <div class="page-header-button-group">But not this</div></h3>
</div>
If this is a common thing in your page, you may also think of a class, e.g.: .color-default { color: #000; } (propably adding !important). Then you can just define the div as <div class="default-color">.

Navbar logo link css

I am trying to make the "alt" text of the brand-logo and brand-logo-collapsed link white instead of the default blue like all the other ones. But am unable to figure out the proper css to specifically call that portion. Will someone please guide me in the correct direction.
<a href="#/" class="navbar-brand">
<div class="brand-logo">
<img src="#" alt="Dealer Tracking" class="img-responsive">
</div>
<div class="brand-logo-collapsed">
<img src="#" alt="Dealer Tracking" class="img-responsive">
</div>
</a>
CSS
a > navbar-brand > img {
color: #fff;
}
Your element with navbar-brand class is the same element as the anchor, so need to be treated as such in the CSS (be removing the space in between). Also classnames should be prepended with a ., and as you have a div in between the image and the anchor, it will break the rule, as > only selected direct descendants, so get rid of that:
a.navbar-brand img {
color: #fff;
}
Should get it working.
You can do this:
.brand-logo > img, .brand-logo-collapsed img{
color: white;
}
And if you want to to this for all of your images:
img{
color: white;
}

CSS3 - style part of div after <br /> tag

I have following div:
<div class="mydiv">
This is some introduction text
<br />
click me
</div>
Is it possible to style the click me differently than the rest of the div using CSS only?
You can style the :first-line differently. If there's only 2 lines, it's kind of feasible to style the 2nd and last line than the first one in pure CSS.
Codepen
BUT
you can't style every property (MDN)
being certain that a text will occupy exactly 2 lines would be ignoring narrow devices like smartphones (hello RWD) or zooming at the will of each user (graphical or text zooming). The web is not a PDF :)
+1 to Pevara suggestion: it should be a link or a button and then it can easily be styled
div {
text-transform: uppercase;
font-size: 2rem;
color: red;
}
div::first-line {
text-transform: initial;
font-size: 1rem;
color: initial;
}
<p>OK</p>
<div class="mydiv">
This is some introduction text
<br />
click me
</div>
<hr>
<p>#fail</p>
<div class="mydiv" style="width: 100px; border: 1px dotted blue">
This is some introduction text
<br />
click me
</div>
No, without modifying the HTML or using JavaScript there is no pure CSS way to select the text click me.

Can't change font family in boostrap "well" component

I have a well boostrap component containing some text
<div class="well well-sm" id="well_job">
<p>
<h5><%= "#{job.job_description}" %></h5>
</p>
<p>
<h6><%= "#{job.from_date} -" %></h6><h6><%= "#{job.to_date}" %></h6>
</p>
</div>
when I try to select it by one of its classes to change the font family it doesn't change(I tried to select it by .well-sm but nothing changes as well):
.well{
font-family: 'Rock Salt', cursive;
}
How can I select the well and change the font-size to its inside text?
First of all, your syntax is incorrect as you cannot place a header tag inside a paragraph tag. The following syntax
<p>
<h1>Some Header</h1>
</p>
will be interpreted by the browsers as
<p></p>
<h1>Some Header</h1>
</p>
and you will end up having an unexpected </p> end tag. Validating your html will lead to this error:
No p element in scope but a p end tag seen.
Back to your question, in case of using header tags you also need to specify a style targeting that specific header tag.
.well {
font-size: 14px;
}
.well h5 {
font-size: 24px;
}
Have you import the font into the tag <head>?
<link href='https://fonts.googleapis.com/css?family=Rock+Salt' rel='stylesheet' type='text/css'>
Then for change the font size:
.well{
font-family: 'Rock Salt', cursive;
}
.well p h5{
font-size:30px;
}
.well p h6{
font-size:20px;
}

CSS on hover effect not working

Why does the css :hover effect not work?
http://jsfiddle.net/t7on1k15/
body,html
{
font-family: courier;
height:100%;
min-width: 100%;
margin:0;
padding: 0;
}
#idDivBodyWrapper
{
margin:0;
padding:0;
height: 100%;
width: 100%;
background: lightgray;
}
#four:hover
{
color:black;
}
The HTML
<div id="idDivBodyWrapper" style="vertical-align:middle;">
<div style="position:absolute;display:block;float:left;left:0;Top:0"><button class="btn btn-default btn-lg" style="opacity:1;background:transparent;font-family:courier;font-weight:bold;" onclick="location.href='http://vqplan.com';"><i style="color:white;opacity:1;" class="fa fa-th fa-fw fa-5x"></i><br><span style="opacity:1;color:white">home</span></button></div>
<table style="width:100%;height:100%;background:black;clear:both;vertical-align:middle;text-align:center;"><tr><td>
<h1 id="four" style="font-size:10vh;color:white;">Code that lasts.<br><br><i id="one" class="fa fa-terminal fa-3x fa-fw" style="color:white;"></i></h1>
</td></tr></table>
</div><!--end idDivBodyWrapper-->
Here is one that does work:
http://jsfiddle.net/tuxdukz4/
CSS - CASCADING style sheets. You've got style="color:white" inside your h1#four element. That color:white is at a higher precedence level than your external style sheet rule, so color: white overrides the :hover style.
If you mod your fiddle and put color:purple into the h1's style= attribute, you'll get the exact same behavior: the hover won't work.
Because of CSS Specificity. I truly recommend you to read about it: http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
You have an element-level style color: white that overrides the hover effect.
Check this for a working one: http://jsfiddle.net/t7on1k15/1/
fiddle: http://jsfiddle.net/t7on1k15/2/
change the <h1 id="four" style="font-size:10vh;color:white;"> html to this:
<h1 id="four">Code that lasts.<br><br></h1>
and then add this css:
#four {
font-size:10vh;color:white;
}
your inline style has highest precedence over other css code.
I believe that putting the style inline ("style="font-size:10vh;color:white;") takes precedence over css. Inline style has higher priority. You actually couldn't style #four without hover in css if you use an inline style.

Resources