The HTML header is not displaying at the proper width as intended

Let me lay out the blueprint I had in mind for my webpage:

  • The body will have a width and height of 600 x 800 pixels with no padding, allowing elements to snugly align without any margin.
  • Inside the body, there will be 3 key elements - a header, main content, and footer, all designated as classes since they will be used across multiple pages of my site.
  • Each of these 3 elements will have a width of 598 pixels, with 0 margin and a 1-pixel border for a precise fit within the body. Additionally, the borders will be styled as dashed for visual effect.
  • The vertical distribution of these elements within the body will be divided into segments of 150, 500, and 150 pixels respectively. The 1-pixel top/bottom borders of each element will overlap, creating a layout with defined spacing.

If possible, could you point out where I might have erred in my HTML structure? Currently, when I preview the page, the header's width doesn't seem right. (Of course, once completed, my page will be vibrant and engaging, but for now, my focus is on getting the design just right.)

<html>

<head>
    <title>Practice DIVs</title>
    <style type="text/css">
        body
        {
            padding: 0px;
            height: 800px;
            width: 600px;
        }
        .header
        {
            margin: 0px;
            border: 1px dashed;
            width: 598 px;
            height: 148px;
            position: absolute;
            top: 0px;
            left: 0px;
        } 
        .mainContent
        {
            margin: 0px;
            border: 1px dashed;
            width: 598px;
            height: 500px;
            position: absolute;
            top: 148px;
            left: 0px;  
        }
        .footer
        {
            margin: 0px;
            border: 1px dashed;
            width: 598px;
            height: 148px;
            position: absolute; 
            top: 648px;
            left: 0px;
        }
    </style>
</head>

<body>
     <div class="header">
        <p>Header Content Goes Here</p>
     </div>
     <div class="mainContent">
        <p>Main Content Goes Here</p>  
     </div>
     <div class="footer">
        <p>Footer Content Goes Here</p>     
     </div>
</body>

</html>

Answer ā„–1

To make a correction in your CSS code, update the .header styles from width: 598 px; to width: 598px;

The value 598 px is not valid and will be ignored by the browser. Removing the space should fix the issue.

Additionally, consider adding the following code snippet:

*, *:before, *:after {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

This change adjusts the box model so that padding and borders are included within the specified width, rather than added to it. This method simplifies calculations and is advantageous for responsive design. Using this approach allows you to set the header width to 600px; while still applying border and padding styles without impacting the overall width.

Answer ā„–2

My recommendation for a layout plan would be as follows:

1) Set the width of your body to 100%

body{
 width: 100%;
}

2) Introduce an outterWrapper div to encompass all elements on your page.

.outterWrapper{
    width: 600px; // adjust to match your page width
    margin: 0 auto; // center align on the page
    border: 1px solid #000; // if a border is needed
}

3) Begin styling your header, content, and footer divs

.header, .footer, .content{
 width: 100%;
 padding: 5px;
 margin-bottom: 10px;
}

.header, .footer{
 background-color: #cfe09b;
}
.footer{
    margin-bottom: 0;
}
.content{
 background-color: #89ccca;
}

You can view an example implementation here >> http://jsfiddle.net/salota8550/EPsk2/

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

Tips for customizing column width in v-simple-table with Vuetify.js component

For my most recent projects UI component, I decided to use vuetify.js. I attempted to adjust the width of the th and td elements within a v-simple-table using CSS, but unfortunately, nothing seemed to happen. My goal was to set the width of every th and td ...

How can TypeScript be used to update the values and text of an HTML element?

Is it possible to update specific attributes of an html element using typescript? Below is the code snippet: HTML:- <a ref="#" id="userProfileName" style="padding-top: 0px; padding-bottom: 0px; padding-right: 10px; padding-left ...

Centered inline-block divisions

I've been coding for a number of years now, but I've recently started learning CSS. I'm currently facing an issue and need some help. I want to place two divs next to each other and center them. Here's the code I'm using: HTML: & ...

Should you include the dollar sign in a Vue HTML variable or not?

Iā€™m a bit confused about whether or not I should include $ when using a Vue HTML variable: new Vue({ data: { a: "myData" } }); Do I need to use: <h1>My value is {{ a }}</h1> or <h1>My value is {{ $a }}</h1> What ...

What is the best way to navigate between different areas of an image using html and javascript?

