Why is my column height being adjusted?

I may not be a professional web developer, but I am taking on the task of designing a website for a non-profit organization. After spending several days searching through resources and tutorials on CSS, float, position, and more, I finally managed to create the layout I desired with the functionality I needed. However, there is still an issue that I cannot seem to resolve or comprehend. Please take a look at the page located at "http://www.missione-berna.ch/index2.php" along with its source code. I have included all the code within the page for easy access (eventually, styles, scripts, menu, and header will be in separate files included via PHP). I am puzzled as to why my "Menu" div does not match the size of its content or the neighboring "Content" div. While I am aware that achieving matching heights for two column divs is challenging, where is this seemingly arbitrary height coming from? Any assistance or advice would be greatly appreciated. Thank you in advance.

Answer №1

Primarily, be cautious when using position: absolute as it may cause undesirable effects. It is best to avoid it unless necessary for elements to be taken out of the page flow (such as layering one element on top of another).

Furthermore, the property height: 100% does not behave as expected intuitively. Instead of setting the height of the menu div to 100% of the entire page, it actually sets it to 100% of the viewport's height (the browser window).

If your menu has a simple background, there is a clever trick you can employ to make it appear to have the same height. You can visit this link for an example: CSSDesk

To achieve this effect, I have added a wrapper div around your menu and content. Here are the relevant portions of HTML:

<body>
<div id="Fascione">
    <img id="FotoAngolare" alt="ChiesaEsterno" src="images/esterno.jpg" width="195" height="122">
    <div id="Impressum">
        <span class="Intestazione">Missione Cattolica Italiana</span><br>
        <span class="Titolo">Chiesa "Madonna degli Emigrati"</span><br>
        <span class="Testo">Bovetstrasse 1 - 3007 Bern<br>Tel. 031 371 0243 / Fax. 031 372 1656</span><br>
        <a class="Email" href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a070319190305040f44080f18040b2a08061f0f1d0304440902">[email protected]</a>"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b565248485254555e15595e49555a7b59574e5e4c5255155853">[email protected]</a></a>
    </div>
</div>
<div id="wrap">
<div id="Menu">
    <a href="top"></a>
    <ul id="MenuList" class="Testo"></ul>
<div id="Contenuto">
<p></p>
</div>
</div>
</body>

The styling applied to these elements is as follows:

#wrap { background: #e8e8e8; }
#Menu {float:left; width:195px; }
#Contenuto { background: #fff; border-left: 2px solid black; margin-left: 196px; min-width:829px; padding: 1px 1px 1px 15px; }

This setup ensures that the entire content area has a gray background. The menu is floated left over the gray background while the content div clears the menu with a left margin of 192px and a white background. The wrapper and content divs expand to accommodate the size of your content.

A couple of additional tips:

  1. Exercise caution when using height: 100%.
  2. Remember that float: left or float: right inherently set display: block, so you cannot use display: inline on floated elements.

Answer №2

In my opinion, the best way to achieve your goal is by enclosing everything in a wrapper div. Here's an example:

<div class="wrapper"> 
    <div class="Fascione">...</div>
    <div class="Menu">...</div>
    <div class="Contenuto">...</div>
</div> 

After that, apply height: 100% to Menu and set min-height for both Menu and Contenuto.

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

On a smaller screen size, the event listeners I add dynamically are successfully attached using the exact same HTML, however, they fail to attach on a larger screen size

I recently created a small website where I dynamically add code to HTML divs. Once the data is set, I attach click and mouse enter/leave events using the div's ID. The site consists of plain HTML, javascript, and CSS. However, I noticed that when I v ...

What is the method to enable both text and numbers in an input field while restricting special characters?

Is it possible to allow both text and numbers but disallow special characters in this input field? Currently, my code only allows numbers. How can I modify it to also allow text? Is it possible to achieve this using JavaScript? http://jsfiddle.net/mhgv0 ...

Why is it important to incorporate the CSS property background-repeat: repeat; into our code?

It is believed that if you don't expressly mention the background-repeat in CSS styling, browsers will automatically set it as background-repeat: repeat. With this default behavior in place, one might wonder why there is even a need for a separate ba ...

Filtering and selecting tables in HTML

