Aligning three hyperlinks evenly to spread across the webpage

My professor provided the class with an image that may resemble something he could ask us to recreate on an upcoming exam. He suggested we try replicating it at home to study. I have most of it figured out, but there are three links positioned perfectly across the top of the page that I can't seem to get right.

I've spent hours tweaking the numbers, trying different widths and margins, like setting the link width to 33% and margin to 1.66%. However, my attempts led to unexpected outcomes where one of the links ended up below the others in the browser. It's becoming more confusing than helpful. The perfection of his image suggests a mathematical solution rather than arbitrary number adjustments.

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="practiceTest.css">
    <title>Document</title>
</head>
<body>
    <div id="box1">
        <a href="https://www.google.com" id="googLink">Google</a>
        <a href="https://www.microsoft.com" id="microLink">Microsoft</a>
        <a href="https://www.yahoo.com" id="yahooLink">Yahoo</a>
    </div>

    <hr>
    <div id="box2">
        <h1 id="header">Guest Book</h1>

        <form action="post">
            First Name:
            <input type="text" id="firstName">
            Last Name: 
            <input type="text" id="lastName">
            College:
            <input type="checkbox" name="Business" id="business">
            Business
            <input type="checkbox" name="Education" id="education">
            Education
            <input type="checkbox" name="arts" id="arts">
            <br>
            Current Profession:
            <select>
                <option value="idk">unemployed</option>
                <option value="idk1">idk1</option>
            </select>
            <br>
            Comments:
            <br>
            <textarea name="comments" id="comments" cols="30" rows="2"></textarea>
            Would you like to share your comments with others?
            <br>
            <input type="radio" name="yes" id="yes">
            <input type="radio" name="no" id="no">
            <hr>
            <button type="submit">Send</button>
            <button type="reset">Clear</button>
        </form>
    </div>
    <hr>
    <div id="box3">
        Copyright - Made up Name
    </div>
</body>
</html>

CSS

#box1{
    background-color: black;
    align-self: center;
    padding: 20px;

}

a{
    align-content: center;
    width: 20%;
    margin: 0 5.33%;
    padding: 10px 0;
    color: azure;
    background-color: red;
    display: inline-block;
    text-decoration-line: none;
    color: white;
    text-align: center;

}

body{
    background-color: whitesmoke;
}

#box2{
    padding: 20px 20px;
    margin: auto 10px;
    background-color: white;
    color: darkred;
}

#box3{
    color: white;
    background-color: black;
    padding: 20px;
    text-align: center;
}

Answer №1

If you set a margin of 1.66% on the left and right sides, remember to subtract this from your width, resulting in 33.33% - 1.66% - 1.66%. This means your width should be 30.01% in this scenario. Make sure to use float:left instead of display:inline-block to avoid extra space around the element.

If you plan on adding padding inside the a tags, remember to apply box-sizing:border-box so that the padding is included within the element's width.

New Advice:

Alternatively, consider using display:flex to evenly distribute spacing. You can easily find guides on how to utilize display:flex (or the css flexbox layout model) through Google.

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

Deconstructing JavaScript scripts to incorporate HTML5/CSS3 functionality for outdated browsers such as Internet Explorer

I have been researching various resources and guides related to different scripting libraries, but none of them seem to address all the inquiries I have regarding performance and functionality. With so many scripts available, it can be overwhelming to dete ...

The fluid table within the Bootstrap container is not adapting to different screen

Can't figure out why the bootstrap container fluid table is not responsive. Even though I used an example of My First Bootstrap Page that works fine and is responsive, this particular table remains unresponsive. I want to avoid using a scroll but will ...

I'm looking to make my PayPal donate button smaller after noticing that PayPal is making it larger. How can I adjust the size of my customized PayPal

I am seeking your help in resolving an issue with PayPal enlarging my button from 130px x 65px to 300px x 150px. I have checked the button on both a local browser and within the Square Space editor, but the result remains the same. I even attempted to adju ...

Can CSS be utilized to consistently display text in a uniform manner?

Currently developing a unique Qur'an app for Muslims, standing out from the already existing ones in the market. There are two common types of Qur'an apps available: one that replicates the exact look of a physical copy, page by page, using imag ...

