Tips on creating two columns with varying backgrounds and spacing on the left and right sides in Bootstrap

I am in need of assistance to create a website top bar similar to the image provided at this link: https://i.sstatic.net/wfc1w.jpg

The first column should display color-1, while the second column should showcase color-2. I want an angled design between these columns.

My attempt so far looks like this:

Below is the HTML code I have used:

<section class="topbar">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12 col-md-6 left">
        <p>Welcome to Remote Auto Diagnostics</p>
      </div>
      <div class="col-12 col-md-6 right">
      </div>
    </div>
  </div>
</section>

Here is my CSS code:

.topbar {
    background: #f41004;
    padding: 5px;
    color: #fff;
    line-height: 30px;
}

.topbar .left {
    background: #00f;
}

.topbar .left:after {
    content: "";
    display: block;
    width: 100px;
    height: 200%;
    background: blue;
    position: absolute;
    right: -20px;
    top: -10px;
    transform: skew(-45deg);
}

However, the result produced doesn't quite match the desired outcome: https://i.sstatic.net/U4cvm.jpg

There seems to be some padding on the left and right sides due to the container placement, affecting the display of the .topbar background. How can I adjust it so that the .left background color starts directly from the left side?

Interestingly, when using container-fluid instead, the left and right padding disappears, resulting in something like this:

https://i.sstatic.net/NOpfJ.jpg

Answer №1

My approach was unique: instead of using :after to skew the content, I simply skewed the "left" with the blue background and then skewed back the content within "left".

Check out the demo here: http://jsfiddle.net/aq9Laaew/81233/

HTML

<section class="topbar">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12 col-md-6">
                <div class="skewed">
                    <div class="content">
                        Welcome to Remote Auto Diagnostics
                    </div>
                </div>
            </div>
            <div class="col-12 col-md-6">
                Menu
            </div>
        </div>
    </div>
</section>

CSS

.topbar {
    background: #f41004;
    color: #fff;
    line-height: 2rem;
}

.topbar .skewed {
    background-color: #00f;
    transform: skew(-45deg);
    margin-left: -2rem;  
}

.topbar .skewed .content {
    padding-left: 2rem;  
    transform: skew(45deg);
}

Result

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

Note: To avoid the skew effect on small screens, consider styling the topbar directly using flex-box for better control.

Answer №2

One way to add a gradient effect to your website is by using CSS gradients. You can learn more about it here.

background: linear-gradient(135deg, blue 50%, red 50%);

*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.topbar {
    /*background: #f41004;*/
    background: linear-gradient(135deg, blue 50%, red 50%);
    color: #fff;
    padding: 5px;
    line-height: 30px;
}

