Avoid using poorly structured HTML/CSS wrappers

I am currently working on a website with multiple pages that have unique structures. All the HTML elements are wrapped in a container defined as:

<div class="wrapper">

On one page, I have used the following CSS for the wrapper:

    .wrapper{
    display: grid;
    grid-template-columns: 5% 45% 45% 5%;
    grid-template-rows: 5% auto 5%;
    width: 100;
    margin: auto auto;
}

However, there is another page with content wrapped in the same container but requiring a different grid layout. My solution was to create separate wrapper classes for each page:

<div class="wrapperhome">
<div class="wrappercontact">

and adjust the CSS accordingly.

As someone with limited experience using wrappers, I am unsure if this approach is considered bad practice or if there are better alternatives to solve this problem.

Answer №1

Honestly, I don't think it makes a huge difference. However, when it comes to finding the best approach, I understand your point.

In my opinion, it would be best to use different classes, such as .wrapper for common properties. If a specific page requires unique styles, you can create .wrapper-home and add or override properties as needed.

So, in practice, you could have

<div class="wrapper wrapper-home"></div>
.

Answer №2

You have the option to utilize sub classes for customization

.wrapper {
  display: grid;
  width: 100;
  margin: auto auto;
}

.wrapper.subClassName {
  grid-template-columns: 8% 20% 20% 8%;
  grid-template-rows: 5% auto 5%;
}

.wrapper.anotherSubClassName {
  /*
  Different Layout
  */
}
<div class='wrapper'></div>
<div class="wrapper subClassName"></div>
<div class="wrapper anotherSubClassName"></div>
<!-- ANd SO ON -->

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

Why is my HTML a:active not functioning properly?

CSS Code for Highlighting Active Tab: // To highlight the current tab that the user is viewing // CSS styles for the active tab .HeaderTabs li.tab a { display: block; // Defines anchor tab padding: 12px 8px 12px 8px; } .HeaderTabs li.ta ...

HTML Scroll Blocking

Recently, I have been working on designing the mobile version of a website. However, I noticed that when I try to scroll quickly on my phone, the scrolling gets interrupted and I have to wait for it to catch up. I am using the fullpage.js library in this ...

Guide on eliminating flex in CSS

Having an issue with aligning two grids created in HTML using Bootstrap. Below is the code: <!DOCTYPE html> <html lang="en"> <head> <title>IRIS Flower Classification</title> <link rel="stylesheet" href="{{ url_for( ...

Solving the Django Dilemma: Fixing the "No Reverse Match" Issue

My goal is to create a user-friendly experience where users can click on a product, go to the product page, and add a review directly to that page. The reviews will be displayed as users submit them. I'm not entirely convinced that this is the most ef ...

What is the best way to create a loop that is constantly changing?

Below is a PHP array that I am working with: echo "<pre>"; print_r($notifications); /* output: Array ( [0] => Array ( [score] => 120 [type] => 5 [post_id] => 1 [subject] => ...

What could be the reason for not just removing the pseudo-class, but instead deleting the entire CSS document altogether?

var style = document.styleSheets[1] style.deleteRule(`.block__header::after`) console.log(`.block__header::after`) What is preventing it from being removed from the CSS document? The pseudo-class is still found in the console, and when trying to dele ...

Display the JSON data in a table when the button is clicked

My goal is to display JSON data retrieved from a web service in a table format only after a button click. Although I have successfully fetched the data, I want it to be visible in a table only upon clicking the button. The current code displays table row n ...

Tips on positioning the navbar to the right edge of the screen

Currently using bootstrap, in the process of learning css and bootstrap. Looking to align links within ul to the far right of the screen. Assistance would be greatly appreciated <nav class="navbar navbar-expand-lg navbar-light bg-light"> ...

If the DIV does not contain a P tag, then the minimum height of the div should be removed

I have a div that contains an h2 and p tag. I am curious if there is a way to remove the styling from the div if the P tag does not exist. Here is the markup and styling: <style> .hotel-header { min-height: 100px; } </style> <div class="h ...

navigating to the start of a hyperlink

I'm having issues with scrolling to anchors and encountering 3 specific problems: If I hover over two panels and click a link to one of them, nothing happens. When I'm on section D and click on section C, it scrolls to the end of section C. ...

Maintaining CSS elements in position

Hello everyone, I have a project at work where I need to create a map with specific cities pinpointed. I've completed it on my computer and now I'm trying to ensure that when I transfer it to another device, like a laptop, the points remain in t ...

Font Awesome Icons not displaying properly following implementation of GetSimple CMS

Seeking help with a problem I encountered. I successfully created a company webpage and integrated Font Awesome. The static version of the page, built using HTML5, CSS3, and jQuery, is working perfectly. However, when trying to integrate this static webpag ...

Validating Forms in AngularJS: Ensuring At Least One Input Field is Not Empty

Consider the following basic HTML form: <form name="myForm" action="#sent" method="post" ng-app> <input name="userPreference1" type="text" ng-model="shipment.userPreference" /> <input name="userPreference2" type="text" ng-model="shipm ...

extract various information from a csv file

Having trouble reading items from a CSV file and adding them to an input form? When using a specific option value that allows you to add items by pressing comma, it doesn't work when reading from the .csv file. What could be causing this issue? with ...

Ways to overlook concealed elements within a Bootstrap Button Group

Within my button group, there are 10 buttons. On certain screen widths, using media queries for responsiveness, I hide some buttons. The issue arises when the last button is hidden - the rounded edges of the succeeding visible button are not maintained. ...

The output from calling getText() on the input field does not return any text

I'm a bit confused about how getText() works in selenium. Take a look at this snippet from a webpage: <input checked name=servClass type=radio value="Coach"> <font face="Arial, Helvetica, sans-serif">Economy class <br> <in ...

The menu using sprites does not function properly when placed within a fixed position div

On this platform, I've discovered a slew of valuable resources for creating a fixed position menu and a sprite based rollover menu. Nevertheless, I'm encountering difficulties when attempting to merge the two together. Despite my best efforts, I ...

Ways to establish a specific minimum width for a container and disregard small breakpoints in Bootstrap 5

I want to set a fixed minimum width for a container while ignoring small sizes like sm and xs. Basically, when the screen size is less than 960px, I want the width to be fixed and only display a scroll. This is the code I have: <div class="contain ...

Due to the feature in VISUAL STUDIO CODE that presents folders and subfolders at the same level

While working on my Angular project, I encountered an issue with creating a subfolder within a folder. Despite trying the same process in Windows Explorer, I faced the same problem of them appearing on the same level. What could be causing this discrepan ...

What is the best way to determine the width of the browser in JavaScript?

I'm attempting to create a JavaScript function that retrieves the current browser width. After searching, I came across this method: console.log(document.body.offsetWidth); However, it doesn't work well if the body width is set to 100%. Are ...