Stylish Bootstrap sidebar featuring a vibrant background hue

I am facing an issue with my bootstrap layout where I have two columns - one on the LEFT and one on the RIGHT. The left column should be 8 units wide using the Bootstrap's 12 column grid format, while the right column should be 4 units wide as shown below.

<div class="row">        
    <div class="col-md-8">Left Content</div>    
    <div class="col-md-4">Right Content</div>
</div>

The challenge now is how to center a CONTAINER within the row so that the content is centered while also having the right column stretch to full browser width with a background color. For example, if the left column has a blue background and the right column has a pink background, both colors should run full width while keeping the content centered via the container.

BOOTPLY

Answer №1

Simple Solution.
View the working solution at: https://jsfiddle.net/qbe2k1he/

/** Custom CSS **/
body {
background-color: #4E8FD8;
overflow-x: hidden;
}

.content, .sidebar {
border: 1px solid white;
color: white;
padding: 20px;
text-transform: uppercase;
min-height: 500px;
}

.content {
min-height: 2000px;
}

.sidebar::before {
content: '';
position: fixed;
top: 0;
width: 100vw;
height: 100vh;
background: #DB4ECB;
z-index: -1;
margin-left: -35px;
}
...
...
...
.we've successfully implemented a responsive grid system using customized CSS along with Bootstrap classes to display content in a two-column layout. Check out the full code above for more details.

Answer №2

This method has been effective for me personally, and involves the addition of a new CSS class.

<div class="container col-md-12 nopadding">
     <div class="row">    
        <div class="col-md-8" style="background-color:blue;">Content on the Left</div>    
        <div class="col-md-4" style="background-color:pink;">Content on the Right</div>
     </div>
</div>

The corresponding CSS is shown below:

.nopadding {
  padding: 0 !important;
  margin: 0 !important;
}

Answer №3

It's surprising that there are only a few questions like this one. I encountered a similar requirement and found a solution by utilizing absolute positioned elements and vw units.

The approach involves using a wrapper element with the background color of the left side to give the appearance of extending to the border of the screen. An absolute positioned div, matching the viewport width, serves as the background for the right side.

You can view the implementation in action on this codepen

The markup is structured as follows:

<div class="wrapper"> <!-- styling bg without affecting container margins -->
  <div class="container">
    <div class="row">
      <div class="col-md-8 left"></div>    
      <div class="col-md-4 right">
        <div class="bg"><!-- an additional element acting as background --></div>
      </div>
    </div>
  </div>
</div>

And the corresponding CSS:

/* Wrapper with bg color for left side */
.wrapper,
.left {
  background-color: blue;
}

/* Styling for right container */
.right {
  background-color: pink;
  position: relative; /* Allows absolute positioned children  */
  z-index: 0;
}

.right .bg {
  background-color: pink;

  /* Sizing bg element to match parent size and positioning it behind to act as a background */
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  z-index: -1;

  width: 100%; // For older browsers
  width: 100vw; // Sets bg width equal to screen width, extending beyond the screen

}

Note: To prevent horizontal scrolling bars due to the bg extending outside the container, ensure the wrapper div or its parent has overflow-x set to hidden.

If needed, utilize css pseudo elements like :before within the right column instead of declaring the bg element separately.

Adjust the styling for smaller screens by setting appropriate breakpoints.

Answer №4

Feel free to experiment with this code and make any changes you see fit, no extra CSS required.

<div class="container col-md-12">
  <div class="row col-md-6 col-md-offset-3">    
      <div class="col-md-8" style="background-color:green;">Left Content</div>    
      <div class="col-md-4" style="background-color:yellow;">Right Content</div>
  </div>
</div>

Check out the demo here

Answer №5

<div class="_100">
    <div class="container col-md-8 nopadding" style="background-color:blue;"><br>
        <div class="col-md-8 right nopadding" style="background-color:blue;border:white 1px solid;margin:5px">Left Content</div><br>
    </div>
    <div class="container col-md-4 nopadding" style="background-color:pink;">
        <div class="col-md-6 nopadding" style="background-color:pink;border:white 1px solid;margin:5px">Right Content</div>
    </div><br>
</div>

css:

