PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 9, 2022

[FIXED] Why Does My CSS Grid when I add <a href> to an image?

 November 09, 2022     css, html     No comments   

Issue

When I add an anchor to an image, the grid breaks. with anchor tag](https://i.stack.imgur.com/ykr64.jpg) without acnchor tag](https://i.stack.imgur.com/6HPE4.png)

I quadrouple checked my code, I searched overstack, and google, and nothing addresses this directly. I also noticed someone asked this question 2 years ago, but he didn't get a clear answer. Please help me. Thanks in advance.

<div class="food-box">
     <h1 id="food-title">FEATURED MENUS</h1>
     <a href="./brunch.html"> <img id="dish1" src="./resources/images/ft-food1.png" /></a>
     <h3 id="dish-title1" >BRUNCH</h3>                
     <a href = './lunch.html'><img id="dish2" src="./resources/images/ft-food1.png" /></a>
     <h3 id="dish-title2" >LUNCH</h3>
     <a href="./dinner.html"><img id="dish3" src="./resources/images/ft-food1.png" /></a>
     <h3 id="dish-title3" >DINNER</h3>
.food-box {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto;
    row-gap: 0em;
    color: #262626;
    background-color: #fdfdfd;
    font-family: 'Roboto', sans-serif;
}


#food-title {
    grid-column-start: 2;
    position: relative;
    justify-self: center;
    }

#dish1 {
    grid-column-start: 1;
    padding-left: 1em;
    grid-row-start: 2;
    max-width: 20em;
    }

#dish-title1 {
    position: relative;
    left: 7em;
    grid-column-start: 1;
    padding-left: 1em;
    }

#dish2 {
    grid-column-start: 2;
    grid-row-start: 2;
    max-width: 20em;
    }

#dish-title2 {
    position: relative;
    left: 7em;
    grid-column-start: 2;
    grid-row-start: 3;
    
    }

#dish3 {
    grid-column-start: 3;
    grid-row-start:2;
    max-width: 20em;
    }

#dish-title3 {
    position: relative;
    grid-column-start: 3;
    grid-row-start: 3;
    left: 7em;
    }    


Solution

You have specific grid styling for your images (e.g. #dish1 { grid-column-start: 1; }).

When you wrap the images in links, the images are no longer grid children. The links are the grid children instead. You're styling the wrong elements.



Answered By - Quentin
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing