My preference is for only the content to have the ability to scroll

I have a code snippet that functions correctly in Chrome but not in IE or Firefox. I want to make only the content area scrollable when the viewport is less than 300px or if the content overflows. My main concern is with IE, specifically version 10 and above. How can I achieve this same behavior for IE?

* {
  font-family: Helvetica, Sans;
  border: 0px;
  margin: 0px;
  padding: 0px;
}
html,
body {
  height: 100%;
  overflow: hidden;
}
#table {
  display: table;
  height: 100%;
  width: 100%;
}
.navBar {
  width: auto;
  height: 72px;
  overflow: auto;
  border-bottom: 1px solid #bbb;
  display: table-row;
}
.results {
  background: gray;
  width: 100%;
  height: 100%;
  overflow: auto;
  display: table-row;
}
.results > div {
  height: 100%;
  overflow: auto;
}
@media screen and (max-height: 300px) {
  footer {
    display: none;
  }
}
<body>
  <div id="table">
    <div class='navBar'>header</div>
    <div class='results'>
      <div>Lorem ipsum dolor sit amet...ex velit sit amet nibh rhoncus lacinia. Ut sed aliquet odio. Phasellus ut eros a nulla viverra convallis aliquet vel risus. Integer eu tellus congue, sodales
        leo et, placerat nisi. Quisque semper bibendum tortor. Maecenas sed est sit amet neque convallis lacinia. Praesent vitae dapibus nibh, accumsan lobortis velit. Mauris sed imperdiet lectus. Nunc est turpis, lobortis sit amet hendrerit eu, eleifend
        sed dui. Vivamus vulputate semper elit, vitae finibus metus mollis sed.</div>
    </div>
    <footer>footer</footer>
  </div>
</body>

Answer №1

What are your thoughts on this potential solution? Is this the answer? I found inspiration from this source

<div class="table">
<!-- Header -->
<div class="row header">Header</div>
<div class="row content">
    <!-- Utilize inner divs with position relative and absolute to enforce cell height, allowing for correct overflow.-->
    <div class="wrapper">
        <div class="inner-content">
            <input type="text" />
            <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi faucibus sem quam, quis finibus leo pretium sit amet. Sed imperdiet venenatis enim at sagittis. Praesent porta purus nec aliquet pellentesque. Nunc bibendum urna non risus lacinia, at venenatis nisl interdum. Duis porta tristique augue vel dictum. Curabitur feugiat tincidunt risus eget semper. Aliquam quis cursus nibh, feugiat commodo arcu. Aliquam non dolor vel ex dapibus interdum vitae nec lorem. Phasellus fermentum neque ut nibh hendrerit tempus. Pellentesque sit amet ligula dui. Donec laoreet est erat. Etiam aliquet sem sit amet quam tempus aliquam. Vivamus eleifend nunc ipsum, a viverra neque efficitur at. Duis mi nisl, accumsan quis ex et, al...
            <div>Some text.</div>
        </div>
    </div>
</div>
<!-- footer -->
<div class="row footer">Footer</div>

html, body {
height: 100%;
max-height: 100%;
padding:0px;
margin:0px;
}
.table, .row {
    outline: none;
    border: none;
    outline-style: none;
    vertical-align: top;
    text-align: left;
}
.table {
    border-collapse: collapse;
    display: table;
    table-layout: fixed;
    /* This will ensure the cells within the table will keep there width. */
    width: 100%;
    height: 100%;
}
.row {
    display: table-row;
    width: 100%;
}
.header {
    background-color: red;
}
.content {
    height: 100%;
}
.footer {
    background-color: green;
}
.wrapper {
    position:relative;
    height: 100%
}
.inner-content {
    overflow: auto;
    position: absolute;
    top: 0;
    right:0;
    bottom: 0;
    left: 0;
}
@media screen and (max-height: 300px) {
    .footer {
        display: none !important;
    }
}

Answer №2

I'm a bit uncertain about your request for the "only content area being scrollable". Here's what I understand from it:

http://jsfiddle.net/5q1Lgsy6/11/

By implementing a position: fixed and width:100% top bar, you can ensure that only the content below it will have scrolling functionality.

I removed all instances of display: table tags because they are not necessary for layout organization unless the content is specifically intended for a table display.

Below is the CSS code snippet used:

* {
    font-family: Helvetica, Sans;
    border: 0px;
    margin: 0px;
    padding: 0px;
}
html, body {
    height: 100%;
}
#table {
    height: 100%;
    width: 100%;
}
.navBar {
    background-color: white;
    top: 0;
    width: 100%;
    height: 72px;
    border-bottom: 1px solid #bbb;
    position: fixed;
}
.results {
    margin-top: 72px;
    background: gray;
    width: 100%;
    height: 100%;
    overflow: auto;
}
.results > div {
    height: 100%;
    overflow: auto;
}
@media screen and (max-height: 300px) {
    footer {
        display: none;
    }
}

EDIT: To also keep the footer fixed at the bottom, include the following in your CSS:

footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 20px;
    background-color: white;
}

Answer №3

Want to style your website for different versions of Internet Explorer?

For IE-6:

* html #div { 
    height: 300px;
}

For IE-7:

*+html #div { 
    height: 300px;
}

For IE-8:

#div {
  height: 300px\0/;
}

For IE-7 & IE-8:

#div {
  height: 300px\9;
}

For Non-IE-7 only:

#div {
   _height: 300px;
}

