Does inserting an href into a table link cause additional spacing to appear?

Currently tackling a website project and encountering an issue where inserting an href link into a table causes the text to shift forward. Seeking insights on why this is occurring.

<!DOCTYPE html>

<head>
<title>Title</title>
<link href="css/styles.css" media="screen" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="site_title1">
    <h2><span>Title</span></h2>
</div>
<div id="site_title2">
        <h4><span>subtitle</span></h4>
</div>
<div id="menu">
    <ul>
        <li class="about"><a href="about.html">About</a></li>
        <li class="events"><a href="events.html">Events</a></li>
        <li class="music"><a href="music.html">Music</a></li>
        <li class="contact"><a href="contact.html">Contact</a></li>
    </ul>

</div>
</br>
<div id="tablelist">
    <p><a href="#Orchestral">Orchestral</a> | <a href="#Chamberensemble">Chamber            Ensemble</a> | <a href="#Solo">Solo</a> | <a href="#Choral">Choral</a> | <a href="#Electronic">Electronic</a> </p>
</div>

    <a name="Chamberensemble"></a>
        <h1>Chamber Ensemble</h1>
            <table border="1">
                <tbody>
                    <tr>
                        <th>Title/Year</th>
                        <th>Instrumentation</th>
                        <th>Length</th>
                    </tr>

                    <tr>
                        <td><a href="linkinquestion.html">the link in question</a></td>
                        <td>Mezzo-soprano, Piano</td>
                        <td>15 minutes</td>
                    </tr>

                    <tr>
                        <td>this is not a link</td>
                        <td>Mezzo-soprano, Piano</td>
                        <td>15 minutes</td>
                    </tr>


</body>



<footer>
<p>Copyright 2014</p>
<br>

CSS:

    /* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}


/* main font style, background color, and body margins */

...

Also, wondering about the placement of my footer being above my table text. It appears fine in the actual code with more content, but curious nonetheless.

Appreciate your input!

JSFiddle: http://jsfiddle.net/GBuN3/

Answer №1

The reason for this behavior is due to the padding applied in your code. Here is the snippet that is causing the issue:

#menu, a { padding: 20px; }

This piece of code will apply the padding to all a elements throughout the document. If you want the padding to be exclusive to a elements within #menu, you should modify it like this:

#menu, #menu a { padding: 20px; }

You can see the updated version on this fiddle: http://jsfiddle.net/GBuN3/4/

Answer №2

After removing various sections of CSS code from the file, I discovered that the issue resolved itself. It appeared that the last piece removed was the source of the problem. The culprit turned out to be:

#menu, a {
padding: 20px;
}

Just as setek pointed out, the a tag had a padding of 20px, which explains why there was a 20px indentation on your a href tag.

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

Tips for preventing the appearance of a horizontal scroll bar when utilizing the FlexLayoutModule in Angular

import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-property-feed', templateUrl: './property-feed.component.html', styleUrls: ['./property-feed.component.scss'] }) export class Prope ...

AngularJS - triggering $emit before listening with $on

Currently, I am working on developing directives using the AngularJS framework. These directives include both controllers and sometimes even include each other. Specifically, for every course, I have created a directive to display its information: <li ...

Using jQuery, it is possible to automatically generate a new HTML input element and access it within

My issue is: I am facing a problem with a dynamically generated table on my page using ajax-jquery My table consists of 3 <td> elements: 1 for name and 2-3 for checkboxes representing parameters I have set up an event for all input checkboxes to d ...

What's the best way to vertically center text in a div with overflow hidden?