.nopadding{padding: 0 !important;margin: 0 !important;}
._100 {width:100%;}  
.right{float:right;}

Answer №6

To achieve the desired layout, it is essential to be precise with the widths and make adjustments at breakpoints. Here is a basic starting point:

DEMO: http://www.example.com/ABC123

<div class="container bg-grey">Sample Container</div>
<div class="col-md-8 bg-info" style="height:100px">
  <div class="row">
    <div class="left-container bg-warning pull-right" style="height:50px">
      <div class="col-xs-12">Left Content - wider than in-container col-md-8, occupying 8/12ths of full width.</div>
    </div>
  </div>
</div>
<div class="col-md-4 bg-danger" style="height:100px">
  <div class="row">
    <div class="right-container bg-success" style="height:50px">
    <div class="col-xs-12">Right Content</div>
  </div>
</div>
</div>

Custom behavior will be required at breakpoints, and consider adjusting internal containers to col-7 and col-5 as the initial col-8 may appear too wide within. These modifications are open for your interpretation...

Answer №7

Make sure to review my solution. It seems like this is the one you're looking for - codepen. Remember to switch from bootstrap 3 to bootstrap 4.

html, body, .wrapper{
  height:100%;
}

.wrapper{
  padding:10px;
}


.right {
  position: relative;
  z-index: 0;
  padding:0 !important;
}


.wrapper {
  background-color: #00a2ff;
  overflow-x: hidden;
}
.right:before {
  content:"";
  background-color: #f7469e;
  height: 100%;
  position: fixed;
  top: 0;
  width: 100%;
  width: 100vw;
  z-index: -1;
}

body {
  background-color: #999;
  color: #fff;
}

