What are the top recommendations for implementing typography in SCSS?

As I ponder the best approach to take, I find myself torn between two options and wondering what the 'best practice' in this situation might be.

My objective is to implement a selector that removes the standard global margin of 20px that I have established for typography elements.

Option 1: I could create a global selector class that can be utilized throughout the DOM to achieve the desired outcome:

SCSS
html {margin: 20px 0;}
.no-margin {margin: 0;}

HTML
<h1 class="no-margin">Title here</h1>
<p class=no-margin">Text here</p>

Option 2: Alternatively, I could apply specificity on a more granular level to define these values within the SCSS:

SCSS
html {margin: 20px 0;}
.box {
 h1, p {
  margin: 0;
 }
}

HTML
<div class="box">
<h1>Title here</h1>
<p>Text here</p>
</div>

Therefore, my question revolves around whether it is preferable to have a cluttered SCSS file and cleaner HTML structure without repeated class usage. OR To only specify the SCSS once even if it results in a cluttered DOM?

Answer №1

If you're looking to apply a consistent style to all elements, consider using ***** for universal selector selection

For example:

*{
margin:0;
padding:0;
}
<h1>Hello World</h1>
<h6>This is a 6th level heading with small size.</h6>

<p>this paragraph has the same padding and margin as h1 and h6</p>
<button>Click</button>

  • can be used to apply the same style to all elements

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

Can JQuery be used to specifically target attributes with vendor prefixes?

Is there a way to change the Thumb color for my slider without needing to select the thumb with a vendor prefix? I want to be able to dynamically pick the color without simply appending a class. $('.button').on('click', function (e) { ...

smoothly slides into view and playfully bounces

http://jsfiddle.net/E6cUF/ The concept involves a grey box sliding left from behind a green box after the page is fully loaded, with a slight bouncing effect if possible. Update: I created a new version inspired by modifications made by others on the jsf ...

Is it possible to implement AngularJS Routing for displaying HTML pages within a slideshow?

I have a vision for my website in mind - a stunning slideshow with a sleek navigation bar at the top. The idea is to have each slide represent a different category or concept, all uniquely customized with their own HTML page. However, I'm facing a cha ...

QuickSearch displayed at the center with a floating left alignment

I have been trying to center a QuickSearch div with multiple Q & A sections, but I am having no success. The div is floated to the left and has a background image. HTML <div class="l-row"> <div class="QuickSearch"> <div class="loop"& ...

The standard jQuery Mobile CSS styling does not seem to be working across various browsers, extensive testing has been conducted

I'm currently experimenting with jQuery Mobile to enhance my skills, but I'm facing issues with applying the basic CSS styling. I have included the css link from the jQuery Mobile website and ensured that I am connected to the internet. However, ...

Adjust the size of the mat-expansion indicator to your desired height and width

Trying to modify the width and height of the mat indicator has been a bit challenging. Despite following suggestions from other similar questions, such as adjusting the border width and padding, I am still unable to see the changes reflect in my CSS file ...

Adjusting the vertical dimension of an Angular 17 Material Dropdown Field?

Check out this demo where I'm exploring ways to decrease the height of the select field. Here's the code snippet: <mat-form-field appearance="outline"> <mat-label>Toppings</mat-label> <mat-select [formControl]=& ...

Troubleshooting problems with anchor-targets in Skrollr

I am experimenting with having divs overlap each other as the page is scrolled using Skrollr. Initially, I was able to achieve the desired effect with two divs. However, when trying to incorporate a third div, only the first and last ones seem to work prop ...

The navbar-fixed-top class in Bootstrap seems to be malfunctioning

As I work on expanding my portfolio website using Bootstrap, I decided to incorporate the 'navbar-fixed-top' class to make the navigation bar stick to the top of the window. I found a helpful example of this feature here: https://getbootstrap.co ...

Left-aligned Bootstrap Navbar Brand with about/gallery on the right

https://i.sstatic.net/pymGo.png Although I am content with the current state of my brand, I would like to adjust the positioning of my About, Gallery, and icons to the right. There seems to be a noticeable gap at the end of the "envelope" icon that I woul ...

Fine-tuning the page design

I'm working on a registration page using Bootstrap-5 for the layout. Is there a way to place all elements of the second row (starting with %MP1) on the same row, including the last field that is currently on the third row? See image below: https://i. ...

Quick CSS tweak

Below is my CSS code: .wrapper { display: inline-block; margin-top: 60px; padding: 15px; width: 100%; } I am looking to create a new class that inherits all the properties from wrapper and only changes the width property: .wrapper .exten ...

Certain divs have an opacity of zero while others do not

Currently in the process of creating a bootstrap template, which is being hosted at this link: Encountering a peculiar bug where the title spice road seems to be blocking the lorem ipsum text, yet is allowing the text in the gray jumbotron div to show thr ...

Is there a way to adjust the transparency of a span element's background without affecting the text itself?

I have some code that needs to be customized. This is my HTML: <div class="text-rotator add-top-half add-bottom-half align-left white-txt medium-txt uppercase highlight-bg"> <div class="rotator-wrap" style="display: block;"> <sp ...

What is the process for implementing SEO on dynamic websites? Is each page individually created as a static page?

My food delivery website features a search function where users can find restaurants by entering their area name. I am aiming for my website's LONDON search page to appear in Google results when users search for TAKEAWAYS IN LONDON. I have noticed th ...

Achieve a sliding effect between two divs using CSS only

I'm trying to create a design with 2 divs that are the same size. The first one is visible by default, while the second one is hidden initially. My goal is to achieve an effect where when you hover over the first div, the second one slides upward and ...

Image Positioned Outside Border in HTML

I'm working on creating a personalized homepage for my browser and I want to display 3 images with captions evenly spaced within a divider. Although everything seems to be in place, the border of the outermost divider is not covering the images. How c ...

I currently have two responsive menus and I'm trying to figure out how to modify the javascript so that when one menu is opened, the other

I am facing an issue with my responsive menus on a webpage, similar to the example provided in the jsfiddle link below. Currently, when one menu is open and I click on another, both remain open. How can I modify the JavaScript code so that when one menu op ...

What is the method for toggling background URLs?

Currently, I am utilizing flaunt.js by Todd Moto for my navigation system. My goal is to seamlessly switch the hamburger image with another image when the mobile-menu is shown and hidden. Check out the demo here. For a detailed tutorial, visit this link. ...

Images are obstructing the drop-down menu from being fully visible

I'm having trouble understanding why the drop-down menu when hovering over the "about" section is showing up behind the images on this website: (I hope it's okay to share the link). After looking at search results, I see that z-index might be t ...