Creating visually stunning full-width sections with graphic backgrounds using Bootstrap

Trying to bring a unique design concept to life, courtesy of my talented graphic designer. However, this sleek look is proving to be quite the challenge as I navigate through bootstrap implementation.

We are focusing on a call to action section that perfectly aligns with the 12 column grid system at its extremes on the left and right sides.

The design also demands that it stretches seamlessly to the view-port edges:

  1. A bold red background spans all the way to the edge on the left side.
  2. On the right side, a textured grey background extends stylishly to the view-port edge.

Although I am having trouble finding references or search terms for this particular layout, let alone where to start (apart from utilizing the background in full width for cta, then adding an element overlay on the left).

Any suggestions on how to code the following graphical layout using bootstrap?

<section class="cta" style="background: grey; position: relative">
    <div class="red" style="position: absolute; left: 0; width: 10%; background: red"></div>
    <div class="text-outer">
        <div class="container">
            <div class="row">
                <div class="col-xs-6">left</div>
                <div class="col-xs-6">right</div>               
            </div>
        </div>
    </div>      
</section>

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

Answer №1

Starting with the

<div class="container-fluid">
, I have made assumptions about your page layout. Here is a proposed solution:

Take a look at the code snippet below:

.cntn {
  border: 1px red solid;  /* You can remove this if not required */
}
.red {
  background-color: red;
  text-align: right;
  margin: 0;   /* Optional */
  width: 100px; /* Adjust as needed */
  float: left;
}
.cta {
  margin: 0;  /* Optional */
  float: right;
  border: 1px solid green;  /* You can remove this if unnecessary */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!-- Create a fluid container -->
<div class="container-fluid">
  <div class="row">
    <!-- Heading area: Hexagon -->
    <div class="red">
      <img src="http://placehold.it/100/100" />
    </div>

    <!-- Heading area: Call-to-Action -->
    <section class="cta">
      Action
    </section>
  </div>
  <div class="row cntn">
    <div class="col-xs-6">left</div>
    <div class="col-xs-6">right</div>
  </div>

</div>

Answer №2

To switch from 'div class="container"' to 'div class="container-fluid"', you just need to update the class name.

Answer №3

Is this what you had in mind? Instead of black, the gradient should be grey and max-width:400px can vary.

.cta {
  overflow-x: hidden;
  position: relative
}

.text-outer .container {
  width: 100%;
  max-width: 400px;
  background: grey;
  z-index: 2;
  position: relative;
}

.text-outer:before,
.text-outer:after {
  content: "";
  position: absolute;
  width: 50%;
  height: 100%;
  top: 0;
}

.text-outer:before {
  background-color: red;
  left: 0;
}

.text-outer:after {
  background-color: grey; /*Changed from black to grey*/
  right: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<section class="cta">
  <div class="text-outer">
    <div class="container">
      <div class="row">
        <div class="col-xs-6">left</div>
        <div class="col-xs-6">right</div>
      </div>
    </div>
  </div>
</section>

Answer №4

Check out this jsFiddle link

I have designed a layout with 3 divs named Left, Center, and Right. However, if you only need Left and Center, you can create your own custom class. The code below should help you achieve that:

.custom {
    width:calc(100% - (50% - 768px/2));
}

.custom {
    width:calc(100% - leftCellWidth);
}

You can adjust the height of the left div according to the height of the hex image.

Answer №5

To achieve a full-width layout, use the jumbotron class outside of the container class. You can find more information on this here.

Here is an example in HTML:

<div class="jumbotron">
   <div class="container">
     <div class="row">
        <div class="red col-xs-4">
        </div>
        <div class="grey col-xs-8">
        </div>
     </div
   </div>     
</div>

And the corresponding CSS:

.red {
  background: url('awesomeredimage.png');
  background-size: cover;
}
.grey {
  background: url('awesomegreyimage.png');
  background-size: cover;
}

Answer №6

It is important to ensure that all your divs are enclosed within the container div. One helpful suggestion is to use container-fluid for greater flexibility. The code snippet below demonstrates this concept:

If you prefer a quick solution, you can simply turn the CTA image into a clickable image by using .img-responsive in a col-xs-12. This revision will only take about 2 minutes:

<section style="background: grey; position: relative">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12">
                <img src="/img/cta.jpg" class="img-responsive">
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <div class="container">
                    <!-- Insert remaining content here -->
                </div>
            </div>
        </div>
    </div>
</section>

Alternatively, you can customize the design by creating columns as shown in the following code snippet. Adjust the sizes according to your preferences:

<section style="background: grey; position: relative">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-3 red">
                <img src="/img/hexagon.png" class="img-responsive pull-right">
                <!-- Specify a negative margin for the image to flow over to the grey area -->
            </div>
            <div class="col-xs-1 grey-image"></div>
            <div class="col-xs-3 grey-image">
                <h3 class="text-center">Call to action</h3>
                <p class="text-center">Discount information, etc.</p>
            </div>
            <div class="col-xs-5 grey-image">
                <button class="btn center-block">Request quote</button>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="container">
                    <!-- Insert remaining content here -->
                </div>
            </div>
         </div>
    </div>
</section>

Answer №7

Switch to using class="container-fluid" instead of class="container", then apply the following styling:

.container-fluid {
margin-right: auto;
margin-left: auto;
padding-left: 0px;
padding-right: 0px;
}

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

Adjust the height of the outer div automatically

Currently, I am attempting to dynamically set the height of div#container so that it adjusts based on its relative positioning and the absolute positioning of inner divs. Essentially, I want the inner divs to be centered within the container. <div id=" ...

Display a pleasant alert message when the file is not recognized as an image during the loading

Is there someone who can assist me? I have attempted multiple times but without success. How can I display a sweet alert when a file is selected that is not an image? <input type ="file" /> ...

What are the steps for positioning material-ui icons to the right?

I have a list that is dynamically generated with the following code snippet: <list className = "todos-list"> {allTodos.map((todo, index)=> { return ( ...

Sticky sidebar that adjusts to viewport size in a responsive layout

When designing a CSS fluid layout, most divs utilize percentages to adjust based on the viewport size. However, I have a specific scenario where I need my sidebar to maintain a fixed position. For instance: <aside style="width:25%; float:left; positio ...

Is HTML5 capable of supporting a multi-file uploader system in browsers?

Can you tell me which web browsers currently support the ability to select multiple files in an upload form, as introduced in the HTML5 spec? And does Adobe AIR also support this feature? As a bonus question, I'm curious if there are any JavaScript l ...

JavaScript preloader function isn't functioning properly when paired with a button

I'm currently working on developing a preliminary landing page for my game using JavaScript. I have integrated a class that overlays my main content, and added an 'onclick' function named fadeOut() for my button in JavaScript. However, the f ...

increase the width of the side menu bar to accommodate more content on the Bootstrap

At the moment, the line that separates the content from the side menu stops at the side menu's content. However, the content is going to be longer than the side menu, causing the page to look uneven. I attempted to adjust the page-content d-flex but d ...

What is the best way to retrieve classes from arrays and apply styling to them using javascript?

Imagine having 3 unique classes: alpha, beta, and gamma. Each class contains 3 individual div elements like so: <div class="alpha"></div> <div class="alpha"></div> <div class="alpha"></div> <div class="beta">< ...

Difficulty integrating Bootstrap with JavaScript file in Visual Studio Code

I am attempting to incorporate a dynamic progress bar by utilizing Bootstrap's progressbar and creating a custom JavaScript file. The goal is to continuously adjust the width of the progress bar at regular intervals to give the appearance of a moving ...

AngularJS radio buttons can now be selected as multiple options

Currently, I am in the process of learning angular and have implemented a radio button feature in my program. However, I have encountered a perplexing issue that I cannot seem to explain. <!DOCTYPE html> <html> <head> <meta ch ...

Tips for ensuring elements in a button are not vertically centered

My dilemma is unique: while many struggle with vertically aligning elements, I face the opposite issue. The contents of my button are currently vertically aligned, but I want them to wrap around like a normal <div> while retaining its clickable funct ...

Looking to determine if a specific element is assigned multiple class names

Help needed! Can you tell me how to check if an element contains more than one classname using pure javascript, without using jQuery? For example: If #test has both the classnames "classA and classB", then { alert(true) } else { alert(false) } Here is ...

Tips for rearranging button placements by utilizing multiple owl carousels across various webpages

I have successfully implemented two owl carousels on my Shopify website, and they are both functioning properly. However, I am facing an issue with the navigation buttons on the second page. The navigation buttons seem to be picking up a style that I had i ...

Implementing a jQuery method in a PHP page that is loaded through AJAX

I am facing an issue on my page where I am using jquery/ajax to load a series of buttons into a div. This script loads buttons every time the user scrolls the page and each button should run a jquery function when clicked. The problem arises when I switche ...

What is the reason behind the varying display of values?

When trying to set a value using the input tag, I encountered an issue. For example, if I type 1000.0009 into the input text, the valid value should be 1000.0001. However, the value displayed in the input tag is incorrect, while the value outside the tag i ...

Is it possible to customize the appearance of a toast notification using Toastr beyond the default settings? If so, what options are available for creating

Working with Angular 9 and ngx-toastr has presented me with an interesting challenge. I am tasked with creating custom toast styles that differ significantly from the default ones provided by toastr. Each toast in the set will have unique border colors, f ...

I am having trouble adding multiple items on different occasions - is it something to do with JQUERY

I have been working on a dynamic website that loads Firebase values into a table. However, I encountered an issue where the data does not appear when going back to the orders page after visiting another page. After some testing, I found that placing a but ...

Struggling to access the height attribute from a CSS file

Hey there. I'm pretty confident that the solution to my query is quite simple. So, I have a .css file with this particular code snippet: div.site { text-align:center; border:2px solid #4b6c9e; padding:1px; margin-top:10px; font-size:medi ...

Implementing a Method to Detect Keypress Event on Anchor Element

Within our application, we have implemented anchor tags as buttons to enable specific style implementations. An interesting feature of the anchor tag is that it does not receive focus when navigating through tabs. Although we have successfully implemented ...

Group HTML Tables According to Specific Attributes

Let's cut to the chase. My table is functioning well, printing all the necessary information without any issues. However, I'm facing a challenge when it comes to grouping the data rows under Program 1 together. Instead of having Program 1 print, ...