I'm trying to override woocommerce css class which by default is set to !important. How can I override this?
The Default is:
.woocommerce-error, .woocommerce-info, .woocommerce-message{
padding: 1em 2em 1em 3.5em!important;}
I have tried the following but does not want to know:
main .post .entry .woocommerce-error, .woocommerce-info, .woocommerce-message{padding: 0 0 10px 0 !important;}
Not sure if I can change the original woocommerce stylesheet as I assume the changes I make will be overridden when plugin is updated.
Many thanks.
That's because you're overlooking the comma, there are actually 3 rules inside that line of yours, and you will have to specify it for every one of them. This should work:
main .post .entry .woocommerce-error,
main .post .entry .woocommerce-info,
main .post .entry .woocommerce-message {
padding: 0 0 10px 0 !important;
}
In order to over ride default Woocommerce styles it is best to disable the stylesheets by entering the below in your functions.php file:
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
This way you can avoid using !important as this is bad practise and customise the shop to look as you wish.
By default Woocommerce enqueues 3 stylesheets and the above snippet will disable all of them, if you wish to disable just each one individually you can add:
// Remove each style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
Please see here for more info: Woomerce Docs
!important is amazingly evil and should be avoided unless you really 10000% sure you won't regret it (or maybe you want to do a simple utility class, which is okay). I never use Woo-commerce but it is such a shame for them to use !important rule in the css, which will be amazingly hard to make any other style that will beat that specificity.
Anyway, the best way I know is to add an ID to element that you want to override if possible, and add a new selector to improve specificity, and add !important rule to that selector (example below). But if not, wellllllll, I don't know.
#newselector{
padding: 1em 2em 1em 3.5em!important;
}
!important is evil, I hope you won't afraid if it's suddenly eating you alive.
Related
I'm using the WordPress antispambot code, from their Code Reference:
https://developer.wordpress.org/reference/functions/antispambot/
It's working, but I want to style the email addresses that the code displays. If the obfuscated email address is in the footer I want to apply a particular style, but if the obfuscated email address is, for example, in the body of a page I want to apply a different style.
I've tried adding a title attribute to the tag as shown in the code below:
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
if ( ! is_email( $content ) ) {
return;
}
return '<a href="mailto:' . antispambot( $content ) . '" title="encrypted-email">' . antispambot(
$content ) . '</a>';
}
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
And then style it using the following CSS:
/* GENERAL STYLE FOR ENCRYPTED EMAILS */
a[title="encrypted-email"]{
color:#4472e6 !important;
text-decoration:none !important;
}
a[title="encrypted-email"]:hover{
text-decoration:underline !important;
}
/* STYLE FOR ENCRYPTED EMAILS IN FOOTER */
.fusion-footer-widget-area .custom-html-widget a[title="encrypted-email"]{
color:#ff0000;
text-decoration:none !important;
}
.fusion-footer-widget-area .custom-html-widget a[title="encrypted-email"]:hover{
color:#e4d06f;
}
However, using the CSS above, ALL encrypted emails, including encrypted emails in footer, take the 'General' styles.
I wondering if this method is the best way to set up different CSS styles for encrypted emails in different parts of the page (eg body text vs footer).
And also, is my CSS correct?
UPDATE
The generated HTML is as follows:
<ul style="list-style-type:none; margin:0; padding:0;">
<li style="font-size:16px; margin-bottom:0px;"><a
href="mailto:wbu#bd"
title="encrypted-email">wbu#bd</a></li>
</ul>
1. The problem you are having is because of the use of !important in your CSS rules. Using this on your a[title="encrypted-email"] rules mean they will take precedence over the more specific "footer" rules.
To make your footer rules take precedence, the most preferable option is to remove !important from the main a[title="encrypted-email"] - Using !important is generally discouraged because it causes problems just like this.
If that is not possible, you need to use !important on all more specific rules to override the !important style. (Assuming the rules match your actual HTML elements), the following should work:
/* STYLE FOR ENCRYPTED EMAILS IN FOOTER */
.fusion-footer-widget-area .custom-html-widget a[title="encrypted-email"]{
color:#ff0000 !important;
}
.fusion-footer-widget-area .custom-html-widget a[title="encrypted-email"]:hover{
color:#e4d06f !important;
}
Note - you don't actually need the !important for the text decoration because you are not changing it from the style rule that it is overriding.
2. You also asked if this is how you should set up the CSS rules for this. Yes, this is the right way to style them - this is what the cascading part of the CSS name means. All you need to override the style is to use a more specific selector e.g. instead of "encrypted email links", you can say "encrypted email links in the footer widget".
So .fusion-footer-widget-area .custom-html-widget a[title="encrypted-email"] would normally work for your footer emails (i.e. if the other rules didn't use !important) because it is more specific (as long as the email addresses in an element with the class .custom-html-widget which is in an element with the class .fusion-footer-widget-areaof course!)
I want to create custom css unit, that I'll be able to use in sass with node.js. Is there any guide about creating sass plugin for this? Just for example, I want to create unit "dpx", that will work as double pixel, so "width: 20dpx" will be processed to "width: 40px".
Other solution (not sass plugin), that can work with node is also acceptable.
Use a SASS function that accepts a font-size and returns the value doubled.
#function dpx($size) {
#return $size * 2;
}
div {
font-size: dpx(20px); // output: font-size: 40px;
}
As a simplified version of the current answer, you could also write the following:
$d: 2px;
div { font-size: 20*$d; }
I know this is an old question, but since I found it, other people will find it too.
In such case as yours a good solution would be to make a 1rem equal to 2px.
You can do it this way:
html {
font-size: 2px;
}
now each 1rem will be equal to 2px. If you want to make sure this doesn't break your current page, you can always add
body {
font-size: 8rem;
}
to set the global font-size to 16px (just a guess since this is a default value).
I've created a child theme of the Renovation theme. In the child's theme folder I have a "style.css" and a "functions.php" file. My style.css looks like this:
/*
Theme Name: Renovation Child
Theme URI: http://renovation.thememove.com/
Author: ThemeMove
Author URI: http://thememove.com/
Version: 2.0.4
Template: tm-renovation
*/
/*
* #charset "UTF-8";
*/
.vc_custom_1438936121266 {
margin-bottom: 70px!important;
padding-top: 65px!important;
padding-bottom: 35px!important;
}
My functions.php looks like this:
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
// BEGIN ENQUEUE PARENT ACTION
if ( !function_exists( 'renovation_enqueue_scripts' ) ):
function renovation_enqueue_scripts() {
wp_enqueue_style( 'renovation-child-style', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css' );
}
endif;
add_action( 'wp_enqueue_scripts', 'renovation_enqueue_scripts' );
// END ENQUEUE PARENT ACTION
Unsing the inspector I see that the parent css is being loaded first and it looks like this:
.vc_custom_1438936121266 {
margin-bottom: 70px!important;
padding-top: 30px!important;
padding-bottom: 35px!important;
}
My CSS is being loaded after the parent CSS and it looks like this, except it's all crossed out:
.vc_custom_1438936121266 {
margin-bottom: 70px!important;
padding-top: 65px!important; <-- MY CHANGE
padding-bottom: 35px!important;
}
I've read alot of threads about specificity, and I noticed that my css and the parent css are identical, except for the "padding-top" change I made. Since the child is loaded last, I expected my css to take precedence, but it's not. My css is crossed out in the inspector and the parent is being used.
This doesn't seem right to me, and I was hoping that someone could clarify my understanding of the parent/child relationship and help me fix this problem. Thank you.
if you are only going to override one element and not apply this to multiple it might be best to use an id instead of a class. The id is always overwrites a class.
I'm trying to remove the line under the logo at: http://buyfireworks-shop.co.uk/product-category/roman-candles/ I can't remove the white border under the logo. I have tried various css to no avail.
Update this class in inline style sheet #4, you might need to do it in your page builder if you're using one, like Visual Composer or DiviBuilder if you can't find it in WooCommerce; from memory Woo doesn't have admin side styling accessible:
.mk-header { border-bottom: 1px solid #ededed; }
Remove the white border by setting border-bottom to none:
.mk-header { border-bottom: none; }
This style is being added with an inline stylesheet on the page, so you'll need to override it either with important or being really careful about specificity; making sure your .mk-header border fix is in the last css file after the WooCommerce stuff loads.
If you're still having trouble with WooCommerce styles you can disable them entirely in functions.php
// Remove each style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
// Or just remove them all in one line
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
I am using thematic and have created a childtheme.
Whilst trying to style something in the header I discovered that in my head there are some inline stlyes.
How do I get rid of these styles please:
<style type="text/css">
#blog-title, #blog-title a, #blog-description {
color:#blank;
}
#branding {
background-position: center bottom;
background-repeat: no-repeat;
margin-top: 32px;
}
#blog-title, #blog-title a, #blog-description {
display:none;
}
#branding {
height:235px;
width:940px;
padding:0;
}
</style>
</head>
These styles are likely being added by a function hooked to the wp_head action. For example, something in either your theme or maybe in a plugin you have activated is doing something like this:
function hook_css() {
$output = '<style> .example { color : #eee; } </style>';
echo $output;
}
add_action( 'wp_head', 'hook_css', 10 );
You can either delete the function and the hook to wp_head or you can remove the action via the remove_action() function. For example:
remove_action( 'wp_head', 'hook_css', 10 );
Ref:
http://codex.wordpress.org/Function_Reference/remove_action
http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head
Have you got a url for us to look at?
A quick way would be to use jQuery to strip it out.
$('head style').remove();
However removing it properly via php or the theme/plugin would be best
These are generated by theme settings in the admin area, your best option is to find the hook to wp_head and just remove it if it's that necessary.
THanks all.
I have found the offending code. Its burried in the functions.php file in the sample theme that comes with thematic.
Seems a bit weird to me that its in there really... still, it isn't now!