The right float property is malfunctioning

As a beginner in web development, I am attempting to recreate this website from scratch.

However, I have hit a roadblock.

I'm currently facing an issue with the float: left property (within @media). I double-checked by including box-sizing: border-box to accommodate padding and borders within the total width and height of an element.

Here is my code snippet:

* {
    box-sizing: border-box;
}

body{
    margin-top: 40px;
    background-color: #F9F9FB;
}

.container-fluid {
    margin-top: 50px;
}

h3 {
    border-left: 1px solid black;
    border-bottom: 1px solid black;
    margin: 0px;
    padding: 1px;
    width: 33.33%;
    height: 28px;
    float: right;
    text-align: center;
    background-color: #B59F84;

}

.row div {
    border: 1px solid black;
    padding: 0px;
    margin: 10px;
    background-color: #FFFFF5;
}

p {
    margin: 0px;
    padding: 10px;
    clear: right;
}

/********** Large devices only **********/
@media (min-width: 992px) {
  .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
    float: left;
  }
  .col-lg-1 {
    width: 8.33%;
  }
  .col-lg-2 {
    width: 16.66%;
  }
  .col-lg-3 {
    width: 25%;
  }
  .col-lg-4 {
    width: 33.33%;
  }
  .col-lg-5 {
    width: 41.66%;
  }
  .col-lg-6 {
    width: 50%;
  }
  .col-lg-7 {
    width: 58.33%;
  }
  .col-lg-8 {
    width: 66.66%;
  }
  .col-lg-9 {
    width: 74.99%;
  }
  .col-lg-10 {
    width: 83.33%;
  }
  .col-lg-11 {
    width: 91.66%;
  }
  .col-lg-12 {
    width: 100%;
  }
}
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="style.css">
    <title>Assignment Solution for Module 2</title>
</head>
<body>
    <h1 style="text-align: center;">Our Menu</h1>
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-4">
                <h3>Div 1</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
            </div>  

            <div class="col-lg-4">
                <h3>Div 2</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
            </div>          
            <div class="col-lg-4">
                <h3>Div 3</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
            
            </div>
        </div>
    </div>
</body>
</html>

Ensuring that I applied box-sizing: border-box to accommodate padding and borders within an element's total dimensions.

Edit: It should be float: left, not float: right

Answer №1

To begin, the width of the card must be established. For responsiveness, consider utilizing max-width. I am implementing flexbox with max-with:400px in this instance (adjust as needed) for each individual card. By incorporating these additional lines of code, your row will adapt to varying screen sizes. (In my demonstration, they are horizontally centered on the page, but you can modify this by adjusting the justify-content property).

.row {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  justify-content: center;
}
.row div {
    border: 1px solid black;
    max-width: 400px;
    padding: 0px;
    margin: 10px;
    background-color: #FFFFF5;
}

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

Understanding the percentages of CSS in relation to other elements

Can you define a CSS dimension in a percentage relative to an element other than its parent? Specifically, I want the border-radius of a div to be 10% of its width. However, using border-radius: 10% creates an elliptical border when the height and width ...

If you click outside of a Div element, the Div element will close

I am looking for a way to implement a function that will hide a specific div when I click outside of its area. The div is initially set to Position: none and can be made visible using the following function: Div Element: <div id="TopBarBoxInfo1" oncli ...

Is there a way to launch only a single popup window?

Recently, I came across this piece of Javascript code which is causing me some trouble: function call() { popup = window.open('http://www.google.co.in'); setTimeout(wait, 5000); } function caller() { setInterval(call, 1000); } func ...

Stopping the use of <script> tags within HTML form submissions

After launching my website at , I discovered that a user is attempting to redirect it to different websites using HTML form input tags. While I'm unsure of the exact method they are employing, I am seeking a way to block users from entering these nefa ...

Tips on how to add a file input type:

When working with my HTML code, I encountered an issue. When I change the type attribute to "text", everything works fine. However, when I change it to "file", nothing happens when I click. <input type="file" name="pic[]" accept="image/*">a <inpu ...

