Two boxes each taking up half of the width, with content placed inside a container

How can I achieve the appearance seen in this image?

The layout consists of four columns using regular Bootstrap code. The first two columns should have a white background within a .container, while the other two columns should have a black background that stretches all the way to the end.

View on CodePen

<div class="container">
<div class="col-md-3">
  <p>First column</p>
  </div>
<div class="col-md-3">
  <p>Second column</p>
  </div>
<div class="col-md-3">
  <p>Third column</p>
  </div>
<div class="col-md-3">
  <p>Fourth column</p>
  </div>
</div>

Answer №1

utilize the linear-gradient property within the body, with your .container as the parent element, without any additional wrapper around .container

Apologies for the inconvenience, but what I intended was to position the image in this manner image.prntscr.com/image/78940c8115c943a186500ac24556758b.jpeg

Add a new parent div (as a child of body) and apply a background-image to that div

body {
  background: linear-gradient(to right, white 0%, white 50%, black 50%, black 50%, black 100%);
}
#wrap {
  background: url(//lorempixel.com/200/200) no-repeat  66.6% 0 / 25% auto
}
.container {
  border: 1px solid #f01;
}
[class^="col-"] p {
  color: white;
  height: 75px;
  background-color: blue
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div id="wrap">
  <div class="container">
    <div class="col-xs-3 col-md-3">
      <p>First column</p>
    </div>
    <div class="col-xs-3  col-md-3">
      <p>Second column</p>
    </div>
    <div class="col-xs-3 col-md-3">
      <p>Third column</p>
    </div>
    <div class="col-xs-3 col-md-3">
      <p>Fourth column</p>
    </div>
  </div>
</div>

Answer №2

To achieve a stylish look, consider implementing a linear gradient background on a parent element.

I have implemented a media query to accommodate narrow views. It's unclear what specific changes you are looking for in this scenario.

For an expansive view, switch to fullscreen mode:

.container {
  border: 1px solid #f01;
}
.col-md-3 {
  border: 1px solid #333;
}
.bg {
  padding: 30px;
  background: linear-gradient(to right, #ffffff 0%, #ffffff 49%, #ffffff 50%, #000000 50%, #000000 100%, #000000 100%);
}
@media (max-width: 992px) {
  .bg {
    padding: 30px;
    background: linear-gradient(to bottom, #ffffff 0%, #ffffff 49%, #ffffff 50%, #000000 50%, #000000 100%, #000000 100%);
  }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>


<div class="bg">
  <div class="container">
    <div class="col-md-3">
      <p>First column</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quia recusandae omnis praesentium dolorum soluta aperiam iste eum, neque necessitatibus pariatur. Neque nam modi mollitia in autem molestiae corporis harum placeat quos quaerat, labore ex
        ratione, possimus quod quo soluta libero, quis dolor! Porro similique natus eius et voluptatibus autem dolores.</p>
    </div>
    <div class="col-md-3">
      <p>Second column</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quia recusandae omnis praesentium dolorum soluta aperiam iste eum, neque necessitatibus pariatur. Neque nam modi mollitia in autem molestiae corporis harum placeat quos quaerat, labore ex
        ratione, possimus quod quo soluta libero, quis dolor! Porro similique natus eius et voluptatibus autem dolores.</p>
    </div>
    <div class="col-md-3">
      <p>Third column</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quia recusandae omnis praesentium dolorum soluta aperiam iste eum, neque necessitatibus pariatur. Neque nam modi mollitia in autem molestiae corporis harum placeat quos quaerat, labore ex
        ratione, possimus quod quo soluta libero, quis dolor! Porro similique natus eius et voluptatibus autem dolores.</p>
    </div>
    <div class="col-md-3">
      <p>Fourth column</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quia recusandae omnis praesentium dolorum soluta aperiam iste eum, neque necessitatibus pariatur. Neque nam modi mollitia in autem molestiae corporis harum placeat quos quaerat, labore ex
        ratione, possimus quod quo soluta libero, quis dolor! Porro similique natus eius et voluptatibus autem dolores.</p>
    </div>
  </div>
</div>

Answer №3

To solve this issue, simply nest one more level:

<div class="container">
<div class="col-md-6">
<div class="col-md-3">
  <p>First column</p>
  </div>
<div class="col-md-3">
  <p>Second column</p>
  </div>
</div>
<div class="col-md-6">
<div class="col-md-3">
  <p>Third column</p>
  </div>
<div class="col-md-3">
  <p>Fourth column</p>
  </div>
</div>
</div>

Consider assigning an ID to the md-6 class element for color management.

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

Top tip for combating form misuse in Django applications

Is there a reliable method to restrict form submissions in Django? I need the form to be submitted a maximum of 5 times from the same IP address within one hour. Can this restriction be implemented in Django? I experimented with Django Ratelimit, but unfo ...

HTML SVG text elements styled with varying background shades

Looking to enhance an image by adding multiple labels with distinct background colors: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <svg version="1. ...

Having trouble getting your Raspberry Pi web server to display the background image?

Recently, I successfully set up a LAMP server on my raspberrypi which was quite exciting. One of the first things I did was configure an FTP server to transfer webpage files to the Pi. I managed to create a basic form of the final webpage and transferred i ...

I'm looking for a Visual Studio add-in that can identify and flag any unused CSS classes or IDs within the entire solution

Exactly as the headline suggests. If not, what are some reliable online services you've tried for decluttering oversized stylesheets? ...

Alignment dilemmas

I'm experimenting with HTML and CSS and have a query concerning the text-align properties. As I work on constructing my personal website, I aim to align text content to start while having it centered in the middle of the page. Currently, I've ma ...

Why is the inline-block element in the list displaying on two lines? The text contains a number, but does it affect the layout?

What could be the reason for 'Maroon 5' moving down to a second line? Despite adding extra characters and testing with an integer, the issue persists. <ul id="soundsLike"> <li>Foo Fighters</li> <li>Maroon 5</ ...

How can you center a div at the top of another div?

I am working with a nested div structure and trying to center the inner content of one div within another. Is it possible to achieve this using CSS? <div id="outer"> bla, bla....... <div id="inner"> <p>Test</p> </div> ...

Construct a structure containing the key/value pairs of cells within an HTML table row using JavaScript

I'm completely new to JavaScript so please be patient with me; I'm not even sure if I'm searching for the solution correctly. Despite spending hours googling and experimenting, I still can't get it to work. My issue is related to an HT ...

Using Angular 4 for HTML 5 Drag and Drop functionality

I have been working on integrating native HTML 5 drag & drop functionality into my angular application. While I have successfully implemented the drag and dragOver events, I am facing an issue with the drop event not firing as expected. Here is the snipp ...

Preventing Past Dates from Being Selected in JQuery Date Picker

Need help with a date picker that only allows selection of the 1st and 15th dates of each month. How can I prevent users from selecting previous dates? <link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" ty ...

Is your JQuery Gallery experiencing issues with the next button function?

I'm working on developing a simple gallery using JQuery. The main concept is to have all image files named x.png (where x is a number), and the program will then add a number to the current one, creating x+1.png and so forth. Here's the code I ...

JavaScript Navigation Bar Error: The value of 'undefined' is not recognized as an object

Having just started learning HTML, CSS, and JavaScript, I encountered an error message that reads: TypeError: 'undefined' is not an object. Despite my best efforts to troubleshoot the issue, I have been unable to resolve it. Is there anyone who c ...

Tips for deciding on the appropriate CSS for an Angular 6 navbar component

I am currently working on an angular 6 application where users are assigned different roles that require distinct styling. Role 1 uses Stylesheet 1, while Role 2 uses Stylesheet 2. The Navbar component is a crucial part of the overall layout structure of ...

What is the standard size for PHP files, or the suggested maximum limit?

I created a tool at where users can upload a .php file with comments and spaces, and it will compress it for a smaller file size. It functions similar to but is web-based and provides instant results. Once you click upload, you receive a prompt to downl ...

Navigate post Ajax call

When I make an unauthenticated GET request using AJAX, my server is supposed to redirect my application. However, when I receive the redirect (a 303 with /login.html as the location), the response tab in the Firebug console shows me the full HTML of the lo ...

Adjust Font Size inside Circular Shape using CSS/jQuery

I have been searching for different libraries that can resize text based on the size of a container. However, my container is circular and I am facing difficulty in preventing the text from overflowing beyond the border. Below you will find a Fiddle conta ...

Incorporate h:outputText into your JavaScript code segment

After populating some information into a h:outputText, I am now looking to trigger a JavaScript function upon clicking a button that will retrieve the text from the outputText. The structure of the code is as follows: <p:tabView id="tabView"> & ...

My attempts to decrease the volume of an HTML5/CSS3 Audio element have been unsuccessful

Hey there! I'm currently working on my very first webpage and recently added an audio element that is functioning perfectly. The only issue I'm encountering is trying to position the element at the bottom of my page. I've already attempted ...

Restore checkbox to default setting

Is it possible to reset checkboxes in a form back to their initial status using javascript, PHP, jQuery, or any other method? Here is the code I am currently using: <form method="POST> <input type="text" name="name" id="name" value="default val ...

I am encountering an issue with the Link tag from next/link that is throwing an error. The error message states: "React.Children.only expected to receive a single React element

Hey everyone, I've come across an issue with using next/link in my code. Every time I replace the anchor tag with the "Link" tag, I encounter an error. I've searched for a solution but haven't found one yet. Any help would be greatly appreci ...