Wrapping an <h1> tag inside an <a> link can create unwanted empty space on a web page

I am currently in the process of rebuilding the Porsche website using HTML, CSS, and JS. Specifically, I am looking to implement a "build your Porsche" link by enclosing it within an anchor tag. However, this seems to be causing excessive spacing on the page.

I have attempted to resolve this issue using the following CSS code:

  overflow: hidden;

Unfortunately, this solution did not work as expected. Can anyone shed light on why this might be happening?

This is a snippet of my HTML code:

<!DOCTYPE html>
<html>
    <head>
        <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
        <div id = "links">
        <link href = "element.css" type ="text/css" rel = stylesheet>
        <script src = "functions.js"></script>
        </div>
        <title> Porsche </title>
        <link href="https://fonts.googleapis.com/css?family=Exo+2" rel="stylesheet">
        <link href="https://fontmeme.com/porsche-font/" rel = stylesheet>

        </head>
    <body>
        <video id = "fast_cars" muted loop  width= "1350" height = "1000" autoplay>
            <source src = "Porsche-main.mp4" type = "video/mp4">
            <!-- Error Message -->
            Your browser does not support this video
        </video>
        <div id = "video_screen">
        <h1 id = "porsche">
            Porsche 
            </h1>
            <a id = "cool_stuff" href = "https://www.porsche.com/usa/eventsandracing/"><h2 id = "button_main"> Rediscover Driving </h2></a>
        </div>
        <div id = "under_video">
        <div id = "images">
        <img id = "718" src = "718_p.jpg" alt = "718 Porsche" />
        <img id = "911" src = "911_p.jpg" alt = "911 Porsche" />
        <img id = "cayene" src = "cayene_p.jpg" alt = "Porsche Cayan" />
        <img id = "macan" src = "macan_p.jpg" alt = "Porsche Macan" />
        <img id = "panarama" src = "panarama_p.jpg" alt = "panarama" />
            </div>
        <div id = "black_main"></div>
        </div>
        <h2 id = "para_text"> Producing state-of-the-art sport and racing automobiles since 1931 </h2>
        <a id = "link2" href = "https://www.porsche.com/usa/modelstart/"><h1 id = "builder"> Build Your Porsche </h1></a>
    </body>
</html>

Below is part of my CSS styling:

    body {
                background-color: black;
            }

            @font-face{
                font-family: logo_font;
                src: url('911porschav3title.ttf');
            }
            
            /* More CSS rules here */

#link2 {
    overflow: hidden;
}

Answer №1

When it comes to styling web elements, browsers often provide default styles for certain tags. Take Chrome, for instance, which applies specific styles to the h1 tag. The extra spacing you're witnessing may be due to properties like "display: block and -webkit-margin-*".

display: block;
font-size: 2em;
-webkit-margin-before: 0.67em;
-webkit-margin-after: 0.67em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
font-weight: bold;

As a best practice, many developers include a cleanup CSS file at the beginning of their projects, such as normalize.css.

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

Three.js not rendering any objects, only displaying a blank black screen

I've encountered a similar issue with a few of my other three.js codes. I've set up the JavaScript within HTML, but the objects aren't appearing on the screen. Every time I run the file, it just shows a black screen. The file is supposed to ...

Is the CSS parser malfunctioning?

