【问题标题】:How do I add a link (href) to the image如何向图像添加链接(href)
【发布时间】:2020-01-20 05:27:51
【问题描述】:

我想将图片设为链接,这样当您点击图片时,它会将您带到链接。

我尝试了锚链接,但它不起作用。下面是我的 HTML 和 CSS 代码。

.ideas-grid{
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(25rem, 1fr));
    grid-gap: 2.5rem;
    margin-bottom: 2rem;
}

.title-heading{
    text-align: center;
    text-transform: uppercase;
    margin-bottom: 10rem;
    color: rgba(0,0,0,.7);
    background-color: white;
}

.title-heading h1{
    font-family: 'Aldrich', sans-serif;
    font-size: 2rem;
    margin: .5rem 0 1rem;
    text-align: center;
}

.title-heading p{
    text-transform: none;
    padding: 0 50px;
}

.idea-grid-item{
    height: 50rem;
    width: 50rem;
    padding: 5rem;
    color: white;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    z-index: 1;
}

.idea-grid-item{
    content:"";
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    height: 30rem;
    background-image: linear-gradient(135deg, rgba(49,24,131,0.9) 0%, rgba(72,56,149,0.8) 100%);
    z-index: -1;
}

.idea-grid-item p{
    color: rgba(0, 0, 0, 0.7);
}

.idea-grid-item a{
    float: right;
}
<div class="ideas-grid">
           <!--Idea grid item 1-->
           <div class="idea-grid-item number-1">
           <p>
           </p>
           <a href="https://www.instagram.com/p/B5NVsqhhp9O/?utm_source=ig_web_copy_link"></a>
</div>

【问题讨论】:

  • 您是否尝试将&lt;div class="idea-grid-item number-1"&gt; 包装在锚标记中。像这样&lt;a href="your/target/"&gt;&lt;div class="idea-grid-item number-1"&gt;&lt;/div&gt;&lt;/a&gt;
  • @Eisenheim 非常感谢你是唯一一个有正确答案的人,我没想到谢谢!
  • 感谢您的反馈。我很高兴听到这有效:)
  • 这能回答你的问题吗? How do you make an image into a link in HTML?

标签: html css


【解决方案1】:

如果您希望整个图像成为链接,请将其包装在 &lt;a&gt; 元素中,如下所示:

<a href="http://yoursite.com">
    <img src="image.jpg" alt="">
</a>

【讨论】:

    【解决方案2】:
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <a href="https://sitelink.xyz"><img src="image.jpg"/></a>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2018-04-15
      • 2015-06-26
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      相关资源
      最近更新 更多