Dividing Content into Four Columns

I'm working on setting up a 4 column <div> layout.

Why aren't the row containers displaying a border around each row? Is my CSS optimized for fluidity and dynamic resizing of the browser window?

If you have any suggestions or guidance, I would greatly appreciate it.

Check out my current attempt here.

Answer №1

For proper handling of floats, it is important to set the overflow property to auto. Visit this link for an example: http://jsfiddle.net/gJJHs/

Answer №2

It appears that the issue lies in the float property applied to your columns, causing them to take up minimal space.

One potential solution is to remove the float from the "last" class and insert a "dummy column" at the end of each row.

Here is the suggested CSS code:

.col
{
    float: left;
    width: 25%;
}

.last{
    clear: left;
}

.row{
    border: 1px solid green;
}

Updated HTML (including dummy last column):

<div class="row">
    <div class="col">1</div>
    <div class="col">2</div>
    <div class="col">3</div>
    <div class="col">4</div>
    <div class="last" />
</div>

<div class="row">
    <div class="col">5</div>
    <div class="col">6</div>
    <div class="col">7</div>
    <div class="col">8</div>
    <div class="last" />
</div>

Answer №3

When an element is floated, it breaks free from its parent's containment due to being removed from the flow. The floated element disrupts the natural layout, causing block elements to act as if the float doesn't exist, resulting in a parent container not fully expanding to accommodate the floated child.

This displacement may make the border appear as if it's surrounding nothing at all. For a clearer understanding of how CSS Float property functions, check out this informative article:

The Mystery Of The CSS Float Property

To address this issue, adding overflow: auto; to your .row class can serve as a solution. Here's another resource that delves into the benefits of using overflow:

http://www.quirksmode.org/css/clearing.html

I trust this information proves helpful.
Hristo

Answer №4

The float left property causes the divs to be taken "out of flow," resulting in the border being drawn around empty space.

Answer №5

Yet another approach, alongside other solutions, is to include overflow: hidden; in your .row CSS.

The reason behind the observed behavior is that using float pushes the div outside of the normal document flow. As a result, the div occupies no space within the document.

This logic becomes clear when considering the typical use case of floating an image to wrap text around it. The following p tag, for instance, is positioned as if the floated image didn't exist, potentially overlapping with the image. Subsequently, the browser wraps the text within the 'p' tag around the image. (Without removing the floated image from the flow, the p tag would naturally display below the image—failing to achieve the desired effect.)

Below is a sample code implementation:

HTML:

<div class="row">
    <div class="col">1</div>
    <div class="col">2</div>
    <div class="col">3</div>
    <div class="col">4</div>
</div>
<div class="row">
    <div class="col">5</div>
    <div class="col">6</div>
    <div class="col">7</div>
    <div class="last">8</div>
</div>

CSS:

.col
{
    float: left;
    width: 25%;
}
.row{
    border: 1px solid green;
    overflow: hidden;  /* Alternatively, "overflow: auto;" can be used */
    width:100%;        /* Aiding older IE versions */
}

Answer №6

To achieve the desired layout, try adding "float:none;clear:both" to your .row class. If you want a fluid design that works well across different browsers, consider incorporating some javascript such as jQuery Equal Height. You can find more information about it here:

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

JavaScript - Populate canvas with selected image from gallery upon clicking an image

A photo gallery on my website is filled with images fetched from a local directory using PHP. I would like users to be able to select an image by clicking on it and then have the option to draw on that image within a canvas element. The gallery has been c ...

What is the best way to emphasize a row in an Angular Material table based on a

I am facing an issue with highlighting row colors conditionally in my code. Although there are no errors, the background color is not being applied to the rows as expected. I have a total of 5 rows with the 'riskIndex' value set to 'H'. ...

Displaying variables in JavaScript HTML

