Specificity when overriding bootstrap using less - html

I am customizing bootstrap using less. I want to add a shadow to the .navbar.
My solution is as follows:
//Import of bootstrap core navbar - second as to save specificity
#import "bootstrap/navbar.less";
//Overrides:
.navbar {
position: relative;
min-height: #navbar-height; // Ensure a navbar always shows (e.g., without a .navbar-brand in collapsed mode)
margin-bottom: #navbar-margin-bottom;
border: 1px solid transparent;
border-bottom: 1px solid #FFF;
-moz-box-shadow: 0px 3px 10px #888;
-webkit-box-shadow: 0px 3px 10px #888;
box-shadow: 0px 3px 10px #888;
//Prevent floats from breaking the navbar
&:extend(.clearfix all);
#media (min-width: #grid-float-breakpoint) {
border-radius: #navbar-border-radius;
}
}
This way I do not modify bootstraps original source, and it will be easy to update bootstrap, however the new navbar class receives higher specificity than all bootstrap classes. So the following:
<div id="navigationbar" class="navbar navbar-default navbar-static-top" ng-cloak ng-controller="NavController">
The navbar border-radius will override navbar-static-top an the result is round corners.
If i import the bootstrap/navbar.less after I define my own class it does work. But is there a better solution?

I wonder if your problems really have to do with CSS specificity.
You Less code will be read from top to bottom (only for variables last declaration wins).
Bootstrap defines the .navbar class first and than the style classes (.navbar-default) and position classes (.navbar-static-top).
When the .navbar-default override some styles of the .navbar class you undo this overrides by defining the .navbar class again after .navbar-default.
As far as i understand you only need the following Less / CSS code:
.navbar.navbar-default {
-moz-box-shadow: 0px 3px 10px #888;
-webkit-box-shadow: 0px 3px 10px #888;
box-shadow: 0px 3px 10px #888;
}
Demo: http://www.bootply.com/VhEmBcAYhY
Cause the Bootstrap navbar classes do not declare the box-shadow property at all, you can add this code anywhere in your Less code.
Good location you this code seems at the end of bootstrap.less or even navbar.less. Or create a custom.less file and import that at the end of bootstrap.less.

