Twitter Bootstrap column overflowing the container boundaries

Hey there, I'm encountering a couple of small issues.

When I try adding the code below to resolve the issue, it works but breaks the layout causing one div to go under the other when resizing the browser window = https://i.sstatic.net/knflM.jpg

.col-sm-2, .col-sm-3, .col-sm-4, .col-sm-12 {
    width: 48%;
    margin-left: 20px;
}

The goal is to keep the divs beside each other with adequate spacing like this = https://i.sstatic.net/gMlqC.jpg

Also, I've noticed that including the space between the divs disrupts the responsiveness, causing them to stack on top of each other when the screen size decreases to less than 992px = https://i.sstatic.net/Y049G.jpg

I'm generally satisfied with the responsiveness right now, but introducing space between the divs seems to compromise it. Can anyone offer assistance in resolving this issue?

Here's the jsfiddle link: https://jsfiddle.net/vkb1aLeo/

<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afcdc0c0dbdcdbddcedfef9a819e819c">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
<link href="style.css" rel="stylesheet" />
</head>
<style>
.col-sm-2,
.col-sm-3,
.col-sm-4,
.col-sm-12 {
border: 1px solid #030303;
padding: 20px;
margin-top: 10px;
}

.item-name {
float: left;
width: 50%;
font-weight: 600;
}

.item-price {
float: right;
width: 50%;
font-weight: 600;
text-align: right;
}

.item-desc {
float: left;
color: #0d6583;
width: 58%;
}

.item-image {
float: right;
/* width: 40%; */
}

h4 {
padding: 10px;
font-size: 32px;
background: #945002;
color: white;
margin: 10px 0 10px 0;
}
</style>
<body>
<div class=" container">
    <h1>Test:</h1>   
            <div class=" row">
                <div class="">
                    <h4>Test</h4>
                </div>
                <div class="menu-item col-12 col-sm-12 col-lg-6">
                    <div class="item-name">
                        <p>Salad</p>
                    </div>
                    <div class="item-price">
                        <span ><span ><p>€1.00</p></span></span>
                    </div>
                    <div class="item-desc">
                        <p>Packed with super foods</p>
                    </div>
                    <div class="item-image">
                        <img  src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="Salad" />
                    </div>
                </div>
                <div class="menu-item col-12 col-sm-12 col-lg-6">
                    <div class="item-name">
                        <p>Soup</p>
                    </div>
                    <div class="item-price">
                        <span ><span ><p>€1.0a0</p></span></span>
                    </div>
                    <div class="item-desc">
                        <p>
                            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse non vehicula tellus, quis lobortis augue. Vivamus fermentum maximus sapien sit amet semper. Vivamus in nunc id magna consectetur laoreet. 
                        </p>
                    </div>
                    <div class=" item-image">
                        <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="Soup" />
                    </div>
                </div>
            </div>
        </div>
   
</body>

</html>

Answer №1

To enhance your design without overriding the col-sm class, consider implementing a new class called border_div:

<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a1acacb7b0b7b1a2b8839839f9138bc">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="    sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
<link href="style.css" rel="stylesheet" />
</head>
<style>
.border_div {
    border: 1px solid #030303;
    padding: 20px;
    margin-top: 10px;
    display: block;
    float: left;
}

.item-name {
float: left;
width: 50%;
font-weight: 600;
}

.item-price {
float: right;
width: 50%;
font-weight: 600;
text-align: right;
}

.item-desc {
float: left;
color: #0d6583;
width: 58%;
}

.item-image {
float: right;
/* width: 40%; */
}