Taking an item out of a List causes a disruption in the order of the remaining items

I'm currently working on a Blazor project where I have an HTML table that populates by looping over a list. Here is the relevant code snippet: @foreach (var line in lines) {@{ var linenumber = lines.IndexOf(line)} <td> ...

Tips for customizing the appearance of the "Read More" button on an Elementor card

I'm new to the world of wordpress and I'm struggling to customize the CSS for a button on a card. My goal is to center the "Read more" button on the post card and give it a border, but I'm not having any luck in Elementor. I tried tweaking t ...

Setting up a CSS Grid development environment for Windows users

Currently, I am looking to update my website development environment. Despite using Adobe Dreamweaver out of habit, I need a more efficient setup that can offer the following: An editor with syntax highlighting, code/tag completion, and code hints for wr ...

CSS - Tips for preventing elements from wrapping onto multiple lines

I am facing an issue with spans displayed inline in my browser. The text within my spans is being cut off when it reaches the right border of the browser, with half on one line and half on the next. I want to prevent this from happening by having the conte ...

Stick Table Column to Top Using Bootstrap Framework

Is it possible to keep the content of column one at the top regardless of the amount of text lines in the other column? Currently, my layout looks like this: but I would like the poster's info to stay at the top, like this: so that no matter how mu ...

Create a layout with four columns, ensuring that each set of two columns has equal heights

Trying to create a container with two columns, each containing two columns of their own, all with equal heights using only CSS. The issue: the inner columns in their parent column do not align with the other inner columns in their respective parent column ...

Alignment and placement of rotated text within a table or grid in a vertical position

Struggling to rotate text in an HTML table, I've encountered alignment and text flow issues no matter what. Various CSS combinations of writing-mode and rotate have been attempted but the problem persists. Here is the test table: Code snippet: tab ...

Setting the display property to none continues to impact the positioning of elements

Currently, I am in the process of making my portfolio website responsive by using media queries. For mobile screens, I have successfully implemented a nav select drop down menu. However, when it comes to iPad screens, I want to display a regular menu. To a ...

Inconsistencies in Height Among JQuery Elements

I am encountering an issue with my datatable.js, where I am attempting to limit its height based on a specific row number, such as 4.5 rows. However, I am facing a problem with the row height (tr height). For example, when using the following method with m ...

Tips for creating a mobile-friendly Bootstrap carousel that is both scalable and zoomable while maintaining the default slide functionality

I have a website using Bootstrap 4.x carousel. The layout is user-scalable with the following viewport meta tag: <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2, shrink-to-fit=no">. Currently, users can pinch to z ...

Exploring the child element of the present DOM node within Angular

In my template, I have a code snippet similar to the one below: <button class="btn" > <audio src="mySourceFile.wav"></audio> </button> When the button is clicked, I want to play the audio object. Ideally, I would like to achieve ...

Draw on the canvas by retrieving specific image data from it using the getImageData function

In the code snippet below, I am uploading an image and manipulating it using JavaScript: > var canvas = document.createElement('canvas'); > var context = canvas.getContext('2d'); > context.drawImage(image, 0, 0); While the ab ...

Troubleshooting the Inline-Block Problem with Jquery Image Bubble Display

Recently, I've been exploring ways to eliminate the padding that is creating space between images before they align correctly. The culprit causing the padding seems to be the display: inline-block property. While it was suggested to have all the li t ...

Having difficulty locating the html sub-elements within a specific element

As someone who is somewhat new to scraping websites with numerous sub-elements, I am seeking the best way to navigate through elements that contain desired data within deeper levels of sub-elements. Let's take a look at an example HTML snippet: <d ...

Splitting a table into two separate tables using jQuery based on a specified row number

Is it possible to divide a table into two separate tables based on a specific row number by using jQuery? I tried searching for a solution online, but unfortunately, I couldn't find anything helpful. Considering jQuery's capabilities, I assumed ...