.left, .right {
  outline: 1px solid #fff;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css" rel="stylesheet"/>
<div class="wrapper">
<div class="container">
  <div class="row">
    <div class="col-8 left">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>    
    <div class="col-4 right">Right Content -THIS CONTENT MUST NOT BE FULL WIDTH. MUST ONLY BE WIDTH OF col-md-4. THE BACKGROUND COLOR must be full-width.</div>
  </div>
</div>
</div>

Answer №8

Here is the provided solution. The blocks are designed to be adaptive, allowing you to customize the height of each block according to your needs, with the content automatically adjusting the height. Visit CodePen

<section>
  <div class="container">
    <div class="block block_left">
      <div class="block__content">
        <p>
             On the other hand, consultation with a wide asset base contributes to the preparation and implementation of a personnel training system that meets urgent needs. It should not be forgotten, however, that the established organizational structure requires an analysis of the personnel training system that corresponds to urgent needs.           
          </p>
          <p>
             Our mission! frames and places for staff training require our analysis of significant financial and administrative conditions.          
          </p>
        </div>
      </div>
      <div class="block block_right">
        <div class="block__content">
          <p>
               Therefore, the established organization structure largely dictates the creation of a development model.            
            </p>
           </div>
        </div>
      </div>
    </div>
  </section>
</style>

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

Ways to verify an iCheck located on the following page

Here is the code snippet I am currently working with: $("#add-new-size-grp").click( function (event) { event.preventDefault(); $.ajax({ type: "get", url:"ajax-get-sizes.php", success: function(result){ $("#sizeg ...

The h3 element is not responding to the adjacent sibling selector

Below is my HTML DOM structure. I am trying to remove the margin and padding for all h3 elements that are immediate siblings of a div with the id "successor". I attempted to achieve this using the adjacent sibling selector "+", but unfortunately, I'm ...

Display or conceal a division underneath a dropdown menu based on selections retrieved from a SQL Server database

Presented here is my JavaScript code. function appendItemforPurchaseOrder() { debugger var rowNumber = parseInt($(".itemmapContainer").attr("data-rownumber")); rowNumber = isNaN(rowNumber) ? 1 : rowNumber + 1; var addNewItemDetailHtml = ...

Investigating the Hierarchy of CSS Selectors

I've been pondering this question: What exactly is the functional distinction between these two code snippets, if any? I'm not certain how the use of a comma impacts statements. Does the #page > have an influence on the link in the first examp ...

Is there a way to make the edges of this table more curved?

I utilized an HTML code generator to easily create this table, but I am struggling to give it rounded borders. .tg { border-collapse: collapse; border-spacing: 0; } .tg td { border-color: black; border-style: solid; border-width: 3px; font- ...

The inline variables in CSS transitions are failing to be detected

The CSS transitions are not recognizing the inline variables, or if they are, they are not receiving the correct information. Below is an illustration of how the inline variables are defined in the HTML: <p class="hidden" style="--order ...

Implementing a two-column infinite scrolling feature using ISCroll

I am looking to incorporate multi-column infinite scrolling using IScroll infinite scrolling. I want the content of my HTML to appear as follows: <ul> <li>A</li> <li>B</li> <li>C</li> <li>D</li> ...

Please ensure to close the dropdown menu once the function has been called

I'm encountering an issue with a dropdown menu. When I expand the dropdown menu, everything works as expected. However, is it possible to disable the first search button and the txtSearch input field (referring to the class "glyphicon glyphicon-search ...

Changing the Position of HTML Scripts in React

I am facing an issue where I need to relocate an external script within a specific section of my page. However, I am unable to access the CSS attributes associated with this item. It seems that it is displayed as an iFrame, making it difficult to modify th ...

Assistance needed in keeping an image with absolute positioning CSS fixed to the top left corner of the browser

Looking for some CSS help as a beginner here! I've been trying to position a transparent PNG image over a centered table, but it seems stuck in the upper left corner of the browser. Absolute positioning should give me freedom to move it around, right? ...

Having Trouble Styling Radio Buttons with CSS

Hello, I'm facing an issue with hiding the radio button and replacing it with an image. I was successful in doing this for one set of radio buttons, but the second set in another row is not working properly. Additionally, when a radio button from the ...

(no longer supported) We are unsure about the usage of /deep/, >>>, and ::ng-deep, ::v-deep

Since /deep/ has been deprecated, I have found that using global styles instead is the only viable solution. Does anyone know of an alternative solution where we can still maintain encapsulation or scoped styling? ...

The content on my HTML webpage exceeds the width of the screen on mobile devices and certain PCs

I've exhausted most of the solutions available online, yet I haven't been able to resolve the issue. The content on my webpage is appearing wider than the screen size on mobile devices and some PCs URL: html, body,{ max-width: 100%; ...

Mastering the art of CSS float and positioning techniques

Struggling with CSS positioning yet again. I'm trying to design a webpage with one main element in the center, surrounded by 10 others. The challenge is to maintain consistency across different screen sizes (excluding mobile). However, every time I r ...

Enhancing x-axis presentation in D3.js-generated charts

I created a bar chart using D3.js, but I have encountered an issue with one of the values on the x-axis being too long. I attempted to use CSS properties like text-overflow: ellipsis, width: 10px, and overflow: hidden to abbreviate values that exceed a cer ...

Leveraging font as a comprehensive repository of icons

I have been experimenting with using entypo as the icon source for my web application. The UI technology I am working with is ZK. However, I encountered an issue when trying to include an icon from that font by using: <span sclass="entypoWhite">&am ...

Modifying the URL does not alter the selected tab

As part of my project, I wanted to ensure that when the page is refreshed, the previously selected tab remains active. To achieve this, I created a basic HTML page and added some jQuery. However, I encountered an issue when manually changing the URL from ...

Guide to creating a dynamic amount of slides in a React carousel for optimal responsiveness

Looking for a solution to adjust the number of elements displayed in my React Carousel based on available size? I have a React Carousel that currently shows 3 elements at one time. Here is the code snippet: const RCarousel = ({items}) => { const numIt ...

When taking a vertical picture on my iPhone, my Vue component does not function properly

Having trouble with displaying recently uploaded images on a form. If the image is taken from a phone, it may have an exif property that browsers do not handle correctly, causing the picture to appear flipped or sideways. Upside down photo To fix this is ...

The styles applied to the Angular 5 Component host element are not being reflected correctly in jsPlumb

As a beginner in Angular >2 development, I am excited to build my first application from scratch. One of the features I'm trying to implement is drawing flow charts using jsPlumb. However, I have encountered an issue where the connectors are not be ...