Set the background color of the container row to extend the full width, encompassing

I am working on a grid container and I want to change the background color of the second row within it.

Check out my Fiddle

This is the HTML markup:

<div class="totalContainer totalContainer__space">
  <div class="totalContainer__text">
    <label>Test test test test test</label>
  </div>
  <div class="totalContainer__text totalContainer__result">
    <label><strong>50</strong></label>
  </div>
  <div class="totalContainer__row totalContainer__text">
    <label>Test2 Test2 Test2 Test2 Test2 Test2 Test2 Test2 Test2</label>
  </div>
  <div class="totalContainer__text totalContainer__row totalContainer__result">
    <label><strong>20</strong></label>
  </div>
</div>

Here's the SCSS code snippet:

.totalContainer {
  display: grid;
  grid-template-columns: 4fr 1fr;
  margin-top: 30px;
  border: 1px solid rgba(72, 82, 93, 0.8);
  border-radius: 12px;

  &__row {
    background-color: #E5E5E5;
  }

  &__space {
    padding: 10px 0 10px 10px;
    margin-left: 160px;
    margin-right: 58px;
  }


  &__text {
    font-size: 13px;
    padding: 10px 0 10px 0;
  }

  &__result {
    text-align: right;
  }

  div:nth-child(2),
  div:nth-child(4),
  div:nth-child(6) {
    margin-right: 20px;
  }
}

The issue I am facing is that the background does not cover the entire width of the container

https://i.sstatic.net/tHar9.png

I want the background color to fill the empty spaces marked in red, but setting the width to 100% for the row class did not work. Any suggestions on how I can achieve this?

Update: I managed to remove the right space by changing margin-right: 20px; to padding-right: 20px;

However, I cannot eliminate the left space as I still need room for the text. The background seems to be affected by the padding property as well, making it challenging to solve this issue.

Answer №1

If you're looking to make some adjustments in the CSS file, consider the following changes:

  &__space {
   padding: 10px 0 10px;
   margin-left: 160px;
   margin-right: 58px;
  }

  &__text {
   font-size: 13px;
   padding: 10px;
  }

Additionally, it's recommended to remove the following code:

  div:nth-child(2),
  div:nth-child(4),
  div:nth-child(6) {
    margin-right: 20px;
  }

Check out this Fiddle for reference.

You can also view an image of the changes here.

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

What is the reason for min-content not being compatible with auto-fill or auto-fit?

My confusion lies in the fact that this code snippet works: .grid { display: grid; grid-template-columns: repeat(4, min-content); } Whereas this one does not: .grid { display: grid; grid-template-columns: repeat(auto-fill, min-content); } I am ...

having difficulty with an intricate flexbox grid within another flexbox

I attempted to create a grid-like pattern using a negative margin based grid system (Susy) but was unsuccessful. Next, I tried employing flexbox for the task. However, I'm unsure if it's achievable. My initial idea was to have 2 columns (side A ...

Manipulating values in JavaScript using an onclick event in PHP

I am looking to remove the "http" from the URL part of an input link before sending the data. This is my input code that looks like this when clicked: <input style="outline: none;" type="button" onclick="formatText ('link:url');" class="btn ...

Use the .html() function to alter the content of several sets of radio buttons simultaneously by changing

Here are the different options for a product. I need help with the .change() syntax to update pricing based on the following calculations: Bundle One + Marble Color = 15$ Bundle One + Black Color = 18$ Bundle Two [Most Popular] + Marble color = 25 ...

The autocomplete feature in Google Maps is not functioning properly when used within a modal

I've integrated the Google Maps API to enable autocomplete address functionality for an input box on my page. However, I'm encountering an issue where everything works fine on the page itself, but it doesn't work when the input box is placed ...

Stop text from being selected across all browsers in Firefox

My current CSS includes: *{ -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } If you visit http://jsfiddle.net/KyF5x/ and click be ...

"Creating a new element caused the inline-block display to malfunction

Can someone explain why the createElement function is not maintaining inline-block whitespace between elements? Example problem First rectangle shows normal html string concatenation: var htmlString = '<div class='inline-block'...>&l ...

Utilizing background images in CSS to enhance bootstrap icons

Here is the HTML code snippet I'm working with: <a class="iconContainer" href="#"> <span class="containerIcon chevron-right"/> Test </a> And this is the corresponding CSS code: .chevron-right::befor ...

Challenges related to height

Having an issue with height in my code. My footer is set up like this: <html> <body> <div class='wrap'> <div class=principal></div> <div class='clear'></div> <foo ...

Continuous loop of images displayed in a slideshow (HTML/JavaScript)

Greetings everyone, I am currently working on creating an endless loop slideshow of images for my website. Despite researching several resources, I am still struggling to get the code right. The issue I am facing is that only the image set in the HTML code ...

Exploring the Concept of Nested ViewModels in Knockout.js Version 3.2.0

I have a global view model that is applied to the main div and I also have other view models that I want to apply to nested elements within my main div However, I am encountering an issue: You cannot bind multiple times to the same element. Below is ...

How do I utilize AJAX and HTML to invoke a RESTful web service in Java?

How to call a RESTful webservice in Java using HTML Ajax? I have created a simple webservice in Java and want to POST data into a database using HTML Ajax by calling a Java webservice in Eclipse. However, I encountered an error in my Java program. How can ...

What steps can be taken to prompt the layout to transition?

I have an element that sticks to the top based on the current scroll offset. The issue is that the layout doesn't update when there is space available after the stuck element. This creates a ghost gap where the stuck element used to be... http://fidd ...

Is it feasible to incorporate two distinct images into a single element using CSS layering?

I have a question about setting a background image for a web page using CSS. Currently, I have the following code: body { font-size: 62.5%; /* Resets 1em to 10px */ font-family: Verdana, Arial, Sans-Serif; background-color: #9D5922; color: #000; margin ...

Adding a popover to a cell in a table: A step-by-step guide

Currently, I am attempting to display data in a single cell when hovered over using a popover. The problem I'm facing is that adding the data-toggle inside the td tag has no effect. Each cell is structured like this: <td style="padding: 0px; back ...

Looking to extract latitude and longitude data using an Autocomplete Address Form

I am currently attempting to utilize Google Maps autocomplete feature in order to save latitude and longitude. Unfortunately, I am encountering difficulties in making this functionality work as intended. Given that I am unfamiliar with the Google Maps API, ...

Is there a way to effectively overwrite CSS styles when utilizing @extend with another class in SCSS?

Here is some SCSS code I am working with: .a { height: 100px; width: 100px; } .b { @extend .a; height: 200px; } After compiling, the CSS appears as follows: .a, .b { height: 100px; width: 100px; } .b { height: 200px; } Whe ...

Issues with CSS preventing proper display on mobile devices like iPad and iPhone

My designer recently converted a PSD file, but for some unknown reason, the webpage is not displaying correctly on iPhones or iPads. The only visible element is the div that contains a feedback link. I have been troubleshooting this issue for a while now ...

Creating a custom route in Node.js using Express for posting content and adding it to a specific user's page

I am currently working on a node.js express project where I am developing a health app for a trainer to manage his clients. The main functionality of the app includes allowing the trainer to access individual client profiles and view their exercise list by ...

Setting a border on a specific column in ag-grid is a simple task that can help you customize

I have a table where the first set of columns differs from the rest. I am looking to emphasize this distinction by adding a vertical border on the right side of the specific column to highlight it both in the header and rows. Our setup includes using the ...