Override CSS with fewer declarations - css

I'm trying to override the css from bootstrap.
I going to design the navbar without color.
.navbar-inner {
min-height: 40px;
padding-right: 20px;
padding-left: 20px;
background-color: #fafafa;
background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f2f2f2));
background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2);
background-image: -o-linear-gradient(top, #ffffff, #f2f2f2);
background-image: linear-gradient(to bottom, #ffffff, #f2f2f2);
background-repeat: repeat-x;
border: 1px solid #d4d4d4;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff2f2f2', GradientType=0);
*zoom: 1;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
}
with
.navbar-inner {
min-height: 40px;
padding-right: 20px;
padding-left: 20px;
}
I delete background color replacing it in the bootstrap .css.
Is it possible to just override it with another value?

Short Answer: YES
Long Answer Follows
The way CSS works is called specificity. There's is an order in which styles are applied to an element. Think of it as 4 separate numbers with the default value of each being 0. So 0,0,0,0 is the default
The first number represents inline styles
e.g., <span style="color: red">I'm Red</span>
The second number represents IDs
e.g., #IdSelector
The third number represents classes
e.g., .ClassSelector
The fourth number represents element and pseudo selectors
e.g., div and :first-child
These rules are applied in the order of internal style sheet first, external stylesheet second. If there's a rule defined ANYWHERE that applies to your element and you don't override it with a selector that has a higher specificity, then it will stay the same.
The following will override
.navbar-inner {
background-image: none;
}
Going back to specificity.
If your element is <div id="mainNav" class="navbar-inner"></div>
#mainNav {
background-image: none;
}
.navbar-inner {
background-image: url(img.png);
}
Then the image will be set to none. The ID selector has a specificity of 0,1,0,0 and the class sector has a specificity of 0,0,1,0.
Even if you added 11 classes the ID would still win, the specificity in that case would be 0,0,11,0
There is one last number, a hidden number. so 0,0,0,0,0 The one in front represents !important, which can be added after any style declaration to make it apply no matter what. If you have two conflicting declarations which have !important listed, it falls back to the order of inline vs. embedded vs. external. Generally you should avoid !important at most costs, except where it absolutely makes sense.
!important example that makes sense.
.hide {
display: none !important;
}

Related

Inherit and add value to multi-value CSS property?

As we all know, some CSS properties can have multiple values simultaneously. A good example is CSS3's box-shadow.
However, sometimes it may be desirable for a class or ID to add to these values. For example, if I have an element with an inset box-shadow value, I may want to add an outer glow to the box with an .active class. Unfortunately, this overwrites the previous value.
Is it possible to inherit a value and simultaneously add to it? Below is a non-working example of what I am hoping can be accomplished. Notice how the end-result does not glow.
div {
background-color: #09F;
border-radius: 10px;
box-shadow: 3px 3px 10px #FFF inset, -3px -3px 10px #00F inset;
height: 100px;
width: 100px;
}
div.active {
box-shadow: inherit, 0 0 10px #FF0;
}
<div class="active"></div>

Overwriting CSS classes and ids

