The internal div is too large for the external div despite both having a padding of 10px and a width of 100%

I'm struggling to make my internal div fill the external div even though it's set at width: 100%. I suspect the padding might be causing the issue, but I can't be sure. Any ideas on how I can get the internal div to match the width of the external div? Thanks.

Check out my jsfiddle for reference

Here's the HTML:

<html>
<head>
    <title>Clinical Molecular Incident Reporting System</title>
    {% load staticfiles %}
    <link rel="stylesheet" type="text/css" href="{% static 'error_tracking/css/master.css' %}">
</head>
<body>
    <div id="content">
        <div id="pagetop">
            <b>Clinical Molecular Incident Reporting System</b>
            <span id="navigation">
            {% if user.is_authenticated %}
                <a href="/search_incidents/">search incidents</a> | 
                <a href="/report_incident/">report incident</a> | 
                <a href="/resolve_incident/">resolve incident</a>
                <span id="user-info">{{ user.username }} | <a href="/logout/">logout</a></span> 
            {% else %}
                <span id="user-info"><a href="/login/">Login</a></span> 
            {% endif %}
            </span>
        </div>
        {% block content %}
        {% endblock content %}
    </div>
</body>
</html>

And here's the CSS:

html,body {font-family: Verdana; font-size: 16px;}

#content {
    width: 90%; 
    margin-left: auto; 
    margin-right: auto; 
    background-color: #F6F6EF;
    box-sizing: border-box;
    ms-box-sizing: border-box;
    webkit-box-sizing: border-box;
    moz-box-sizing: border-box;
    padding: 0px 10px 10px 10px;
}

#pagetop {
    width: 100%; 
    background-color: #04B4AE; 
    font-family: Verdana; 
    box-sizing: border-box;
    ms-box-sizing: border-box;
    webkit-box-sizing: border-box;
    moz-box-sizing: border-box;
    padding: 10px;
}

#pagetop  a:link {color:#000; text-decoration: none;}  /* unvisited link  */
#pagetop  a:visited {color:#000; text-decoration: none;}  /* visited link    */
#pagetop  a:hover {color:#000; text-decoration: underline;}  /* mouse over link */
#pagetop  a:active {color:#000; text-decoration: none;}  /* selected link   */ 

#navigation{padding-left: 15px;}

#user-info {float: right;}

Answer №1

Eliminate the width property and include negative left and right margins for the element with ID #pagetop.

#pagetop {
    margin: 0 -10px; 
    width: auto; /* this line is unnecessary, just remove width: 100% */
}

https://example.com/jsfiddle

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

Mentioning VARs found on additional pages

I'm currently designing a website. At the moment, I have set up the site to prompt users for their name on the landing page and store it in a string variable. var username = ""; Once users enter their name and click "Enter Site," they are directed ...

Add a prefix to every hyperlink in an HTML document

I'm looking to transfer an HTML template to a Google site using embedded code. The template includes a table with over 500 links that need to be prepended. Is there a method to achieve this without relying on JavaScript? <table class="wikitabl ...

Tips on concealing all elements besides the one with the ID of "mainContainer"

Efforts have been made to conceal everything except the main content on this particular Facebook post The following CSS code has been attempted without success - I would appreciate any assistance. html body * { display:none; } #contentArea { display:b ...

The chart is not properly aligned in the center

The issue I am facing is that when my chart does not have any data loaded, it appears perfectly centered and contained within its element. However, when the chart has data, it gets pushed to the right and becomes smaller. Here are the options I have set f ...

Issues arising from utilizing Twitter Bootstrap 3.1.x, the box-sizing property, and Revolution Slider

I'm currently working on a PyroCMS theme that is built with Twitter Bootstrap 3.1.x and includes Revolution Slider. However, I've encountered an issue where the property box-sizing: border-box; creates an unwanted grey border as shown in the imag ...

Why is it necessary to type in localhost in the address bar when using node.js and socket.io instead of simply opening the client.html file directly?

I am intrigued by this topic. My suspicion is that it may be related to the temporary file created by socket.io, but I'm struggling to fully understand it... ...

