Resolved issues with the bootstrap content

Currently working on a responsive template using Bootstrap and aiming to create a design similar to https://i.sstatic.net/9jNOQ.png

I noticed that the background can be set with .container-fluid, but the content is aligned within a container. How can this effect be achieved? Here is my current structure:

<div class="services">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12 col-md-4 services-black">
                <h1>SEO Optimized</h1>
                <p>
                    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
                </p>
            </div>
            <div class="col-12 col-md-4 services-red">
                <h1>Responsive</h1>
                <p>
                    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
                </p>
            </div>
            <div class="col-12 col-md-4 services-green">
                <h1>Cloud Services</h1>
                <p>
                    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
                </p>
            </div>
        </div>
    </div>
</div>

As of now, the text extends to the full width of the container. Should I incorporate a nested-container like so?

<div class="container-fluid">
    <div class="container">
        ..
    </div>
</div>

or is there a better approach to achieve this layout?

Answer №1

Unique Gradient Approach

To create a unique gradient background, use the following CSS code:

background:linear-gradient(to right,black,black,green,green)
. Apply the class container to your content.

.services {
  background: linear-gradient(to right, black, black, green, green);
}

.services-red {
  background: red;
  color: white;
}

.services-green {
  background: green;
  color: white;
}

.services-black {
  background: black;
  color: white;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="services">
  <div class="container">
    <div class="row">
      <div class="col-12 col-md-4 services-black">
        <h1>SEO Optimized</h1>
        <p>
          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
        </p>
      </div>
      <div class="col-12 col-md-4 services-red">
        <h1>Responsive</h1>
        <p>
          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
        </p>
      </div>
      <div class="col-12 col-md-4 services-green">
        <h1>Cloud Services</h1>
        <p>
          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
        </p>
      </div>
    </div>
  </div>
</div>

New Approach with Bootstrap+Flex

Follow these steps to achieve the desired layout:

  1. Add another <div> inside each of your services-* sections
  2. Assign a width value for each inner <div> as needed
  3. Apply the following CSS properties to your container classes (e.g., services-black)

    .services-black{
      display:flex;
      justify-content:flex-end; // Align box to right
    }
    .services-green{
      display:flex;
      justify-content:flex-start;  //Align box to left
    }
    .services-red{
      display:flex;
      justify-content:center;    //Align box to center
    }
    

.cloud,
.seo,
.responsive {
  width: 60%;
}

.services-black {
  background: black;
  color: white;
  display: flex;
  justify-content: flex-end;
}

.services-green {
  background: green;
  color: white;
  display: flex;
  justify-content: flex-start;
}

.services-red {
  background: red;
  color: white;
  display: flex;
  justify-content: center;
}

@media (max-width: 768px) {
  .cloud,
  .seo,
  .responsive {
    width: 100%;
  }
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.css" rel="stylesheet" />
<div class="services">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12 col-md-4 services-black">
        <div class="seo">
          <h4>SEO Optimized</h4>
          <p>
            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
          </p>
        </div>
      </div>
      <div class="col-12 col-md-4 services-red">
        <div class="responsive">
          <h4>Responsive</h4>
          <p>
            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
          </p>
        </div>

      </div>
      <div class="col-12 col-md-4 services-green">
        <div class="cloud">
          <h4>Cloud Services</h4>
          <p>
            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
          </p>
        </div>

      </div>
    </div>
  </div>
</div>

Answer №2

You have the option to nest a .container within a .container-fluid, and you can also style the classes .services or .container-fluid to set the background-color. An example would be using pseudo-elements for the .services class.

.services:before {
  position: absolute;
  left: 0;
  top: 0;
  background-color: black;
  height: 100%;
  width: 33.333%;
  display: block;
  content: "";
  z-index: -1;
}

.services:after {
  position: absolute;
  right: 0;
  top: 0;
  background-color: green;
  height: 100%;
  width: 33.333%;
  display: block;
  content: "";
  z-index: -1;
}

 /* You can also apply styles to the .container-fluid */
.services {
  position: relative;
  color: white;
}

.services:before {
  position: absolute;
  left: 0;
  top: 0;
  background-color: black;
  height: 100%;
  width: 33.333%;
  display: block;
  content: "";
  z-index: -1;
}

.services:after {
  position: absolute;
  right: 0;
  top: 0;
  background-color: green;
  height: 100%;
  width: 33.333%;
  display: block;
  content: "";
  z-index: -1;
}


.services-black {
  background-color: black;
}

.services-red {
  background-color: red;
}

.services-green{
  background-color: green;
}
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
        
         <div class="services">
<div class="container-fluid">
<div class="container">
<div class="row">
<div class="col-12 col-md-4 services-black">
<h1>SEO Optimized</h1>
<p>
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
</p>
</div>
<div class="col-12 col-md-4 services-red">
<h1>Responsive</h1>
<p>
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
</p>
</div>
<div class="col-12 col-md-4 services-green">
<h1>Cloud Services</h1>
<p>
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
</p>
</div>
</div>
</div>
</div>
</div>

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

Creating a Submenu with HTML and CSS

After trying several guides on creating sub-menus, some involving JS, I decided to attempt a CSS-only approach. Unfortunately, I have encountered difficulty in making the submenu function correctly. You can view my code on fiddle here: http://jsfiddle.net ...

Is there a way to determine if a variable includes Chinese or Japanese characters?

Is there a way to determine if a variable includes Chinese or Japanese characters? I have found this line effective: if (myVariable.match(/[\u3400-\u9FBF]/)) My goal is to apply the same concept to a specific variable, rather than the entire do ...

Guide to making an adaptive hamburger menu using Bootstrap

I am currently working on a project where I am attempting to create a responsive navbar with a hamburger menu that shifts the menu to the left when the device has a max-width of 480px. However, I seem to be facing some issues and can't quite figure ou ...

Tips for Retrieving and Modifying Bounds in Google Maps to Add or Remove Markers from a List

I'm currently facing a challenge where I need to retrieve the Bounds and Change Bounds in order to add and remove Marker information on my Added List below my Google Map. Similarly, with the Zoom change, I need to make adjustments because I am utiliz ...

Fade Effect on Bootstrap Icons

Is there a way to show the filled version of a bootstrap icon when hovering over it? Here is the code I have: <svg width="80px" height="80px" viewBox="0 0 16 16" class="bi bi-cloud-plus" fill="#5cb ...

Is it possible to enable auto-completion for IDs in a separate CSS file using WebStorm 7?

I am new to using WebStorm 7 and currently working on building a simple HTML/CSS website. Initially, I included my CSS within the HTML file using the style tag, but now I have decided to move it to a separate file. Auto completion is functioning for all h ...

Inject a jQuery form submission using .html() into a div element

I am currently working on developing a basic forum where users can view listed topics and have the option to add new ones on-the-fly by clicking a link or image. How can I detect and handle the form submission event for the dynamically added form within an ...

Adding a row from two drop-down lists to a table and deleting it upon selection

Looking to dynamically update a table based on dropdown selection in jQuery. When a value is selected from the first dropdown list (projects), followed by a selection from the second dropdown list (employee), the selected values should be added as a new ro ...

Bootstrap grid. Instead of moving to the next row, scroll horizontally when the content overflows

Here is the code snippet: <div class="row shochatgroup"> <div *ngFor="let message of messages" class="col-auto"> <button *ngIf="message.state.attributes.shochatpaid > 0 && message.state.at ...

The text/font-weight of the header button is mysteriously shifting without warning

While creating a header for my webpage, I encountered an issue where the text family was changing when the dropdown menu was launched in Safari 8. Curiously, this behavior did not occur when using Chrome to launch the jQuery function. Even after attempting ...

What is the process for embedding iframe content onto a main webpage?

I'm facing a challenge with an iframe on my page that contains important content. How can I add additional content to the page where this iframe is located? Any suggestions would be greatly appreciated. Thanks! ...

I am having difficulty with my ajax code and I am unsure of how to resolve it

Here is the code snippet. I am encountering an issue where pressing the button does not trigger any action, while I simply want to ensure that the AJAX functionality is working properly. The expected behavior is for an alert message to be displayed when th ...

Radio button default checked value remains unchanged when a different selection is made

My radio group consists of options for Male and Female. Based on the stored data in the database, I have set a default checked radio button. Upon inspecting the element, I found everything as expected: However, when I select Female, the JQuery still read ...

Overflowing Bootstrap navbar problem

After adjusting the navbar height, the overflowing issue was resolved, but I specifically want it to be set at 5rem. Currently, the content of the navbar exceeds the 5rem height and mixes with the main body content, regardless of what modifications I make. ...

The one-click button is functional on larger screens, while on mobile devices, only a double click will register

I am facing an issue in angular where a button works perfectly fine with one click on larger screens, such as Macbook. However, on iPhone, it requires a double click to function properly (it works fine on Android too). The alert triggers with a single cl ...

How can I ensure that my Bootstrap 4 column adjusts to its content appropriately?

In the following container, there are two rows: the first row serves as the header, and the second row contains a left navigation bar and main content on the right side. The left nav bar is designed to shrink to the width of the content. By pressing a tog ...

Identifying rectangular shapes in an image and overlaying a div on top using Jquery

I am currently exploring the possibility of achieving the following: Imagine having an image within a div (serving as the background image). This image resembles an Excel sheet. My goal is to generate an input tag or contenteditable div when a user clicks ...

Encountered a challenge when attempting to substitute styles using classes in material-ui

While working on implementing a table using the TableRow component from material-ui, I encountered an issue with customizing the background color when the "selected" property is true. The default theme applies a pink background-color in such cases, but I w ...

Is it more effective to be precise when choosing IDs in CSS?

If you have a unique identifier on a div element called main, how should you reference it in CSS - with div#main or just #main? What is considered best practice? Considering that only one element can have a specific id, using div#main essentially duplicat ...

Issues with Autofocus while Searching and Selecting from Dropdown menu

Here is the JavaScript code I am using: <script type="text/javascript"> function handleSelectionChange(selectElement, nextField) { nextField.focus(); } function handleKeyPress(event, currentField, nextField) { i ...