Prevent the image from increasing in size when removing padding from the Bootstrap Col

Using Bootstrap 4 Beta 3, I have set up a col-4 | col-8 layout. The first column contains an image, while the second column should contain both an image and text side by side.

Currently, I have split the second column into another row with two columns. I need these two columns to stick together without any gutters (e.g. using the class no-gutters). However, when I remove the gutters, the image inside the second column becomes larger than the one in the first column. I can't remove all gutters from all three columns because there should still be a margin between the main column 1 and column 2.

You can view the code on Codepen: https://codepen.io/SchweizerSchoggi/pen/mpjgLP

<div class="container mt-3">

  <div class="row">

    <!-- Teaser 1 -->
    <div class="col-12 col-md-4" id="teaser_Umzug">

      <div class="teaser-img teaser-stick">

        <img src="https://placeimg.com/640/480/tech" alt="Bild XY Company Umzug" class="img-fluid z-1 mr-1" />

        <div class="teaser-overlay pt-2 pl-4 z-2">
          <div class="teaser-txt">
            <h2 class="mb-3"></h2>
            <p class="mb-4">
              <span class="bold clearfix">Settelen &ndash;</span> ist Ihr Partner<br/>für <a href="#">regionalen</a> und <a href="#">nationalen</a> Umzug.
            </p>
            <button type="button" class="teaser">Mehr erfahren</button>
          </div>
        </div>

      </div>

    </div>

    <!-- Teaser 2 -->
    <div class="col-12 col-md-8" id="teaser_AutoService">

      <div class="row">

        <!-- Teaser 2 Img -->  
        <div class="col-12 col-md-6 bg-box-light">
             <div class="ml-0 mr-0"><img src="https://placeimg.com/640/480/tech" alt="Bild XY Company Auto und Service" class="img-fluid" /></div>
        </div>

        <!-- Teaser 2 Text -->
        <div class="col-12 col-md-6 bg-box-light">
          <div class="teaser-txt pt-4 pl-4">
            <p class="mb-4">
              <span class="bold clearfix">XY Company &ndash;</span> Ihr starker Partner in Sachen <a href="#">Auto</a> und <a href="#">Service</a>.
            </p>
            <button type="button" class="teaser">Services</button>
          </div>
        </div>

    </div>

  </div>

</div>

Answer №1

Here is a solution that I have devised...

To achieve the desired effect, apply the pl-md-0 class to the column containing the teaser 2 image. This will remove the left padding for medium screens.

Next, move the contents of the first column (containing the teaser 1 image) into a new row-column pair.

Then add the pl-md-0 class to the inner column housing the teaser 1 image.

If necessary, you can also eliminate both the left and right paddings by using the px-md-0 class.

Below is the code snippet:

.bg-box-light {
            background-color: #eee; /* TBD ! */
        }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">


<div class="container mt-3">
    <div class="row">

        <!-- Teaser 1 -->
        <div class="col-12 col-md-4" id="teaser_Umzug">
            <div class="row">
                <div class="col pl-md-0">
                <div class="teaser-img teaser-stick">
                    <img src="https://placeimg.com/640/480/tech" alt="Bild XY Company Umzug" class="img-fluid z-1 mr-1" />

                    <div class="teaser-overlay pt-2 pl-4 z-2">
                        <div class="teaser-txt">
                            <h2 class="mb-3"></h2>
                            <p class="mb-4">
                                <span class="bold clearfix">Settelen &ndash;</span> ist Ihr Partner<br/>für <a href="#">regionalen</a> und <a href="#">nationalen</a> Umzug.
                            </p>
                            <button type="button" class="teaser">Mehr erfahren</button>
                        </div>
                    </div>

                </div>
            </div>

            </div>

        </div>

        <!-- Teaser 2 -->
        <div class="col-12 col-md-8" id="teaser_AutoService">
            <div class="row">

                <!-- Teaser 2 Img -->
                <div class="col-12 col-md-6 pl-md-0 bg-box-light">
                    <div class="ml-0 mr-0"><img src="https://placeimg.com/640/480/tech" alt="Bild XY Company Auto und Service" class="img-fluid" /></div>
                </div>

                <!-- Teaser 2 Text -->
                <div class="col-12 col-md-6 bg-box-light">
                    <div class="teaser-txt pt-4 pl-4">
                        <p class="mb-4">
                            <span class="bold clearfix">XY Company &ndash;</span> Ihr starker Partner in Sachen <a href="#">Auto</a> und <a href="#">Service</a>.
                        </p>
                        <button type="button" class="teaser">Services</button>
                    </div>
                </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

Show a loading spinner with a smooth transition effect

After incorporating a loading circle template, I noticed that the circle abruptly appears when the submit button is clicked. I want to achieve a smoother transition for this loading circle. I attempted to use transitions, but it didn't have the desire ...

Create a minimalist Vue table design that enforces a maximum of 2 or 3 columns within

