我怎样才能将 link 添加到这些框中

how can i add link to these box

我想 link 每个盒子都不同 link。整个盒子不仅是内容或图像,所以如果用户尝试单击其中任何一个,将被发送到 link applied 。 我试过在这些盒子上贴上标签,但我的盒子颜色变了,出了问题。 需要帮助

.container{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 1000px;
    height: 500px;
    display: flex;
}
.container .box{
    position: relative;
    width: 33.33%; /*Change Applied*/
    height: 500px;
    background: #ccc;
    transition: 0.5s;
}
.container .box:hover{
    transform: scale(1.1);
    z-index: 1;
    box-shadow: 0 5px 20px rgba(0,0,0,1);
}
.container .box .thumb{
    position: absolute;
    width: 100%;
    height: 250px;
    overflow: hidden;
}
.container .box:nth-child(odd) .thumb {
    bottom: 0;
    left: 0;
}
.container .box .thumb img{
    width: 100%;
}
.container .box .details{
    position: absolute;
    width: 100%;
    height: 250px;
    overflow: hidden;
    background: #262626;
}
.container .box:nth-child(even) .details {
    bottom: 0;
    left: 0;
}
.container .box:nth-child(1) .details {
    background: #65214a;
}
.container .box:nth-child(2) .details {
    background: #fd3f41;
}
.container .box:nth-child(3) .details {
    background: #ffb539;
}
.container .box .details .content{
    position: absolute;
    top: calc(50% + 16px);
    transform: translateY(-50%);
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
    transition: 0.5s;
}
.container .box:hover .details .content{
    top: calc(50%);
}
.container .box .details .content h3{
    margin: 0;
    padding: 0;
    padding: 10px 0;
    color: #fff;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="activity.css">
</head>
<body>
    <div class="container">
        <div class="box">
            <div class="thumb">
                <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
            </div>
            <div class="details">
                <div class="content">
                    <img src="/images/facebook.png" alt="">
                    <h3>Desert Safari</h3>
                </div>
            </div>
        </div>
        <div class="box">
            <div class="thumb">
                <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
            </div>
            <div class="details">
                <div class="content">
                    <img src="/images/facebook.png" alt="">
                    <h3>Desert Safari</h3>
                </div>
            </div>
        </div>
        <div class="box">
            <div class="thumb">
                <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
            </div>
            <div class="details">
                <div class="content">
                    <img src="/images/facebook.png" alt="">
                    <h3>Desert Safari</h3>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
我想 link 每个盒子都不同 link。整个盒子不仅是内容或图像,所以如果用户尝试单击其中任何一个,将被发送到 link applied 。 我试过在这些盒子上贴上标签,但我的盒子颜色变了,出了问题。 需要帮助

您可以像这样使用“a”标签:

<a href="<your_link>">
   <your content>
</a>

如果您可以将 div class="box" 更改为 <a class="box",那么您可以设置 link

的样式

否则使用JavaScript:

const links = ["https://www.apple.com/us/search/mac", "https://www.apple.com/us/search/iphone", "https://www.apple.com/us/search/ipad"];
document.querySelectorAll(".container .box").forEach((box, i) => box.dataset.idx = i);
document.querySelector(".container").addEventListener("click", function(e) {
  const tgt = e.target.closest(".box");
  if (tgt) {
    location = links[tgt.dataset.idx]
  }  
})
.container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 1000px;
  height: 500px;
  display: flex;
}

.container .box {
  position: relative;
  width: 33.33%;
  /*Change Applied*/
  height: 500px;
  background: #ccc;
  transition: 0.5s;
}

.container .box:hover {
  transform: scale(1.1);
  z-index: 1;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 1);
}

.container .box .thumb {
  position: absolute;
  width: 100%;
  height: 250px;
  overflow: hidden;
}

.container .box:nth-child(odd) .thumb {
  bottom: 0;
  left: 0;
}

.container .box .thumb img {
  width: 100%;
}