h4 {
padding: 10px;
font-size: 32px;
background: #945002;
color: white;
margin: 10px 0 10px 0;
}
</style>
<body>
<div class=" container">
    <h1>Test:</h1>   
            <div class=" row">
                <div class="">
                    <h4>Test</h4>
                </div>
                <div class="menu-item col-12 col-sm-12 col-lg-6">
                    <div class="border_div">
                        <div class="item-name">
                            <p>Salad</p>
                        </div>
                        <div class="item-price">
                            <span ><span ><p>€1.00</p></span></span>
                        </div>
                        <div class="item-desc">
                            <p>Packed with super foods</p>
                        </div>
                        <div class="item-image">
                            <img  src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="Salad" />
                        </div>
                    </div>
                </div>
                <div class="menu-item col-12 col-sm-12 col-lg-6">
                    <div class="border_div">
                        <div class="item-name">
                            <p>Soup</p>
                        </div>
                        <div class="item-price">
                            <span ><span ><p>€1.0a0</p></span></span>
                        </div>
                        <div class="item-desc">
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse non vehicula tellus, quis lobortis augue. Vivamus fermentum maximus sapien sit amet semper. Vivamus in nunc id magna consectetur laoreet. 
                            </p>
                        </div>
                        <div class=" item-image">
                            <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="Soup" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
   
</body>

</html>

Answer №2

To adjust the spacing between rows' columns, you can customize

--bs-gutter-x: 2rem; /* control column gap */

Consider moving the .menu-item class to a new wrapper for .menu-* items as shown in the Code Snippet below. This adjustment will align your code more effectively with the BS-grid-way.

.menu-row {
  --bs-gutter-x: 2rem !important; /* control column gap */
  --bs-gutter-y: 2rem !important; /* control row gap */
}

.menu-item {
  display: inline-block;
  width: 100%;
  height: 100%;
  border: 1px solid #030303;
  padding: 20px;
}

.item-name {
  float: left;
  width: 50%;
  font-weight: 600;
}

.item-price {
  float: right;
  width: 50%;
  font-weight: 600;
  text-align: right;
}

.item-desc {
  float: left;
  color: #0d6583;
  width: 58%;
}

.item-image {
  float: right;
  /* width: 40%; */
}

