Skip to content
- Tutorials
- Python Tutorial
- Taking Input in Python
- Python Operators
- Python Data Types
- Python Loops and Control Flow
- Python Functions
- Python OOPS Concept
- Python Data Structures
- Python Exception Handling
- Python File Handling
- Python Exercises
- Java
- Java Programming Language
- Java Collections
- Java 8 Tutorial
- Java Programs
- Java Interview Questions
- Java Exercises
- Java Quiz
- Java Projects
- Advance Java
- Programming Languages
- System Design
- Interview Corner
- Computer Science Subjects
- DevOps
- Linux
- Software Testing
- Databases
- Android
- Excel
- Mathematics
- Python Tutorial
- DSA
- Data Structures
- Algorithms
- Analysis of Algorithms
- Searching Algorithms
- Sorting Algorithms
- Greedy Algorithms
- Dynamic Programming
- Graph Algorithms
- Pattern Searching
- Recursion
- Backtracking
- Divide and Conquer
- Mathematical Algorithms
- Geometric Algorithms
- Bitwise Algorithms
- Randomized Algorithms
- Branch and Bound
- Algorithms Tutorial
- DSA Tutorial
- Practice
- All DSA Problems
- Problem of the Day
- Company Wise Coding Practice
- GfG SDE Sheet
- Practice Problems Difficulty Wise
- Language Wise Coding Practice
- Curated DSA Lists
- Competitive Programming
- Company Wise SDE Sheets
- DSA Cheat Sheets
- Top Interview Questions
- Puzzles
- Data Science
- Web Tech
- Courses
-
Last Updated : 15 May, 2024
Summarize
Comments
Improve
To override CSS properties with another class, use the `!important` directive in CSS, emphasizing a style’s importance, overriding others. Applying a new class to an element replaces or modifies styles from its original class, allowing targeted adjustments to appearance, layout, or behavior.
Table of Content
- Using !important property
- Using specific selector
Using !important property
The !important property in CSS ensures a style declaration takes precedence over others, regardless of specificity. It’s used to enforce a specific style, overriding any conflicting styles defined elsewhere, thus ensuring consistency and control.
Syntax:
element1 {
property-x: value_y !important; /* This will be applied. */
}
element2 {
property-x: value_z; /* This will not be applied. */
}Example: Implementation to show to override the CSS properties by using !important property.
html <!DOCTYPE html><html><head> <title>Using !important property</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <link href="https://fonts.googleapis.com/css?family=Indie+Flower&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Mansalva&display=swap" rel="stylesheet"> <style> h1 { text-align: center; color: green; } .my_fav_font { font-family: 'Indie Flower', cursive !important; /* This will be applied. */ } .my_para { font-family: 'Mansalva', cursive; /* This will not be applied. */ text-align: justify; background-color: powderblue; font-size: 130%; } </style></head><body> <div class="container"> <h1>GeeksforGeeks</h1> <hr /> <p class="my_fav_font my_para"> Cascading Style Sheets, fondly referred to as CSS, is a simply designed language intended to simplify the process of making web pages presentable. CSS allows you to apply styles to web pages. More importantly, CSS enables you to do this independent of the HTML that makes up each web page. </p> </div></body></html>
Output:
Using specific selector
Using a specific selector in CSS overrides styles by targeting elements more precisely. By specifying a more specific selector, such as an ID or nested class, styles can be applied selectively, ensuring that the desired properties take precedence over others.
See AlsoHow to Use the !important Property in CSS!important - CSS: Cascading Style Sheets | MDNHow CSS style overriding works ? - GeeksforGeeksHow to replace text with CSS? - GeeksforGeeksSyntax:
/* Original style */
.container {
background-color: lightblue;
}
/* Override with specific selector */
#special-container .container {
background-color: lightgreen;
}Example : Implementation to show to override the CSS properties by using specific selector and then overriding.
HTML <!DOCTYPE html><html><head> <title>Without Using !important</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <link href="https://fonts.googleapis.com/css?family=Indie+Flower&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Mansalva&display=swap" rel="stylesheet"> <style> .body-style { text-align: center; font-family: 'Indie Flower', cursive; /* Apply font to body directly */ } .my_para { font-family: 'Mansalva', cursive; text-align: justify; background-color: powderblue; font-size: 130%; /* Overriding property */ color: red; } </style></head><body class="body-style"> <div class="container"> <h1>GeeksforGeeks</h1> <hr /> <p class="my_para"> Cascading Style Sheets, fondly referred to as CSS, is a simply designed language intended to simplify the process of making web pages presentable. CSS allows you to apply styles to web pages. More importantly, CSS enables you to do this independent of the HTML that makes up each web page. </p> </div></body></html>
Output:
Please Login to comment...
Similar Reads
How to override inline styles with external in CSS ?
In this article, we are going to learn how we can override inline styles with external CSS. Generally, we use inline CSS to override all the other styles. In some circ*mstances, we have to do the opposite. We have to override the inline CSS which has come from foreign sources and cannot be removed. Approach: To override the inline CSS, !important k
3 min read
Tailwind CSS 3 Classes doesn't Override Previous Classes
Tailwind CSS is basically a Utility-first CSS framework for building rapid custom UI. It is a highly customizable, low-level CSS framework that gives you all of the building blocks that you need. Also, it is a cool way to write inline styling and achieve an awesome interface without writing a single line of your own CSS. Syntax<div class="bg-blu
2 min read
How to override the current text direction using HTML ?
In this article, we will override the current text direction by using the dir attribute in the particular element. It is used to specify the text direction of the element content. It contains three values: ltr: It is the default value. This value represent the text in Left-to-right text direction. rtl: This value represent the text in right-to-left
1 min read
How to override a JavaScript function ?
In this article, we are given an HTML document and the task is to override the function, either a predefined function or a user-defined function using JavaScript. Approach: When we run the script then Fun() function is called. After clicking the button the GFG_Fun() function is called and this function contains another function that will run. Examp
2 min read
How to override React Bootstrap active Tab default border styling?
React-Bootstrap provides various components with basic default styling. Sometimes, there is a need to override those basic default styles as per requirements. In this article, let us discuss overriding that default styling for the border of the active tab in the navbar. PrerequisitesReact JSReact-BootstrapSteps to create React Application and insta
3 min read
How to override nested NPM dependency versions?
In projects the packages download and used using npm are called dependency and each dependencies can have their own nested dependencies that also gets downloaded. These nested dependency creates conflicts due to the presence of multiple version of the same dependency. This will lead to issues like compatibility, security vulnerabilities, and unexpe
5 min read
How to Override Functions of Module in Node.js ?
Overriding functions in a Node.js module allows you to alter or extend the behaviour of existing functions without modifying the original module's code. This approach can be useful for customizing library functionality, adding new features, or fixing bugs in third-party modules. Here’s how you can achieve this in different scenarios. Table of Conte
3 min read
Primeng 15- How to Override Default Sort Icon in Angular 15?
Angular is a powerful, open-source web application framework maintained by Google. Using angular you can build dynamic, single-page applications (SPAs) with multiple tools and features provided in angular material. Angular supports TypeScript, to provide a strong typing system and improved tooling. Steps To Implement Primeng in Angular AppStep 1: I
See AlsoUsing CSS variables in Bootstrap3 min read
Why Transition properties does not work with display properties ?
When we want to use transition for display:none to display:block, transition properties do not work. The reason for this is, display:none property is used for removing block and display:block property is used for displaying block. A block cannot be partly displayed. Either it is available or unavailable. That is why the transition property does not
2 min read
How to copy properties from one object to another in ES6 ?
The properties of one object can be copied into another object through different methods. Here are some of those methods. Object.assign(): By using the Object.assign() method, all enumerable properties of one or more source objects are copied to the target object. This method returns the modified target object. The properties of the target object a
3 min read
How to Play and Pause CSS Animations using CSS Custom Properties ?
In this article, we will see how to control CSS animations using custom properties, along with knowing their implementation through examples. CSS Animations are the automatic transitions that can be made on the web page which lets an element change from one style to another. CSS Custom Properties are variables defined by CSS developers that contain
5 min read
How to define all the list properties in one declaration using CSS ?
Sometimes a web page has good content for reading but the styling of the texts looks improper, so it becomes boring for the readers, and lastly, they leave the web page. But when they read articles with proper styling and lists they read them fully because of the good visuals stated there which keep them attracted to the article and readings. So wh
3 min read
How to add CSS properties to an element dynamically using jQuery ?
In this article, we will see how to add some CSS properties dynamically using jQuery. To add CSS properties dynamically, we use css() method. The css() method is used to change the style property of the selected element. The css() method can be used in different ways. This method can also be used to check the present value of the property for the s
1 min read
How to create a hidden border using CSS properties ?
In this article, we will learn how to create a hidden border using CSS properties. In the following examples, both inline styling and style definition is used in the head section to define the hidden border. Approach: We will use two headings in which one will show the border color and the other will not show because it will be hidden using CSS.The
2 min read
How to set all the font properties in one declaration using CSS ?
In this article, we will learn how to set all the font properties in one declaration using CSS. This can be used for quickly setting the required font properties without specifying each of them separately. Approach: We will use the font property of CSS which is the shorthand property for all the font properties. This takes five values font-style, f
2 min read
How to Change CSS Properties using JavaScript EventListner Methods ?
In this article, we will be using JavaScript to update the web page's CSS styling by taking input from the user. Generally, we have seen a few webpages update the various styling properties dynamically by taking the user input that enhances the user interaction with the webpage, along with improving the overall user experience by engaging the users
3 min read
How to overlay one div over another div using CSS
Creating an overlay effect simply means putting two div together at the same place but both the div appear when needed i.e while hovering or while clicking on one of the div to make the second one appear. Overlays are very clean and give the webpage a tidy look. It looks sophisticated and is simple to design. Overlays can create using two simple CS
2 min read
Which property is used as shorthand to specify a number of other font properties in CSS ?
In this article, we are going to discuss a property that is used as shorthand to specify different font properties. The font property is a shorthand property for various font-related properties. Shortening the code in Cascade Style Sheet (CSS) helps to specify all individual related properties into a single property. The font property is used as sh
2 min read
CSS | Shorthand Properties
Shorthand properties allow us to write multiple properties in a single line and in a compact way. They are useful as they provide clean code and also decrease the LOC (Line of Code). The Shorthand properties we will be covering: BackgroundFontBorderOutlineMarginPaddingList Background: The CSS Background property is used to set the background on a w
4 min read
Difference between CSS Custom Properties and Preprocessor Variables
In this article, we will learn the difference between CSS Custom properties and Preprocessor Variables. CSS Custom Properties: CSS custom properties are also referred to as CSS variables or cascading variables. These entities contain specific values that will be reused in the entire document & can be accessed using the var() function (e.g., col
3 min read
Which Property sets all Outline Properties at once in CSS?
The outline property in CSS sets all outline properties at once, allowing you to specify the color, style, and width of an element's outline. This consolidated property simplifies the process of styling outlines for better visual presentation and accessibility. Syntax:/* Setting all outline properties at once */.element { outline: 2px dashed #3498d
1 min read
Logical Properties in CSS
CSS logical properties use the terms block and inline to elaborate the direction of the flow of writing. Block properties: Sets up the top and bottom properties of the webpage (for standard English text), you could say that the dimension is perpendicular to the flow of text within a line. In simpler words, the vertical dimensions in horizontal writ
4 min read
CSS Flexbox and Its Properties
CSS Flexbox, or Flexible Box Layout, is the layout model designed to create flexible and responsive layout structures without using float or positioning. By applying display: flex to a parent container, it becomes a flex container, and its children become flex items. This allows control over the items' growth, shrinkage, and space distribution. Not
3 min read
CSS Properties Complete Reference
CSS properties are the fundamental building blocks for creating stunning and functional web experiences. Understanding their structure, and syntax, CSS Properties Complete Reference serves as a comprehensive guide to CSS properties, covering their usage, syntax, and browser support. Organized alphabetically, it provides detailed explanations and ex
13 min read
Transition shorthand with multiple properties in CSS?
The transition shorthand in CSS allows specifying multiple properties for smooth transitions between different states or values. The transition property in CSS is used to create transitions in an element, enabling changes to occur smoothly over a specified duration. This article demonstrates how to use the transition shorthand to apply hover effect
2 min read
What are CSS Custom Properties ?
In this article, we will learn about CSS custom properties & their implementation. CSS custom properties are also referred to as CSS variables or cascading variables. These entities contain specific values that will be reused in the entire document & can be accessed using the var() function (e.g., color:(--primary-color);). The property nam
4 min read
How to resolve 'Next Image not taking class properties' issue?
In this article, we will solve the problem of "Next Image not taking class properties" occurring due to the way the 'next/image' component handles its underlying HTML layout and overall structure. The 'next/image' component is the component that generates the additional wrapper elements and inline styles to perform the image optimization. Understan
5 min read
How to include one CSS file in another?
Yes, It is possible to include one CSS file in another and it can be done multiple times. Also, import various CSS files in the main HTML file or the main CSS file. It can be done by using the @import keyword. Example 1: To showcase to include a CSS file in another first create a structure of HTML without using any CSS properties. C/C++ Code <!D
3 min read
How to make Div on Top of Another in Tailwind CSS ?
Positioning elements in Tailwind CSS allows for creating complex layouts with ease. One common requirement is overlaying one div on top of another. Below are the approaches to make div on top of another in Tailwind CSS: Table of Content Absolute Positioning and Z-indexTailwind CSS Utility Classes for Absolute PositioningAbsolute Positioning and Z-i
2 min read
Inherit a class to another file in Sass
Sass or syntactically awesome style sheets is a CSS preprocessor that gives CSS such powers that are not available in plain CSS. It gives the power of using expressions, variables, nesting, mixins(Sass form of functions), inheritance, and more. Other well-known CSS preprocessor examples include Less and Stylus but Sass is more popular. Sass include
4 min read
Article Tags :
Trending in News
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, check: true }), success:function(result) { jQuery.ajax({ url: writeApiUrl + 'suggestions/auth/' + `${post_id}/`, type: "GET", dataType: 'json', xhrFields: { withCredentials: true }, success: function (result) { $('.spinner-loading-overlay:eq(0)').remove(); var commentArray = result; if(commentArray === null || commentArray.length === 0) { // when no reason is availaible then user will redirected directly make the improvment. // call to api create-improvement-post $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); return; } var improvement_reason_html = ""; for(var comment of commentArray) { // loop creating improvement reason list markup var comment_id = comment['id']; var comment_text = comment['suggestion']; improvement_reason_html += `
${comment_text}
`; } $('.improvement-reasons_wrapper').html(improvement_reason_html); $('.improvement-bottom-btn').html("Create Improvement"); $('.improve-modal--improvement').hide(); $('.improvement-reason-modal').show(); }, error: function(e){ $('.spinner-loading-overlay:eq(0)').remove(); // stop loader when ajax failed; }, }); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ $('.improvement-reason-modal').hide(); } $('.improve-modal--improvement').show(); }); function loadScript(src, callback) { var script = document.createElement('script'); script.src = src; script.onload = callback; document.head.appendChild(script); } function suggestionCall() { var suggest_val = $.trim($("#suggestion-section-textarea").val()); var array_String= suggest_val.split(" ") var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(suggest_val.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `
${suggest_val}
`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-section-textarea').val(""); jQuery('.suggest-bottom-btn').css("display","none"); // Update the modal content const modalSection = document.querySelector('.suggestion-modal-section'); modalSection.innerHTML = `
Thank You!
Your suggestions are valuable to us.
You can now also contribute to the GeeksforGeeks community by creating improvement and help your fellow geeks.
`; }, error:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 5 Words and Maximum Character limit is 2000."); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('#suggestion-section-textarea').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // load the captcha script and set the token loadScript('https://www.google.com/recaptcha/api.js?render=6LdMFNUZAAAAAIuRtzg0piOT-qXCbDF-iQiUi9KY',[], function() { setGoogleRecaptcha(); }); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.improvement-reason-modal').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); });