Stylish Tabbed Design

Imagine I have this html and css snippet

h1{
    color: rgb(61, 133, 200);
    font-size: 3em;
    margin-left: 0px !important;
}

h1 ~ *:not(h1) {
    margin-left: 0px;
}

h2{
    font-size: 1.8em;
    margin-left: 40px !important;
}

h2 ~ *:not(h2) {
    margin-left: 40px;
}

h3{
    font-size: 1.4em;
    margin-left: 80px !important;
}

h2 ~ *:not(h2) {
    margin-left: 40px;
}
<h1>Hello First</h1>
<p>This is a paragraph that I wrote that belongs to p</p>
<p>This paragraph should also belong to the first p</p>

  <h2>Tabbed</h2>
  <p>I want this paragraph to be tabbed directly</p>
  <p>This paragrah should be tabbed too<p>

    <h3>Tabbed</h3>
    <p>This should be more tabbed</p>
    <p>This paragrah should be more tabbed too<p>

    
  <h2>More Tabby</h2>
  <p>This should be single tabbed</p>
  <p>How tabby<p>
    
    
<h1>Return of The Title</h1>
<p> This should no longer be tabbed </p>
<p> Nor should this <p>

I am struggling to apply the specified CSS style without using !important tags. How can I achieve consistent margins for all elements below a specific heading?

If you have any suggestions on how to tackle this issue, please share them!

Answer №1

Utilize the :active selector to customize and style the active link. A link is considered active when it has been clicked.

Below is an example showcasing the use of the background-color property:

h1{
    color: rgb(61, 133, 200);
    font-size: 3em;
    margin-left: 0px !important;
}

h1 ~ *:not(h1) {
    margin-left: 0px;
}

h2{
    font-size: 1.8em;
    margin-left: 40px !important;
}

h2 ~ *:not(h2) {
    margin-left: 40px;
}

h3{
    font-size: 1.4em;
    margin-left: 80px !important;
}

h2 ~ *:not(h2) {
    margin-left: 40px;
}
p:active {
    background-color: yellow;
}
h3:active {
  background-color: red;
  }
h1:active {
  background-color: red;
  }
h2:active {
  background-color: red;
  }
<h1>Hello First</h1>
<p>This is a paragraph that I wrote that belongs to p</p>
<p>This paragraph should also belong to the first p</p>

  <h2>Tabbed</h2>
  <p>I want this paragraph to be tabbed directly</p>
  <p>This paragrah should be tabbed too<p>

    <h3>Tabbed</h3>
    <p>This should be more tabbed</p>
    <p>This paragrah should be more tabbed too<p>

    
  <h2>More Tabby</h2>
  <p>This should be single tabbed</p>
  <p>How tabby<p>
    
    
<h1>Return of The Title</h1>
<p> This should no longer be tabbed </p>
<p> Nor should this <p>

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

Challenges with CSS div styling (border and image issues)

I won't bore you with the details, but I'm trying to overlay image links on top of a background image in specific positions. Despite my best efforts, the images are not changing no matter how much I tweak their parameters. Here is the HTML code: ...

Retrieve an image located outside of a container

I have multiple SVGs inside separate div elements. <div id="divA"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect x="10" y="10" height="130" width="500" style="fill: #000000"/> ...

Issue with CSS animations not functioning correctly within React application

Currently in the process of creating a basic dice roller and aiming to incorporate a spin animation for added visual interest. Strangely, the animation only triggers on the first roll and not on subsequent attempts (unless I refresh the page). Here is the ...

Attempting to apply two different animations to a single element

Trying to implement two different animations, with one triggering before the other. In the Codepen and snippet below, you can observe that the initial animation rearranges the icons to their original positions upon page load. The second animation involves ...

What is the best way to ensure the right six-column DIV remains at the top in responsive web design?

I have implemented a custom 12-column grid and have created a row structure as follows: <div class="row"> <div id="the-pink" class="lg-6 md-12 sm-12"><!-- content --></div> <div id="the-violet" class="lg-6 md-12 sm-12"&g ...

There seems to be an issue in Angular as it is unable to retrieve /

