By introducing margins, the final column will automatically create a new row

"I'm encountering an issue with my code. I need to add margins between columns in Bootstrap without them wrapping to a new row. Can someone help me prevent this from happening?"

<div class="container attributes-div">
        <div class="row attributes">
            <div class="col-xl-4 attribute-center info-1">
                <img class="attribute-pic" src="house2.png">
                <h3>Quality Cleaning</h3>
                <h5>We aim to leave your home spotless! Our goal is to ensure cleanliness at its best!</h5>
            </div>

        <div class="col-xl-4 attribute-center info-2 middle-attribute-margin">
            <img class="attribute-pic" src="dollarsign2.png">
            <h3>Affordable Rates</h3>
            <h5>We offer reasonable rates that won't break the bank!</h5>
        </div>

        <div class="col-xl-4 attribute-center info-1 info-3">
            <img class="attribute-pic" src="maid.png">
            <h3>Professional Staff</h3>
            <h5>Our professional staff values customer feedback and ensures homes are left just the way you like it. Your satisfaction is our top priority!</h5>
        </div>
    </div>
</div>

"Here is my CSS:"

.attributes-div{
margin-top: 200px;
max-width: 90%;
}


.attribute-pic{
width: 50px;
}

.attribute-center{
text-align: center;
padding-top: 15px;
padding-left: 10px;
padding-right: 10px;
}

