What is the best way to ensure that the size of a header is balanced on both margins?

I just recently began learning CSS about a week and a half ago, and I'm facing a challenge that I'm struggling to overcome. I want my webpage to have the same design as shown in this image, but despite trying various solutions, I can't seem to achieve the desired 50%-50% look.

<body>
    <header class= "header">
            <div class="box-1">
                <h1>TOP STUDENTS</h1>
                <b>Historic best averages</b>
            </div>
    </header>


/*CSS Styles*/
.header{
    display: inline-block;
    top:2vw;
    left:2vh;
    width:50vh;
    right:2vh;
    height:5vh;
    margin:5% 25%;
    position:relative;
}

.box-1{
    min-width:400px;
    min-height:60px;
    padding-top:5px;
    padding-bottom:5px;
    text-align:center;
    box-sizing:border-box;
    border: 4px rgba(24, 26, 1, 0.705) solid;
    font-size:24px;
    display:inline-block;
    background-color: rgba(200, 220, 150, 0.7);
    box-shadow: inset 0 0 15px rgba(0,0,0,.5);
}

.box-1:hover{
    width:400px;
    height:110%;
    font-size:30px;
    background-color:rgba(226, 208, 40, 0.822);
    transition: 2s;
}

I have noticed that when I switch between two monitors with different resolutions, the page layout gets distorted. However, my main focus is not on fixing this issue as it's not part of the exercise requirements. I have tried implementing some suggestions from previous posts, but nothing seems to be working. It appears that I might be missing something crucial. If you take a look at this image, you'll see how the header (highlighted in orange) should ideally look. Unfortunately, my current implementation falls short of this standard. Thank you for any assistance provided. IMPORTANT NOTE: I am specifically instructed not to use flexbox for this exercise.

Answer №1

Here is a CSS reset that you may want to include in your code:

body {
   margin: 0;
   padding: 0;
}

Your question seems a bit unclear, and when I tested the provided code, it did not match the image you mentioned.

I suggest focusing on applying sizing to the content within the header rather than directly to the header itself. I made some adjustments to center the content using 'margin-left: auto;' and 'right: auto;'. Take a look at the modified code below:

        body {
            margin: 0;
            padding: 0;
        }
        .header{
            width: 100%;
            height: 500px;
            position:relative;
            background-color: #121212;
        }

        .box-1{
            width: 400px;
            height: 200px;
            padding-top:5px;
            margin-left: auto;
            margin-right: auto;
            padding-bottom:5px;
            text-align: center;
            box-sizing: border-box;
            border: 4px rgba(24, 26, 1, 0.705) solid;
            font-size:24px;
            background-color: rgba(200, 220, 150, 0.7);
            box-shadow: inset 0 0 15px rgba(0,0,0,.5);
        }

        .box-1:hover{
            width: 500px;
            height: 260px;
            font-size:30px;
            background-color:rgba(226, 208, 40, 0.822);
            transition: 2s;
        }
<!DOCTYPE html>
<head lang="en">
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <header class= "header">
            <div class="box-1">
                <h1>TOP STUDENTS</h1>
                <b>Historic best averages</b>
            </div>
    </header>
</body>

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

Executing external Javascript within an HTML document

Just diving into this realm, so please have patience with me. I've got an external js file linked in my HTML. The JS code is solid and functions properly in Fiddle - https://jsfiddle.net/0hu4fs4y/ <script src="js/noti.js"></script> <sc ...

Modify the background color of a pseudo-element's property value dynamically

