Difficulties arise when HTML divs do not properly encapsulate their intended content

https://i.sstatic.net/zg35O.png

Having trouble with my div id "topcol" - it's not displaying the full area as intended. Supposed to contain 4 "options". Options have relative positioning to allow option titles to overlay images.

Struggling with what seems like a simple mistake for hours now...


html:
<div id="cols">
            <div id="topcol">
                <h1 id="content_title">BrightWell Smart Page Services</h1>
                <div class="options" id="op1" name="General Links"><img class="optionicons" src="generalLinks.jpg"/><span class="optiontitle">General Links</span></div>
                <div class="options" id="op2" name="Useful Online Tools"><img class="optionicons" src="Toolbox.jpg"/><span class="optiontitle">Useful Online Tools</span></div>
                <div class="options" id="op3" name="IT Links"><img class="optionicons" src="ITSupport.jpg"/><span class="optiontitle">IT Links</span></div>
                <div class="options" id="op4" name="Utility"><img class="optionicons" src="utility.jpg"/><span class="optiontitle">Utility</span></div>
            </div>
            <div id="botcol">
                <div id="infopanel">

                </div>
            </div>
        </div>

css:
html    {
    font-family: 'FuturaW01-LightCondense 774878',Helvetica,Arial,sans-serif;
    font-weight: lighter;
}
#cols {
    z-index:1;
    position: absolute;
    top:0;
    left:0;
    height:100%;
    width:100%;
}
#topcol {
    height:auto;
    width:100%;
}
#botcol {
    width:100%;
}

#content_title {
font-size: 32px;
line-height: 1.2;
}
.options {
    margin-left:2.5%;
    margin-right:2.5%;
    height:30%;
    width:19%;
    float:left;
    border: black solid 1px;
    position:relative;
}
#op1{

}
#op2{

}
#op3{
    float:right;
}
#op4{
    float:right;
}
.optiontitle {
    color: blue;
    position:absolute;
    top:0;
    left:0;
    text-align:center;
    font-size:200%;
    width:100%;
}
.optionicons {
    height:100%;
    width:100%;
}
#infopanel {
    width:100%;
    height:100%;
}

Answer №1

By floating the child divs, they are taken out of the regular flow causing the parent container (topcol) to collapse as though they do not exist. To regain the desired layout behavior, you can include overflow:auto in your CSS rules for #topcol.

Answer №2

#topcol {
    height: auto;
    width: 100%;
    overflow: auto;
}

Simply adding overflow: auto; should solve it.

Update: It appears that someone had already provided this solution before me.

Answer №3

By eliminating the float:right from your CSS, it appears to be functioning correctly for me.

Check out this JSBin example

I have removed the following elements:

#op1{

}
#op2{

}
#op3{
    float:right;
}
#op4{
    float:right;
}

Does this resolve the issue you were experiencing, or were you seeking a different solution?

Answer №4

To improve the layout of your #topcol clearfix hack, consider modifying it to better support the floating elements within.

#topcol {
height:auto;
width:100%;
}

#topcol:after {
  content: "";
  display: block;
  clear: both;
}

Answer №5

Transform your images into background images, steering clear of the position property for styling - experiment with float and margin instead.

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

Top solution for preventing text selection and image downloading exclusively on mobile devices

My plan is to use the following code to accomplish a specific goal: -webkit-touch-callout:none; -webkit-user-select:none; -khtml-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none; -webkit-tap-highlight-color:rgba(0,0,0,0); I& ...

Converting Scalable Vector Graphics to Hypertext Markup Language and

So I've got this SVG file called 7.svg. What's the best way to show this image using HTML or CSS on my index.html page? ...

Creating interactive buttons with CSS and jQuery

As a newcomer to coding, I'm trying my hand at creating two buttons that transition from green to blue with a single click, and eventually incorporating them into a live website. The functionality I'm aiming for includes: Both buttons startin ...

Having trouble accessing properties in AngularJS

