html - 如何向图像添加链接 (href)

标签 html css

我想把图片做成一个链接,这样当你点击图片时它会带你到链接。

我尝试了 anchor 链接,但它不起作用。下面是我的 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>

最佳答案

如果您希望整个图像成为一个链接,请将其包装在 <a> 中像这样的元素:

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

关于html - 如何向图像添加链接 (href),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59011610/

相关文章:

html - 响应式设计两个元素之间的自动边距

javascript - 相对定位下拉菜单

jquery - 创建具有 SP 返回的不同标题的动态框(div)

html - Center 2 div,中间有一张图片

html - 格式化 html 表格列中的文本?

html - 反向拉动-* - Bootstrap 4

html - 如何为子元素设置相同的顶部位置

jquery - 如何使用 jQuery 实现悬停效果

CSS 整洁配置

html - 如何阻止我的背景图像相互重叠