My program is designed to scan css files using the jar cssparser-0.9.5.jar and perform various operations on the data. public static Map<String, CSSStyleRule> parseCSS(String FileName) throws IOException { Map<String, CSSStyleRule> rul ...

Locate an element by its neighboring label with XPath

Struggling to identify the XPATH for a specific element in a sea of similar attributes? Look no further. In this HTML snippet, the key to pinpointing the right element lies in its neighboring label, "Copyright". Here's the code: <div class="row"&g ...

Changing innerHTML with HTML generated by a PHP function? (utilizing xajax)

I have managed to successfully update the content inside a DIV using xajax when clicking a link. However, I noticed that it only works when I directly assign HTML within the function itself, not when calling it from another function. Allow me to demonstra ...

What strategies can be used to ensure that the page layout adjusts seamlessly to even the smallest shifts in window size?

Of course, I am familiar with media queries and how they allow us to set specific min-width and max-width ranges for CSS changes. However, when I look at the website styledotme.com, I notice that the block/div beneath the navigation bar gradually shrinks ...

Tips for stopping the web page from moving due to scrollbar placement?

On my website, I have DIVs that are center-aligned. However, some pages require scrolling while others don't. Whenever I switch between these two types of pages, the appearance of a scrollbar causes the page to move slightly to the side. Is there a wa ...

Could someone provide an example to illustrate the concept of "em is relative to the font size and % is relative to the parent element"?

Could someone provide an example of how "em is relative to the font size and % is relative to the parent element" works? What exactly do "relative to the font size" and "relative to the parent element" mean? ...

Styling Material UI components with CSS is a great way to

I'm facing difficulties while working with Material UI components. Currently, I have a Material UI table and I want to center-align the text within it. The standard CSS of Material UI contains an element named MuiTableCell-root-60 which has a text-a ...

Converting an HTML table into an Excel spreadsheet

In the process of developing an application that populates a table based on a JSON dataset, I am seeking a way to store the filtered data into an Excel file or even a CSV. The structure includes two script files - app.js and mainController.js (organized fo ...

Try placing the div class above the navbar in Bootstrap

I've created these fork me ribbons in CSS with the intention of placing them on top of the navbar, similar to the Github images. Here is how they currently appear: http://jsbin.com/womib/1 .ribbon { background-color: #F38419; overflow: h ...

PHP is unable to properly process JSON data that contains HTML tags

I'm encountering an issue with my website that communicates with a Java REST server using Jersey. Everything is functioning properly except when I try to receive a JSON object with HTML tags embedded in the content. After running a println statement ...

Create a distinct CSS animation 'origin' declaration for every <g> element

I am using CSS animation to apply a 'wobble' effect to each letter within a word. The letters are represented by SVG groups <g>. However, in the provided example, the wobbling effect becomes more pronounced with each subsequent letter, wher ...

Guide on duplicating an HTML page with a button click

How can I duplicate HTML in a new tab when the following buttons are clicked: btn_change_folder_style_seg btn_change_folder_style_raw The content will be: <img src="./pic/web_show/3_seg/01.jpg" alt=""> <img src="./pic/web_show/3_seg/02.jpg" al ...

The age calculator is failing to display the accurate age calculation

This code is designed to compute the age based on the selected value in the combo box, and display the result in the text box below. The age should update every time the user changes the selected value in the combo box. However, the computed age is not cur ...

What is the best method for accommodating various web devices effectively?

Those deciding to close this as not conducive, please read through the entire post. Specific questions will be posed at the end. Seeking practical examples and strategies. Situation As more and more people use devices like smart-phones and tablets to acce ...

JavaScript function to substitute instead of writing

function replaceHTML(a,b) { var x = document.getElementById("canvas_html").contentDocument; x.innerHTML = b; } Although the current function works fine, I would like to update it to directly replace the existing content instead of writing new con ...

Retrieving the value of a formControl within a formArray is made possible through a reactive form in

How can I retrieve the value of ItemName in my HTML code? When I attempt to use {{invoiceForm.controls[i].items.controls.itemName.value | json}}, it returns as undefined. <form [formGroup]="invoiceForm"> <div formArrayName="items" *ngFor="let ...

Is it necessary to include the Roboto font when using MUI?

After reviewing the Material UI documentation, it appears that users are responsible for loading the Roboto font: Material UI is designed to use the Roboto font by default. You may add it to your project with npm or yarn via Fontsource, or with the Googl ...

What is the proper way to utilize document.getElementById() within a standalone js file?

As I dive into learning web development for the first time, I've decided to keep my scripts organized in separate files. However, I'm facing a challenge when trying to access elements from these external files. Below is a snippet of the JavaScri ...

Dynamic resizing container

For most of my websites, I typically place content within a div that features rounded corners with a shadow effect. Recently, I've been trying to figure out if it's possible for this parent div to automatically center both vertically and horizont ...