Enhanced mobile spacing using Twitter Bootstrap 4

While using the Twitter Bootstrap 4 code provided below, I have noticed some extra space appearing where the picture element is placed. Interestingly, when I remove the picture element from the column, the extra space disappears. However, when I replace the picture element with "lorem ipsum text," the extra space reappears.

On the other hand, the element containing the text "content" does not exhibit any additional space thanks to the no-gutters class being applied.

In the past, I have resolved similar issues by adjusting CSS to eliminate the extra space manually. However, this should not be necessary when working within a framework like Bootstrap 4 (v4.3.1).

I am open to any suggestions you may have on how to address this issue effectively.

<style>
body {
  background-color: blue;
}
.container{
  padding: 0px;
}
.bg-blue {
  background-color: #0D1954 !important;
}

.navbar-light .navbar-nav .nav-link,
.navbar-light .navbar-nav .nav-link:hover {
  color: rgba(255, 255, 255, 1);
}

.navbar-light .navbar-nav .nav-link:hover {
  text-decoration: underline;
}

.navbar-light .navbar-toggler-icon {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255,255,255, 1)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}

.navbar-light .navbar-toggler {
  color: rgba(255, 255, 255, 1);
  border-color: rgba(255, 255, 255, 1);
}

.white-background {
  background-color: #FFF;
}
<style>

The HTML code snippet is as follows:

<body>
    <div class="container">
        <div class="row d-block d-lg-none">
            <div class="col-12">
                <picture>
                    <source srcset="https://picsum.photos/600/300" type="image/webp" class="img-fluid">
                    <source srcset="https://picsum.photos/600/300" type="image/jpeg" class="img-fluid"> 
                    <img src="https://picsum.photos/600/300" class="img-fluid">
                </picture>
            </div>
        </div>
        <div class="row no-gutters">
            <div class="col-12 white-background ">
                content
            </div>
        </div>
    </div>
</body>

You can view the code on Fiddle here: Bootstrap Code on Fiddle

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

Answer №1

It appears that the issue lies in the container CSS class, specifically the padding of 0 pixels.

.container{
    padding:0;
}

Prior to this change, the container had a padding of 15 pixels and the row had a margin of -15 pixels, resulting in a total of 0 pixels.

However, when I removed the padding from the container but kept the row margin at -15 pixels, it caused chaos.

To resolve this issue, you can either add a no-gutter class to the row, apply a px-0 class on the row, or include a

.row {
    margin:0;
}

class to your stylesheet to eliminate the odd horizontal slider behavior.

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

Execute two operations using jQuery and PHP

I recently created a form for users to fill out, with the data being sent to my email. However, I also wanted the email information to be posted to my MailChimp account using their API. Unfortunately, this feature is currently not functioning correctly. B ...

What is the best way to remove the box-shadow from a React-Bootstrap Dropdown Button?

I'm attempting to remove the box shadow or second border from the bootstrap dropdown button when it is clicked. I have been unable to identify the specific class responsible for this change. https://i.sstatic.net/9wxRm.png ...

Troubleshooting: Why Printing a List in JSP Might Not Be Working

Update: All systems are functioning perfectly - it turns out the issue was just a simple mistake made by the original poster. Thanks to all the kind individuals who diligently searched for a flaw that didn't actually exist. Also, appreciate the helpfu ...

Struggling with a clash of styles between the float property and the navigation style in HTML

When I apply the float:left style to my <ul>, why does the nav bar appear very large? Consider this example: <ul class="nav" id="ModuleContainer" runat="server" style="float:left"> <li>111111----------------------</li> < ...

Tips for altering the color of two circles when they overlap:

Hello, I am interested in creating an effect where two circles change color when they overlap. Specifically, I would like the overlapped section to become white to represent sets. var canvas = d3.select("canvas"), context = canvas.node().getContext( ...

What is the best way to position one of my links at the end of a bootstrap navbar?

insert image description here I'm currently working on implementing a Bootstrap navbar and I am trying to align one of the links, specifically the last one, to the right side. Although I have searched through the documentation, I have not been able t ...

Update password after initial login success

In the process of developing a web application with existing Auth features in Django, I have encountered a need for enhanced security measures. The system involves an admin creating user profiles with usernames and passwords, which are then provided to use ...

What is the reason for the background image not appearing while utilizing a bootstrap template designed for it?

I recently started working on an asp.net application and decided to integrate a pre-made bootstrap template for the frontend. After some searching, I came across this one. The original site showcasing the template looked really appealing with a background ...

The Slider <h3> Content Does Not Adapt Properly on Mobile Devices Using Bootstrap

I am currently using bootsrap to create a slider that is responsive for phones. However, I have noticed that the texture on the picture becomes invisible when viewed in phone mode. Is there a specific bootstrap code that can be used to address this issue ...

Ensuring elements are correctly positioned

I am struggling to make the images in the following code align horizontally across the top and also need to align the h1's in the same way. I have tried using the vertical-align property, but it seems to behave oddly to me. HTML: <div class=&apos ...

Tips for positioning Bootstrap form labels and input fields in alignment

Currently, I am enhancing bootstrap-4 forms that consist of multiple input fields and labels. The form is functional, but I aim to elevate its visual appeal and user-friendliness. Working Snippet <link rel="stylesheet" href="https://stackpath.bootst ...

Summernote - When validating text, it is shown as raw HTML

I have integrated Codeigniter with Summernote on the frontend. In a form, if certain fields are left empty, the same page reloads for validation checking. The JavaScript and CodeIgniter code I am using is as follows: $(window).load(function(){ &l ...

Creating a handshake process for hybi-17

I am currently in the process of creating the handshake for the websocket hybi-17 protocol. I have been referencing the draft available at . Based on the guidelines provided in the draft, I have developed the following code snippets for both the client (us ...

Display the Vaadin side nav item icon only when the menu is in a collapsed state

Currently utilizing Vaadin 24. I have implemented a side menu with the use of "DrawerToggle" to toggle the visibility of menu items when the burger icon is clicked, which functions smoothly. DrawerToggle toggle = new DrawerToggle();
 SideNav nav = cr ...

Is the menu item a little crooked?

Working on designing a menu, and I noticed that the 'Book Now' option is slightly misaligned (pushed down) after adding a border. This seems to disrupt the horizontal alignment. Is there a way to correct this issue? Check out my Codepen Here is ...

What is the best way to include default text in my HTML input text field?

Is it possible to include uneditable default text within an HTML input field? https://i.stack.imgur.com/eklro.png Below is the current snippet of my HTML code: <input type="text" class="form-control input-sm" name="guardian_officeno" placeholder="Off ...

Utilizing CSS and HTML exclusively, display content on hover

Is there a way to display a child div when hovering over an anchor tag? I'm looking to reveal a div with the class of botm when the cursor hovers over the anchor tag. Here's the specific layout I have in mind, so please maintain the order of tags ...

What is the best way to show a list when hovering the mouse over a

<nav> <a href="login.html" class="dropdown-content" style="text-align: center"><span id="login">您好</span><i class="login"></i></a> <a href="9.html"><i class="like"></i></a> <a href="7 ...

Creating HTML dynamically upon page load with the use of JavaScript

I have a project where I need to create a small block of JavaScript that can be embedded in various websites' home pages. This script will automatically call a URL when visitors hit the home page, collecting specific statistics and returning a small i ...

Users are reporting a problem with the PrimeNG confirmation dialog where it becomes unresponsive and locks up the screen

Previously functioning code seems to have been affected by an update to PrimeNG. The confirmation dialog that was once usable is now hidden behind a gray click-mask, rendering everything on the screen unclickable: https://i.sstatic.net/YN7Iu.png The HTML ...