h4 {
  padding: 10px;
  font-size: 32px;
  background: #945002;
  color: white;
  margin: 10px 0 10px 0;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a6ababb0b7b0b6a5b484f1eaf5eaf7">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
<link href="style.css" rel="stylesheet" />

<div class="container">
  <h1>Test:</h1>

  <div class="row menu-row">
    <div class="col-12">
      <h4>Test</h4>
    </div>
    <div class="col-12 col-lg-6">
      <div class="menu-item">
        <div class="item-name">
          <p>Salad</p>
        </div>
        <div class="item-price">
          <span><span ><p>€1.00</p></span></span>
        </div>
        <div class="item-desc">
          <p>Packed with super foods</p>
        </div>
        <div class="item-image">
          <img src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="Salad" />
        </div>
      </div>
    </div>
    <div class="col-12 col-lg-6">
      <div class="menu-item">
        <div class="item-name">
          <p>Soup</p>
        </div>
        <div class="item-price">
          <span><span ><p>€1.0a0</p></span></span>
        </div>
        <div class="item-desc">
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse non vehicula tellus, quis lobortis augue. Vivamus fermentum maximus sapien sit amet semper. Vivamus in nunc id magna consectetur laoreet.
          </p>
        </div>
        <div class=" item-image">
          <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="Soup" />
        </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

How to eliminate the inner padding border within a Material UI Outlined Text Field

I am currently utilizing the Material UI v5 Outlined TextField component to develop a form. In the image below, you can see a white padding border appearing in the TextField. I have created CSS that changes the input field color to yellow when focused. Th ...

HTML file unable to connect with CSS stylesheet

I'm facing an issue where my CSS stylesheet and HTML files aren't linking properly. Here is the code snippet from my HTML file: <head> <title>Website Sample</title> <meta charset="UTF-8"> <meta http-equiv= ...

Are there any available polyfills for downloading links using data URIs?

My issue involves generating code from the server: <a download="test.csv" href="data:text/plain;charset=utf-8;base64,w4FydsOtenTFsXLFkXTDvGvDtnJmw7p0w7Nnw6lwLg=="> teszt </a> This solution currently works with Chrome, Firefox, and Opera. ...

Problem with showing div when hovering

I'm having trouble displaying a div on hover. When I hover over the div element A, the div element B appears as expected. However, when the mouse pointer leaves the div element A, the div element B does not disappear. $('.display_cal'). ...

Having trouble sending the information to Parse.com using the website

I am a beginner with the Parse database and I am currently working on implementing a code that allows users to sign up, with their information stored in the Parse database. However, I am encountering an issue where the values are not uploading as expected. ...

Place the second division beneath the first within a single navigation bar that adjusts accordingly to all screen sizes

I am experiencing an issue with the layout of my page that has 2 divs within one nav element. When the screen width is greater than 1024px, everything looks fine. However, when I reduce the width to less than 768px, the two divs merge into one line instead ...

Adjust SVG size to fit parent container/division

I am trying to make the SVG completely fill the containing TD. I don't care about preserving the proportions of the SVG. Instead, I want the height of the SVG to be the same as its width when the height should be larger than the width. There is paddin ...

What is the best way to assign unique IDs to automatically generated buttons in Angular?

Displayed below is a snippet of source code from an IONIC page dedicated to shapes and their information. Each shape on the page has two buttons associated with it: shape-properties-button and material-information-button. Is it possible to assign different ...

Guide on deploying Google App Script add-ons on Google Workspace Marketplace

Recently delving into Google App Script, I've taken my first steps in coding within the platform. Utilizing the deploy option provided by Google App Script, I successfully launched my app. However, upon deployment, I encountered difficulty locating my ...

Tips for displaying an asp.net form using javascript functions

I am currently developing a login page in asp.net and have utilized a template from CodePen at http://codepen.io/andytran/pen/PwoQgO It is my understanding that an asp.net page can only have one form tag with runat="server". However, I need to incorporate ...

Building a custom dialog box using Angular Material with HTML and CSS

I've been exploring different approaches to create a customized angular material dialog with a unique header using CSS/SCSS and the TailwindCSS framework. I am aiming for a specific visual effect, similar to what is shown in the figure below. desired ...

When utilizing jQuery in HTML, the Marquee will bounce back upon reaching the end

My issue is that when I use a regular marquee, the text simply goes to the end and does not bounce back to the start as soon as it reaches the end of the div. Instead of using a normal marquee, I am looking to achieve this desired effect by utilizing jQue ...

Navigational menu utilizing hamburger icon in Bootsrap 4 framework

Currently, I am developing a website and have decided to utilize Bootstrap 4 for my project. My goal is to create a navbar layout that features a hamburger menu on the left side with additional navbar items positioned on the right. As the screen size decre ...

Choosing the Offspring: Deliberating on Multiple Children with Identical Names in Selenium

Just starting out with Selenium and web development in general, I've encountered a problem with locating an element using XPath. selenium.common.exceptions.NoSuchElementException I've been trying to troubleshoot for a while now, but haven' ...

Scrolling horizontally with scrollbar functionality

My goal is to create a webpage with a horizontally scrollable DIV element in the center, where the scrollbar appears only at the bottom of the DIV, not at the bottom of the entire page. I am wondering if it is possible to have a scrollbar placed at the ve ...

What is the best way to center align two inner divs within a container?

I've been working on achieving the following design: https://i.sstatic.net/ckC3j.png Just to clarify, the dashed line represents a guide indicating that both .inner-a and .inner-b are aligned in the middle horizontally and vertically within the imag ...

Uncovering Inline Styles Infused with Javascript for Effective Debugging of Javascript Code

SITUATION: I have recently inherited a website from the previous developer who has scattered important functions across numerous lengthy JS files. I am struggling to track down the source of an inline CSS style within the JS or identify which function is d ...

Can you explain the distinction between sockets and proxy passing in nginx compared to uwsgi?

My latest project setup involves flask, uwsgi, and nginx. The backend solely serves json data through an API, while the client side takes care of rendering. Typically, my Nginx configuration looks like this: My usual setup (with basic proxy passing): se ...

Obtain a unique HTML ID dynamically with Selenium and VBA

I am currently working on automating a web form using Selenium and VBA. The form includes a search box that generates an autogenerated list when a value is entered. While I can successfully input a value into the search box and trigger the javascript to cr ...

HTML: keeping script for future use in a variable

Is there a way to store a value in one place within an HTML document without the need for a database or PHP? Avoiding the repetition of typing the same value multiple times is the goal. Consider the following scenario: HTML <!-- Desktop --> <di ...