.info-1{
background: linear-gradient(70deg,#F0E4F0,#eef2f3,#F0E4F0);
background-repeat: no-repeat;
}

.info-2{
background: linear-gradient(70deg,#dfeff5,#eef2f3,#dfeff5);
background-repeat: no-repeat;

Answer №1

In the world of bootstrap, the maximum value is 12. Each of those boxes holds a value of 4. So if you do the math (4*3 = 12) and take into account your margins, it's no wonder they're getting pushed to the next line. Perhaps consider adjusting the box values to 3 (col-xl-3) instead.

Answer №2

It is recommended to avoid using margin directly on columns. Instead, insert a w-100 div within the columns and apply margin or padding to it.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
<div class="container attributes-div">
  <div class="row">
    <div class="col-xl-4 ">
      <div class="w-100 px-3 bg-primary">
        <img class="attribute-pic" src="house2.png">
        <h3>Quality Cleaning</h3>
        <h5>We strive to leave your home spotless! It is always our 
          goal to have your clean at it's best!</h5>
      </div>
    </div>

    <div class="col-xl-4 ">
      <div class="w-100 px-3 bg-primary ">
        <img class="attribute-pic" src="dollarsign2.png">
        <h3>Affordable Rates</h3>
        <h5>We offer REASONABLE RATES that won't hurt your pocket!</h5>
      </div>
    </div>

    <div class="col-xl-4">
      <div class="w-100 px-3 bg-primary ">
        <img class="attribute-pic" src="maid.png">
        <h3>Professional Staff</h3>
        <h5>We listen to our customers and make sure to leave each of 
          their homes to their liking. If you aren't satisfied, we aren't 
          satisfied either!</h5>
      </div>
    </div>
  </div>
</div>


To achieve equal height columns, incorporate d-flex and flex-columns classes for the columns and use h-100 for the w-100 divs.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="container attributes-div">
  <div class="row">
    <div class="col-xl-4 d-flex flex-column">
      <div class="w-100 h-100 px-3 bg-primary">
        <img class="attribute-pic" src="house2.png">
        <h3>Quality Cleaning</h3>
        <h5>We strive to leave your home spotless! It is always our goal to have your clean at it's best!</h5>
      </div>
    </div>

    <div class="col-xl-4 d-flex flex-column">
      <div class="w-100 h-100 px-3 bg-primary ">
        <img class="attribute-pic" src="dollarsign2.png">
        <h3>Affordable Rates</h3>
        <h5>We offer reasonable rates that won't hurt your pocket!</h5>
      </div>
    </div>

    <div class="col-xl-4 d-flex flex-column">
      <div class="w-100 h-100 px-3 bg-primary ">
        <img class="attribute-pic" src="maid.png">
        <h3>Professional Staff</h3>
        <h5>We strive to meet our customers' expectations with our professional staff. Your satisfaction is our top priority!</h5>
      </div>
    </div>
  </div>
</div>

Visit this link for reference.

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

I am receiving a high volume of row data from the server. What is the best way to present this information on a redirected page?

There is a scenario where Page 1 receives a substantial amount of row data in JSON format from the server. The goal is to present this information on Page 2, which will be accessed by clicking on Page 1. To accomplish this task, JavaScript/jQuery and PHP ...

What is the best way to position an element on the left side of the navbar without having it animated?

Could someone assist me in placing the Life's Good logo on the left side of the nav bar without applying the animation from the "btn" class? Below is a snippet of my code with an example where I want the logo highlighted in Yellow: * { padding:0; m ...

Utilizing radio type as a button while excluding the need to submit a form

I have implemented radio type buttons in my form: <div class="d-block"> <div class="btn-group" role="group" aria-label="Basic example"> <button type="radio" name="type" value= ...

Retrieve information from the database upon clicking the submit button

My table is not getting data from the database when I click a button. I tried using this code but it returned an error. <div class="wrapper wrapper-content animated fadeInRight"> <div class="row"> <div class="col ...

Animating Text with CSS for Different Message Lengths

I have been exploring alternatives to the marquee tag and discovered a way to achieve this through CSS. However, the messages I am working with vary in length. Is there an alternative to setting the '45s' attribute to maybe 100% so that regardles ...

How can I ensure my game or website fits perfectly on the screen without any need

I have recently developed a fun Erase-A-Man game that is optimized for mobile devices. However, I am facing an issue where users need to scroll to view all the letters on their screens. My goal is to make the game fit perfectly on all phone screen sizes so ...

What is the method for altering the background color of an input field upon entering text?

As a beginner in Javascript and jQuery, I am struggling to understand why my code is behaving the way it does. I have written two similar functions aimed at changing the background color of an input field. The objective is to set the background color of t ...

Navigate to the location using AngularJS elements in the JavaScript iframe1

Dealing with an issue while working on AngularJS. I am facing a frustrating problem where I am attempting to use one link to open links in two separate iframes. All aspects of this function correctly, except for the actual links. The issue arises when usin ...

What is the best way to set a div's size to a constant value?

I recently designed a webpage that includes a feature where clicking a button adjusts the font size within the div. Within the div, there is a ul containing the buttons. However, when the font size changes, the div expands and the nav buttons also shift a ...

Instructions on how to navigate back one page to determine which page initiated the action

I am looking for a solution to implement a back button that takes me back one page while caching it. Currently, I am using the following code: <a id="go-back" href="javascript:history.go(-1)" type="button" class="btn btn-danger">Back</a> Howe ...

Dimensions by the height of the content

In this particular div block, I have set a height as shown below: <div> <!-- content --> </div> Along with the following styles: div{ height:100px; } However, I am interested in dynamically adjusting the height of the div base ...

Animate CSS with Javascript in reverse direction

Forgive me if this is a silly question, but I'm having trouble. I need a slide-in navigation menu for smaller screens that is triggered by JavaScript. Here is what I currently have: HTML <nav class="responsive"> <ul class="nav-list unstyl ...

Utilizing jQuery Mobile to tap into smartphone functionalities like camera and calling capabilities

Can mobile features like the camera and sensors be accessed from an HTML page created with jQuery Mobile? In simpler terms, is it feasible to utilize mobile features using jQuery Mobile? It's clear that I will be accessing this page on a mobile phon ...

Animate elements with jQuery, moving them from the bottom right corner to the

I am currently working on a project to create a responsive webpage that involves clicking on a circle in the middle of the screen and having a div enlarge from the circle to the top left corner of the webpage. To achieve this effect, it seems like I would ...

My website's links are fully functional with Mozilla Firefox, providing a seamless browsing experience for users

When accessing my website using Google Chrome, Safari, and Internet Explorer from different computers in various locations, I noticed that certain links do not work properly. Surprisingly, these links function perfectly when using Firefox. For instance, o ...

What is the best way to align two round buttons on each line with a single button centered above them, all without any spacing between the buttons below, and vice versa

https://i.sstatic.net/oOwY6.png Is it possible to align the buttons on the left side like they appear on the right? Each group should have padding and display with flow-root. .group { display: flow-root; padding: 7px 0px 7px 0px; } button.a { ...

Is dividing a container into equal sections possible with flexbox?

Is there a way to create an HTML/CSS structure that divides a fixed-size container into three sections horizontally? The first section should expand based on its content, while the remaining two sections should evenly split the leftover space, with scrollb ...

Utilize multiple iframe elements stacked underneath each other

Currently, I have set up 2 iframes overlapping each other. My goal is to interact with a button inside the iframe that has a lower z-index value. ...

A step-by-step guide on customizing the background color of a Dialog in Angular Material (Version 16)

I've been attempting to modify the background color of my Angular Material Dialog by utilizing the panelClass property in the MatDialogConfig. Unfortunately, I'm encountering a partial success. I am aiming to set the background color as red (jus ...

Create waypoints on multiple elements

I am working on implementing a unique feature using a div tag with the class "dipper." <div class = "dipper"> <p>Peekaboo</p> </div> As part of this implementation, I have included a script that triggers the display of the "dipper ...