Make the height equal to 100% with padding included

I need help with a setup where I want a div to fill 100% of the screen with a margin of 10px. Inside this div, there should be a navigation pane at the top, followed by a content div below with padding, and an inner content dive also with padding. The issue I'm facing is that setting the height to 100% plus adding margin/padding stretches the div beyond what I want. I've tried using absolute positioning, but it messes up the layout of other divs and makes resizing non-fluid. Is there a CSS solution to achieve this without resorting to JavaScript?

Below is the code snippet:

ASPX

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <link rel="Stylesheet" href="test.css" />
</head>
<body>
    <div id="wrapper">
        <div id="navigation">
        </div>
        <div id="content">
            <div id="inner">

            </div>
        </div>
    </div>
</body>
</html>

CSS

html, body
{
    height:100%;
    width:100%;
    margin:0px;
    padding:0px;
    background-color:Black;
}
#wrapper
{
    height:100%;
    margin:10px;
    background-color:Blue;
}
#navigation
{
    height:100px;
    background-color:Green;   
}
#content
{
    height:100%;
    padding:10px;
    background-color:Orange;
}
#inner
{  
    height:100%;
    width:100%;
    padding:5px;
    background-color:Lime;
}

Answer №1

To achieve 100% height and padding at the same time, consider adding box-sizing:border-box to the specific elements you want.

This method is compatible with IE8+ as well as modern browsers, making it a widely supported solution.

Find more information about box-sizing here

Answer №2

Here are a couple of suggestions to consider...

1) Adjusting the height of the container, navigation bar, main content, and inner sections to around 98% could be worth trying.

2) Experiment with adding a subtle transparent border of 1 pixel thickness to the container and various other elements. This simple trick can sometimes alter the spacing between elements.

I hope you find these tips helpful!

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

Fixed elements inside an iframe do not display properly in Safari

Our team is encountering an issue where elements containing position: fixed; within an iframe are not rendering properly. We have observed this problem specifically on macOS in Safari. Below is the expected appearance: https://i.sstatic.net/ZD1VH.png An ...

What causes the difference in behavior when selecting multiple elements in CSS?

My attempt to create a responsive menu resulted in unexpected outcomes when selecting specific elements. For instance, choosing "nav ul li" for list styles at the default size and using "ul li" for the breakpoint did not produce the desired effect. The is ...

Tips for identifying unique digits within numbers

I've encountered an issue with my function that splits the input value on space and then loops through to search for numbers. However, only the last value is shown as checked, not the ones before it. One solution I found was to remove the else statem ...

Using Django to run a function and display the output on a template without needing to refresh the page

Currently, I am using django to work on my website. On a specific page, there is an input 'x' which triggers a function when the enter key is pressed. Once this happens, the page refreshes and displays the result. But what I really want is for it ...

When an image is clicked, I would like it to redirect to a different page

In my slider image list, each image has an ID. If the ID becomes equal to a specific number, such as 24, I want that particular image to move to another page when clicked. Here is the code snippet: <?php $sql = "select * from ".$tblImages." Where cid= ...

Toggle Form Section Visibility

I am working on a table with five rows that have upload buttons. Each time I submit a row, the page refreshes, but I want to hide all but one row at a time. When the first submit button is clicked, it should show the next row and hide the previous ones. Th ...

Is there a way to position the dropdown arrow on an HTML5 date input to the right side?

As a newcomer to HTML and Bootstrap, I find myself facing this code conundrum: <dd class="col-4"> <div class="input-group input-group-sm form-group"> <span class="input-group-addon ...

Span within a span using Bootstrap

I am facing some challenges in figuring out how to nest a span within another span using Bootstrap. My objective is to have a centrally aligned block, with the following structure inside: - One row containing: - A block on the left (span6) ...

CSS: Inaccurate positioning and border-radius causing gap between div and border-bottom

My goal was to create a card game with multicolored, double-sided borders, but I encountered issues when trying to implement this feature. Initially, I attempted to use an onclick event to change the border color, but it didn't work as expected. I fi ...

Linking a button to a (click) event within HTML content fetched from the backend

Hey there, I'm facing a scenario where I have an angular service that sends a HTTP request to the backend for some HTML code. Once the HTML is received, I'm inserting it into the component's HTML using <div [innerHTML]="..."/>. The iss ...

Navbar struggling to contain overflowing div content

I'm encountering an issue with my navbar responsiveness as it overflows at smaller screen sizes (sm/xs). https://i.sstatic.net/AgXJO.png Although I used the code from the Bootstrap website, I have made some modifications. Could these changes be caus ...

Discovering the technique to display data in PHP only from the database that is specific to the authenticated user

When creating a to-do list, I want the user (not admin) to only see tasks assigned to them. This should be indicated under the assignee column with their name. https://i.stack.imgur.com/WP5C8.png However, currently the user named Lala can see not only th ...

Tips on displaying a confirmation box when the page is refreshed or closed

I need to implement a confirmation box for users who try to close the window without saving the content of a textarea within a form. Here is the code I currently have: var myEvent = window.attachEvent || window.addEventListener; var chkevent = window.att ...

What is the best way to create more space between dashed borders in a styled component?

Looking for help to add a space between two dash borders within a styled component. Any solutions? https://i.sstatic.net/AzpfP.png const LogoBox = styled(Box)(({ theme }) => ({ width: '145px', height: '145px', display: 'fl ...

Bring the element into view by scrolling horizontally

I am facing a challenge with a list of floated left divs inside another div. This inner block of divs can be hovered over to move it left and right. Each inner div, known as 'events', has class names that include a specific year. Additionally, t ...

Using event delegation on a selector obtained from an AJAX response

Is it necessary for Event Delegation to always be bound to an element that is present in the DOM upon page load, or can we bind to a selector returned in an ajax response? Using jQuery 3.2.1 and researching Event Delegation at http://learn.jquery.com/even ...

What is the best way to align the second line of the title directly below the first line without using icons?

I am facing an issue where the icon and title are not aligning properly. When the title exceeds a certain length, it wraps under the icon instead of staying next to it. I need assistance in ensuring that the title always starts on a new line below the firs ...

Set up two separate tables with sufficient space in between each other

Is there a way to align these two tables next to each other with some space between them? Currently, they appear one below the other. How can I make them sit beside each other with spacing in between? If anyone knows how to do this, please help me out. &l ...

Tips for uploading a photo in Selenium Webdriver using Java when the input type is not 'File'

<span> <span class="glyphicon glyphicon-plus avatarUploacIcon"></span> Upload profile image</span> Here is the code I am currently using: WebElement uploading=driver.findElement(By.cssSelector("div[class='form_advanced_wrapp ...

I am facing an issue where the weather information is not being displayed even after sending a request to

I'm working on building an app that will provide users with weather data once they input a city. Utilizing the openweathermap.org API for this purpose, I've noticed in my console under networks that an API call is made when the city is entered, b ...