There appears to be an unnecessary space forming between the header and section tags in an HTML5 and CSS3 setup

          <!doctype html>
        <html>
        <head>
            <title>Page Title</title>
            <meta charset="UTF-8">
            <meta name="viewport" content="initial-scale=1.0">
            <style> 

                body{
                    padding:0;
                    margin:0;
                    font-family:sans-serif;
                }
                .container{

                    width:80%;
                    margin:0 auto;


                }

                header{
                    margin:0;
                    min-height:90px;
                    background-color: #344249;
                    border-bottom:#e8491d 3px solid;

                }
                header h1{
                    float:left;
                }
                h1 span{
                    margin-left:70px;
                    display:inline-block;
                    color:#db1c1c;
                }

                nav{
                    float:right;
                }        
                nav ul li{
                    display: inline-block;
                    list-style: none;
                }

                nav ul li a{
                    display:inline-block;
                    text-decoration:none;
                    padding:10px;
                    margin-top:12px;
                    color:white;
                    border:2px solid #be1414;
                    background-color:#be1414;
                    margin:5px;
                    border-radius:4px
                }

                nav ul li a:hover{
                    background-color:black;
                    color:red;

                }
                #one{
      min-height:400px;
      background:url('./img/showcase.jpg') no-repeat 0 -400px;
      text-align:center;
      color:#ffffff;
      margin:0;
    }
    #one h1{
    margin-top:100px;
        font-size:55px;
        margin-bottom:10px;
     }
                #one p{
                    font-size:20px;
                  }
      </style>
        </head>
        <body>
    <header>
        <div class="container">

            <div id="branding"> 
            <h1> <span>ė</span>View</h1>
             <nav>
                 <ul>
                     <li><a href="#">Home</a></li>
                     <li><a href="#">AboutUs</a></li>
                     <li><a href="#">Services</a></li>


                 </ul>

             </nav>  

      </div>
        </div>
    </header>

    <section id="one">

        <div class="container">

            <h1> Welcome  To Tech 
            </h1>
            <p> This is a <br>
            Example </p>
        </div>
    </section>


        </body>
    </html>    

Output

// Need help with optimizing the spacing in my HTML code. The unnecessary margin on heading h1 is causing a gap between the header and section, and I can't seem to resolve it.

I attempted to use margin-top property for heading h1 within section id one to center align it as follows: #one h1{margin:100px}

Setting margin to 0 inside the id one's h1 effectively removes the gap between header and section, but it also eliminates the margin flexibility for h1 within section with id one.

Answer №1

Here is a suggestion for your header design:

.header{
     position:absolute;
     top: 0;
     right: 0;
     left: 0;
     height:90px;
     background-color: #344249;
     border-bottom:#e8491d 3px solid;

}

#one h1{

margin-top:100px;
    position: absolute;
    top:90px;
    font-size:55px;
    margin-bottom:10px; 
}

Instead of using a <header> tag, try using a <div class="header"> element.

If you encounter any issues with your other CSS rules, feel free to ask for help by leaving a comment :)

Answer №2

Replace margin-top with padding-top

#one h1{
    padding-top:100px;
    font-size:55px;
    margin-bottom:10px;
 }

In essence, the use of margin creates space outside elements while padding generates space inside elements.

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

Employing a masked container for displaying text

Currently working on creating a button using html5 and css3. My goal is to implement a hover animation similar to the one shown in this example. The desired effect is for a white circle to expand from the center when the mouse hovers over the button, with ...

Enhancing the window.print() Functionality

I recently utilized the window.print() function to print a web page containing a table. The headers of the table were styled with font color, however when printed, they appeared black instead. Below is the code snippet: <thead> <tr style="color:r ...

Align the images in a div to the center of the page

After discovering a jQuery code that rotates images within a div, I am now aiming to centralize this entire process on the webpage. The CSS styles used for the images include: #rotating-item-wrapper { position: relative; } In addition, the following ...

Creating a tooltip within a table cell using HTML