I am dealing with an HTML table that combines static data and MySQL input. The filtering functionality is working properly, but I am struggling to add the options "yes" and "no" to the selection list. These values are test inputs fetched from MySQL. I need ...

The mismatch between the number of elements in the type definition string and the number of bind variables in the mysqli_stmt::bind_param() function prevents the UPDATE operation from

I am encountering an issue with submitting or updating this data. The data does not seem to update when I try. Here is the code causing the problem: if(isset($_GET['newsid'])){ if(isset($_POST['submit'])){ $sql = $connect- ...

Error: The identifier has already been declared and cannot be re-declared

I am attempting to create a modal-cookie feature that will display a modal on page load if a cookie named "name" does not exist. However, I encountered an error: Uncaught SyntaxError: Identifier 'addCookie' has already been declared. This erro ...

Looking for assistance with CSS styling

I've been attempting to align two custom fields on a checkout form next to each other, but I'm running into an issue where the fields below are overlapping. I've experimented with using clear: both/left/right; to address this problem, but it ...

Animating the opacity of elements using jQuery and CSS

Trying to put together a fading slideshow with five slides that will loop back to the beginning. My code seems like it should do the trick, but there's something not quite right. <script type="text/javascript"> $(document).ready(function( ...

Newly designed Bootstrap 4 input field with search feature positioned off-center on smaller screens

I have successfully positioned an input text next to a button as shown below: While it displays perfectly on a regular computer screen, the alignment gets skewed when viewed on a phone device: This is the functional code I am using: <!-- Add Filer Fo ...

Transforming nested JSON files into nested jQuery divs

Is it possible to iterate through two JSON files that have a parent-child relationship based on simple ID primary and foreign keys? Can we then display the data in a list of divs with the following characteristics: Hierarchical - child divs should only a ...

Swap out HTML lists for a PHP array structure

For my assignment, I was tasked with creating an HTML list from an array and generating a drop-down menu based on another array. The requirement is that when a particular subject is selected from the drop-down menu, only that subject along with its teacher ...

Using JQuery to hide elements by setting CSS display as none instead of block

Is there a way to change the display of a content div to block when a specific tab is selected by the user, while hiding all other content divs? Here is the JQuery code I have tried so far: $(document).ready(function() { function resetTabs() { $("# ...

The runtime is experiencing difficulty in loading the Bootstrap files

File Structure in eclipse The issue is that the CSS files are not loading at runtime, causing me to lose the design I created. Below is my code for the login page. When clicking on the links for the CSS files, they open in the Eclipse IDE instead of load ...

JavaScript JQuery alert popup fails to display

I have been attempting to create an alert pop-up using JQuery that will display when a user clicks on submit without filling out the form. However, when I test my code by leaving the form empty and clicking 'submit', the page just refreshes with ...

Are you experiencing font compatibility issues on iOS devices? Is it possible that only certain fonts are not displaying correctly?

Working on a mobile landing page specifically tailored for iPhones, I want to make Rockwell the h1 font on the page. Here is the URL that I am referring to: radionowheremusic.com/mobile7.html Interestingly, when I view the page on my phone, the header fo ...

Create a new class in the body tag using Javascript

If the operating system is MAC, I set a variable and then based on a condition, I want to add a new class in the body tag. Check out my code snippet: <script type="text/javascript" language="javascript"> var mac = 0; if(navigator.userAgent.index ...

Unexpected output from Material UI Textfield

When attempting to print a page of my React app using window.print(), everything prints correctly except for the Textfield component from Material UI. It works fine when there are only a few lines of text, but when there is a lot of text, it appears like t ...

The unequal division of space between two flexed child divs is caused by varying image sizes

In my parent container, I have set the display property to flex. Inside, there are two divs with both having flex:1 set. However, the first child div contains an image and takes up twice as much space as the second div. If the screen is 1000px in height, ...

Struggling with proper vertical alignment using Flexbox and achieving center alignment

I've been using JavaScript for displaying dynamic text and images, but I'm facing some formatting issues. Currently, I'm utilizing display: flex to position the text and image next to each other, but I'm struggling with horizontal alig ...

What causes variations in layouts when using the same CSS grid code across different pages?

I've encountered an issue where the CSS on two pages, with slight color changes, is behaving differently in terms of grid layout. Despite multiple attempts to troubleshoot by adjusting items, grid-template-layout, and other parameters, the issue persi ...