Tips to prevent scrolling in md-content or set a minimum height for mobile devices

Utilizing Angular Material's md-content directives, I am working on creating a section that adjusts in height to fill the available vertical space while allowing its content to scroll. However, a problem arises when viewing the page on a small screen as the content shrinks dramatically and almost becomes invisible. My goal is for the md-content to either stop scrolling or have a minimum height so that the page scrollbar shows up and users can still view the content.

Update: Take a look at this plunker link for a demonstration of the issue: https://plnkr.co/edit/NVbEHo0CPxX5Zzi4U88U?p=preview

  <body layout="column">
  <div>
    <h1>Header</h1>
  </div>
  <md-content layout="row">
    <div flex="50">Left Column</div>  
    <md-content flex="50" layout="column">
      <h2>Section Header</h2>
      <md-content layout="column" flex>
        <h3>Scroll Header</h3>
        <md-content flex layout="column" style="min-height: 300px">
          <md-content flex>
            Scrollable content here...<br/>
          </md-content>
        </md-content>
      </md-content>
    </md-content>
  </md-content>
</body>

When the browser window is large, the scrollable content functions correctly. However, upon resizing the browser, the md-content containing the scrollable element collapses until it disappears.

Update 2: I have now updated my plunker with a more illustrative example. In order to make the desired section scrollable and flexible to the bottom of the viewport, I have set all parent elements as md-content with a layout attribute. While I can enforce a min-height on the scrollable component, reducing the browser size results in its parent md-content displaying a scrollbar. Adding another min-height to that md-content would require knowledge of the content height, which might be dynamic.

Ideally, during vertical browser shrinkage, I aim for the scrollable content to only reduce to its minimum height, prompting all parent md-content elements to cease scrolling behavior and displaying just the body scrollbar.

Answer №1

There are 2 javascript errors present in both the example and the answer. The first issue is that Angular-material is not loaded, possibly due to the md-content directive causing conflicts. Additionally, there seems to be an angular2 error in the console related to how it operates with angular2.

To address this, I have updated the example to angular-material-1.0.0/angular-1.4.8 and included a module with the ngMaterial dependency.

In regards to your problem with small screen dimensions, you can utilize the angular-material layout breakpoints. In my solution, I use the xs/gt-xs breakpoint (599/600px width) to toggle between layouts using layout-xs/layout-gt-xs and flex-gt-xs. Small devices display a column layout where only the outer md-content scrolls, while larger devices show a row layout with inner md-content scrolling.

angular.module('app', ['ngMaterial']);
<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css" />
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=RobotoDraft:300,400,500,700,400italic" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

<body ng-app="app" layout-gt-xs="column">
  <md-content flex layout="column">
    <div>
      <h1>Header</h1>
    </div>
    <md-content flex-gt-xs layout="row" layout-xs="column">
      <div flex-gt-xs="50">Shrink the browser vertically to see the problem with the scroll bars. The parent md-content scrolls instead of the body.</div>  
      <md-content flex-gt-xs="50" layout="column">
        <h2>Section Header</h2>
        <md-content flex-gt-xs layout="column">
          <h3>Scroll Header</h3>
          <md-content flex-gt-xs layout="column">
            <md-content flex-gt-xs>
              scrollable content...
            </md-content>
          </md-content>
        </md-content>
      </md-content>
    </md-content>
  </md-content>
</body>
</html>

For a more detailed examination, you can view the code on Plunker, as testing the layout functionality may be challenging within snippets.

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

JavaScript code to modify a table row

I have a dynamic table that increases with Firebase data, and I am trying to incorporate a delete and edit button on each row. While the remove button is working fine, I am facing issues with implementing the edit functionality. Although I came across some ...

Why isn't the input appearing on the succeeding line below?

<label for="email2">Enter Your Email Address</label> <input type="text" name="email2" id="email2" placeholder="example: [email protected]"> <label for="phone2">Phone Number</label> <input type="text" name="phone2" id= ...

Retrieve the dropdown value that matches the label

How can I ensure that the value of a dropdown option matches its label? Currently, when getting options from a JSON file and populating the dropdown, the values do not match the labels. For example, how can I set the value to be "4.90a-ea02" when the label ...

What is the process for incorporating a unique font into an HTML document?

My goal was to incorporate a unique font into my website using HTML and CSS, but I'm encountering difficulties in properly linking the custom font. style type="text/css"> @font-face { font-family: "Uni Sans"; src: local(unisans) forma ...