This is my code snippet: app.controller('userController', function UserController($scope, userFactory) { $scope.users = []; $scope.user = { items : [] }; $scope.editMode = false; $scope.addItem = function () { $scope.use ...

Customize the font size in Bootstrap 5 using REM units

When it comes to setting font sizes for easier calculations in REM values, I currently use this approach: html { font-size: 62.5%; } body { font-size: 1.6rem; } /* 16px */ However, Bootstrap 5 uses the root value (which is typically set at 62.5%) to calc ...

Deciphering specialized file selection in Bootstrap 4

Utilizing bootstrap and referencing this document: <div class="custom-file"> <input type="file" class="custom-file-input" id="customFileLang" lang="es"> <label class="custom-file-label" for="customFileLang">Select File</label> ...

Selected jQuery plugin is not updating HTML select option

I've been attempting to update the select tag in my HTML file to match the style used in the example on the Chosen v1.8.7 website, but despite following the instructions, the select element remains unchanged: test.html <head> <link rel=& ...

Is it possible to utilize AJAX requests in order to create a marker on google maps that updates in real-time?

My goal is to develop an app that generates a real-time updating google map, and I have been advised that AJAX requests can help achieve this. Nevertheless, after studying the documentation, I am uncertain about how to apply this method to solve my issue ...

Animating slides with CSS Keyframes and React, incorporating toggle slide fade out and slide fade (back) in

I am seeking a solution for toggling a box (div) with slide-out animation and then sliding back in animation (in reverse) upon button press. My requirement is to have no animations during the initial page render. While I can successfully slide the box to ...

HTML: What is the best way to position one <a> element underneath another <a> element?

My website contains a <div> that serves as a link to address1. Adjacent to this div is a drop-down menu with a link to address2. Strangely, the second link seems to override the first one, making Link1 non-clickable. https://i.sstatic.net/eBAEM.png ...

Increase the nestling of bullet points with inner indentation <li>

Hey there, I'm currently facing an issue with the right-side indentation of the bullet points. I have included a code snippet and an image that should help clarify the situation: https://i.sstatic.net/vmOVc.png <h1 style="display: block;marg ...

Center-align the text vertically in relation to the icon

A query has arisen, regarding a div that contains text and an icon. The issue at hand is that on larger screens the text is not vertically aligned in the center. For further reference, please visit this bootply link: http://www.bootply.com/CHKeRxKOX6 http ...

My goal is to develop a PHP photo gallery using either an array, session variables, or cookies

I am in need of a solution for my issue. https://i.stack.imgur.com/Xe65l.png The image shows the front end, and I require a corresponding function to be developed for it. ...

Guide on using CSS to position text around an image

I need to figure out a way to wrap text around an image positioned in the bottom left corner of a CSS table. Since the amount of text may vary each time I use it, I am wondering if there is a solution for this and how I can achieve it? ...

Navigating the ins and outs of Bootstrap 4 grids

I am trying to create a layout with two columns, each using the class col-md-6. In both columns, there are six images. However, I want to have only one image displayed in the left column if the right column is empty. How can I achieve this? The current se ...

Adjust choices in a dropdown menu based on the selection of another dropdown menu

I am attempting to create a scenario where selecting an option from one dropdown list will dynamically change the options available in the next dropdown list. You can find my code on jsfiddle <!DOCTYPE html> <html> <body> &l ...

Change the class of the div when the first div is selected

My goal is to switch the class of the #klapp element (from .klapp to .klappe) whenever a click event happens inside the #label-it container, including when the #klapp element itself is clicked. The challenge is that I am not able to use unique IDs for each ...

The Jodit editor is appearing incorrectly

Encountering an issue with the jodit wysiwyg editor or any similar plugin editor while working within a Bootstrap tab. When adding an editor to the tab content, the display is incorrect upon selecting the tab (displayed at a fraction of the height and miss ...

Modify the button input value within a PHP script

I am currently working on a piece of code that involves following different users and inserting values from a MySQL table. <td align="center"> <input type="button" name="<?php echo $id; ?>" id="<?php ech ...

ASP Table extends into adjacent column

Having some trouble with the table layout here. In the screenshot, you'll notice a grid view within another gridview. There are currently 3 grid views - the main one and one in each table. I'm looking to move the description to the Price 2 column ...