I'm using the Gantry Framework for WordPress and I'd like to completely remove the formatting. For example, this is some of the styling applied to one of the positions.
#rt-top-surround {
background-color: #363636;
background-image: -moz-linear-gradient(top,#3b3b3b,#2e2e2e);
background-image: -webkit-gradient(linear,0 0,0 100%,from(#3B3B3B),to(#2E2E2E));
background-image: -webkit-linear-gradient(top,#3B3B3B,#2E2E2E);
background-image: -o-linear-gradient(top,#3b3b3b,#2e2e2e);
background-image: linear-gradient(to bottom,#3B3B3B,#2E2E2E);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3b3b3b', endColorstr='#ff2e2e2e', GradientType=0);
color: #ADADAD;
text-shadow: 0 2px 3px #000;
-webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 0 2px 4px rgba(0,0,0,0.4);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
border-bottom: 1px solid #000;
}
What I do to get rid of it (in the child style.css file) is the following:
#rt-top-surround {
background-color: #AAA89C;
background-image: none;
background-repeat: inherit;
filter: progid: none;
color: inherit;
border-bottom: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
text-shadow: none;
}
Is there a better way? Maybe a catch all way of removing the styling? I can't remove it from the main style.css file as any future updates would bring it back.
I'm fine with the way that I am handling it, I guess I'm just wondering if there is an easier way to overwrite styles like this?
EDIT
Seems to be some confusion, sorry for not being clear. I guess I'm looking for something like the CSS all shorthand property that resets all attributes. So instead of having to write out each attribute and set it to the default, I would only have to write
#rt-top-surround {
all: initial;
}
And that would save me a bunch of coding. I don't think this property is quite ready to go yet, though.
You should be able to create another style sheet and set it to take priority over all other style sheets. override.css Please see the link below; I would suggest option 2.
http://wordpress.org/support/topic/overriding-all-other-stylesheets
You can use "!important" property. For example ..
#rt-top-surround {
background-image: none !important;
}
This will override the main Stylesheet. You can place this into a separate override.css file.
Read about "!important" here: http://webdesign.about.com/od/css/f/blcssfaqimportn.htm

How to add new property within existing css?

I have two css file.I have a class following in one css below
input[type="submit"], input[type="button"], .butLink {
padding: 3px 9px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-khtml-border-radius: 3px;
border-radius: 3px;
-moz-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.3);
-webkit-box-shadow: inset 1px 1px 0 rgba(255,255,255,0.3);
box-shadow: inset 1px 1px 0 rgba(255,255,255,0.3);
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 12px;
font-weight: bold;
cursor: pointer;
color: #FFFFFF;
background: #A5BD24;
background: -moz-linear-gradient(top, #A5BD24 0%, #7DAC38 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#A5BD24), color-stop(100%,#7DAC38));
background: -webkit-linear-gradient(top, #A5BD24 0%,#7DAC38 100%);
background: -o-linear-gradient(top, #A5BD24 0%,#7DAC38 100%);
background: -ms-linear-gradient(top, #A5BD24 0%,#7DAC38 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a5bd24', endColorstr='#7DAC38',GradientType=0 );
background: linear-gradient(top, #A5BD24 0%,#7DAC38 100%);
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
border: 1px solid #781;
}
Now I want to change this style from another css file.I tried following below which isnt working -
input[type="submit"], input[type="button"], .butLink
{
background-color:#000 !important;
}
Any Idea?
Writing background will override previously defined properties.
Write:
input[type="submit"], input[type="button"], .butLink{
background:#000;
}
Try using the background rule instead of background-color, and make sure that your stylesheets are in the correct order in the <head> of your HTML. If they are in the correct order, the rule should not need the !important.
You can do it easily.
Option one: If you apply this css rule for the particular page so use internal css .Add this rule within the header tag like this
<style>
input[type="submit"], input[type="button"], .butLink
{
background-color:#000 !important;
}
</style>
It will perfectly works because internal css overwrite the external css rule.
Option two: If you apply this css rule for the all pages so use external css .Add this rule after the last css property:value;like this
color: #FFFFFF;
background: #A5BD24;
background:#000;/* This will overwrite with the previous background property value #A5BD24;
Hope the answer!

Multiple borders, with padding, around image

I want to create multiple border, with some padding, around my image like shown below. I prefer to do this with CSS only, but I don't know if this is possible.
While I googled for this I only found examples like this with multiple borders directly around the object using box shadow.
I tried creating this just using a border and padding around the image. But the padding didn't even worked out and with box-shadow like in the example above I won't get something like I want.
How would you guys handle this problem, and is it even possible?
Edit:
Sorry, forget to show what I've currently have: code pen link
Easy peasy!
Padding, border and couple of box-shadows will do the trick.
img {
border-radius: 50%;
padding: 3px;
border: 1px solid #ddd;
box-shadow: 0 0 0 7px #fff,
0 0 0 8px #ddd;
}
Fiddle
When devising your markup, if possible to use a bg image instead of an inline image element this is highly recommended. A couple reasons, but the 2 main ones are:
Inline img elements cannot use the css pseudo classes, :before and
:after
Inline images are harder to mask the corners when using border
radius, especially will be trickky with multiple borders.
Also, that means this design can be created entirely using one div. Here's how I would do it:
HTML
<div class="thumbnail"></div>
CSS
.thumbnail {
height: 50px; width: 50px;
border-radius: 50px;
background: url(http://www.tapdog.co/images/welcome/satelite-bg.jpg) no-repeat;
background-size: cover;
border: solid 1px #aaa;
box-shadow: 0 0 0 4px #eee, 0 0 0 5px #aaa;
}
The key point here is that you can create as many pseudo borders as you want with box-shadow. You can still add a real border using the border property, and then can go even further and add borders using the pseudo classes, which each can take their own border and box-shadow properties.
Another notable point here is the use of the background-size property, which can be very helpful in getting the image to scale proportionally when cut by the borders. especially when dealing with user generated images, or images of variable sizes. Should add vendor prefixes for cross browser compatibility
And here's a codepen with an example. http://codepen.io/anon/pen/dKxbh
this might help you refer this fiddle
.round{
width:150px;
height:150px;
border-radius:50%;
border:10px solid #fff;
background-color: #eaeae7;
-webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.2);
-moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.2);
box-shadow:0 1px 4px rgba(0, 0, 0, 0.2);
}
I think the link is exactly the right way to do this! I would use the box-shadows.
http://jsfiddle.net/chriscoyier/Vm9aM/
box-shadow:
0 0 0 10px hsl(0, 0%, 80%),
0 0 0 15px hsl(0, 0%, 90%);
Here is another example with box-shadows from Lea Verou.
http://lea.verou.me/css3-secrets/#multiple-outlines
you mean something like this:
jsFiddle
HTML:
<div class="container">
<div class="inner"></div>
</div>
CSS:
.container{
width:100px;
height:100px;
padding:10px;
background:white;
border:1px solid #555;
border-radius:50%;
}
.inner{
width:100%;
height:100%;
background:tomato;
border:1px solid #555;
border-radius:50%;
margin-top:-1px;
margin-left:-1px;
}
<div class="border"> bipin kumar pal</div>
.border {
border: 5px solid hsl(0, 0%, 40%);
padding: 5px;
background: hsl(0, 0%, 20%);
outline: 5px solid hsl(0, 0%, 60%);
box-shadow:
0 0 0 10px hsl(0, 0%, 80%),
0 0 0 15px hsl(0, 0%, 90%);
color:#fff;
}

How to style non text or anchor elements in the bootstrap navbar

I've figured out how to change background color of things such as the heading in the navbar along with the links but what about the rest of the bar? I'm talking about the area left and right of any links. I assume it's in the following code but I do not know what to edit as it isn't clear. Note: Changing background color has no effect. This is in the bootstrap.css. The color is currently black.
.navbar-inner {
min-height: 40px;
padding-right: 20px;
padding-left: 20px;
background-color: #8900ff;
background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f2f2f2));
background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2);
background-image: -o-linear-gradient(top, #ffffff, #f2f2f2);
background-image: linear-gradient(to bottom, #ffffff, #f2f2f2);
background-repeat: repeat-x;
border: 1px solid #d4d4d4;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff2f2f2', GradientType=0);
*zoom: 1;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);
}
The code below in my style.css has worked to color the background color for the links:
.navbar .navbar-inner .container .nav-collapse > ul > li > a {
background-color: #E89800;
}
Solved: What I had to do was get rid of the background image like so:
.navbar .navbar-inner {
background-color: #e89800;
background-image: none;
}
It set the background image of the navbar to none and I was able to change the background-color for the rest of the bar.
Response was found: Change background color in navbar fixed menu bar Bootstrap
There is a class that ships with bootstrap that is called .navbar-inverse
You can use that class there where you have .navbar (just add on so it looks more or less like navbar navbar-inverse
This will invert the white to black and it's something you can target easily to change as well.
Here is a JS fiddle using only stock bootstrap: Demo
As a final recommendation and to help you understand things better with the CSS in bootstrap. I recommend that you don't modify any bootstrap files and you instead use your own custom.css file (place it after the bootstrap CSS so it weights more) and do your modifications there. Read the bootstrap documentation, it's very short and simple to understand.
You can find the source of this information here: http://twitter.github.io/bootstrap/components.html#navbar , just look for the "Inverted variation" part of the documentation for the navbar and you should be good to go. It's also note worthy to say that there are more things that you can invert, such as buttons with btn-inverse so read the documentation a little more so you can engage in better and simpler programming with bootstrap.

Resources