Tips for preventing DIV elements from overlapping

In the process of creating a CSS design for a SIM game I enjoy playing, a client requested four boxes: two large ones with two smaller ones aligned horizontally in between. Everything was going smoothly until I attempted to add headers to the boxes. The entire website is constructed using an excessive amount of tables, reminiscent of coding from the 90s. All the boxes I created are divs and were positioned to coincide with the existing layout on the page.

The primary concern lies with getting the headers to display separately on all four boxes without any scrolling. Unfortunately, as illustrated in this fiddle, the alignment is off. Whenever I try adding headers to the horizontal boxes, the alignment becomes even more distorted. As a relatively new coder, I would greatly appreciate some assistance.

div {
display: block;
color: #fff;
}
.topcontain{
width:500px;
height:300px;
}
.topleftbox {
width:240px;
height:300px;
overflow:auto;
float:left;
background:#505665;
color:#fff;
text-align:center;
display:block;
font-family: 'Snippet', sans-serif;
font-size: 12px!important;
margin: 5px;
opacity: .75;
}

(remaining code stays the same)

To visualize how it currently appears on the web page under development: example

Your help is greatly appreciated!

Answer №1

http://jsfiddle.net/6bEsE/6/

   <div class="bottomcontain">
      <div class="header">Lorem ipsum</div>
      <div class="bottombox">
         [TOP]
      </div>
   </div>
   <div class="topcontain">
        <div class="topleftbox">
            <div class="top">Lorem ipsum</div>
            <div>
                [MIDDLE LEFT]
            </div>
        </div>
        <div class="toprightbox">
            <div class="top">Lorem ipsum</div>
            <div>
                [MIDDLE RIGHT]
            </div>
        </div>
    </div>


    <div class="bottomcontain">
        <div class="header">Lorem ipsum</div>
        <div class="bottombox">
            [BOTTOM]
        </div>
    </div>

    <div class="credit">Layout and CSS by Echo [#15480]</div>

I quickly cleaned up your code in just 5 minutes, but there is still more work to be done

Firstly, you have improperly closed div tags. Secondly, the fixed height of the divs could cause overflowing text and scrolls.

Before adding all the text, try fixing the containers starting with the simple example I provided above. You might also need to adjust the HTML structure to group those floating middle divs together.

Answer №2

Check out the live demo

This is a demonstration of using CSS to create a clearing div:

.clearfix {
    clear: both;
}

Here is how you would implement it in your HTML code:

<div class="clearfix">&nbsp;</div>

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 facing an issue where the weather information is not being displayed even after sending a request to

I'm working on building an app that will provide users with weather data once they input a city. Utilizing the openweathermap.org API for this purpose, I've noticed in my console under networks that an API call is made when the city is entered, b ...

Animating distance with the power of animate.css

I have implemented animate.css for a login form, but it is not behaving as desired. Currently, I am utilizing the fadeInDown animation, however, it is fading in from a greater distance than intended. I would prefer it to fade in from just around 20px below ...

How to center align an input vertically with Bootstrap 3

I am having trouble vertically aligning an input in my project. Interestingly, my code works for a span but not for the input! I'm puzzled - what could be the reason behind this? JSFiddle Here is the CSS code snippet: .float { display: table-cel ...

Prevent Cordova from shrinking the view when focusing on an input

Currently working on developing an app using Cordova/Phonegap (v6.5.0). Platforms where I've installed the app: - IOS (issue identified) - Android (issue identified) - Browser (no issue found) I am facing a known problem without a suitabl ...

"Trouble with the external CSS file - it's not

I have a question regarding my jsp file, top.jsp, and css file, top.css. Despite specifying a background color in top.css, the color is not showing up on my top.jsp file. Code snippet from top.css: @CHARSET "ISO-8859-1"; body { background-color: bl ...

Is there a way to leverage the extensive Bootstrap 5 color palette within an Angular application?

Currently working on a project in Angular 12 with Bootstrap 5 and SCSS, I'm facing a challenge in utilizing the new extended Bootstrap 5 color palette such as indigo-300 or pink-200. I'm not sure if I need to import them in a certain way or how t ...

Toggle sidebar: expand/collapse

Looking for some assistance with my website project. I currently have two arrows to open and close the sidebar, but I would like one button to handle both actions instead. Can someone help me edit my code snippet to achieve this? Keep in mind that I am new ...

Tips for positioning elements within an ng-repeat list using absolute positioning?

Here is the HTML code: <div class = "container"> <form ng-submit = "createSticky()"> <input ng-model="formData.data" type="textarea" name="sticky_content" placeholder="add sticky text" required="true"/> <input ng-model= ...

The AngularJS element fails to display on the screen

I am currently learning AngularJS and I am struggling to understand how components are linked to the view in the tutorial. I have created a component that is quite similar: angular.module('phonecatApp').component('nameList', { temp ...

Transferring data from a table to another window

Currently, I am retrieving values from a database and displaying them in a table. I would like to add a button to each row that will allow users to view more details about that specific row. At the moment, only ThesisID, AuthorID, and Title are visible. ...

Discover the Ultimate Guide on Altering the Course of Mega Menu!

I am working on a mega menu that is set to display in the usual direction. However, for the last two items, I would like them to appear from the button upwards. I'm not quite sure how to explain it. What I envision is something similar to this: ...

Exploring Next.js Font Styling and Utilizing CSS Variables

I'm attempting to implement the "next" method for adding fonts, but I find the process described quite complex just to preload a font. I experimented with exporting a function to create the font and then using a variable tag to generate a CSS variabl ...

The issue of CSS Grid not adapting fully to different screen sizes and

Recently, I took on a coding challenge from Frontend Mentor (this one) and managed to complete it successfully. However, the grid I designed is not fully responsive. It only adapts correctly when the page width matches the media query specifications. The c ...

Is it possible to personalize the Carousel-indicators feature within react-responsive-carousel?

I am currently utilizing the react-responsive-carousel library. I would like to modify the default indicators CSS, changing the dots shape to a line shape. Here is my code snippet: <CarouselWrapper sx={{ marginTop: "124px", maxHeight: & ...

dragging and dropping files for easy upload

Here is a challenge I am facing: I am looking for a solution that allows users to drag multiple images from their local file system onto the flash/flex/html5 app. The app should then extract the file name details and communicate with the server. Once t ...

ui-router: Issue with ui-sref causing font color to remain unchanged

I've been trying to customize the font color of a navigation link using ui-router's ui-sref functionality, but I'm facing an issue. While I can change the background color by adding it to the .active class in my CSS, the font color remains u ...

What is the best way to align the main navigation at the center of

Even though I have utilized text-align: center, the style of .main-nav did not change. What is the most effective way to center this navigation menu? /***** Navigation *****/ .main-nav { font-family: 'Lato', Helvetica, Arial, sans-serif; f ...

What is the process for adjusting the font in my VS Code editor?

Currently diving into an Angular2 development video course, I stumbled upon something intriguing: https://i.stack.imgur.com/CIBcx.jpg Yes, aesthetically pleasing HTML attributes won't make me a coding genius. But let's be honest, who doesn&apos ...

How can I extract particular combinations from a PHP array?

I have a unique question that is quite specific and despite searching online, I couldn't find an answer. So, I decided to seek advice here. Imagine my webpage has three sliders: one for selecting color options for a square, another for a circle, and ...

Having trouble getting the product PHP script to upload properly

I have been struggling with a Php script that I created to upload products to my website for over 5 days. Unfortunately, it's not functioning properly and no errors are being displayed. Despite my best efforts, I am unable to identify the error in the ...