Tips for making your div taller on all screen sizes

On any screen size, the red box height should increase with data and body while maintaining a 20px margin for the div. The data is displayed inside the red box on a 1920*1080 screen, but overflows on a 1360*768 screen.

background-color: red;
border: 10px solid yellow;
margin: 20px;
height: calc(100vh - 62px);

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

Answer №1

The main cause for the overflow of letters in the div is due to using vh, which represents 1% of the currently displayed height. Setting the height to 100vh makes it equal to 100% of the current screen's length. In this specific example, the CSS is defined as calc(100vh - 62px), meaning it is set to the current viewed height minus 62 pixels. Even with a screen size of 1920 * 1080, the example CSS still causes an overflow of text content. overflowed

In order to keep the letters inside the tag, it is essential to apply appropriate scripting.

<style>

    #test {

        background-color: red;

        border: 10px solid yellow;

        margin: 20px;

    }
</style>
<body>
    <div id="test">
        put text here
    </div>
<script>
    //Get id
    let div = document.getElementById('test')
    //It's the height of whole screen
    let height1 = document.body.clientHeight

    div.style.height = height1 + 'px'
</script>
<body/>

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

The hyperlink for pulling information from a form field to populate a signature template webpage is not functioning properly

I've been developing a signature template page for our company's Intranet and have successfully implemented it with almost satisfactory appearance. My current challenge involves updating link information from my forms without altering the displa ...

Creating a Submenu with HTML and CSS

After trying several guides on creating sub-menus, some involving JS, I decided to attempt a CSS-only approach. Unfortunately, I have encountered difficulty in making the submenu function correctly. You can view my code on fiddle here: http://jsfiddle.net ...

Ways to apply inline styling with CSS in a React class-based component

Is it possible to apply inline CSS in a React class component? Here is an example of the CSS I have: { font-size: 17px; 
 font-family: Segoe UI Semibold; color: #565656; text-shadow: 0 1px 1px white; } While this CSS works fine ...

Alter the background color of a table cell in Angular HTML depending on a boolean value

Attempting to use Angular ng-class to set the background color of a table cell. I'm referencing code snippets from these resources: Angular: How to change the color of cell table if condition is true Change HTML table cell background color using ...

The font style in React appears distinct from that of Bootstrap

I am looking to create a login page using both bootstrap and react. I found the perfect style on the official website. To implement this, I included all the necessary bootstrap and CSS files in my index.html file: <!DOCTYPE html> <html lang="en"& ...

Create a layout with a single column that features a dynamic image, paired with another column housed within a modal using Bootstrap

I'm facing a design issue with a row that has two columns - one with an image and the other with a list of users in a modal window. As more users are loaded when scrolling down the modal, I want the image to remain fixed in its position. Here's t ...

Images failing to load properly

Hi there, I'm new to programming and I'm in the process of creating a website. However, when I open my HTML file directly, the images are not displayed. Strangely, when I use VS Code or Brackets editor's live server, all the photos and pictu ...

The Infinite scroll feature in Fuel UX is ineffective when a specific height is not defined for the

In my current project, I am utilizing Bootstrap and Fuel UX v3.4.0 with the goal of implementing Infinite scroll throughout my entire page. Unfortunately, I have encountered difficulties in achieving this implementation. By replicating the infinite scroll ...

What is the method for customizing the default dropdown color of a bootstrap 4 selectpicker?

In my form, there are single and multiple dropdown selects. To keep things simple, I use the selectpicker class for both types. However, I want to customize the default grey color for Bootstrap 4 Dropdown with the selectpicker class to a clear color. Which ...

What is the best way to access Sass variables in a different Sass file?

I'm currently working on a WordPress theme and running into an issue with utilizing SASS from another file using the @use method. For those of you who may not know, the @import rule method will soon be deprecated which is why I am trying to implement ...

Tips for adjusting the icon size within the <IconContext.Provider> dynamically

Currently, I am using the 'IconContext.Provider' tag to style my icons from the 'react-icons' library. Are there any solutions available to dynamically change the size of the icon based on the size of my media? Is using the global styl ...

Ways to boost CSS transform with GPU acceleration

Is there a way to ensure smooth animations by utilizing GPU acceleration for CSS transforms in browsers? When does this acceleration occur and how can it be forced? For more information, check out this article ...

The CSS styling is not taking effect

I'm having trouble with my CSS changes not appearing on the webpage, and I can't seem to figure out why. Specifically, I'm attempting to modify the font, which has previously worked but is now not taking effect. Both my CSS and HTML files ar ...

I am unable to incorporate added height into the component

In my current project using react.js, material-ui, and sass, I had the task of creating a ChatBit component. After writing it, here is the code: customComponent.js file. // @flow import * as React from 'react'; import { useState } f ...

What is the best method to insert multiple rows of the same height into a table cell in

My datatable is causing me trouble as I try to add more rows in the td after the Name column. The rows are not aligning properly, and I need a solution. I want these new rows to be aligned with each other, but the number of rows may vary based on user inp ...

Launch a modal from a separate webpage

I've been trying to implement a modal using Bootstrap 4, and after referring to the documentation, it seems to be working smoothly. <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/> <scri ...

Shift the plus-minus icon on the bootstrap accordion all the way to the right side

I'm struggling to adjust the position of the plus-minus icon on a Bootstrap accordion to the far right, but my current code isn't producing the desired result. Here's the CSS snippet: .mb-0 > a:before { float: right !important; ...

Is it possible to eliminate the *:after effect for specific elements in my CSS?

I struggle with CSS, so I decided to use a library that includes the following CSS code: *, *:before, *:after { box-sizing: inherit ; } While this code works well for some views, it messes up others and is unnecessary for some. For instance, in this b ...

Adjust the dimensions of the embed code to specify a width and height

Looking to integrate Appreplica on my website for embedding content, but struggling with the length of the embedded window. My Tweets seem to extend beyond the page boundaries. ...

Achieve this effect by making sure that when a user scrolls on their browser, 50% of the content is entered into view and the remaining 50%

Is there a way to achieve this effect? Specifically, when the user scrolls in the browser, 50% of the content is displayed at the top and the other 50% is shown at the bottom. ...