Full-width row background within a column of width 8 in Bootstrap

I am working with a classic HTML structure using Bootstrap 4. I have a specific panel within a col-8 where I want to apply a background color that spans the full width of the screen. Here is my code :

<div class="container">
  <div class="col-8">
    <div class="row">

    </div>

    <div class="row my-panel">
     <!-- The goal is to have this panel fill the entire width of the screen with a background color-->
    </div>
  </div>
  
  <div class="col-4">
     <!-- This is a sticky top panel that scrolls vertically with the page-->
  </div>
</div>

The issue I am facing is that the my-panel does not fill the full width because it is contained within the col-8 element. My objective is to achieve a full-width background color for my-panel, spanning across 100% of the screen's width.

Answer №1

Initially, your question lacks clarity but I have attempted to comprehend it based on your mention of editing.

Bootstrap operates using a grid system. When you assign a class like col-4, it creates a small box (column) within the grid for you to place your elements in, leaving the rest of the row empty. Additionally, as HTML divs function in a parent/child relationship, setting width: 100%; (CSS) in a col-8 inside a container will not stretch the container as expected.

To achieve the desired result, you need to modify the CSS attributes of the container. Alternatively, consider creating an additional parent div before the container and applying CSS to that instead.

It seems like you are aiming for something similar to the referenced image below. The background colors added to the divs serve as visual cues to illustrate the changes made. This approach should address your query regarding adding background colors.

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

Below is the code snippet:

<body>
    <div style="background-color: green;">
        <div style="background-color: blue;">

            <div class="container">
                <div class="col-8" style="background-color: red; width: 100%;">
                    <div class="row" >
                
                    </div>

                    <div class="row my-panel">
                    <!-- i want to fill this panel with a full width background color -->
                        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Maiores iusto consectetur,
                        aliquid laborum dicta nobis magni atque voluptatem ullam, natus deserunt, animi corrupti sunt nesciunt fugiat asperiores nam delectus quam.
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-4" style="background-color: yellow;">
            <!--  a sticky top panel which vertically scroll with the page -->
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Maiores iusto consectetur,
            aliquid laborum dicta nobis magni atque voluptatem ullam, natus deserunt, animi corrupti sunt nesciunt fugiat asperiores nam delectus quam.
        </div>
    </div>

</body>

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

Tips for styling carousel images seamlessly (HTML/CSS/Bootstrap4)

I am a beginner in HTML, CSS, and Bootstrap and I am currently working on implementing a carousel on my webpage. Although the carousel is functional, I am facing an issue with the images not fitting properly on the page. The size of the images appears to ...

Showing text instantly upon clicking a radio button, in real-time

I'm working with a set of radio buttons that are linked to numbers ranging from 1 to 24. I need to show the selected number in another part of the page when a radio button is clicked. What would be the best way to achieve this? ...

Utilizing Dojo to apply additional styles to an already existing class when a customized sorting feature is implemented on an improved

