Add styles to every table with the exception of a single one

Is there a way to avoid applying certain styles to a table when the screen size is small without having to introduce new CSS properties?

I want to exclude specific tables from inheriting certain styles that are applied globally.

Any suggestions on how I can target all tables except for one in particular? Maybe using a unique identifier?

Thank you in advance

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0px;
}   
td,
th {
  padding: 10px;
  border: 1px solid #ccc;
  text-align: left;
  font-size: 15px;
} 
<table>
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Job Title</th> 
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>James</td>
      <td>Matman</td>
      <td>Chief Sandwich Eater</td> 
    </tr>
    <tr>
      <td>Andor</td>
      <td>Nagy</td>
      <td>Designer</td>  
    </tr>
    <tr>
      <td>Tamas</td>
      <td>Biro</td>
      <td>Game Tester</td> 
    </tr> 
  </tbody>
</table>

Answer №1

If you're looking to hide specific elements, the :not selector is a handy tool.

div:not(.main){
  display:none;
}
<div>A</div>
<div class="main">B</div>
<div>C</div>

For instance, let's say you have 3 tables and only want to show one thead :

table {
  border: 1px solid black;
}

table:not(.main) thead {
  display: none;
}
<table>
  <thead>
    <tr>
      <th>A</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
    </tr>
  </tbody>
</table>

<table class="main">
  <thead>
    <tr>
      <th>B</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>2</td>
    </tr>
  </tbody>
</table>

<table>
  <thead>
    <tr>
      <th>C</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>3</td>
    </tr>
  </tbody>
</table>

To target the thead specifically and add a class if needed, try using thead:not(.main)

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

Place a lone div at the bottom of a row containing divs with varying heights

I've been working on aligning a div inside a (bootstrap v4) col within a (bootstrap v4) row that has a variable height. Here's a quick reference codepen link - https://codepen.io/ajmajma/pen/veNRdY Here's the code snippet: html <div c ...

Creating a Responsive New Row for Grid Cells in CSS Grid

I am currently working on making my webpage responsive. I have encountered an issue where my text overflows into another grid cell because there is not enough space. Is there a way to move these cells into a new row so that the text has enough room and all ...

Center the text within a span element in an inline-block container

I'm currently working on a website design that features a flat aesthetic. I have a header at the top and two blocks of different colors placed side by side underneath it. Initially, I attempted to use float left and right for positioning but was recom ...

"Adjusting the width of columns in a Datatable

I have arranged a data table with multiple rows and columns, and I am seeking guidance on how to increase the width of the "Tel. 1, Tel. 2, and Fecha" columns to ensure that the text appears on a single line. I've attempted adjusting the s width and t ...

Excessive greed in 2 column layout is causing left alignment issues

Check out the sample code here: http://jsfiddle.net/YUhgb/ HTML Markup <html> <body> <div class="left"></div> <div class="right"> <div class="container"> <div class="i ...

A customizable and adaptable Tetris-inspired CSS design perfect for any screen size

If we imagine having a block like this: <div class="block"></div> There are different sizes of the block: <div class="block b1x1"></div> <div class="block b2x1"></div> <div class="block b1x2"></div> For i ...

Centered div's overflow remains visible

Yes, the positioning of the parent container is set to relative. I am attempting to achieve a ripple effect by expanding multiple circles from a central point in all directions until they stretch beyond the viewport. I have created circular divs that are ...

Modifying Blocks in Prestashop: A Step-by-Step Guide

I'm looking to make some changes to the "categories" block in my left navigation column. Currently, it appears like this: https://i.sstatic.net/MpUD5.png I would like it to look like this by default: https://i.sstatic.net/fJTr8.png Here are the mod ...

Utilizing jQuery to delete items once their corresponding checkboxes are checked

I have successfully implemented a feature where I can add more fields by clicking a button. However, I am facing an issue when trying to delete a field after checking the checkbox. Any assistance on this matter would be greatly appreciated. jQuery: $(doc ...

Building a stable sidebar design using Bootstrap 4 - A step-by-step guide

https://i.sstatic.net/QLeA4.png Struggling to replicate a layout similar to the provided screenshot using Bootstrap 4. The issue arises when trying to make the sidebar fixed while maintaining the desired layout. To illustrate with a basic example: <d ...

The bug in Polymer 1.0 where a custom element is causing issues when clicking under the toolbar

Issues have arisen with a custom element I created, named <little-game></little-game>. Here is the template code for <little-game></little-game>: <template> <a href="{{link}}"> <paper-material elevation=& ...

What steps can I take to ensure that the v-main element occupies at least 70% of the viewport height in Vuetify?

As a newcomer to Vuetify, I am still learning the ropes. One thing I've noticed is that <v-main> automatically expands to fill the space between <v-app-bar> and <v-footer>, taking up the entire viewport height. My concern arises wh ...

Ways of distinguishing the variance between vertical align: -0.125em and vertical align: middle explained

Upon coming across the code vertical-align: -0.125em;, I begin to ponder about the contrasts between this and vertical-align: middle. ...

include a button next to the input field

As you reduce the browser window size, you may notice a different layout designed specifically for iPhone. One question that arises is how to add a button next to the search text box dynamically using JavaScript. The issue at hand is that the text box is b ...

What are some tips for customizing the NavBar Bootstrap 4 Layout to fit a unique design?

Good evening everyone, I am currently working on a website project for a client who has provided me with specific requirements for the Navbar design. While it seemed straightforward at first, I have spent several hours trying to perfect the layout. I am ...

Divs placed side by side are displaying a 1px gap in Safari, however, this issue is

On the website , there is a noticeable 1px gap between adjacent divs in Safari. However, this issue does not occur in other browsers such as Chrome and Firefox. The menu div is floated left and occupies 34% of the width, while the gallery div is floated r ...

Overflow-y modifies the text color

I am currently delving into the world of HTML and CSS, tackling a specific issue. I have a lengthy list of items and I've applied overflow-y using external CSS. However, there's a hiccup - it changes the font color of the list. Additionally, any ...

Multiple instances of jquery click event firing when utilizing class selector

Here is the HTML code I have: <li><div class="myLink" id=1>A<div> <li><div class="myLink" id=2>b<div> <li><div class="myLink" id=3>c<div> <li><div class="myLink" id=4>d<div> <li> ...

Add flair to the ButtonBase element within a Tab component

I'm currently exploring how to override Material UI styles with a nested component. For instance, what if I want to increase the bottom border height on an active Tab, which is applied by the underlying ButtonBase. Below is the style definition: con ...

Adaptive Video Backdrops

I am planning to create a website similar to Taylor Swift's with two different video backgrounds for desktop and mobile. I would like some advice on the best way to achieve this using Bootstrap or a framework like react. Would using the following code ...