css 可点击的卡片,其中包含链接

ckx4rj1h  于 2023-11-19  发布在  其他
关注(0)|答案(2)|浏览(117)

我创建的内容卡,需要可点击。点击这些卡带你到页面,在那里你可以看到完整的内容。此外,对于某些用户,卡也有内部通过不同的页面链接(如编辑或报告)。你可以看到这里所需的设计:https://jsfiddle.net/4s8b5kb1/1/(卡将转到更多的细节页面)。
通过浏览以前的问题,我遇到了一些方法,可以通过添加onClick处理程序或具有持久的“查看更多”链接来使卡片div可点击。理想情况下,我想只使用普通的CSS,而不想添加onClick处理程序来完成链接的工作,也没有持久的“查看更多”按钮。
我也读过一些策略,你在div中创建一个链接,然后使用z-index,你可以让它作为整个div的链接,而其他更具体的链接有更高的z-index
我已经试过了,但运气不太好。下面是到目前为止的代码:https://jsfiddle.net/4s8b5kb1/1/
任何想法都非常赞赏!

cetgtptt

cetgtptt1#

我把position:relative放在edit类上

.edit {
color: indianred;
font-size: 1rem;
z-index: 10;
position: relative;
}

字符串
你可以在这里检查:

.parent {
	display: flex;
	justify-content:center;
	align-items:center;
	height: 100vh;
}

.card {
	height: 200px;
	width: 260px;
	background: #FFF;
	border: 1px solid #FAFAFA;
	box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.12);
	border-radius: 20px;
	overflow-y: auto;
	
	padding: 2em;
	font-family: Courier New;

	font-size: 0.7rem;
	cursor: pointer;
	
	position: relative;

}

.card p {
	z-index: 10;
}

.edit {
	color: indianred;
	font-size: 1rem;
	z-index: 10;
  position: relative;
}

.view {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	z-index: 1;
	opacity: 0;
}
<div class ="parent">

<div class="card">
   <a class="edit" href="#edit">EDIT</a>
   <a class="edit" href="#edit">REPORT</a>
	<p>
        For those who have seen the Earth from space, and for the hundreds and perhaps thousands more who will, the experience most certainly changes your perspective. The things that we share in our world are far more valuable than those which divide us. As
        we got further and further away, it [the Earth] diminished in size. Finally it shrank to the size of a marble, the most beautiful you can imagine. That beautiful, warm, living object looked so fragile, so delicate, that if you touched it with
        a finger it would crumble and fall apart. Seeing this has to change a man. When I orbited the Earth in a spaceship, I saw for the first time how beautiful our planet is. Mankind, let us preserve and increase this beauty, and not destroy it!
    </p>
	<a class = "view" href = "#view">View</a>
</div>
</div>

的数据

yc0p9oo0

yc0p9oo02#

我已经设法在不使用任何z-index操作的情况下实现了这一点。如下所示:

<div class="parent">
  <div class="card">
    <a class="edit" href="#edit">EDIT</a>
    <a class="edit" href="#edit">REPORT</a>
    <p>
      ...your text
    </p>
    <a class="view" href="#view">View</a>
  </div>
</div>

字符串
使用以下CSS:

.edit {
  position: relative;
}

.parent {
  position: relative;
}

.card {
  position: static;
}

.view::after {
  content: '';
  position: absolute;
  inset: 0;
}

相关问题