Is there a way to make my v-simple table with v-chips and v-badges align correctly in two or three column peer cell format? Here is the table for reference: https://i.sstatic.net/OFCyx.png Currently, I only have scoped styling applied: <style scoped> ...

Update the bootstrap navigation bar

I'm currently using bootstrap to construct my website. The navbar I have is quite typical with menu options, but I am aiming to modify the CSS in order to achieve a design similar to the image provided below (this design should be responsive and funct ...

Guide: Implementing Bulma Button Styles in React Components

Looking to integrate a Filter Buttons component into a To Do List Application. Specifically, I want to add four buttons for filtering tasks (All, Active, Completed, Important). Can someone guide me on how to incorporate Bulma CSS Rules with this react comp ...

Creating a sticky section with Tailwind CSS utility classes

I have a page in my Next.js web app, and I want to make the section highlighted in blue (wrapped in <aside> tag) sticky so that it stays in place while scrolling, with only the main section containing the chart scrolling. The code snippet below is f ...

You can move freely between classes A and B, as well as classes A and C, but there is no transition allowed between

A Brief Overview... Take a look at the HTML structure below: <div class="wrapper"> <div class="item above"></div> <div class="item active"></div> <div class="item below"></div> <div class="item ...

React Hamburger Menu not working as intended

I am facing an issue with my responsive hamburger menu. It is not functioning correctly when clicked on. The menu should display the navigation links and switch icons upon clicking, but it does neither. When I remove the line "{open && NavLink ...

Issue with setting default value and functionality of todayBtn in Django Bootstrap Date Picker

Using Django and Bootstrap, I developed a Date Picker. When clicked on the calendar field next to the input field, it defaults to: 06/Fr/yyyy. I attempted setting the todayBtn attribute as True, but encountered an error. You can see an example in the image ...

Do not apply hover effect to a particular child div when the hover effect is already applied to the parent

I am encountering a problem with the hover effect. I have 3 child div's structured as follows: <div class="parent"> <div class="child1">A</div> <div class="child2">B</div> <div class="child3">C</div ...

Change the class of the div when the first div is selected

My goal is to switch the class of the #klapp element (from .klapp to .klappe) whenever a click event happens inside the #label-it container, including when the #klapp element itself is clicked. The challenge is that I am not able to use unique IDs for each ...

Showcasing the JavaScript source code of a website on an HTML background using solely front-end code

Is there a way to dynamically display the current front-end JavaScript source code (1 file) on an HTML as a background? Currently, I am manually updating a static image of my code as the background whenever there are changes, which is not ideal. The JavaSc ...

Show the textbox automatically when the checkbox is selected, otherwise keep the textbox hidden

Is it possible to display a textbox in javascript when a checkbox is already checked onLoad? And then hide the textbox if the checkbox is not checked onLoad? ...

Is there a way to update the content of both spans within a button component that is styled using styled-components in React?

I am interested in creating a unique button component using HTML code like the following: <button class="button_57" role="button"> <span class="text">Button</span> <span>Alternate text</span> ...

Tips for adjusting the arrangement of Horizontal Cards on mobile using Materialize CSS

I'm currently working on a design layout similar to this example. The goal is to have the image and text displayed side-by-side on desktop and tablet devices, while on mobile they should be stacked on top of each other. I'm utilizing the Horizont ...

Tips for defining the width of columns that adapt to different screen sizes in Bootstrap version 4

Utilizing Bootstrap 3, I can effortlessly create a responsive table with adjustable columns using the grid system. Additionally, I have the ability to hide certain columns on smaller devices. For instance, consider this example where the table consists of ...

Adjusting the width of the rail in Material UI's vertical Slider component in React

After attempting to adjust the width and height of the rail property on the material ui slider I obtained from their website demo, I have encountered an issue with changing the thickness. import React from "react"; import { withStyles, makeStyles } from " ...

Unable to change background-image as intended

Here is an example of my HTML code with an initial background image: <div id="ffff" style="width: 200px; height: 200px; background-image: url('/uploads/backroundDefault.jpg')">sddsadsdsa<br>dffdsdfs</div> Everything seems to b ...

Adjust the stroke and fill colors of an SVG element when hovering over it

I am facing a challenge with an SVG image that I have: https://i.stack.imgur.com/r4XaX.png When hovered over or clicked, it should change to https://i.stack.imgur.com/EHRG2.png Current Icon <svg width="24" height="24" viewBox="0 0 24 24" fill="non ...

Learn how to achieve a sleek animation similar to the famous "Ken Burns effect" by utilizing the CSS property "transform" instead of "object-position". Check out the demo to see it in action!

I am currently exploring how to create an animation similar to the "Ken Burns" effect using CSS transform properties. While I have been using object-position to animate, I am facing challenges with the fluidity of the movement. I am seeking help to achiev ...

Can inline styling be overridden with CSS?

<td class="subrubr" nowrap="nowrap" valign="bottom"> <a name=""></a> Some lengthy text to be shown here. </td> This snippet of code is automatically created by a PHP script. However, ...