Using JavaScript to modify a section of an anchor link attribute

I am looking to dynamically update part of the URL when a specific radio button is selected. There are three purchase links, each representing a different amount. After choosing an animal, I need to select one of the three amounts to spend. How can I modi ...

Is it causing issues having the same version of jQuery included multiple times?

Within my HTML file, referred to as x.html, I've included other HTML files as well. In x.html, I have integrated the jquery library version 1.4.1. It seems that this same version of jquery is also being included from the other HTML files. Even though ...

What could be causing the position-sticky feature to malfunction within a nested nav on Bootstrap version 5.3.1?

I'm in the process of developing a user-friendly dashboard that incorporates Bootstrap 5.3.1's nested nav feature. However, I've encountered a problem where the navigation disappears when there is too much content on the page. To address thi ...

Utilize jQuery to dynamically add a CSS class to a button

When using jQuery to create dynamic buttons, is there a way to add a CSS class to the button during creation without needing an extra line of JavaScript to add the class afterwards? Below is a example code snippet: $.each(data, function (index, value) { ...

What steps should I take to ensure my Bootstrap CSS3 code is error-free and W3C validated?

My customer is requesting that I validate the HTML5 & CSS3 code using W3. I plan on incorporating Bootstrap 3.3.4 into the project, but after including it and checking at , I discovered 32 errors and 142 warnings. The W3C CSS Validator results for (C ...

The event tooltip in fullcalendar does not show up as expected

Within my Laravel 5.8 / Bootstrap v4.1.2 / jQuery jQuery v3.3.1 fullcalendar v4.3.1 application, I am attempting to incorporate tooltips for events in the fullcalendar plugin. To achieve this, I referred to a specific example provided here: Sample Example ...

Impeccable method to safeguard element from external css interference

Currently, I am working on a script that will be utilized across various pages and I want to ensure that the elements it generates are not affected by the CSS styles of those pages. Some individuals suggest using CSS like this: body>*{min-height:200px; ...

Nested scrolling bars within each other

Currently, I am importing photos from a Facebook page and displaying them on my jQuery mobile webpage using the photoSwipe plugin. However, there seems to be an issue with the final appearance of the images. Pay attention to the image where the red arrow ...

Creating borders around Material UI grid items can be achieved by applying a border style to the

import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; import Paper from '@material-ui/core/Paper'; import Grid from '@material-ui/core/Grid'; const useStyles = makeStyles((theme) => ({ ...

Keep fancybox items in their designated spot

When the window is opened at full size, everything looks fine. However, when you resize the window horizontally, the thumbnails shift and disappear. I want them to remain fixed in their position like the large pop-up image so that users can still see them ...

The process of organizing and arranging the content that appears on a webpage is in

Seeking a solution to achieve a similar effect like this example. Wanting the sections to transition nicely when clicked on. Should I use a Jquery plugin or implement it with CSS? ...

Material-ui v5's DataGrid now includes a new filter icon feature

The current default setting for the new DataGrid is to only display a filter icon when hovering over the column header with an applied filter. In contrast, the previous version had the icon visible at all times. For reference, you can view the Codesandbox ...

Resizing images in different web browsers: Chrome, IE, and Safari

I'm currently in the process of building a website that utilizes the jquery tabs api. Each tab on the site contains an image that I would like to resize dynamically as the browser window size changes. Here is an example of one of the tabs: <li st ...

The Angular 2 view will remain unchanged until the user interacts with a different input box

I am currently working on implementing form validation using Reactive Forms in Angular 2. Here is the scenario: There are two input fields Here are image examples for step 1 and step 2: https://i.stack.imgur.com/nZlkk.png https://i.stack.imgur.com/jNIFj ...

Guidelines for transforming an HTML string into a JavaScript document

Is there a simplified method to transform an HTML string into JavaScript code that generates the same markup using the DOM? Something similar to: Input <div class="foo" tabindex="4"> bar <button title="baz">bar ...

Retrieve the parent element of the selected tag within an iframe

I have an embed iframe that displays an HTML page. Now I am trying to retrieve the class of the parent item that was clicked. <iframe src="//example.com" id="frame" ></iframe> This is the CSS styling for the iframe: #frame{ width:380px; he ...