CSS/HTML: Resolving Internet Explorer's Div Positioning Challenges

I've been struggling to find a resolution for this issue but I haven't been able to come up with anything effective. Here's the basic concept of what I'm trying to achieve.

My goal is to have my layout divided into 3 divs. The first section will be a header displaying a logo, the second section will consist of a horizontal menu, and the third section will display content specific to the selected menu option. Additionally, I want to eliminate the browser scroll bar and ensure that the first two sections are always visible. Meanwhile, the third section should extend to the bottom of the browser window with a scrollbar that remains visible at all times. Although my code functions well in Firefox, it encounters issues in IE8. I understand that using both top and bottom in the same div is generally not recommended, but it actually works as intended in Firefox. I attempted to set the top property and use a height of 100%, but since I'm setting the top position at 163 pixels, it positions the bottom 163 pixels below the window. Ideally, I would like the third section to expand and contract as the window size changes vertically. Below is a simplified version of my code. To simplify testing and minimize working with multiple files, I've utilized inline styles. The presence of the index.css file is unimportant in this context.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title>Test Junk</title>
    <link rel="stylesheet" type="text/css" href="index.css">
  </head>

  <body>
<div style="background-color:#cccea2; text-align:center;height:136">
    section 1
</div>
<div style="background-color:#ccace2; text-align:center;height:27">
    section 2
</div>
<div style="background-color:#225522;     text-align:center;position:absolute;top:163;bottom:0;width:100%;overflow-y:scroll;overflow-x:hidden;">
section 3    
</div>
</body>
</html>

UPDATE: I've made some progress by using the XHTML doctype and I'm currently working on finding a proper solution. However, during my extensive search for a resolution, I stumbled upon this example which further added to my confusion as to why using top and bottom properties together in a div is discouraged despite them serving different purposes.

Answer №1

It is crucial to avoid using top and bottom as they are considered improper. Merely functioning in Firefox does not validate their correctness. Why not give this alternative a shot:

Instead, try employing padding-bottom: 1000em with margin-bottom: -1000em;

Answer №2

I have implemented a workaround using an alternative doctype. It still baffles me why some people discourage the use of both TOP and BOTTOM on the same div. In my opinion, it is similar to suggesting not to use margin-top and margin-bottom together on a single div. I find it puzzling.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title>Testing Random Content</title>
  </head>
<style>
body {
    background-color:#448844;
    margin:0;
    padding:0;
    font-family: Tahoma, Arial, Times;
    font-size: 12pt;
    overflow:hidden;
    width:100%;
    height:100%;
}
</style>
  <body>
<div style="background-color:#cccea2;width:100%;text-align:center;height:136px;">
    First Section
</div>
<div style="background-color:#ccace2; position:absolute;top:136px;width:100%;text-align:center;height:27px;">
    Second Section
</div>
<div style="background-color:#225522; text-align:center;position:absolute;top:163px;bottom:0px;width:100%;overflow-y:scroll;overflow-x:hidden;">
Third Section a <br>   
Third Section b <br>   
Third Section c <br>   
Third Section d <br>   
Third Section e <br>   
Third Section f <br>   
Third Section g <br>   
Third Section h <br>   
Third Section i <br>   
Third Section j <br>   
Third Section k <br>   
Third Section l <br>   
Third Section m <br>   
Third Section n <br>   
Third Section o <br>   
Third Section p <br>   
Third Section q <br>   
Third Section r <br>  
Third Section s <br>   
Third Section t <br>   
Third Section u <br>   
Third Section v <br> 
Third Section w <br>   
Third Section x <br>   
Third Section y <br>   
Third Section z <br>   
Third Section aa <br>   
Third Section ab <br>   
Third Section ac <br>   
Third Section ad <br>  
Third Section ae <br>   
Third Section af <br>   
Third Section ag <br>   
Third Section ah <br>   
Third Section ai <br>   
Third Section aj <br>   
Third Section ak <br>   
Third Section al <br>   
Third Section am <br>   
Third Section bb <br>   
Third Section cc <br>   
Third Section dd <br>   
</div>
  </body>
</html>

Answer №3

It seems that the doctype you are currently using is incorrect, which has put your website in quirks mode. To resolve this issue, I suggest switching to a different and more suitable doctype: <!DOCTYPE html>

I understand that you mentioned using the XHTML doctype, which may have improved the performance of your website by taking it out of quirks mode. However, I would advise against using this doctype unless you are specifically serving XHTML markup.

In addition, please note that you have not specified any units for the values in your CSS. It is essential to include appropriate measurements such as pixels (px), ems (em), or percentages (%).

Answer №4

Check out this solution:

        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <meta content="text/html; charset=ISO-8859-1"
          http-equiv="Content-Type">
        <title>Custom Test Page</title>
        <link rel="stylesheet" type="text/css" href="custom.css">
      </head>

      <body>
    <div style="background-color:#a2eccd; text-align:center;height:136">
        Section A
    </div>
    <div style="background-color:#e2accf; text-align:center;height:27">
        Section B
    </div>
    <div style="background-color:#225522;text-align:center;bottom:0;width:100%;overflow-y:scroll;overflow-x:hidden; height:100%;">
    Section C    
    </div>
    </body>
    </html>

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

