Website header extends beyond normal boundaries, exceeding 100% width

Here is the CSS code I used for styling the header:

#header {
    font-size: 3rem;
    width: 100%;
    height: 4.5em;
    display: flex;
    align-items: center;
    padding-left: 1em;
}

Despite setting it to 100% width, on the website it displays with a horizontal scroll bar as shown in this screenshot.

The header seems to extend beyond the HTML tag, and using overflow: hidden or adjusting to 100vw doesn't seem to resolve the issue. Other div elements also have a width of 100%, and no console errors are present. Below is an excerpt of my HTML markup:

<body onload="setBgColors()"> <!-- Function to set background colors -->
    <div id='header'>
        <div class='flag-container'><img src="images/tree.png" alt="Flag" id="flag"></div>
        <h1 id="title">Fussajle</h1>
        <button id='edit-button'>Edit</button>
    </div>
    <ul class="tabs">
        <li data-tab-target="#overview">
            <div class="tab-button" id='default-button'>
                Overview
            </div>
...
</body>

Below are additional CSS styles applied to different elements in the layout:

.flag-container {
    width: calc(2.75em + 10px);
    height: calc(2.75em + 10px);
    background-color: #fcfcfc;
    border-radius: 50%;
}

/* Remaining CSS styles omitted for brevity */

.tabs div {
    font-size: 1.5rem;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

If anyone can offer assistance in resolving this issue, it would be greatly appreciated.

Answer №1

It appears that the issue lies within the padding-left property of the header.

#header {
    font-size: 3rem;
    width: 100%;
    height: 4.5em;
    display: flex;
    align-items: center;
    padding-left: 1em; /* This is where the problem arises */
    box-sizing:border-box; /* Consider trying this solution */
}

To resolve this, ensure that box-sizing:border-box is applied to either the header or all elements.

As stated on MDN:

The box-sizing CSS property determines how an element’s total width and height are calculated. [Learn More]

An alternative option is setting box-sizing:border-box for all elements by implementing a basic reset at the beginning of your CSS file:

*{
   margin:0;
   padding:0;
   box-sizing:border-box;
}

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

What is the method to display an error log using the .show() and .hide() functions when .click() is triggered?

My latest project involves a page where users can search by name, address, or phone number using corresponding tabs ("Name", "Address", and "Number") with input form fields and a "Search" button. One thing I want to implement is the ability to display an ...

Tips for adjusting the height and border of Bootstrap tabs

I'm facing an issue with the modal and nav-tabs I created. There are a couple of problems that need to be addressed. Firstly, the tabs have excessive height and I've tried adjusting it using CSS height property, but it's not working as e ...

What is the most effective method for achieving a desired outcome?

Is it a valid approach to get an action result, and if so, how can this be achieved? For instance, if there is a page with a form for creating entities, after successfully creating an entity, the user should be redirected to the entity's detail view. ...

When the window size is minimized, containers are colliding with each other

On smaller window sizes or certain small screen phones, the buttons are overlapping the heading. Take a look at the code below: <style> body { font-family: Arial, Helvetica, sans-serif; } .x2 { position: absolute; left: 50%; top: 50%; tran ...

Incorporating a delete button onto an image using JavaScript

I am currently developing a BlogApp and facing difficulty in attempting to include a button on an image. The image is being retrieved from the Django database in JavaScript (HTML). My goal is to have a clickable button overlaid on the image. views.py def ...

The command "cordova" cannot be identified as a cmdlet

After running the npm command, Cordova was successfully installed on my system. The files and folders can be found in the directories %appdata%/npm and %appdata%/npm/node_modules. However, when attempting to use any Cordova command within the VS Code termi ...

Leveraging the power of Vue to elevate traditional multi-page/server-rendered web applications

After spending hours searching, I still haven't found anything that fits my specific case. My e-commerce website is classic, multi-page, and server-rendered using JAVA One of the pages displays a list of products with pagination Currently, to enhanc ...

Tips for showcasing data in the autocomplete feature

I have implemented the following code to show values: function retrieveValues(input) { var xhttp; if (input.length == 0) { document.getElementById("output").innerHTML = ""; return; } xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = functi ...

What could be causing my supposedly correct-looking JSON to be invalid?

I've been trying to figure this out for a while now, but I just can't seem to understand why my JSON keeps showing as invalid... When I run it through JSONLint, I get the following error Error: Parse error on line 107: ...pair?", "answ ...

Tips for sorting through existing data without resorting to a remote call - Material Table repository by mbrn (mbrn/material

Currently I am using the mbrn/material-table library which includes filtering on a column and remote data feature. However, when I apply a filter term, the table sends an API call to the server with the filter criteria in the query object. My desired outco ...

Ensuring the height of the HTML element for menu items matches the navigation bar

I've been struggling to customize a navigation bar styled with Bootstrap 4. My goal is to create a hover effect on the menu items similar to the image or code snippet provided, but without that annoying thin blue flashing offset below the item. Despit ...

Example when a specific $scope.apply() is needed:

I am currently delving into the world of Angular and experimenting with different ways to learn how it functions. One of my projects involves creating a simple application where users can add new entries through an HTML interface, store them in a SQLite da ...

incorporating the same model into the scene multiple times

Currently, I am loading a single model multiple times using the following code: var loader = new THREE.JSONLoader(); loader.load(model, load_func); The function load_func is responsible for creating a mesh and adding it to the scene: var mesh = new THRE ...

Strangely peculiar glitch found in browsers built on the Chromium platform

During a school assignment, I'm attempting to adjust the width of a button using Javascript. Below is my code: const button = document.querySelector("button"); button.addEventListener("click", () => { console.log(button.offsetWidth); butto ...

Troubleshooting Missing Cookies Issue in Live Next.js Application

I've encountered an issue with a Next.js application I'm working on. After a successful login, I set a cookie to store an authentication token. While this functionality works perfectly in my local development environment, the cookie fails to be s ...

I noticed a change in the state between dispatches, but I did not make any alterations to the state

Although this question has been previously raised, most of the discussions focus on the OP directly mutating the state. I have taken precautions to avoid this by using techniques like the spread operator with objects and arrays. However, despite these effo ...

Retrieve all visible rows using the AngularJS UI-scroll feature

As of now, I have integrated angular-ui/ui-scroll to dynamically load items into a table. Is there a method available to retrieve the visible items that are currently being rendered on the UI using ui-scroll? I have been utilizing adapter.topVisible and ...

Unable to detect Selenium xpath to click on a webpage

My objective is to click on the rate button in order to assign a rating for the movie titled Mona Lisa and the Blood Moon on the IMDB website, as depicted in the image below. I have experimented with different selenium xpath values and researched various ...

"Enhance your website with a dynamic animated background using Bootstrap container

I'm struggling to understand why the Bootstrap container is blocking the particles-js animation behind the text. I want the background surrounding the text to be animated as well... :/ Example Code: .gradient-bg { background: rgba(120, 87, 158, ...

Adjusting the size of elements and the dimensions of the browser window

My challenge involves a container with multiple buttons that are absolutely positioned. I would like these buttons to dynamically resize based on the width of the browser window. Essentially, I want both the size and position of the buttons to adjust accor ...