To hide from IE 6 and lower versions:

#div {
   height/**/: 300px;
}

html > body #div {
      height: 300px;
}

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

Exploring the root of an abnormal behavior on Bootstrap 4

Currently, I am encountering an issue with a dropdown menu that I created by modifying Bootstrap's example. I had to replace buttons with links in my version. You can view the code on jfiddle. Here is the code snippet: <a class="nav-link nav-link ...

Creating an email-friendly button in Outlook without using images by styling a hyperlink with padding

Presenting a basic HTML code snippet - https://jsfiddle.net/mark69_fnd/6g0L0jwc/ <body style="background-color: white; font: normal 14px Verdana"> Hello <p></p> <a style=" font: bold 11px; text-decoration: none; background-color ...

Is it possible to alter the text color within a Semantic UI vertical menu?

Looking for a solution: the vertical menu contains an active red link item, but I only want the pointer to be red. What is the best way to change the text color to black? Have tried wrapping it in a paragraph element, but it ends up making repositioning di ...

Ways to use flexbox to position an image beside an input field in the center

I'm struggling to center an image next to an input field. Even when I try using vertical-align: bottom;, the image doesn't end up centered where I want it to be. I attempted to use position:relative and adjust my image using top, bottom, etc., b ...

Padding for Bootstrap card on mobile devices

I'm having trouble adding padding to the right and left sides of the card in Bootstrap 4. Here is the code snippet: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0i ...

Is it possible to modify the dirpagination filter in AngularJS from an input box to a select box?

I have been experimenting with the AngularJS dirpagination library. Feel free to check it out at this link. You can also see a code demo at: this link. My question is, is it possible to change the input box to a select box and still have the same functio ...

Is it possible for Google to crawl links that are generated using JavaScript?

I have developed four websites using HTML, CSS, and JavaScript without utilizing any server-side languages like PHP. My main goal is to acquire backlinks with various anchor text. To achieve this, I have decided to use a single JavaScript file on all my w ...

Issues arise when attempting to use the Android KeyUp, KeyDown, and KeyPress events in conjunction with Angular2

I am encountering an issue where I consistently receive a keyCode of 229 in Android Chrome browsers when running either: <input type="text" (keydown)="testKeyCodes($event)"/> <!-- or --> <input type="text" (keyup)="testKeyCodes($event)"/& ...

Using a CSS gradient with a variable in React.js - A guide to implementation

Looking to incorporate the following CSS property into the Navlink component. In the CSS file, the property is usually written like this using gradient. .ele { background-image: linear-gradient(45deg, #808080 25%, transparent 25%), li ...

Tips for positioning a popup in the center of a window

Hello everyone, I'm attempting to integrate a Facebook popup like box into my Blogger blog. However, I am facing an issue where I want the popup to appear in the center of the webpage using absolute positioning. Below is the code that I am currently u ...

SVG with a background image that is centered

Looking to include a centralized image within an SVG. This image will act as a user avatar, but my attempts have been unsuccessful so far. .body { width: 100%; height: 100%; background: #1f1b33; padding: 2rem; } svg { width: 120px; } <div ...

Enhancing images with dual captions using CSS hover effects

I have been experimenting with creating an image that, upon hover, displays a caption sliding out from left to right on the top and bottom. I have managed to achieve this effect on two separate images - one displaying the top caption and the other displayi ...

The horizontal layout for the Bootstrap 3 sub menu is not displaying beneath the dropdown as expected

Check out my testing site here. I envision the navigation of my website to look like this in the near future, albeit at a lower resolution. While experimenting with the inspector tool, I noticed that changing the display property to inline-block causes t ...

Save a specific row from the table into a basic array

Within my source code, I am generating a table with the following content... echo "<form id=\"center\" Name=\"Form2\" Method=\"Post\" Action=\"\">"; echo "<table border=\"1\">"; for ...

Contact Form with Bootstrap 4 Font Awesome Icons Positioned Beside

https://i.sstatic.net/whRD8.pngI need to reposition my font awesome icons next to the contact form, instead of having them at the top of the form - please refer to the image. Also, can you advise me on how I can adjust the length and width of the form? I ...

Centering text in a D3 donut chart

Struggling with centering text inside a d3 donut chart for a project. While trying to modify a piece of code, I find myself lost in the complexity of it. Despite my efforts, the text added to the center is not perfectly centered. I have attempted various ...

Access data from an array using xpath in Chrome Console

Currently, I am utilizing the Google Chrome Console to extract an array of elements that are tagged with the class name attrValue. This is the line of code I am using: $x('//*[@class="attrValue"]'); Below is the output of my code: <td class ...

Ways to eliminate the Horizontal scroll bar

Currently, I am in the process of transforming a Static Page into a Responsive Page. However, when I resize my page to a lower width, I notice that a horizontal scroll-bar appears along with some margins at the bottom and right side of the last div/Footer. ...

What steps can be taken to modify Gmail settings so that annotations are visible in the promotions tab?

I'm currently looking into how to properly utilize annotations in the promotion tab. I sent a test email to myself, but I am unable to see any annotations in my promotion tab. Is there a specific setting within Gmail that needs to be adjusted in order ...

Angular not updating the values in real time

First and foremost, I am utilizing socket.io to emit data. Data is emitted upon connection (so the website does not appear blank) as well as when certain events occur. Upon initial connection or page refresh, everything updates and functions smoothly. Howe ...