Displaying information collected from a submission form

I am in the process of designing a cheerful birthday card and I need to transfer data from a form to the birthday card page. How can I take information from the first div (which contains the form) and display that data in the second div? <!DOCTYPE ...

Implement a function to trigger and refresh components in various Vuejs2 instances simultaneously

I currently have index.html with two Vue instances in different files: <!DOCTYPE html> <html lang="en"> <body> <div id="appOne"> </div> <div id="appTwo"> </div> </body> </html ...

jQuery is failing to properly render dynamic content data identifiers

Need help with a dynamic HTML div <a data-id="17" onclick="getcustomer();"> <div class="note note-success"> <h4 class="block">A</h4> <p>Email : <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Is there a way to include two functions within a single ng-click event?

Is it possible to incorporate two functions in a single ng-click event? Below is the code snippet: <button class="cButtonSpeichern" ng-click="saveUser()">Speichern</button> In addition, I would like to include this function as well. alert ...

How can I incorporate a search bar or similar feature on my website that mimics the functionality of Ctrl+F?

Is there a way to incorporate a search bar on certain pages of my website that functions similarly to the Ctrl+F feature in Google Chrome? Essentially, I am looking for a "find" function that searches the entire page(s). My site is built using WordPress, ...

These coding languages are becoming more popular; however, the <p> tag is nowhere to be found in the slid

Inspect and Fix the Code: Missing p tag when clicked HTML Slide up/down <div class="slideme" class="center"> <h1>Hello,</h1> <p>Can you see Me</p> </div> <but ...

Display the picture for a few moments, then conceal it. A button will appear to reveal the following image after a short period

For my project, I want to create a webpage for school where I display one image that disappears after 5 seconds, followed by a button. The user must click the button before the next image appears and stays for another 5 seconds. This sequence repeats each ...

Text remains constant until the mouse hovers over the image

Check out this Example Here is the HTML code: <ul class="img-list"> <li> <img src="http://s11.postimg.org/ynw9rnexf/Cetina_river.jpg" width="360px" height="280px" /> <span class="text-content"><span> Text To Dis ...

Implementing a Class Addition Functionality Upon Button Click in AngularJS

I have a form that initially has disabled fields. Users can only view the information unless they click the edit button, which will enable the fields with a new style (such as a green border). I want to add a class to these fields that I can customize in m ...

I am struggling to make php redirect work using onclick() function

My PHP button is not redirecting properly. Assuming the page destination is correct, is there anything else that could be causing this issue? echo "<button id=\"create\" onclick=\"location.href('/team/teams.php?op=create');&bso ...

Ways to prevent a page from scrolling

I'm currently working on a webpage that features a vertical drop-down menu. The issue I'm facing is that when the menu drops down, it causes the text below it to be pushed downwards and off the page. While this behavior is anticipated, it also tr ...

Is there excessive spacing following an A tag or an img tag?

Hi there, I'm currently facing an issue while building a table cell using the div tag. Specifically, I have encountered some unwanted spacing after my img within the cell. <div style="display:table"> <div style="display:row"> <div s ...

What is the best method for incorporating a YouTube embedded video into an image carousel using HTML and CSS?

I'm encountering an issue with my product carousel that includes an image and a video. The image displays correctly, but when I attempt to click on the video to have it appear in the main carousel view, it doesn't function as expected. Here is a ...

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& ...

Arrange, Explore (Refine), Segment HTML Chart

Is there a way to efficiently sort, paginate, and search (based on a specific column) data in an HTML table? I've explored several JQuery plugins such as DataTable, TableSorter, Picnet Table Filter, but none seem to offer all three functionalities (se ...

With *ngFor in Angular, radio buttons are designed so that only one can be selected

My goal is to create a questionnaire form with various questions and multiple choice options using radio buttons. All the questions and options are stored in a json file. To display these questions and options, I am utilizing nested ngFor loops to differ ...

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The server is unable to process the request sent by the browser or proxy. This error occurred in a Flask web application

Can someone guide me on troubleshooting this issue in Flask? I am still learning. Server running at (Press CTRL+C to exit) 127.0.0.1 - - [26/Jul/2020 11:19:45] "GET /predict HTTP/1.1" 500 - Traceback (most recent call last): raise exceptions. ...

A confined space that is scrollable, yet keeps any overflow hidden without displaying a scroll bar

Is there a method for creating a overflowing div that conceals the overflow, does not display a scroll bar, but remains scrollable (via mouse wheel or touch input)? For example: <!DOCTYPE html> <div id="longtext" style="width:100px; height ...

React-Tooltip trimming

Currently, I am facing a dilemma that requires some resolution. The issue at hand is related to the placement of React-Tooltip within the List element. Whenever it's positioned there, it gets clipped. On the other hand, placing it at the bottom isn&a ...

Customize the drawer background in Vue Material

Recently, I developed a vuejs application incorporating Google's material design components. I've been exploring options to customize the background color. <template> <div class="page-container"> <md-app> ...