.container .box .details {
  position: absolute;
  width: 100%;
  height: 250px;
  overflow: hidden;
  background: #262626;
}

.container .box:nth-child(even) .details {
  bottom: 0;
  left: 0;
}

.container .box:nth-child(1) .details {
  background: #65214a;
}

.container .box:nth-child(2) .details {
  background: #fd3f41;
}

.container .box:nth-child(3) .details {
  background: #ffb539;
}

.container .box .details .content {
  position: absolute;
  top: calc(50% + 16px);
  transform: translateY(-50%);
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  text-align: center;
  transition: 0.5s;
}

.container .box:hover .details .content {
  top: calc(50%);
}

.container .box .details .content h3 {
  margin: 0;
  padding: 0;
  padding: 10px 0;
  color: #fff;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="activity.css">
</head>

<body>
  <div class="container">
    <div class="box">
      <div class="thumb">
        <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
      </div>
      <div class="details">
        <div class="content">
          <img src="/images/facebook.png" alt="">
          <h3>Desert Safari</h3>
        </div>
      </div>
    </div>
    <div class="box">
      <div class="thumb">
        <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
      </div>
      <div class="details">
        <div class="content">
          <img src="/images/facebook.png" alt="">
          <h3>Desert Safari</h3>
        </div>
      </div>
    </div>
    <div class="box">
      <div class="thumb">
        <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
      </div>
      <div class="details">
        <div class="content">
          <img src="/images/facebook.png" alt="">
          <h3>Desert Safari</h3>
        </div>
      </div>
    </div>
  </div>
</body>

</html>

我认为您的问题是将需要应用于 .container 的直接子级的样式应用于 <a> 标签内的 div。您可以将 <div> 替换为 <a>

.container{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 1000px;
    height: 500px;
    display: flex;
}
.container .box{
    position: relative;
    width: 33.33%; /*Change Applied*/
    height: 500px;
    background: #ccc;
    transition: 0.5s;
}
.container .box:hover{
    transform: scale(1.1);
    z-index: 1;
    box-shadow: 0 5px 20px rgba(0,0,0,1);
}
.container .box .thumb{
    position: absolute;
    width: 100%;
    height: 250px;
    overflow: hidden;
}
.container .box:nth-child(odd) .thumb {
    bottom: 0;
    left: 0;
}
.container .box .thumb img{
    width: 100%;
}
.container .box .details{
    position: absolute;
    width: 100%;
    height: 250px;
    overflow: hidden;
    background: #262626;
}
.container .box:nth-child(even) .details {
    bottom: 0;
    left: 0;
}
.container .box:nth-child(1) .details {
    background: #65214a;
}
.container .box:nth-child(2) .details {
    background: #fd3f41;
}
.container .box:nth-child(3) .details {
    background: #ffb539;
}
.container .box .details .content{
    position: absolute;
    top: calc(50% + 16px);
    transform: translateY(-50%);
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
    transition: 0.5s;
}
.container .box:hover .details .content{
    top: calc(50%);
}
.container .box .details .content h3{
    margin: 0;
    padding: 0;
    padding: 10px 0;
    color: #fff;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="activity.css">
</head>
<body>
    <div class="container">
        <a href="#" class="box">
            <div class="thumb">
                <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
            </div>
            <div class="details">
                <div class="content">
                    <img src="/images/facebook.png" alt="">
                    <h3>Desert Safari</h3>
                </div>
            </div>
        </a>
        <a href="#" class="box">
            <div class="thumb">
                <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
            </div>
            <div class="details">
                <div class="content">
                    <img src="/images/facebook.png" alt="">
                    <h3>Desert Safari</h3>
                </div>
            </div>
        </a>
        <a href="#" class="box">
            <div class="thumb">
                <img src="https://m.media-amazon.com/images/I/81z07Nvam1L._SL1500_.jpg" alt="">
            </div>
            <div class="details">
                <div class="content">
                    <img src="/images/facebook.png" alt="">
                    <h3>Desert Safari</h3>
                </div>
            </div>
        </a>
    </div>
</body>
</html>