Creating personalized Bootstrap components

I am attempting to achieve a custom content layout in bootstrap that resembles the design of https://i.sstatic.net/nSK23.jpg

However, I am facing an issue where the div with the black background overflows the parent div.

Below is the code snippet:

<div class="thumbnail shadow">
    <div class="row">
        <div class="col-sm-12 col-md-12 col-lg-12" style="background-color:black">
            <h3 style="color: white">Purchase Order</h3>
        </div>
    </div>
    <div class="caption">
        <h3>3</h3>
        <p>...</p>
        <p><a href="#" class="btn btn-primary" role="button">View</a></p>
    </div>
</div>

Please visit http://www.bootply.com/OO8elZZx5j for reference.

-Alan-

Answer №1

The issue of overflow arises due to the background assigned to a column within a .row class. By default, .row grants negative margins which are countered by padding applied through col-xx-xx.

To address this, you can either eliminate the margins by overriding them on the row:

.shadow > .row {
  margin-right: 0;
  margin-left: 0;
}

Alternatively (and preferably), assign a left margin and reduce the width of the target element:

<div class="col-sm-12 col-md-12 col-lg-12" style="background-color:black; margin-left: 15px; width: 90%;">
  <h3 style="color: white">Purchase Order</h3>
</div>

A demonstration of these solutions is available in a new fiddle, accessible here.

In such scenarios, it's unnecessary to nest a row inside each column. A more efficient approach would involve having a standard DIV within the outer column for the header (with a background) and another div for the body. Here's a suggested implementation:

<div class="col-sm-3 col-md-3 col-lg-3">
  <div class="thumbnail shadow">
    <div class="header">
      <h3 style="color: white">Purchase Order</h3>
    </div>
    <div class="caption">
      <h3>3</h3>
      <p>...</p>
      <p><a href="#" class="btn btn-primary" role="button">View</a></p>
    </div>
  </div>
</div>

This structure will automatically manage the widths. You can then style .header to include the background and adjust margins if needed to enhance the headers:

.header {
  background-color: #000;
  padding: 5px;
  //margin-left: -5px;
  //margin-right: -5px;
}

An updated fiddle showcasing this setup can be viewed here.

I trust this guidance proves helpful! :)

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

Can the .scroll function be turned off when a user clicks on an anchor link that causes the page to scroll?

I am currently developing a timeline page and I want to implement a feature similar to the chronological list of years displayed on the right side of this webpage: As part of this feature, I have set up a click event which adds a circle border around the ...

tips for aligning text to the right of an image

For my college project, I am working on a website. However, I have encountered an issue with using a jsp script to display products in a specific way on the webpage. The problem is that I cannot control where the information about price, name, and descript ...

Hide elements on desktop viewport using media queries

If you want to see the code I'm using on my live site, visit www.randolphlibrary.org/mobilesite.htm In short: How can I implement a list-view style for users with a viewport of max-width 768px so that it caters to mobile users? My plan was to add th ...

Vertical stability bar

I need help creating a vertically fixed navigation bar for my website. Currently, I am using a method that has been discussed in various posts: HTML: <html> <head> src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">< ...

Prevent the Stop Function from being executed repeatedly while scrolling

I have implemented infinite scrolling in my react/redux app. As the user nears the bottom of the page, more contents are loaded dynamically. However, a challenge arises when the user scrolls too fast and triggers the function responsible for fetching cont ...

Show the table in a vertical orientation with HTML and CSS

I am currently tackling a project that involves generating a PDF file from HTML. However, I have encountered an issue where the table exceeds the page width. As a result, I am seeking a solution to display this table vertically. Is there a way to achieve ...

Looking to tidy up the HTML produced by JQueryUI?

Is there a way to achieve this? I am developing a template generator that includes resizable and draggable elements within a preview window. The issue arises when I try to extract the generated HTML, as it contains unwanted JQueryUI classes and divs for ea ...

What steps are involved in updating control hues using CSS variables?

Bootstrap v5.2.2. The Bootstrap developers have introduced a range of CSS variables for dynamic customization. Today, I want to dynamically change the color of all "primary-" controls. <html> <head> <link href="https://cdn.jsdelivr ...

Adjusting the color of text upon selection, ideally using CSS styling

::selection { background: #000000; opacity: 0 } ::-moz-selection { background: #000000; opacity: 0 } I am struggling with setting the color of selected text on my website to be pure black, however, since my text is already black, it gets hidden by the sel ...

Is it permissible for H2 heading to resemble H1 visually, and vice versa, in compliance with WCAG guidelines?

My expertise lies in Accessibility testing. Currently, we are dealing with Two headings <h1 class="CssPropertywithSmallFontSize">Heading One</h1> <h2 class="CssPropertywithBiggerFontSize">Heading Two</h2> From a visual standpoint, ...

What is the best way to add space between div elements with bootstrap classes?

For my project, I am utilizing bootstrap and I need to create space between divs. Here is the code I am using: <div className="container"> <div className="row"> <div className="col-lg-4 col-md-4 col-sm-12 col-12 box">a</div&g ...

Integration of a QR code scanner on a WordPress website page

I'm in the process of setting up a QR code scanner on my Wordpress site or within a popup. The goal is for users to be able to scan a QR code when they visit the page/popup link. Specifically, the QR code will represent a WooCommerce product URL, and ...

HTML form for selecting shipping method in PayPal

In my shopping cart setup, I offer two shipping methods: 'express' and 'standard'. I'm wondering if it's feasible to transmit this data to PayPal using HTML variables? ...

Is it possible to integrate a v-for loop within a Bootstrap grid for dynamic content rendering?

I am currently facing an issue with displaying my JavaScript objects in columns on my website. When using only HTML and CSS, the grid worked perfectly fine. However, after incorporating Vue into the mix, the columns now appear stacked vertically instead of ...

How can I rename attribute values in a dropdown menu and ensure they work properly?

I'm facing an issue with my code. How can I store the option values in a database when they have numbering like value="1" or value="2"? Can I change it to something like value="1000" and have the other select box change to value="250" when selected? ...

I am attempting to trigger a mouseup event following a mousedown action

elements[0].onmousedown = function(){ console.log('screen clicked.'); triggerMouseUp(); }; I just need to incorporate a function in my code that simulates mouseup event, even when the user is still holding down the click button. e ...

"Enhance user experience: Utilizing multiple dropdowns with the power

I found a helpful tutorial that I am currently following - Upon examining the demo - , I noticed that the second dropdown only appears once the first selection is made, and the same applies to the appearance of the third dropdown based on the second choic ...

Struggling to retrieve the image URL from a TypeScript file

I'm currently developing a basic app in Ionic that will include a feature to display a list of registered users along with their profile pictures. These profile images are stored in Firebase storage. Although I have successfully retrieved the URLs fo ...

Unique events catered to specific devices: mobile vs. desktop

When a user clicks on the login icon from a desktop, I want a modal dialog to appear. However, when using smaller devices like mobile or tablets, I prefer that a reactjs route is triggered to display in the main content area instead of using a modal dialog ...

Animating an upward movement of a div nested inside another div

Recently delving into the world of web development with HTML, CSS, and JavaScript, I've encountered an issue that has me stumped. I can't seem to figure out how to move a div upwards when the mouse hovers over it within its containing div. .prof ...