How can I dynamically add sort arrows (up/down) to a dojo enhanced Grid without using CSS? var mygrid = new EnhancedGrid({ id: "grid", store: gridStore, structure: gridStructure, canSort : function(index){ alert(index); } }, ...

Enhance the aesthetic appeal of the Search and Filters component in ASP.NET Core using Bootstrap styling

I am struggling to enhance the style and layout of multiple search filters on the page so that the User Experience is improved. I'm unsure how to effectively design this search component. <section class="search-sec"> <div class=&qu ...

How can I adjust the alignment of the text in a select menu in jQuery Mobile?

Exploring the world of jquery for the first time, I am excited about building a mobile web application. Utilizing jquery mobile (1.4.5), I encountered a simple issue - I couldn't figure out how to change the location of the text in the select menu. De ...

What is the best way to continuously add items to a div until their heights are equal?

In my layout, I have two divs positioned next to each other. Typically, the left div displays n+2 items while the right div displays n items. The value of n changes depending on the category and is already set. However, there are instances where certain ...

Removal of div elements based on checkbox being unchecked - a step-by-step guide

How can I delete elements from a div when the checkbox is unchecked? function removeCampaignName(id) { var campaignDisp = $('#camp' + id).html(); if ($("#campaign-name-disp").text().search("" + campaignDisp) === -1) { ...

Validating user input fields to display error messages when empty

As part of my program, I need to gather information from users regarding their name and the number of pets they have. If a user enters an empty string, I want to display an error message prompting them to input something and fill the text box with their en ...

What is the best way to eliminate the box-shadow on the top of a dropdown menu using CSS?

Can someone assist me with removing the top box-shadow in CSS? Check out the image for reference: You can view a live demo here: www.hobbu.org Below are some code snippets: HTML <nav> <ul class="container_12"> <li><a href="# ...

What is the process for transferring the most recent data from a database to an HTML textbox following form submission?

Process : 1) Retrieve record from the database 2) Populate HTML textbox with the retrieved record 3) User makes changes to the value in the textbox 4) User clicks the "Save" button on the webpage. 5) Form is submitted using method="post" action="curr ...

Achieve a perfect balance with Flex by centering items using justify-content and align

Seeking assistance, please. Utilizing Bootstrap 5 and attempting to achieve this specific layout alignment: https://i.sstatic.net/zVP7T.png <html class="h-100" lang="en"> <head> <!-- Required meta tags --> <meta charse ...

Effective Strategies for Preserving Form Input Values during Validation Failure in Spring MVC

I am currently working on validating user input, and I want the user's input fields to be retained in case of any validation errors. This is how I have set up my input fields: <form:input path="firstName" class="text short" id="firstName" value=" ...

Adjusting the width of the header in Wordpress themes like Genesis and Foodie Pro

Struggling with the header appearance on my website. I want the blue section to be full width while keeping the logo and navigation the same width as the content area (1040px). I'm new to Wordpress and unsure how to make this adjustment. Someone sugg ...

What is the process for generating and connecting a new webpage using Visual Studio Code?

I am currently exploring online tutorials that involve using a single index.html file and app.js file to create just one page. However, I am interested in creating multiple pages that can link back and forth with the click of a button. How can I achieve th ...

Executing PHP Code following a JavaScript Confirmation Box: Best Practices

How can I run the following code in PHP? var answer = window.confirm("Do you want to overwrite the file..."); Based on the user's selection of "OK" or "CANCEL"; If the user chooses "OK", I need to execute the following PHP code without using AJAX. ...

AngularJS button click not redirecting properly with $location.path

When I click a button in my HTML file named `my.html`, I want to redirect the user to `about.html`. However, when I try using `$location.path("\about")` inside the controller, nothing happens and only my current page is displayed without loading `abou ...

What's the best way to adjust the card column for mobile view resizing?

I am trying to modify the card view for mobile devices to display as a 2-column layout. I have adjusted the flex length and grid size in my code, but I still can't achieve the desired result. Can someone guide me on how to make this change? Current d ...

Content is not centered with Bootstrap's flexbox

The alignment of content is not centered using bootstrap flex <div class="d-flex flex-row bd-highlight mb-3"> <div class="p-2 bd-highlight text-left"><i class="fa fa-chevron-left" aria-hidden="true"></i></div> <div cla ...

Disable all borders for PrimeFaces p:panelGrid elements

How can I remove borders from all panelgrids in primefaces? I've attempted the following code without success: table { border: none; } table tr, table td { border: none; } Is there another method I should try? ...

I am unable to access the Xml data using VBA's `selectsinglenode` function as it is returning nothing

Below is the XML data: <NewZipCdListResponse> <cmmMsgHeader> <requestMsgId/> <responseMsgId/> <responseTime>20220526:085103847</responseTime> <successYN>Y</successYN> <returnCode>0 ...