I am currently in the process of learning how to develop mobile applications, and I am still in the early stages. Although this question is not directly related to mobile development, it pertains more to html/css/js. My goal is to create a simple game wh ...

How can the selected value be shown in the dropdown menu after moving to a different webpage in HTML?

My application features 4 roles displayed in a dropdown menu. When a specific role is clicked, it should go to the corresponding href link that was specified. However, I encountered an issue where after navigating to the second HTML page, the selected rol ...

What is the reason behind hyperlinks breaking the continuity of the text on a line? Is there a

When I have a line of code containing several hyperlinks, my desired output is a single line. However, despite using CSS to set white-space to nowrap, the result is not as expected. The line of code in question is: <a href="profile.php?v=<?php echo ...

JQuery validation and qTip2 - Remains visible even after successful validation

Struggling with getting both libraries to work together has been a challenge for me, but I'm almost there now! Initially, I attempted the suggested method: Create the form Set validation rules using escaped name attributes, as RoR automatically set ...

Ways to implement a filter pipe on a property within an array of objects with an unspecified value

Currently, I'm tackling a project in Angular 8 and my data consists of an array of objects with various values: let studentArray = [ { Name: 'Anu', Mark: 50, IsPassed: true }, { Name: 'Raj', Mark: 20, IsPassed: false }, { Na ...

Invoking an *.aspx method from an external HTML file

Greetings, I am a newcomer to the world of web application development. I have successfully created an *aspx page that communicates with a webservice through a method returning a string. My next goal is to invoke this aspx method from a remote HTML 5 page ...

Build a photo carousel similar to a YouTube channel

Is there a way to create an image slider similar to the one on YouTube channels? I've noticed that when there are multiple videos on a channel, YouTube displays them in a slider with back and forth buttons to navigate through the videos that aren&apos ...

Automatically refresh a table within a webpage with updated database information without the need to manually refresh the

I'm a beginner in PHP and AJAX. The issue I am currently encountering is displaying a table on a JSP page and wanting to auto-update the table without refreshing the page every 10 seconds. I retrieve values from a database using a PHP page Below is t ...

Utilizing Angular's directive-based *ngIf syntax instead of passing a string parameter

Currently, I'm studying the article on reactive forms by PluralSight to brush up on my knowledge and I'm having trouble understanding the syntax provided below. <div *ngIf courseForm.get('courseName').valid && courseForm.get ...

The menu bar becomes distorted when the page is zoomed out

Hey everyone, I could really use some assistance with my menus. Whenever I zoom out of the page, they become distorted. Here is the link to my website: https://dl.dropbox.com/u/22813136/Finding%20Nemo%20Inc/FNemo_front.htm# I tested the link on Internet E ...

Using jQuery, how can I dynamically change the stacking order of an element when clicked?

I'm struggling to change the z-Index on button click. I have a static image and a dynamic div, and I want to send the #imgDiv1 behind the static image. Unfortunately, despite trying everything, I haven't been able to achieve this. You can check ...

Progress Bar Countdown Timer

I have made some progress on my project so far: http://jsfiddle.net/BgEtE/ My goal is to achieve a design similar to this: I am in need of a progress bar like the one displayed on that site, as well as the ability to show the days remaining. Additionally ...

Any ideas on how to successfully implement this CSS text-decoration override?

There are moments when I question my sanity, and today seems to be one of them. Despite what I thought was a straightforward CSS code, it's just not functioning properly. What could I possibly be overlooking? Here is the CSS snippet in question: ul ...

Implementing selective image loading with HTML and angularJS

This image reveals the issue at hand Within this HTML code snippet, some of my images are displaying on the webpage while others are not. How can I go about resolving this? <img src="img/uploadFiles/{{room.imageLocation.split('//')[6]}}/{{ro ...

splitting lengthy words into several lines

Does anyone know how to break words like the examples below using CSS or jQuery? SAMPLE 1 ConfigTechnologyHormonyAppComponentBackOfficeLaunch It needs to be broken into ConfigTechnologyHo rmonyAppComponentB ackOfficeLaunch SAMPLE 2 WorkAppComponentBa ...

What is the best method for showcasing two images side by side in a column layout?

I need to showcase 2 images in a row using AngularJS, with the next two images in the following row and so forth. Img1 Img2 Img3 Img4 This is my code: <section id="content"> <div class="content-wrap"> <div class="container clearfix "& ...