<script type ="text/javascript"> var current = 0; </script> <h3 style={{marginTop: '10', textAlign: 'center'}}><b>Current Status: <script type="text/javascript">document.write(cur ...

I am in search of an HTML listbox featuring the different UTC Timezones

Looking for an HTML listbox (dropbox) with all timezones similar to the Windows7 timezone listbox. I couldn't find a sample on Google, but I'm willing to rewrite it myself if needed. Just checking if there's already a coded solution availabl ...

The PHP login functionality is malfunctioning due to issues with password verification

I am currently working on a project for my assignment and I seem to be facing an issue with the login functionality. The error message that keeps popping up says: Login error username does not exist. Interestingly, when I tested the customer login and r ...

jQuery Validator - emphasize dropdown selection in Internet Explorer

I am currently utilizing the validator plugin for jQuery, which adds a red border to invalid fields by applying a border style to the css class "error". However, I am encountering an issue with dropdowns (select) in Internet Explorer, as they are not displ ...

Animate a div to swipe left using CSS transition

I am currently designing a drawer that needs to slide from left to right when a button is clicked. I have attempted to achieve this using CSS transitions and jQuery, but unfortunately, it's not working as expected. Here is what I have tried so far: ...

Enable AJAX to dynamically load pages without caching

I am currently using an ajax function to refresh a specific division on a webpage with HTML content. <script> $('#scene_container').load('scene.html', function () { cache: false }); </script> ...

Setting up the html div to contain the three.js container

Within my article container, there are three aside tags. The third aside with id='menuPuzzleType' contains a Three.js script that creates and displays two cube meshes in a Canvas renderer. <article id="popup"> <aside id='close ...

Inject the variable into location.href

I am dealing with a dynamic URL, and I want to achieve the following in my HTML: <a onclick="location.href='myVariable';"><span>Click here</span></a> The issue is that this approach displays the actual string 'myVar ...

What makes Firefox so much speedier than Chrome when it comes to loading hefty documents?

Currently, I am facing an issue with slow loading times for custom HTML build reports on Google Chrome. It takes a significantly longer time to load compared to Firefox. Approximately 5 seconds on Firefox versus 110 seconds on Google Chrome (measured usi ...

Increase the jQuery level and utilize the .find() method

Currently, I am delving into the realm of jquery and facing a minor hiccup with selectors. Below is the structure of my DOM: <li> <header class="title"> <span>Text</span> <a href="#work-1">My trigger</a> ...

Guide to dynamically loading customer data into an HTML table using JavaScript

I'm looking to populate a table with data on customers including their name, customer ID, and rental cost. Can anyone help me with the JavaScript code needed to insert this data into rows of the table? Your assistance is greatly appreciated. Below is ...

Upgrading CSS sprite sheets for retina displays boosts image size by two-fold

I'm currently incorporating CSS sprite sheets into a mobile-friendly page design. The layout appears as intended, and below is the CSS I have implemented (which displays correctly on Chrome Canary's iPhone 3GS emulator): div#logo { backgroun ...

When viewed on a mobile device, the contact information bar should vertically collapse

Here is the code snippet I am working with: <div class="topbarsection"> <ul> <li class="alignleft"> <a href="#">Office Address</a> </li> <li class="aligncenter"> Office Timings ...

What is the best way to display a list of URLs from a dataframe column on a leaflet map?

I am looking to create a map with interactive leaflet points that display popup notes containing clickable links leading to internet pages. The URLs for these popups are stored in a column of my data frame, which contains thousands of rows. Here is some sa ...

The background in the HTML code won't be displayed

I am struggling to make a video background activate, but I can't seem to get it to play. <section class="home-section home-full-height bg-dark-30" id="home" data-background="assets/images/section-5.jpg"> & ...

How can I make an element begin sticking to the page at 50px when scrolling, and then stop sticking at 2000px?

I am looking for a solution to position an image relative or absolute initially, then make it stick after some scrolling, and finally return it to its original behavior before transitioning to another section on the page. I've tried using this script ...

Requiring a compulsory field in PHP and MySQL

I am facing an issue with the following query: $tww_update_sql = "UPDATE `telesales_anc` SET `Ime` = '".$_POST['Ime']; I also have a form with a submit button structured like this: <form id="contact" method="post" action="ANC_pozivanje ...

The HTML code is failing to apply the style to all rows except for the first one in the sql query result

When retrieving all the rows from a SQL database with a query and using a loop to iterate through them, I encountered an issue where only the first row was receiving the specified CSS style. The remaining rows were not applying the style as expected. < ...