.topbar .left {
  position: relative;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<section class="topbar">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12 col-xs-6 left">
        <p>Welcome to Remote Auto Diagnostics</p>
      </div>
      <div class="col-12 col-xs-6 right">
      </div>
    </div>
  </div>
</section>

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

Achieve sliding animations with Pure CSS using slideUp and slideDown techniques

Currently, I have implemented a code snippet to showcase a menu along with displaying submenus upon hovering over the main menus. Now, I am looking to introduce some animation effects for the submenus when they appear, similar to the slideUp and slideDown ...

Utilize jQuery, Flash, or HTML5 to upload an image

Does anyone know of an upload tool or plugin that has a similar look and functionality to the one used on Codecanyon's website? I tried Uploadify, but it doesn't work on all browsers. I need something that is compatible with all browsers, whether ...

Displaying the appropriate DIV element based on the value entered by the user

I am encountering some difficulties... I have an <input> field. Depending on the input, one of the various <div> elements should be displayed. For now, it's just a text (e.g. "Your plan contains less than 1500 kcal!"), but later, the div ...

Using JQuery to eliminate the current div in an image slider

I currently have an image slider that allows users to switch between images. There are two buttons - one adds a new item to the slider, while the other is supposed to remove the current image from the slider, but it doesn't seem to be working properly ...

A guide to accessing the sibling of each selector with jQuery

Imagine you have the following HTML structure: <div class="parent"> <div class="child"></div> <div class="sibling">content...</div> </div> <div class="parent"> <div class="child"></div> <div ...

The Bootstrap navigation pills do not function properly when using a forward slash in the tab link

I am currently working with Bootstrap and using nav pills. I have noticed that if I include a / sign in the link of a tab, it causes that specific tab to malfunction and triggers a JavaScript error in jQuery's own code when clicked on. How can I go ab ...

Showing information on a separate page based on the selected items by utilizing ng-click

I am attempting to display information about various properties on a new screen, which is accessed by clicking on a property name on the main screen. Here's what I have accomplished so far: I have retrieved data from an API and saved it in an array c ...

Encountering Error 404 1668 in CMD preventing connection to my CSS file within my HTML document

In the base.html file, my script is focused on the tree depicted in the image. I have verified that the href is correct and have loaded static at the very top of the HTML file. Despite this, I am still unable to connect the CSS file. Can anyone provide ass ...

Trouble displaying REACT.jsx in browser

I'm currently learning React and struggling to get it running smoothly. HTML function Person(){ return ( <div class="person"> <h1>Max</h1> <p>Your Age: 28</p> </div> ); } ...

The jQuery function fails to execute when the script source is included in the head of the document

I'm relatively new to working with scripts and sources, assuming I could easily add them to the header and then include multiple scripts or functions afterwards. Everything seemed to be working fine at first, but now I've encountered a problem th ...

Steps for creating a jQuery function that responds to changes in a text box value

Currently, I have a text box containing certain values and a submit button alongside a slider. When I click the submit button, the slider changes. However, I would like to achieve the functionality where instead of clicking the submit button, changing the ...

Steps to customize a CSS file within node_modules

Is there a way to make changes to a CSS file in the "node_modules" dependency without them being overwritten when I run npm install? I want to keep the modifications I've made to the node module files. ...

Preventing users from clicking on links unless they double click by using CSS rotation

I'm struggling to figure out why only the white portion of my links is clickable. The links are designed as "3D" buttons using CSS rotate transitions, but I can't seem to fix the issue. Any assistance would be greatly appreciated! Check out the ...

Issues arise when trying to manage HTML received as a response from a server in plain text

I have a scenario where I am dynamically generating an HTML table on the server side using Java and then sending it to the client as JSON data. The response looks something like this: <table class="table"></table><thead class="thead-dark"&g ...

Arranging Bootstrap dropdown and buttons on a single line

Check out my code snippet here: http://jsfiddle.net/52VtD/7462/ I'm facing an issue where I want to align my dropdown and buttons on the same line, but the dropdown being a div, it stays on the line below. How can I ensure they are on the same line? ...

Randomizing jQuery for duplicated HTML/jQuery elements

I'm facing a challenge with my jQuery and HTML scripts. I have a dropdown menu where a randomly generated number is displayed in the supplies field (voorraad) based on the selected option. However, when I clone this field using the add button, the fun ...

What are some techniques to ensure that my "display: grid" layout adjusts properly on mobile devices and tablets by implementing media queries?

Responsive Grid Design I am looking to transform my grid desktop view into a responsive layout for mobile and tablets using media queries in CSS. While it looks great on desktop, it does not adjust well on smaller screens. .grid-container { display: gr ...

How can I customize the tooltip placement in Bootstrap 5 while utilizing the 'text-truncate' attribute?

In my HTML table, I have long text in a cell that I don't want to display fully. To truncate the text, I am using the 'text-truncate' CSS attribute. Additionally, I am considering using Bootstrap tooltip to show the full text when needed. He ...

Guide on Setting up Bootstrap Using NPM in Laravel Installation

After successfully adding Bootstrap to my package.json file using "bootstrap": "^4.3.1" and running npm install without errors, I'm now wondering how to actually integrate Bootstrap into my view. It appears that NPM has installed Bootstrap in the /nod ...

Using Modernizr to determine the presence of nth-child in a test

I'm attempting to utilize modernizr in order to check for browser support of the :nth-child selector, but I am unsure of how to proceed. I came across this particular example on http://jsfiddle.net/laustdeleuran/3rEVe/ which tests for :last-child. How ...