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

What is the best way to add multiple lines of text to a webpage using the span element?

Currently, I am developing a game that involves using a map, which consists of multiple lines. My question is whether it is possible to have the span tag cover multiple lines while ensuring that each line ends with a new line character. Below is an exampl ...

Adjusting the size of images in a Bootstrap lightbox gallery

I am currently working on a website for an artist, making the galleries a key aspect. The website is built using Bootstrap, with the Lightbox for Bootstrap plugin being used for the galleries. Everything seems to be working well in terms of adjusting the i ...

Error encountered during file upload - file field :input not found

I'm dealing with some HTML that looks like this: <div id="promocodesUpload"> <div class="qq-uploader"> <div class="qq-upload-drop-area" style="display: none;"> <span>Drop </span> </div> <a class=" ...

Display images that have been uploaded on the page either as a grid view or a list of

In my Reactjs application, I am uploading multiple images to Azure Blob Storage. On a page, there is a button to open the upload form. Once the upload completes, I want to display all these images on the same page. Since the images have different aspect ...

My preference is for the flex box to expand in width (sideways) without increasing in height (up and down)

Is there a way for flex items to expand in width but only in height when necessary? I enjoy using flexbox, but I find it frustrating that all flex items in a row grow to the same height even when there isn't enough content to fill them, resulting in a ...

Customize your select element's background using jQuery when the content changes

Here is a select element with different options to choose from: <select class="state"> <option value="1">Done</option> <option value="2">Closed</option> <option value="2">Open</option> <option v ...

Having Trouble Styling Radio Buttons with CSS

Hello, I'm facing an issue with hiding the radio button and replacing it with an image. I was successful in doing this for one set of radio buttons, but the second set in another row is not working properly. Additionally, when a radio button from the ...

Is it possible to locate both the child and parent elements by their class names simultaneously using WebDriver?

When conducting a search on eBay that returns more than 50 listings, such as this example, the site displays the results in either grid or list format. Using the WebDriver tool, I am extracting prices by their class name: https://i.stack.imgur.com/dGNzw. ...

Transform JSON data into a PDF file using NodeJS

When a GET request is made to: 'http://localhost:4000/features', the response contains JSON Data with embedded HTML. I am looking to extract and save the content of the "name" and "description" fields as a PDF. Here is a sample snippet: [{"_id ...

Tips for modifying and refreshing data in a live table with JQuery

One challenge I'm facing is figuring out how to transfer the data from a dynamic table back into input fields when clicking on the edit button of a specific row. Additionally, I need to update that particular row based on any changes made to the value ...

One-Time Age Verification Popup Requirement

Hi there! I'm facing a challenge with an age verification pop up on my webpage. Currently, the pop up appears on every page a user lands on, but I only want it to show on their first visit. I've tried using cookies to achieve this but haven' ...

Jekyll is not beginning line numbers from the first line as they should be

My website was put together using Jekyll, specifically with the Beatiful-Jekyll theme. To make syntax highlighting possible, I utilized Rouge. The issue arises when displaying line numbers alongside the code - sometimes they don't align properly or ar ...

The initial navigation pill content failed to display in Bootstrap

I am experiencing an issue with my pills that have 4 tabs. Initially, when I reload the page, the content of the first tab does not show up. However, if I navigate to another tab and then back to the first tab, the content appears. Can anyone suggest a fix ...

Are you in favor of side-to-side scrolling?

I can't quite recall where I've encountered this concept before, but I do know that there must be a method for creating a horizontal scroll. Imagine you have multiple DIVs in the following structure: <div class="container"> <div> ...

Save user input data into an Excel file using PHPExcel

Could someone assist me with storing values from my form inputs to Excel using PHPExcel? I have successfully stored data from my table to Excel, but now I want to store the values from my inputs. Can anyone help me, please? Example of the form inputs: ent ...

Images in assets folder are not showing up in Vue Bootstrap

I'm attempting to showcase an image similar to the example provided in this guide Below is the code I am using: <template> <b-container fluid class="p-4 bg-dark"> <b-row> <b-col> <b-img rounded="ci ...

Exploring HTML5 video playback in AngularJS

When I use this code: <video id="video" class="video-js vjs-default-skin" controls width="640" height="264"> <source src="http://localhost:3000/files/public/photos/Let-her-go.mp4" type='video/mp4' /> <p class="v ...

"Emphasize menu items with an underline as you navigate through the

I am using Gatsby with React and have a navigation menu with links. I would like to make it so that when a link is clicked, a border bottom appears to indicate the current page, rather than only on hover. <ul className="men" id="menu"> ...

Using the <video /> tag on a Next.JS page generated on the server side leads to hydration issues

My Next.js app's index page is rendered on the server side by default. During development, I encountered an error that stated: Unhandled Runtime Error Error: Hydration failed because the initial UI does not match what was rendered on the server. Wa ...

Change the color of the text in a shiny dashboard

While exploring shiny dashboard, I came across this link that explains how to modify colors in the sidebar and header. However, I'm struggling to change the font color for sidebar items. The default white font color becomes unreadable when using light ...