Is it possible to create HTML code that remains unaffected by alterations in CSS class names?

Having been using Twitter Bootstrap 3 for some time, the arrival of Twitter Bootstrap 4 has caught my attention. The new Twitter Booststrap comes with various changes, such as the renaming of .table-condensed to .table-sm, for instance. In anticipation of a potential transition from the current to future version, is there a way to ensure that HTML code remains unaffected by any changes in CSS class names? For instance, if I have a .table-condensed class, is it possible to create my own table-small class that is derived from the existing Twitter Bootstrap's table-condensed class? Perhaps something along the lines of (pseudo-code):

.table-small {
    join(".table-condensed")
}

Up until now, I have solely utilized pure CSS as a Front-End Developer, rather than being a full-stack developer. Therefore, if anyone could enlighten me on whether this is achievable in any way, possibly utilizing preprocessors or similar techniques, I would be extremely thankful - thank you in advance!

Answer №1

In the world of SASS, the @extend function comes in handy for styling.

Although utilizing this function is common practice, it's worth noting that it can result in duplicate styles within your CSS file, effectively increasing its size.

To tackle this issue, you have a couple of options: either stick with your current version of Bootstrap (BS-4) unless absolutely necessary, or make sure to update your HTML code accordingly.

Update:

After diving into the SASS documentation, it appears that the use of commas has been introduced as a more efficient way to achieve the same outcome. This update could be a more effective approach moving forward.

While this method still generates additional CSS due to the duplication of classes, it's a step up from replicating all your styles.

Answer №2

To achieve the same result with fewer lines of code, you can utilize less css by following these steps:

.table-small {
    &:extend(.table-condensed);
}

Unlike sass, this method simply adds the selector without duplicating the class:

Resulting css:

.table-condensed,
.table-small {
    background: red;
}

Try out this preprocessor tool online:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble concealing images in HTML Emails on Outlook 2013

Struggling to properly hide images in Outlook 2013? Even when hidden, they are leaving a line of spacing that stretches the email. Here's the code I'm using to hide an image from the desktop version: <tr style="display: none; line-height: 0; ...

Having trouble identifying the specific CSS property that is being used or inherited

I have incorporated components from Twitter Bootstrap CSS into a custom CSS file, focusing mainly on toolbar components. Specifically, I have set up a toolbar with various features. However, when applying additional CSS to the .signinbox_left:hover select ...

What is the best way to address the excess white space between an image and progress bar on larger screens while utilizing the Bootstrap Grid system?

https://i.sstatic.net/NXMNV.pngLet's begin by visualizing the concept through these images: In Picture (1), the progress bars are positioned below the image on medium to large screens, with the text aligned to its right. https://i.sstatic.net/Cw1aM.pn ...

Changing the background color dynamically of a table header in Angular Material

I have utilized the angular material table following this example. https://stackblitz.com/angular/jejeknenmgr?file=src%2Fapp%2Ftable-basic-example.ts In this case, I modified the heading color with the following CSS code. .mat-header-cell { backgrou ...

Custom HTML structure for WordPress navigation menu - WP Nav Menu

Need help creating a customized Wordpress Menu with HTML structure: <?php wp_nav_menu( array( 'theme_location' => 'global-menu' ) ); ?> The desired HTML output should resemble the following: <nav> < ...

What is the correct way to reset the styling of a web browser element, such as a <button>?

I have come across many sources advising me to reset HTML by manually resetting numerous individual properties, as demonstrated here: https://css-tricks.com/overriding-default-button-styles/ Another approach I discovered in CSS is simply using: button: {a ...

"Internet Explorer text input detecting a keyboard event triggered by the user typing in a

It appears that the onkeyup event is not triggered in IE8/IE9 (uncertain about 10) when the enter button is pressed in an input box, if a button element is present on the page. <html> <head> <script> function onku(id, e) { var keyC = ...

Looking for assistance with fundamental HTML concepts

I'm struggling to make the navigation bar stretch to full height. As a beginner in HTML and CSS, I have limited knowledge about it. I have tried numerous solutions found on the internet but nothing seems to work. The styling and HTML code are provide ...

Embrace the power of React using curly brackets!

Today, I made the decision to dive into learning React. Typically, I use Brackets for my coding environment. The first step I took was adding the necessary sources to my HTML code. <html> <head> <link rel="stylesheet" href="styl ...

Embedding a table row within an anchor element in Angular 4

Currently, I am facing an issue with a table that contains [routerLink] on each <tr>. This setup is preventing the "open link in a new tab" option from appearing when I right-click because there is no <a> tag. I attempted to enclose the table r ...

What strategies can flex-shrink use to triumph over padding in the battle for space

I am facing an issue with a flex-box tag cloud where the sizing is controlled from the outside. I need the tags inside to be collapsible all the way down to zero if necessary, but currently they only collapse up to 2 times their padding. https://i.sstatic ...

Trim the edge of a dynamic picture

Currently, I am facing a challenge with an image that requires the corner to be cut off. The image needs to be responsive in order to adjust its size according to the page dimensions. Since the image is managed by a CMS, the corner cut has to be done progr ...

The keyboard automatically disappeared upon clicking the select2 input

Whenever I select the select2 input, the keyboard automatically closes $('select').on('select2:open', function(e) { $('.select2-search input').prop('focus',false); }); Feel free to watch this video for more i ...

Is there a bug in IE9 with CSS precedence?

Two CSS rules are in place: .avo-lime-table th, .avo-lime-table td { background-color: grey; } Next rule: .avo-lime { background-color: green; } All is functioning correctly in FireFox, Chrome, Opera and Safari. However, as usual, Microsoft&apos ...

Tips for accessing the content within a DIV tag in a new browser tab

$('.menu div.profile-btn').on('click', function () { $('.mainservice-page').fadeIn(1200); } The script above effectively displays the contents of the .mainservice-page div, but I would like to open them in a new tab. Is ...

Tips for implementing validation in a multi-step form as outlined in w3schools tutorial

I came across a multistep form creation tutorial on w3schools. However, the tutorial only covers generic validation (checking if a field is empty), which is not sufficient for my needs. How can I implement HTML validation (e.g., min, max, length) for text ...

What sets apart the <script> tag with a type attribute from the standard <script> tag in HTML?

Similar Question: Is it necessary to include type=“text/javascript” in SCRIPT tags? While working on my HTML project, I noticed that the JavaScript code within script tags is evaluated even if the type attribute is not explicitly set to "j ...

What is the reason behind the addition of '.txt' by the Next.js `Link` Component when redirecting to `href='/'` on GitHub pages?

My website is hosted on github-pages, and I am using the Link Component from Next.js to navigate within it. However, when I click on a component with the href="/", it adds .txt to the end of the URL. My website follows the /app structure. I have ...

Using the jQuery POST method to execute a redirect upon successful completion

I am attempting to utilize jQuery to create a post method. I have implemented it within a form and used bootstravalidator for validation. Once the form is successfully validated, it is posted and the PHP code comes into action. Now, my goal is to redirect ...

Multiple jQuery AJAX requests triggered in a click event handler

I am in the process of developing a PHP web application and utilizing the datatables jQuery plugin along with jQuery AJAX calls to create a dynamic table for editing, deleting, and adding elements. Although it appears to be working correctly, I've not ...