How can we retrieve the user ID in Node.js MySql so that it can be utilized in subsequent queries post login?

I am currently in the process of developing a web application using node.js and MySQL as my database. I have configured a login system, but I am unsure about how to determine what information should be displayed on certain pages based on user data. In ad ...

Modifying linked dropdown selections with jQuery

I'm trying to create a recurrent functionality where I have 3 select elements. When the first select is changed, it should update the second and third selects accordingly. If the second select is changed, then it should also affect the third select. ...

The intersection observer fails to detect any new elements or entries that are appended to the page after it has

When I press the "add section" button to create a new section, the intersection observer does not seem to observe it. Even when I try to run the observer again after pressing the button, it still doesn't work. I suspect that I need to reassign the `se ...

My attempt to use the Redux method for displaying data in my testing environment has not yielded

I've been attempting to showcase the data in a Redux-friendly manner. When the advanced sports search button is clicked, a drawer opens up that should display historical data when the search attributes are selected. For this purpose, I implemented the ...

Title with moderate underline decoration - Bootstrap

Can Bootstrap be used to add a border bottom with a width of 3rem (for example) and specify the color in the tag using a class? Here is an example: .half-title:after{ content: ""; display: block; width: 3rem; height: 4px; margin-top: . ...

Using a CSS3 transition delay for a single HTML element

Is it possible to create a transition delay from one CSS attribute to another on the same element? For example, I want to transition the width of a div element first and then transition its height. <div class="rect" id="box2"></div>​ Here i ...

Is there a feature on GitHub that allows for the rendering of HTML code similar to a compiler?

When using Jupyter notebook, I've learned that you can access compiled content like this - https://github.com/ctgk/PRML/blob/63499fffa5c19ec58ece35ed51692ff64112e4dd/notebooks/ch01_Introduction.ipynb by using .ipynb files. However, as a newcomer to Gi ...

Having difficulty navigating to a new tab when clicking the mouse middle button or using Ctrl+click in AngularJS

Currently, I am working on an Angular 1.6 application and facing an issue with the code I implemented from stackoverflow. It's not solving my problem. Here is the code snippet: app.run(function($rootScope, $state) { $rootScope.navigate = function($ ...

Quickly retrieve the chosen option from a dropdown menu (XHTML Select element)

Scenario In a drop-down menu built with XHTML Select element, there exists an extensive list of options to choose from. I am seeking a way to extract the chosen option using JavaScript. Dilemma My current method involves utilizing jQuery's :select ...

Is there a way to configure gulp-sass to compile the actual bootstrap CSS styles instead of just echoing the import statement?

I recently embarked on a project where I wanted to utilize the Sass bootstrap source (.SCSS), apply some customizations (through another .SCSS file), and generate a CSS output. To achieve this, I decided to employ Gulp in VS2019 with gulp-sass. After goin ...

No match was found for the reverse of 'idname' with arguments '()'. Attempted 1 pattern: ['viewRegistration/(?P<pk_test>[0-9]+)/$']

When setting up my views, I have the following code: def home(request): if request.user.participant: current_user = request.user subscriptionUser = int(Subscription.objects.get(participant=current_user.participant).id) else ...

Partial height side navigation bar

Check out this JS Fiddle: https://jsfiddle.net/wqbn6pe6/2/ This is a simple side navigation, but the grid layout is causing the sidebar not to stretch to the bottom even though it's set at 100% height. Any suggestions or solutions? Here's the ...

Creating a web page with CSS that completely fills the screen and includes a lengthy list within the design

I am looking to create a webpage that takes up the entire browser window. However, I also need to display a long list on this page that requires a scrollbar for navigation. Currently, with my existing HTML code, the list is causing the page to stretch in ...

How to keep the bottom of a CSS {position:sticky; top:0} element within the viewport without using JavaScript

I am working on creating a dashboard frame using Bootstrap 5, and I aim to achieve the functionality shown in these two images: Here is my current setup: <html> <body> <div class="pretoolbar">pretoolbar (non-essential inf ...