I'm facing challenges with setting auto heights on CSS and aligning floating divs

I'm trying to create a simple tiled list with six smaller divs inside a main div, all set to float:left. However, this is causing issues with the auto height and it doesn't seem to work properly within the div. Can anyone help me fix my code or suggest a better approach?

CODE:

HTML:

<div class="main">
   <div class="service-items">
      <div class="service-item">WEB DESIGN</div>
      <div class="service-item">SEO</div>
      <div class="service-item-right">WEB GUIDANCE</div>
      <div class="service-item">GRAPHIC DESIGN</div>
      <div class="service-item">BROCHURE DESIGN</div>
      <div class="service-item-right">CONTACT ME!</div>
   </div>
</div>

CSS:

.main {
    width:930px;
    height:auto;
    margin-right:auto;
    margin-left:auto;
    font-family: 'Roboto Condensed', sans-serif;
    padding:10px;   
}

.service-items {
    width:930px;
    height:auto;    
}

.service-item {
    width:200px;
    height:90px;
    padding-top:90px;
    margin-right:15px;
    text-align:center;
    font-family: 'Roboto Condensed', sans-serif;
    font-size:150%;
    background-color:#69F;
    display:block;  
}

Answer №1

When elements are floated, they do not contribute to the height of their parent element. To work around this issue in more complex situations (such as when custom tooltips are supposed to overlap), various clearfix hacks can be used.

In your scenario, simply adding overflow: hidden to the CSS should solve the problem.

.service-items {
    width:930px;
    height:auto;
    overflow: hidden; // This line prevents clearing floats
}

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

What is the best way to parse a JSON file and create a dynamic webpage using jQuery with the data from the

As someone who is new to working with Node.js and JSON, I am encountering some issues when trying to extract data from a JSON file. Below is the code that I have written: 'use strict'; const fs = require('fs'); let questsRawData = fs ...

What could be the reason for the excess white space at the top and bottom of the page?

Once I implemented a new div class to incorporate a background image, the top, bottom, and side menus on my page suddenly turned white. style.css #boundless{ background-image:url('http://thehypebr.com/wp-content/uploads/2010/09/boundless-sem-branc ...

Ways to eliminate the top space in the background image

After implementing a basic HTML code to add a background image to my webpage, I noticed there is still some empty space at the top of the page. I attempted to adjust the position of the background image using the following code, but it only lifted it upwar ...

Can CSS stylesheets be set up to automatically load based on the browser being used to access the website?

I am inquiring because I recently completed a beautiful homepage design and, after viewing the website on Chrome and Safari on OSX, I noticed that certain elements were broken when I opened it in Firefox. In addition, an issue I was experiencing with the ...

What is the proper way to apply a background color to the entire body using CSS?

I'm facing an issue with getting the background color to cover the entire body of my webpage. Currently, it only captures a certain size and when there is scrolling on the window, two shades of colors appear. I want the background color to span the en ...

What could be causing an unidentified term to be included in the Vue SCSS compilation process

In my Vue application with TypeScript, I encountered an error during compilation that reads as follows: Failed to compile. ./src/style.scss (C:/../node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!C:/.../node_modules/vue-loader/lib/loaders/stylePostL ...

The "else" statement is never being executed

Trying to create a form where users enter their first name, last name, and city. If any input is empty or contains numbers, a message should appear requesting to fill out all boxes without numbers. Otherwise, display a personalized quote using the input in ...

AngularJS Toggle Directive tutorial: Building a toggle directive in Angular

I'm attempting to achieve a similar effect as demonstrated in this Stack Overflow post, but within the context of AngularJS. The goal is to trigger a 180-degree rotation animation on a button when it's clicked – counterclockwise if active and c ...

I would like to embed the HTML page within the specified div element

When attempting to load a HTML page inside the div, I encountered the following issue: <a href="#1" title="" class="base-banner" page="www.google.com for example"> <img src="images" alt=""></a> <div id="landingpage"> </div> ...

Trying to showcase information received from a server using an API

For a school project, I am developing a website that can retrieve weather data (currently just temperature) based on a city or zip code from openweathermap.org using an asynchronous call. I have successfully retrieved the data from the API, but I am strug ...

Adding additional elements to a div in a horizontal orientation

I am currently working on a project where I need to display bars and restaurants based on specific filter criteria. I have a container div called .resultsContainer where all the results will be displayed. While I can easily append more divs (.barContainer) ...

Flow bar for micro-tasks

In my current project, I am faced with the task of organizing a series of 4 mini tasks and displaying to the end user which specific mini task they are currently on. To accomplish this, I have been utilizing image tags for each task. <img>1</img ...

Discover the process of extracting HTML content that's stored within a JavaScript variable

Having a HTML snippet stored in a variable, like this: var parse= 'Hello<i class="emoji emoji_smile" title=":smile:"></i><i class="emoji emoji_angry" title=":angry:"></i>World' I am looking to extract the value of the "t ...

Tips for displaying a variable that contains HTML in PHP

I'm facing an issue with a variable that holds an HTML iframe obtained from a third-party package. When I try to display it using <?php echo $variable ?>, the page shows the raw HTML with tags instead of rendering it properly. Can someone guide ...

What could be the reason behind the lack of vertical centering for the Spartan

I can't seem to figure out why my font isn't aligning vertically correctly. I'm using the Spartan MB font from Google, but it just doesn't look right, you can see here. https://i.stack.imgur.com/wbLc2.png This is my HTML code: <htm ...

AngularJS - Oops! Looks like we encountered an error: [$injector:modulerr]

I have a client-server application and I am facing an issue with this error message: "Uncaught Error: [$injector:modulerr]". Despite searching for solutions, none of them seem to be fixing the problem. Here is my client-side code: angular.module('m ...

What are the steps for submitting a form by clicking on text?

Whenever I try to submit a form by clicking on span id="ToolBarDownload", the form id="myformID" doesn't seem to get submitted. Can someone help me figure out what's wrong with my code? Any suggestions are greatly appreciated! Thanks! Also, just ...

The -webkit-background-clip feature seems to be malfunctioning in Safari

I am experiencing an issue where the code works perfectly on Chrome but fails to function properly on Safari. I have been unable to pinpoint the cause of this discrepancy and any assistance or insights would be greatly appreciated. For those interested, a ...

The issue with the search box not being correctly displayed on Google CSE using Twitter Bootstrap

Having an issue with the Google Custom Search (CSE) as it is not displaying the search box and button correctly. I am using Twitter Bootstrap v3.1.0. <script> (function() { var cx = '009077552906670546181:2ufng0dmsos'; ...

Using a DIV to contain a FileUpload Control in an ASPX page

Scenario: I have an ASPX page (Page A) without a form element, which contains a DIV displaying another ASPX page (Page B) with a FileUpload Control inside a form element. Requirement: Submit the form to upload the file without refreshing or navigating awa ...