Using the <a> tag disrupts the grid's layout

Can someone help me with fixing the grid layout of my learning project? I have created a part of a website, but when I try to link images and captions using anchor tags, the entire layout gets broken. Below is the code without the anchors. How can I integrate them while maintaining the design of the website?


          body {
            margin:0px;
            display:flex;
            flex-direction:column;
          }
          nav {
            position:fixed;
            background:rgb(195, 44, 82);
            width:100%;
            top:0;
            left:0;
            box-shadow:0px 2px 2px;
            display:flex;
            justify-content:flex-end;
          }
          .nav-list {
            list-style-type:none;
            display:flex;
            margin:0;

          }
          li:hover {
            background:#45567d;
          }
          li {
            padding:1.5rem;
            font-family:helvetica;
            font-size:1.5rem;
          }
          a {
            text-decoration:none;
            color:white;
          }
          header {
            display:flex;
            flex-direction:column;
            justify-content:center;
            align-items:center;
            font-size:18px;
            width:100%;
            color:rgb(195, 44, 82);
            background:repeating-linear-gradient(
              60deg, #383838, #404040 20%, #383838 60%);
            height:100vh;
          }
          header > h1 {
            font-style:normal;
            color:white;
            font-size:50px;
            font-family:helvetica;
          }
          header > h2 {
            font-weight:200;
            font-family:sans-serif;
            font-style:italic;
            font-size:30px;
          }
          .projects {
            background:#45567d;
            display:grid;
            grid-template-rows:auto auto auto;
            grid-template-columns:25vw 25vw 25vw;
            justify-content:space-around;
            padding-right:5vw;
            padding-left:5vw;
          }
          #projects-text {
            width:100%;
            font-size:2rem;
            font-family:helvetica;
            color:white;
            text-decoration:underline;
            padding-top:3rem;
            padding-bottom:2rem;
            text-align:center;
            grid-column-start:1;
            grid-column-end:4;
          }
          img {
            width:100%;
            height:25vw;
            object-fit:cover;
            grid-row-start:2;
            grid-row-end:3;
          }
          #projects > p {
            background:#303841;
            color:white;
            grid-row-start:3;
            margin-top:0;
            padding:1.5rem; /* Fixed issue in the original code where padding was missing */
            font-size:1.3em;
            font-family:helvetica;
            text-align:center;
          } 
        
<body>
          <nav id="navbar">
            <ul class="nav-list">
              <li>
                <a href="about">About</a>
              </li>
              <li>
                <a href="work">Work</a>
              </li>
              <li>
                <a href="contact">Contact</a>
              </li>
            </ul>
          </nav>
          <header id="welcome-section">
            <h1 id="hi">Hey I am XXXXX</h1>
            <h2>a web developer</h2>
          </header>
          <section class="projects">
            <h1>These are some of my projects</h1>
            <a href="https://codepen.io/freeCodeCamp/full/zNqgVx" target="_blank"><img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/tribute.jpg" alt="1"><p>Tribute Page</p></a>
            <a href="https://codepen.io/freeCodeCamp/full/zNqgVx" target="_blank"><img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/map.jpg" alt="2"><p>Map Data Across the Globe</p></a>
            <a href="https://codepen.io/freeCodeCamp/full/zNqgVx" target="_blank"><img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/wiki.png" alt="3"><p>Wikipedia Viewer</p></a>
          </section>
        </body>

I would appreciate any assistance.

@EDIT Ok, here is my code in its broken version. It seems like I might need to rewrite the entire code, but I want to understand why. Why is this tag breaking the code? I initially thought it was just something minor that I could add at the end of my work :/.

Answer №1

To enhance your images, simply enclose each of them in an anchor tag following this format

<a href="your link">
  <img src="https://example.com/image.jpg" alt="Description" >
</a>

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

Transmitting an HTML video object (canvas) to Flask through Ajax communication

I've been struggling to retrieve a user image from the camera using Flask. However, I keep getting a base64 encoded image that is not decodable. I've tried various codes from different platforms but haven't been able to achieve the desired r ...

Instructions for integrating a select query within another select query in Codeigniter

I have a question regarding two tables shown below: /* questionnaire table */ | q_id | q_title | | ------- | ---------------------- | | 1 | What is your name? | | ------- | ---------------------- | | 2 | What is your gend ...

What is the process for including icons on buttons?

I have been researching how to use Font Awesome software to incorporate icons into my HTML elements, but I am uncertain about the implementation process for my specific case. Currently, I have created a basic webpage with buttons and I would like to includ ...