In my ASP GridView, I am trying to display a table with a fixed number of lines in each TD element. To achieve this, I have decided to place a div inside each TD so that I can customize the height and layout. table.XDataGridView td div.inner-table-div { h ...

Trouble aligning items in a fieldset with Bootstrap

While working on a wire frame, I am attempting to create the HTML structure based on it. The required structure that needs to be built is outlined in this diagram: https://i.sstatic.net/ypp2f.png Progress has been made on aligning elements using a two-col ...

When the width of a tr tag is reduced, an <select> and <span> tag will split into two lines

I am working on creating a table that includes a field for each row along with a symbol to indicate mandatory fields. As the screen width decreases, I want the content to break into a new line at a specific point. Desired behavior: The field width should ...

Once you exit the input field, a function activates to alter the background color of the input

Is there a way to trigger a function that changes the background color of an input field when the cursor leaves it? I tried implementing this solution, but it didn't work as expected. <!DOCTYPE html> <html> <body> Enter your name: & ...

Creating a single-level menu with Bootstrap using nested angular ng-repeat

I am currently working on developing a single level menu using bootstrap and angularJS. The menu is successfully functioning with JavaScript and HTML when the <li> element is dynamically created. Now, I am attempting to integrate AngularJS into the ...

Discover the Optimal Approach to Implementing Callback Function with JSON Using Javascript and Jquery

I have a function that looks like this : <script> function sticky(json){something here} </script> Now, I would like to utilize Jquery to invoke this function and display its output within a specific div element with the ID of "stickid". H ...

What is the best way to handle media queries when determining the validity of both statements?

I'm trying to figure out how to apply CSS based on whether one of two statements is true. For instance: @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) OR and (max-device-width : 1024 ...

Tips for optimizing SVG icon caching on an external CDN without encountering flash of missing icons

I've mastered the process of getting SVG icons to load on my website, but I am facing a challenge in meeting all the criteria listed below: Need to be able to use SVG icons in CSS Avoid any flash of missing icons (FOMI) Minimize the initial page siz ...

What is the best way to restrict user input to specific numbers only?

I have a text input field, how can I ensure that only numeric values from 1 to 31 are allowed? <input type="number" min="1" max="31"> ...

How to Show a Div When Clicking using Javascript

Looking for a way to toggle the visibility of a div element on click and hide it when clicked anywhere else. window.addEventListener('load', function() { $$('a.tooltip').each(function(link) { var tooltip = document. ...

Is there a way to make an HTML link target the same as JavaScript window.opener?

Within my project, the main page is where users log in and access the primary tables. Additionally, there are numerous supplementary pages that open in separate windows. Once the login session times out, it is essential to restrict user access to any cont ...

Choosing the Right JS Framework for an iPad HTML Prototype

Is there a quality Javascript framework available specifically for creating iPad prototypes? I've been searching but haven't found anything helpful yet. Cheers, Stefan ...

The Bootstrap Alert triggers the appearance of unnecessary whitespace

I'm in the process of setting up a basic support center using HTML. Everything was going smoothly until I incorporated a bootstrap alert. Placing the alert inside col-lg-4 as shown in the code snippet from bootsnipp caused an unwanted whitespace to ap ...

Is it possible for a jQuery selector to retain its object? What can be done to prevent it

One interesting scenario involves a dropdown element within a container. <div class='container' /> <script> var dropdown = "<select class='multi-dropdown'> ... </select>" </script> Every time the value ...

The event 'deviceorientation' does not seem to be firing in iOS browsers when it is referenced within an iFrame

I am currently working on a website that features a "360 panorama viewer" embedded within an iframe. The source page utilizes JavaScript and window.DeviceOrientationEvent to determine if the user is browsing on a mobile device with orientation functionalit ...

Only IE has a different margin-top effect on hover in the slideshow - Check out the CSS & project link for more details

When hovering over the IE slideshow, it moves downward. Any suggestions on why this happens? Visit development.legendarylion.com for more information. Could someone provide insight on why the slideshow increases top margin when hovered over? Explore the ...

Is there a way to recycle an image and ensure that the web browser only needs to download it once?

Is there a way to effectively reuse the same image multiple times on my website without inefficiently downloading it each time? ...