The easiest thing I've found, and this is what we do where I work, is to NOT use the Bootstrap LESS files, and instead using the minified CSS. Since you're ONLY overwriting Bootstrap styles, NOT changing the source styles, it will make it much easier.
With LESS, since you are nesting styles within styles, you'll find that if the styles aren't nested exactly as Bootstrap has them (since you're trying to override them), that their styles may be more specific, and therefor take precedence over your styles.

Related

Angular Material ng-tns class changes margin of items in my table, can use CSS to change the margin but then another variant of ng-tns is applied?

I have an angular project where I'm using Angular Material and material table.
It seems that all the text in my table has the 10px margin top and bottom applied due to a class named something like: .ng-tns-c5-1 or .ng-tns-c6-1 etc.
I can't find a way to change those margins without inspecting element, finding that class and then using CSS to change that margin.
But after some changes to other elements on the app, the .ng-tns-c6-1 (for example) is changed to something like: .ng-tns-c4-0 and then I have to change that. The problem is I've done this 5-6 times now and it's a complete pain.
Because of that the table has a lot of useless white space and just overall makes things look bad.
What is that class and what can I do to make sure the margin remains at the 2-3px I'm setting?
This is the type of thing I have in my CSS:
.ng-tns-c5-1 {
margin-top: 2px !important;
margin-bottom: 2px !important;
}
.ng-tns-c5-0 {
margin-top: 2px !important;
margin-bottom: 2px !important;
}
.ng-tns-c6-1 {
margin-top: 2px !important;
margin-bottom: 2px !important;
}
.ng-tns-c4-0 {
margin-top: 2px !important;
margin-bottom: 2px !important;
}
You can use the following to select all the current and future elements.
[id*='ng-tns-c'] {
}

Can I just use Bootstraps components and not layout system

My web application doesnt currently use Bootstrap or any other framework. I am now looking at making it more polished and realizing that the effect I want to achieve is quite Bootstrap like (i.e rounded buttons).
So if I now add Bootstrap to my website I have two questions
Will it leave my website unchanged until I start referring to Bootstrap components.
Can I use Bootstrap components without have to use the Bootstrap grid system
Can I override Bootstrap using CSS or do I have to use LESS which I dont understand
Q 1. Will it leave my website unchanged until I start referring to Bootstrap components.
Ans: Its totally depends on what classes, you have used in your HTML.
For example if you have used class="btn" and then add bootstrap to your app, it will defiantly try to override the CSS, because Bootstrap has that class defined in its css file.
Q 2. Can I use Bootstrap components without have to use the Bootstrap grid system.
Ans: You can use Bootstrap components without using its Bootstrap grid, but if you are using bootstrap best is it properly,
Because Grid system is something which provide your web app responsiveness.
Q 3: Can I override Bootstrap using CSS or do I have to use LESS which I dont understand
Ans: Yes you can.For example
If you already have class
`.btn-primary{
color: #eee;
background-color: #337ab7;
border-color: #2e6da4;
border: 2px solid transparent;
border-radius: 2px;
}` in your app.
Then you added bootstrap and it also has this class in its library like:
`.btn-primary{
color: #fff;
background-color: #337ab7;
border-color: #2e6da4;
border: 1px solid transparent;
border-radius: 4px;
}`
and overriding your class.
So what you can do is, just use !important in your css for attribute which is conflicting. Like:
`.btn-primary{
color: #eee !important;
background-color: #337ab7;
border-color: #2e6da4;
border: 2px solid transparent !important;
border-radius: 2px !important;
}`
Now the HTML engine will always pick your CSS
Q3: you can override it with higher specificity. That means if the your use the class btn from bootstrap you can add your own own class like my-btn and then reference it in your css like
.btn .my-btn{
color:#123456;
}
Hope that helps

WooCommerce - How to remove DIV shadow and change background color

I have a website with a product page that need changes:
http://weardenali.com/product/everyday-messenger
I'm trying to
a) Change the background color
b) Remove the shadow box
It works on the iPad (which is 768px in height) but as soon as the website height decreases below 768px, the swipe function stops working.
I hope somebody can assist me with this .
This image of my site is here
Here are your changes:
A) change product-main clearfix style background-color: #fcfcfc; to your wish color.
B) Remove
Remove /* -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.1); */
Remove /* box-shadow: 1px 1px 1px rgba(0,0,0,.1);`
from your
summary
class or rename your div.
C) i just test it in chrome version 55........ simulated iphone 5 and ypur carousel still working.
To answer your questions in order:
a) The background of your page is specified as an element style. Probably from the WordPress styling or any other cause that I cannot immediately determine. The root element is styled by .product-main in the sf-combined.min CSS file. Here you can set the background-color to anything you want, as proposed:
.product-main {
background-color: #anything;
}
Considering this may or may not work, I suggest you try to determine why the .product-main has a element style of #fcfcfc. The following is not recommended but you can always set .product-main { background-color: #anything !important; } to override any settings. But this is not best practise.
b) in your CSS in sf-combined.min.css on line 15 (which may be inaccurate because it's a minified CSS document) you have the following line:
.product-fw-split div.product div.summary.
Remove the box shadow entries from the CSS:
.product-fw-split div.product div.summary {
padding: 40px;
margin-bottom: 40px;
-moz-box-shadow: 1px 1px 1px rgba(0,0,0,.1);
-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.1);
box-shadow: 1px 1px 1px rgba(0,0,0,.1);
}
And the box shadow should disappear. Please do check for any responsive queries that may affect the same thing on mobile devices (which I didn't check).
c) I could not determine entirely what your question was in c. I believe you want to know how to prevent the swipe functionality from stopping working when resizing on devices smaller than 768px? It might be WooThumbs intended functionality, in which case I suggest you head over to CodeCanyons support and try to get an answer directly from them. https://codecanyon.net/item/woothumbs-awesome-product-imagery/2867927
Hope it helps.
Next time it might be easier to split your questions off into multiple questions, so that others can find answers more easily.

Remove certain styles from css when printing

I am going about recreating a document in HTML. Thai is all up and running my issue now is i would like to print the page once it has been generated however i would like to remove some of the css styling applied to the display view. I have this so far...
.containerouter {
margin:0 auto;
width:21cm;
height:29.7cm;
padding-left:1.7cm;
padding-right:1.7cm;
padding-bottom:1.7cm;
-webkit-box-shadow: -4px 2px 22px 3px rgba(0,0,0,0.19);
-moz-box-shadow: -4px 2px 22px 3px rgba(0,0,0,0.19);
box-shadow: -4px 2px 22px 3px rgba(0,0,0,0.19);
}
#media print{.no-print, .no-print *{display: none !important;}}
<div class="containerouter no-print" media="print"> CONTENT NESTED INSIDE THIS DIV NEEDS TO BE PRINTED </div>
Basically i would like to remove the shadow properties without removing the sizing format already applied.
What is currently happening is all of the content is disappearing when print is clicked
There is a media class for adding classes when printing:
#media print {
[CSS only shown when printing]
}
if you want to remove some css styles you can do it like this:
#media print {
.containerouter {
box-shadow: none;
}
}
You just need to declare the #media print after you define the class so that your media class get higher specificity.

Custom styles for bootstrap tabs

I am trying to change default bootstrap tab styles. So my custom style should be similar to this image's styles.
I tried it like this, but it's not working. The main thing doesn't skew the bottom of each tabs.
.content .nav-tabs {
background: #dd5b5b;
padding: 15px 0 0 0;
}
.content .nav-tabs > li > a {
padding: 5px 40px;
background: #eaedf2;
border: 1px solid #a48686;
border-bottom: none;
border-top-right-radius: 2em;
border-top-left-radius: 1.5em;
}
JS BIN with the code so far
Can anybody help me to get the output like the above image using pure css?
Thank you.
Bootstrap easily allows to customize tabs and their behaviour.
For the colors, consider using Gradients in your CSS, working in the corresponding classes, as you wish. Here is a nice generator: http://www.colorzilla.com/gradient-editor/
For the icons, you can just use FontAwesome (http://fontawesome.io/icons/) or similar webfont.