I'm encountering an issue with my simple application where I am receiving the error message "Cannot GET /." Also, in the console, I see this error: TypeError: Cannot read property 'checked' of null at Object.SL_BBL_locer. I'm unsure ab ...

Learn how to set up webpack or Next.js to generate a CSS file from custom Material styles and automatically inject it into the header

One of the things I've done is define some custom material styles, like this: import {createStyles, makeStyles, Theme} from '@material-ui/core/styles'; export const useStyles = makeStyles((theme: Theme) => createStyles({ fab ...

Unable to display the complete JSON data using ng-repeat in AngularJS

Utilize ng-repeat to display data retrieved from a web service. Below is my controller JS (GetAllCtrl.js): https://i.stack.imgur.com/GAelG.jpg I have received JSON data: https://i.stack.imgur.com/0xkAU.jpg My goal now is to extract only company informati ...

Generate a list of JS and CSS paths for UglifyJS/UglifyCSS by parsing an HTML file

Seeking a tool that can scan an HTML file (specifically a Smarty template file) to extract paths from <script></script> and <link/> tags for use with UglifyJS/UglifyCSS or similar minification tools. Extra credit if it can handle download ...

What is the best way to center a grid item in Material-UI within a React application?

I'm struggling with centering a grid element in MUI v5 and aligning a long paragraph to the left side while adding horizontal margin for big screens. Can anyone help me out with this? Thank you. <Box style={{ backgroundColor:" ...

Generate gzipped files using Angular CLI

I am attempting to populate a dist folder with the standard files along with their .gz versions. To achieve this, I used ng eject to obtain the webpack.config.js file in order to integrate the compression plugin from https://github.com/webpack-contrib/comp ...

Issue with parallax scroll feature on Mobile Safari not functioning as expected

I created a JavaScript code for parallax scrolling on an image at the top of a webpage. The code functions perfectly on Chrome, Firefox, Internet Explorer, Opera, and Safari on desktop. However, when I tested it on Safari on my iPad, the parallax effect wa ...

Making sure the checkbox stays selected in an angular environment

After experimenting with Angular 9 and a custom input, I achieved the following result => https://stackblitz.com/edit/angular-ivy-rgsatp My goal was to prevent users from disabling a radio button that is currently checked. Therefore, I made changes in ra ...

Is there a way to modify or alter the layout specifically for mobile devices?

Currently, my desktop version displays the image first followed by content (h1, p, button), and then repeats in that order. However, I would like to restructure the HTML for the mobile version to make it more user-friendly. How can I achieve this without d ...

Styling the select dropdown border in Google Chrome

I am encountering an issue with styling HTML select options in Chrome. Despite successfully applying borders to each option in Firefox, I cannot get it to work in Chrome. Can anyone advise on how this can be achieved? <select id="sortingOptions" class= ...

Having trouble with Tailwind CSS not functioning correctly once the font is imported?

I am currently working on a next.js project and utilizing tailwind for styling. I have noticed an odd behavior when importing a custom font into my globals.css file. page.jsx "use client"; import React from "react"; const page = () = ...

PHP failing to insert data

I'm facing an issue where my PHP code is not inserting any data. I have a form that displays values, but the update code doesn't seem to be working. Can someone please help me with this problem? Here is the PHP code snippet: if (isset($_POST[&ap ...

Integrating the Google Translate tool onto a website

My goal is to integrate a translation tool like Google Translator or other reliable options onto my website. I am not looking to translate the entire content of my pages into another language, but instead want to add a feature similar to the one found on t ...

In Google Chrome, the :after element on the left is cleared, while other browsers do not

In an effort to create a button using background images in the :before and :after pseudo-selectors for cross-browser compatibility, an issue arose where only Chrome did not display it correctly (Safari results were unknown). HTML: <div class="btn-cont ...

What are some tactics for avoiding movement in the presence of a border setting?

I created a webpage that has the following structure: .topbar-container { width: 100%; position: fixed; top: 0; background-color: #2d3e50; z-index: 999; display: flex; transition: height 500ms; } @media (min-width: 992px) { .topbar-cont ...