How do I change the background color of my burger menu by clicking on an icon? This is the CSS code I have: :root{ --pseudo-backgroundcolor: yellow; } .menu__icon span, .menu__icon::before, .menu__icon::after{ background: va ...

The dimensions of the box remain fixed and do not change when the screen is resized

Just starting out with HTML and CSS and trying to create a responsive website. Running into an issue where the black striped box on my page is not moving up when I resize the screen. It appears to be stuck in place, causing a gap between it and the slide s ...

Toggle button to collapse the Bootstrap side bar on larger screens

I am currently utilizing the following template: An issue I am facing is that I want my sidebar to either shrink or hide when a button is clicked, specifically on a 22" PC screen. I have experimented with several solutions without achieving success. Alt ...

Tips on fetching data from a different webpage via ajax

Hello, I am new to programming. I am looking for a way to update the content of the current PHP page with content from another PHP page using AJAX without needing to refresh the page. The content that needs to be replaced is located within div elements. ...

Using Python and Django to Populate Form Fields in a Model with values from an Imported JSON dataset

I am facing a challenge where I have a model form that stores all user inputs from form fields into the database as one entry. Additionally, I possess a JSON file with numerous JSON objects whose attributes correspond to the form field of the model. This ...

Unable to prevent ordered lists from overlapping with other content I attempt to place beneath them in HTML

function filterImages() { let input = document.getElementById('searchbar').value; input = input.toLowerCase(); let images = document.getElementsByClassName('gallery'); for (let i = 0; i < images.length; i++) { ...

What is the best way to prevent content from spilling over into the div on the right

I'm having trouble with a two column div where the text in the left column is overflowing into the right column. How can I prevent this? http://example.com <div id="wrapper-industry"> <div id="wrapper-form"> <div id="form_row"> ...

AngularJS dropdown not reflecting changes when using ng-selected

While working with AngularJS, I have encountered an issue where the first child of the select element remains empty despite my efforts to populate it. Below is the HTML code snippet: <select id="connectTV" aria-label="How many Dish TVs" ng-model="conn ...

Strange occurrences with the IMG tag

There seems to be an issue with my IMG element on the webpage. Even though I have set the height and width to 100%, there is some extra space at the end of the image. You can view the problem here: I have also included a screenshot from the developer too ...

The POST request is coming back as null, even though it includes both the name and

Having issues with a login PHP code where the post method is returning an empty string. Here is my HTML code: <form action="iniSesion.php" method="post"> <div class="form-group"> <input type="email" name="email_" class ...

Mastering the art of curating the perfect image for your Facebook timeline

Controlling the Like image presented on Facebook timeline can be done using the header element. In my single-page app, I have multiple like buttons, each should be connected to a different image. What is the best way to associate a specific image with e ...

Is it possible to combine the index page with the login page for a web project, or is it recommended to create a separate login page?

Would it be a violation of any rules if the index page of my web project is used as the login page for users? Do I have to redirect them to a different page? Is this considered best practice? ...

Designing the Mailchimp signup form with React styling techniques

I downloaded the NPM React module for Mailchimp from this link: https://www.npmjs.com/package/react-mailchimp-form. It works well and provides all the necessary forms, but I'm having trouble customizing its style. The documentation suggests adding a ...

Different option for positioning elements in CSS besides using the float

I am currently working on developing a new application that involves serializing the topbar and sidebar and surrounding them with a form tag, while displaying the sidebar and results side by side. My initial attempt involved using flex layout, but I have ...

The download attribute is not functioning properly on both Chrome and Edge browsers

I've been trying to use the download attribute, but it doesn't seem to be working. I have also attempted to use the target attribute to see if there are any issues with downloading from the server or from a web (https) source. Unfortunately, noth ...

Assign the filename to the corresponding label upon file upload

I've customized my file uploader input field by hiding it and using a styled label as the clickable element for uploading files. You can check out the implementation on this jsFiddle. To update the label text with the actual filename once a file is s ...

Bug with the animation of height in Jquery

Unfortunately, I can't share my entire source code here because it's quite lengthy. However, maybe someone can provide some insight into a common issue that may be happening elsewhere. The problem I'm facing is with a DIV element that has r ...

What is the best way to add animation to my `<div>` elements when my website is first loaded?

I am looking for a way to enhance the appearance of my <div> contents when my website loads. They should gradually appear one after the other as the website loads. Additionally, the background image should load slowly due to being filtered by the wea ...

Bootstrap requires Visual Studio Code live-server plugin to function properly

I have been utilizing the Visual Studio Code IDE for my coding projects, along with a helpful plugin called "live server" that allows for quick checks of code changes. Everything was running smoothly with Bootstrap until I encountered an issue. When I att ...