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

What is the best way to deactivate buttons with AngularJS?

I have a situation where I need to disable the save button in one function and permanently disable both the save as draft and save buttons in another function using AngularJS. How can I accomplish this task with the disable functionality in AngularJS? Her ...

jQuery Ajax Redirect Form

I am currently developing an HTML application with a form. Upon clicking the submit button, I initiate a server-side call using jquery.ajax(). However, when the server returns an exception, such as a Status Code 500, I need to display an error message on t ...

Creating a clickable image in the header of an R Shiny app

I've been attempting to create a hyperlink from the image output, but I'm encountering difficulties despite reviewing similar questions on Stack Overflow. svg with clickable links in shiny - not clickable The tags are not working. server.r li ...

Show a variety of logos on the website based on the current date

I've been experimenting with displaying a unique logo on my website based on the current date (for example, showing a Christmas-themed logo during December). Here's what I have so far: <img class="logo" id="global_logo" sty ...

What should be displayed if there are no search results?

My form for filtering a database is working perfectly in the first section: $result=$dbh->prepare("SELECT * FROM performers WHERE accent='$txt_accent' AND hair='$txt_hair' AND gender='$txt_gender' AND location='$txt_l ...

Looping through two arrays of objects using Angular's NgFor directive

I need to iterate through two separate arrays using ngFor in order to display their content in an html format. <div class="form-check ml-5" *ngFor="let item of competencias.competencias; let i = index"> <input class=" ...

Is it possible to have the Target='_blank' attribute open the link in a new window instead of a new tab?

Is there a way to achieve this? When using Firefox, the link opens in a new tab, which I prefer to avoid users having to adjust settings in their browsers. I am looking for a solution where a pop-up contact form appears whenever a user clicks on 'co ...

Transform a Div element into an image, ensuring compatibility with Internet Explorer 7 and 8

Currently, I am utilizing the jqplot charting library to create charts in my ASP.NET MVC application. Within a div element, the chart is being rendered. The goal is to convert this div element into an image and export it to a PDF document. The jqplotToIm ...

Original selection unavailable in pagination

I'm encountering an issue on my website where Bootstrap and JQuery don't seem to work well together. $("ul.pagination li:not(.active) a").on("click",function(){ $(".pagination li.active").removeClass("active"); $(this).parent().addClass("activ ...

Design a stylish table using the format from the specified file

Currently, my goal is to generate a table using data from a csv file. The csv file contains three pre-filtered fields to avoid any issues. However, when I execute the code, no output is generated in the report file. I suspect there may be an error while pr ...

How can I retrieve dt/dd elements and store them in an array using Simple HTML DOM?

Similar Question: Retrieving data from HTML table using preg_match_all in PHP This is the HTML code snippet: <div class="table"> <dl> <dt>ID:</dt> <dd>632991</dd> <d ...

In the Twitter Bootstrap documentation, which element is utilized for the sidebar?

I'm curious about the most efficient method for creating a sidebar like this using Bootstrap 4. https://i.sstatic.net/3eKwN.png From what I can see, it appears to be a custom component designed specifically for the documentation page, rather than ...

Adding gaps between hyperlinks in the sidebar navigation using Bootstrap 4

I created a sidebar containing links and I am attempting to add space between each link. Here is the code snippet I have tried: .sidebar-nav>li>a{ padding-bottom: 500px; } Unfortunately, this code is not producing the desired result. Are there any ...

There seems to be a connection issue between my Jquery and HTML, as they

I've hit a roadblock because my jQuery isn't connecting and I can't seem to figure out why. It's been stumping me for hours. Here is the HTML code snippet from exercise6.html: <!DOCTYPE html> <html lang="en> <h ...

Is there a way to automatically extend my content to fill the space on the page below the Material UI AppBar?

I am currently using React and Material UI React to develop my application. My goal is to implement the AppBar component with content underneath, without causing the entire page to scroll. I want the content to occupy the maximum remaining height and the f ...

Creating a visually appealing Django filter form with custom styling in HTML

Currently, this is how my django filter form appears: Below is the html code I am using: <form action="" method="get" class="form-inline"> {{myfilter.form|bootstrap}} <button class="btn btn-primary&q ...

What are the steps in creating a responsive UI with CSS?

How can I create a responsive UI using css for the following code snippet? <Text className="w-100 mt-0 align-self-center"> Lorem ipsum Lorem ipsum Lorem ipsum<span>{'$200'}</span> </Text> <Text classNam ...

Optimal practices for localization

Looking to translate our site into multiple languages starting with one language but planning for more in the future. Considering the most effective way to accomplish this. The plan is to use subdirectories to organize the html files, with shared files su ...

JQuery for Seamless Zoom Functionality

I am working with some divs that have images as backgrounds, and I have added a zooming effect on hover. However, the zoom effect is not smooth. Is there a way to modify the script to make the zoom effect smoother? Here is an example of my HTML structure: ...

Refining a collection of item elements by examining a string attribute, disregarding letter case differences

I'm working on a code snippet that generates item components from my list of objects (Frivillig). <app-frivillig-item *ngFor="let frivilligEl of frivillige" [frivillig]="frivilligEl"> </app-frivillig-item> Now, I have a new requireme ...