Adding space between Bootstrap columns to align them one below the other on small devices

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

  • Within this illustration, there are two columns - one with the class col-sm-3 and the other with col-sm-8, situated in a single row.
  • Upon resizing the window (as shown in the screenshot provided), the two columns appear to be glued together. Moreover, the second column (col-sm-8) does not expand to its full width at the breakpoint for small screens.

    Note: I aim to maintain spacing between the columns at the small screen breakpoint, while also ensuring that the col-sm-8 column occupies the entire available space.

    Link to Bootstrap code

Answer №1

To make the col-sm-8 full width with space between columns at the sm breakpoint, you just need to add a class.

Add the following class below the col-sm-8 div only:

document.getElementsByTagName("h1")[0].style.fontSize = "80px";
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet"
          href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
          integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
          crossorigin="anonymous"
    >

   ... (continued styling and HTML code)
   
  </body>
</html>

Answer №2

To adjust the layout at a specific screen size, you can apply some margin using a breakpoint like this:

@media screen and (max-width: 576px) {
  .col-sm-8 {
    margin-top: 30px;
  }
}

The term sm signifies small in bootstrap, which triggers at 576px.

This article provides a thorough explanation

Expanding Width

If you want the final div to occupy the entire width, check why it doesn't initially by inspecting it.

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

It's evident that there is padding on each side - padding: 15px. You can eliminate this in a certain breakpoint to retain the space in larger resolutions.

@media screen and (max-width: 576px) {
  .col-sm-8 {
    padding-left: 0;
    padding-right: 0;
  }
}

Your original code now includes the new modifications

Codepen demo

Answer №3

To start, Bootstrap margin properties can be utilized. I suggest considering mb-3 (margin-bottom-3) or mt-3 (margin-top-3) for your needs in this case.

It is also possible to add margins with pure CSS when the width exceeds a certain value, X pixels for instance.

For instance:

@media screen and (max-width: 640px) {
    .do_margin_bottom {
        margin-bottom:20px; /* Similar to mX-3 */
    }
}

Subsequently, apply the .do_margin_bottom class to your col-sm-3 element.

Regarding the second point: Your col-sm-8 appears correctly aligned, as does your col-sm-3. The issue lies in the div.card element adding margin-left:15px & margin-right:15px. Adjust these values on your card element to achieve the desired spacing.

I personally advise against removing these margins. A card without any margins may appear unusual.

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

Creating a stunning effect with radial-gradient on an image element

I am looking to achieve a fading effect on an element using a radial gradient. While it works when I set an image as a background image, it does not work on the element directly. Is there a way I can accomplish this? My goal is to have the image fade fro ...

Switch between Light and Dark Modes effortlessly with just one button

I've created a code that effortlessly switches between light mode and dark mode with the press of buttons. However, I'm looking to combine these two functionalities into a single toggle button for ease of use. If anyone can provide insight on how ...

Issue with jquery_ujs: Font Awesome spinning icon animation functions properly in Chrome but not in Safari

I've integrated font-awesome-rails into my Rails project. When a user clicks the submit button on a form: The submit button should display an animated font-awesome spinner and change text to "Submitting...". The button must be disabled to prevent m ...

Hover over the image with some padding placed around it to see

I am struggling to figure out how to add padding to my image when hovering over it with Onmouseover. I have tried multiple solutions but none seem to be working. Here is the original code: <img src='/wp-content/uploads/2015/04/img-white.png' ...

Unable to insert menu links into the container

Currently, I have a logo and image slider placed next to each other in a container. However, I am facing difficulty in adding 3 menu links horizontally under the logo. Every time I try to do so, the links end up going above the image slider, causing it to ...

Weather Application featuring Circular Slider

I've been on the hunt for a circular slider animation. Imagine it working like this: <input type="range" min="0" max="50" value="0" step="5" onchange="showValue(this.value)" /> <span id="range">0</span> function showValue(newValue ...

