Incorporating a background color/shape that extends beyond the boundaries of the container element

While using bootstrap4, I was wondering if it is feasible to incorporate a background color/shape to a header tag that extends beyond the confines of the container class. Consider the following scenario:

<div class="container">
<div class="row">
    <div class="col-md-8">
        <h1>What is Lorem Ipsum?</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 a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
        <h2>Why do we use it?</h2>
        <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
        <p>Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
        <h2>Why do we use it?</h2>
        <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
        <p>Many desktop publishing packages and web page 
          ...  

This setup currently resembles something like this:

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

To achieve the effect shown below, how can I add a background color and shape:

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

I attempted basic changes to the background color but couldn't find much while searching online. Any guidance or assistance in the right direction would be highly appreciated. Thank you.

Answer №1

.page {
  position: relative;
}

.container {
  width: 500px;
  margin: 0 auto;
}

h1 {
  position: relative;
}
h1::after {
  position: absolute;
  content: '';
  left: -99999px;
  top: 0;
  background-color: green;
  bottom: 0;
  right: 20px;
  z-index: -1;
}
<div class="page">
  <div class="container">
    <h1>Heading</h1>
    <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

</p>
    <h1>Heading</h1>
    <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

</p>
    <h1>Heading</h1>
    <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

</p>

  </div>
</div>

Creating a background within the container is not feasible.

You can experiment with pseudo-elements and positioning techniques. For instance, add an ::after element to each heading with 'absolute' position, left: -9999px, and apply the background color to the ::after element instead of the heading itself.

Answer №2

To achieve your desired effect, try using the clip-path: polygon property in your code. You can experiment with different polygon properties to customize the shape. Check out this handy tool for testing them out:

Here is an example snippet for your reference:

.shape {
    background-color: black;
    color: white;
    clip-path: polygon(0 0, 80% 0, 83% 100%, 0 100%);
}

After editing your code, it will resemble something like this: https://i.sstatic.net/rfTMN.png

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

Angular: Display an element above and in relation to a button

Before I dive in, let me just mention that I have searched extensively for a solution to my problem without much luck. The issue is describing exactly what I'm trying to accomplish in a way that yields relevant search results. If you're interest ...

The dropdown list box within the EditTemplate of a DataGrid does not utilize binding

I am struggling with binding the dropdownlist in the edit template of a grid view. I keep getting the error message "Additional information: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Type'." Below ...

Generate an adjustable grid layout (with rows and columns) to display information retrieved from an API request

I have recently started learning React JS and JavaScript. To practice, I am working on a small project where I am facing an issue with creating dynamic rows and columns. My aim is to display data in 4 columns initially and then move to a new row and column ...

Accessing obj_id within html with django

Why am I able to update the College record, but when I attempt to update, for example, Grade 1, it doesn't update. Every time I try to print the id = request.POST.get('id'), I always get ("id", 14). How can I fix my HTML? This is the code ...

Expand the image background to fit within a div container

Below is the code snippet I am working on: <div id="intro_section_upper" > <%= image_tag("video_background.jpg", :id=>"video_bg") %> <div id="video_table_main" > <table class=" ...

Utilizing CSS to showcase various sections of a webpage

Here is a basic example of an HTML file available at this link: http://jsfiddle.net/WhupP/2/ The webpage consists of 4 main sections - header, left-column, righ-column, and footer. Additionally, there are 2 @media elements named screen and print. When att ...

Endless looping of numerous consecutive animations

Is it possible to apply two animations to an element using only CSS and without the need for JavaScript? These animations should run sequentially an infinite number of times. @keyframes show { from, to { z-index: 100; } } @keyframes wait { ...

Easiest way to operate three different desktop environments

Is there a more cost-effective way to have three web applications running on separate displays with user input? Each display will require users to enter numerical information into the lightweight HTML, CSS, and JavaScript web app. I've considered op ...

CSS HTML parent div cannot contain image properly

Creating a website using Bootstrap: <div class="row padding_zero"> <div class="col section px-0"> <img class="img-trans padding_zero" src="./svg/clouds-00.svg" style="margin-top: -150px& ...

Seamless Navigation with Bootstrap Navbar and SmoothScroll

Currently, I have a custom-built navbar that functions perfectly, with full mobile responsiveness. However, I am facing an issue with the nav-item's (headings). The nav-item's direct users to different sections of the same page using #. I have i ...

Enhance Your Website with GatsbyJS Custom Scrollbars

I'm struggling to customize the default scrollbar on my Gatsby website with an overlay scrollbar. I want to avoid the page 'shifting' slightly to the left when switching between pages that have scrollbars and those that do not. My attempt i ...

Using the flexslider to override CSS styles in an <li> element

I have implemented the flexslider by whoothemes on my responsive website to showcase tiles. However, I am facing an issue with setting a specific width for the tiles on various devices. Upon inspecting with Chrome, I see this code: <li style="width: 21 ...

Issues with button padding in Firefox and Opera

Having an issue with the alignment of my buttons in HTML. In Opera, the button appears centered vertically, but in Firefox it seems like the text is slightly lower, messing up the design of my website. Below is the HTML code for the button: <input ty ...

Struggling to perfectly center the NavBar within the wrap container

After working on my navbar and utilizing this site for guidance, I was able to center it using text align. However, there is an odd indent in the navbar that I can't seem to figure out. This indentation throws off the alignment when centered, giving i ...

Fullpage.js paired with a carousel

Is there a reason why two carousels are not aligning side by side when using fullpage.js? It seems to work perfectly fine without fullpage.js! In Fullpage.js, even after separating the columns for the two carousels, they end up overlapping each other. How ...

Using JQuery to apply fadeIn and fadeOut effects, as well as adding or removing classes from div elements

My website utilizes JQuery to toggle classes with display properties for three divs positioned relatively. The side navigation contains three links that, when clicked, display different divs on the page with a fade in/fade out effect. $(document).ready(fu ...

What are the best methods for integrating Django with html, CSS, and JS?

While creating my website, I discovered that Django is typically used for the backend while HTML, CSS, and JS are used for the front end. For now, I am focused on designing my pages using HTML, CSS, and JS and have not yet begun developing the backend. I ...

href not functioning properly on subsequent clicks, whereas onclick remains active

I'm experiencing an issue with a button that opens a modal. When clicking the button, it's supposed to open a new page in the modal and also make an API call for processing before loading the new page. <a class="btn btn-primary" type='b ...

"Troubleshooting a CSS Problem in the ADF

I've encountered a serious issue with my ADF Application starting yesterday. Everything was running smoothly until suddenly, I saw this unexpected message in my Jdeveloper Console: < org.apache.myfaces.trinidadinternal.style.util.CSSUtils> < ...

error in jquery when splitting

I encountered an issue while trying to split data for checkboxes. var ukuran = data['model'].ukuran_model; var cek = ukuran.split(",").join('], [value='), $inputs = $('input[name^=ukuran]'); $inputs.filter('[value=&a ...