How can we make Internet Explorer 11 mimic Internet Explorer 9 in HTML?

How can I ensure that Internet Explorer 11 uses CSS styles from IE9 in my HTML? I have tried the following code: <script runat="server"> private void Page_PreRender(object sender, EventArgs e) { var meta = new HtmlMeta() ...

Stop header background image from loading on mobile browsers by utilizing the <picture> tag

Is there a method to utilize the <picture> element in order to prevent a page from downloading an image when viewed on a mobile phone? I have a website that features a header image. Unfortunately, due to the site's functionality, using CSS (bac ...

Using Ruby on Rails to create an HTML loop with JavaScript

Using this particular file upload example for Ruby on Rails, I am currently implementing a template to showcase available downloadable files: <script id="template-download" type="text/x-tmpl"> {% for (var i=0, file; file=o ...

Could you explain why my code is not functioning as intended when I attempt to modify the class of a specific element?

I've been trying to change the class of a specific <li></li> element, but none of the methods I've attempted seem to be working. Could you please help me figure out why my code isn't functioning as expected? <script type="tex ...

Receiving a null value when attempting to access the ids of dynamically created HTML elements using JavaScript

Encountering issue with accessing ids of dynamically generated HTML elements using javascript In my current project, I am attempting to dynamically alter the ids of div elements and remove buttons that are appended to the parent div. The desired functiona ...

Creating a disabled HTML button that reacts to the :active CSS pseudo class

CSS: button:active { /* active css */ } button:disabled { opacity: 0.5; } HTML: <button disabled="disabled">Ok</button> After clicking the button, the browser applies the button:active state to give the appearance of a click, despite the ...

Acquiring matching values in list box by selecting a particular value from the dropdown menu

When selecting a value from a dropdown, I want the list box to populate accordingly. For instance, if I click on "obs" in the dropdown, I expect to see "brs1", "crs1", and "drs1" in the list box. [{ "name": "obs", "date": "1458834026000", "attr001": ...

The :not() selector does not currently have the capability to support complex selectors within it

Combining the CSS3 :not() selector with the attribute contains selector can be a challenge, as it seems to not work properly. Here is an example of the markup: <input type='text'/> <input type='text' id="dasd_Date_asd"/> ...

The public folder in Node.js is known for its tendency to encounter errors

I'm facing an issue with displaying an icon on my website. Here is the current setup in my code: app.js const http = require('http'); const fs = require('fs'); const express = require('express') const path = require(&apo ...

Exploring the implementation of if/else statements in Sass/HTML

I need assistance with customizing the appearance of a save button on my form. The button is currently disabled and appears in blue color, but I would like it to change to a different color until all fields within the form are completed. Even though it c ...

Create a shape using a series of points without allowing any overlap between the lines

JS fiddle There is an array of coordinates that gets populated by mouse clicks on a canvas. var pointsArray = []; Each mouse click pushes x and y values into this array using a click event. pointsArray.push({x: xVal, y: yVal}); The script iterates thr ...

Sending a Django form to a different form for submission

I am attempting to develop a form that links to another form. The most recent version is displayed below. The process goes as follows: A user picks a semester from both dropdown menus on form1. When the page is POSTed, the data from these dropdowns are us ...

What is the most efficient way to transfer information from a text box in one form to another in AngularJS?

I am currently using a sample form to send data, and I would like to redirect this data to another page named result.html. Could you please guide me on how to achieve this? The code snippet below shows what I have implemented so far in the main page... ...

Update the chosen option of the <select> element that was generated through PHP if there is a parameter value present in the URL

I'm currently working on a code snippet like this: <select name="id" id="id"> <OPTION VALUE="null">Select<OPTION> <? foreach ($genres as $row){ ?> <OPTION VALUE="<? echo $row->id; ?>"><? echo ...

Combining various types of media stylesheets with a print stylesheet

I'm struggling with a school assignment that is asking me to compare two different ways of linking a print stylesheet with another stylesheet in HTML. The assignment requires me to explain when each technique would be appropriate: <link rel="style ...

Is there a way to make the menu overlap the logo on the website?

Within my Ruby on Rails Spree application that utilizes the Twitter Bootstrap gem, I have the following code snippet for the header section: <body class="<%= body_class %>" id="<%= @body_id || 'default' %>" data-hook="body"> & ...

Outlook-2010 does not support the current display

Looking for help styling a page that will be opened in ms-outlook 2010. The issue is that it does not support the display attribute. Anyone have a recommendation for an alternative? One suggestion could be to create a class with properties similar to disp ...