What causes the Top Navbar in Twitter Bootstrap to exceed the container when fixed?

While working with the default fixed-top navbar in Bootstrap, I encountered an issue where it spans the full width of the viewport. In order to contain it within a specific container div, I tried applying a CSS override for the left side: .navbar-fixed-to ...

Tips for presenting HTML source code with appropriate tag coloring, style, and indentation similar to that found in editors

I need to display the source code of an HTML file that is rendered in an iframe. The source code should be shown with proper tag colors and indentations similar to editors like Sublime Text. https://i.stack.imgur.com/IbHr0.png I managed to extract the sour ...

Looking to extract latitude and longitude data using an Autocomplete Address Form

I am currently attempting to utilize Google Maps autocomplete feature in order to save latitude and longitude. Unfortunately, I am encountering difficulties in making this functionality work as intended. Given that I am unfamiliar with the Google Maps API, ...

Is it possible to generate a PNG blob using binary data stored in a typed array?

I have a piece of binary data that is formatted as a PNG image. I am looking to convert it into a blob, generate a URL for the blob, and then showcase it as an image in various places where an image URL can be used, such as CSS. My initial approach invol ...

V-model prevents checkbox from being checked upon clicking

codesandbox: https://codesandbox.io/s/github/Tapialj/AimJavaUnit6?file=/src/frontend/src/components/AddMovieForm.vue I am currently working on implementing a feature where I need to collect an array of selected actors using checkboxes. I have set up a v-m ...

Step by step guide to showcasing images dynamically in user interface

My current project involves displaying a screen with an HTML table and an image. The HTML table is fully dynamic. The Code Working Process When the user loads a page (with a URL), I render an HTML table in different parts as the page loads. I retrieve al ...

Angular 8 is facing an issue where classes defined dynamically in the 'host' property of a directive are not being properly applied to the parent template

In my Angular 8 application, I am working on implementing sorting using the ng-bootstrap table. I referred to the example available at . In the sample, when I hover over the table header, it changes to a hand pointer with a highlighted class applied as sho ...

Experience the magic of CSS Sprite once it's been successfully uploaded!

Visit the website for testing here Located at the bottom of the page are two images with hover effects - one labeled "Contact us" and the other "Jobs Available!" During local testing, these images are visible. However, once uploaded to a server, they dis ...

Difficulty arises when trying to merge a dropdown menu with a horizontally scrolling menu

I am attempting to include a dropdown menu within a horizontally long menu. In order to achieve this, I have merged the script for displaying a scrollable menu with that of a dropdown menu. However, in doing so, the dropdown menu does not pop out from the ...

React fails to display the content

Starting my React journey with Webpack configuration. Followed all steps meticulously. No error messages in console or browser, but the desired h1 element is not showing up. Aware that React version is 18, yet working with version 17. App.jsx import Reac ...

The chat text will automatically scroll down, displaying information loaded from the database

Is there a way to ensure that chat text always remains scrolled to the bottom of the chat? I have tried multiple tutorials and examples from Stack Overflow, but none seem to work for me. Currently, my chat text overflows the textarea when there are too m ...

Place the cursor at the conclusion of the text box

I am working on creating a user input form for chat messaging and I need some help. Here is the HTML-code snippet that I am currently using: HTML-code Currently, when the user presses ENTER, I retrieve the text from the textbox and save it. If the user ...

Issue with the image posting function in Laravel - why isn't it functioning properly?

Looking for Assistance I've been working on a simple web application using Laravel 6.0 and have encountered an issue with the image post function I developed. Despite not receiving any error messages, the functionality doesn't seem to be work ...

Issue with compiling Tailwindcss in nextjs JIT mode

Our current project involves using tailwindcss and things were going smoothly until the clients requested a "pixel perfect" design. This meant that every element needed to be set in pixels instead of rem units. Instead of adding countless classes like h-1p ...