I have a dynamic table that is populated with data from a database. The column where I'd like to include a tooltip is $row['The_Job']. However, it's crucial that this column has specific styling for the cell content (excluding the tool ...

Creating a weather format user interface in HTML can be accomplished by following a few

I am currently utilizing the open weather API to showcase weather data, however, I am facing difficulties in arranging the data in a format similar to the one shown below. Example output: I attempted to present the data in the following structure: ...

Optimizing responsiveness and side margins for high-resolution displays

Struggling with creating a website design with Bootstrap. My goal is to add margins on the sides when the screen size increases, but once I achieved it, the responsiveness of the page got disrupted. To incorporate the side margins, I enclosed the entire b ...

Tips for adjusting the color of linked text within a jQuery accordion

Is there a way to change the color of a link within a jQuery accordion? css .x { color: red; } html <div id="test"> <h3><a href="#">One</a></h3> <div>111 </div> <h3><a href="#">T ...

Removing background color and opacity with JavaScript

Is there a way to eliminate the background-color and opacity attributes using JavaScript exclusively (without relying on jQuery)? I attempted the following: document.getElementById('darkOverlay').style.removeProperty("background-color"); docume ...

Enhancing BarGraph and Bars Size in Oracle ADF

We have created a web application using Oracle ADF. The application includes a page with a graph displayed below. Currently, we are looking to enlarge the bar graph by increasing its height, width, and size of the bars themselves. Difficulty 1: While we ...

What steps can be taken to avoid the widespread application of [(NgModel)] to multiple input fields?

I'm a little puzzled about what to utilize besides [(ngModel)]. As you can see from the code snippet and images below, ngModel binding is applied to all other input fields when I click on the Edit button due to *NgFor. Can anyone offer some recommenda ...

AngularJS select element not updating ng-selected attribute properly

As a newcomer to Angularjs, I am facing an issue with setting a default value for a select element. I am working with static values and not using ng-repeat or options. Despite my attempts to use ng-selected, I have been unsuccessful in setting the default ...

Alter the div's HTML content once the Ajax operation is completed

I have a div element that looks like this: <div class="progress" id="progress-bar"></div> I am using the following JavaScript code along with an ajax call to retrieve some data. The data returned is 0, however, the content is not being added ...

How can a single value from one table be allocated to multiple values in another table?

There are 3 distinct tables that I am working with: process table: | projectNo | process | studio | +-----------+---------+--------+ | 170001 | ANM BLD | APEX | | 170001 | ANM BLD | CANVAS | | 170002 | CGI MOD | APEX | | 170003 | CGI MOD | ...

Can parameters be effectively passed to the $.change() method in any way?

I created a function that is triggered when the text in an input textbox changes - In my HTML file - <input id="unique" type="text" data-ng-change="KeywordChange(filterKey)" ng-model="$parent.filterKey"> In the controller - $scope.KeywordChange ...

Adjusting the height of an iframe in real-time

Looking for some help with adjusting the height of an iframe based on its src content. I have a basic understanding of JavaScript, but need some guidance on how to achieve this. Here is what I currently have: <iframe id="frame" scrolling="no" framebord ...

What are some strategies for creating a website that caters to both web crawlers and users of single page applications?

Let's get down to the specifics. I've got a frontend website at (don't worry, it's not porn). If you have javascript enabled, the URL becomes [this uses jquery/ajax load]. If you're without javascript, the URL remains as . To ...

Arranging serialized information from a tabular format and retrieving specific data

: I'm currently attempting to utilize an AJAX POST request to send data from a dynamic webpage that includes information gathered from a table form, a date selection box, and comment text input. The webpage is generated as a PHP file on a GET request ...

What is the best method for displaying an external SVG file using the <use> tag in HTML?

I seem to be struggling with a task that I thought was quite simple. Despite trying to replicate 8 other examples I found online, such as this one, I just can't seem to make it work. For the sake of simplicity, let's focus on this scenario: I ha ...

Tips on configuring the values of the outer div in an HTML document

I have a webpage in AngularJS. It consists of two main sections; one displays the total number of users and the other displays a table populated with user data retrieved from a service. Below is the code snippet: app_user.html // This div displays the t ...

`I am facing issues with class binding in Vue 3 when using SwiperJS`

Currently, I am working with Vue 3 along with swiperjs. I have encountered a problem related to the v-bind:class behavior in my project. The issue arises when transitioning to the second slide, where the !h-auto class does not get applied as expected. St ...