Numerous Google Gauges featuring varying sets of options

Currently, I am facing a challenge involving the insertion of multiple instances of Google Gauges (or Highchart Gauges) on a single page. The goal is to utilize different option sets and separate their placement accordingly. Unfortunately, the solution pro ...

Swapping values between HTML tables and arrays with the power of JavaScript

I have a unique table structure that I need help with: https://i.sstatic.net/fr7oJ.png My current table has 2 rows and multiple columns, but I want to change it to have 2 columns and multiple rows like this: https://i.sstatic.net/uhkp9.png To create th ...

Ways to retrieve JSON data using Angular JS

I'm currently working on populating my table with data. The URL returns JSON data, but I'm struggling with how to retrieve it using AngularJS. Here is my services.js: angular.module('OrganisatieApp.services', []) .factory('organi ...

Combining text and images in XSLT using CSS: A comprehensive guide

Greetings! I am facing a situation where I have an XML file containing image tags like this: <pb facs="ciao.jpg">. Additionally, I have an XSL file that includes a JavaScript snippet as shown below: <script type="text/javascript> function ...

The hyperlink to a different webpage does not trigger any JavaScript functionalities or render any CSS styles

I am facing an issue with linking HTML pages that run Javascript and JQuery Mobile from another HTML page. My link setup is as follows: <a href="hours.html">Hours</a> The linking page and the linked pages are in the same directory. However, ...

What is the best method for eliminating tiny spaces between images that are aligned horizontally?

Check out this link for more details: . I am looking to eliminate the slim vertical gaps between the images in html5 without resorting to using the table cellpadding="0" cellspacing="0". Any ideas on how to achieve this? ...

What is the method to establish a fixed horizontal sizing for :before elements?

I am attempting to create a ul menu with a :before pseudo-element on li tags. The text inside the :before's content varies for each row. I am aiming to align this text to the right for each li, like so: pseudo_x li pseudo_xx li pseudo_xxx li li: ...

How to incorporate both image and text links within an HTML div container using JavaScript

I am trying to create a clickable image and text within a div named "films" that both link to the same webpage. However, I am experiencing an issue where only the text link works and the image link is disabled. If I remove the text link, then the image l ...

The HTML content retrieved from the API is not being successfully transformed into rendered HTML entities

I've encountered a challenge where I'm receiving a block of HTML through an API call and attempting to integrate that HTML into my template for display. However, instead of rendering properly, it's being output as a string. Here is an examp ...

`AngularJS-Infused Panoramic Experience on Windows Phone`

Currently, I am working on incorporating the design of Windows Phone Ui into an AngularJS application. To get a visual idea of what the Windows Phone Ui looks like, you can check out this example. Endless Swiping Feature An interesting feature of the W ...

Refreshing Page and Clearing History on Login/Logout with Ionic Framework

My journey into mobile application development with Ionic has just begun. I have encountered an issue where on login and logout, the page needs to be reloaded in order to refresh the data properly. However, using $state.go('mainPage') simply take ...

Angular.js - organizing a list of items and preserving the outcome

Here is a compilation of randomly arranged items: <ul class="one" drag-drop="page.items"> <li ng-repeat='item in page.items|orderBy:page.random as result'> <img ng-src="http://placecage.com/{{item.id*100}}/{{item.id*100}}"& ...

Align the text vertically within a list item

<ul style="text-align: center;"> <li style="margin: 0; padding-bottom: 23px; font-size: 32px; vertical-align: middle;"> <div style="font-family: 'Arial','sans-serif'; color: black; font-size: 17px;">[%code1%]</ ...

Select a checkbox from a dropdown menu

I need help with automatically checking a checkbox when an option is selected from a dropdown menu. Here is an example of the HTML code: <table> <tr> <td> <input type="checkbox" name="check1" />Process 1:< ...

Resolve the disconnection between the model and view in AngularJS following the unbinding process

After seeking assistance from the stackoverflow community, I successfully customized the default AngularJS validation to trigger on blur and submit. You can find more information about this process here: Trigger validation of all fields in Angular Form sub ...

Processing Incoming HTTP Requests in AngularJS Server Backend

Recently diving into AngularJS for my web development projects has been a game-changer. However, being a newbie in the realm of web programming, I've been struggling to find a concise answer to my current query. The burning question on my mind pertain ...