【发布时间】:2018-09-04 06:20:00
【问题描述】:
我正在处理一些 Wordpress 网站的自定义样式,并且我想让一个特定的 DIV 可点击,而不是使用其中的内容。由于网站使用的页面构建器,我发现它很困难,在我去创建一整段自定义 HTML 内容之前,我想知道我是否可以通过 CSS 或 JS 修改模块,以便网站所有者仍然可以修改内容。
例如。
.container {
width: 100%;
height:400px;
}
.container .module-content {
display: block;
height:150px;
bottom:0;
position: absolute;
width:100%;
overflow:hidden;
transition: ease .5s;
color:white;
text-align:center;
}
.container:hover .module-content {
display: block;
height:250px;
overflow:visible;
}
.container .module-content .module-title {
display: block;
font-size:30px;
height:100px;
padding:50px 25px 0;
margin:0;
background: -moz-linear-gradient(top, rgba(66,114,184,0) 0%, rgba(66,114,184,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(66,114,184,0) 0%,rgba(66,114,184,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(66,114,184,0) 0%,rgba(66,114,184,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#004272b8', endColorstr='#4272b8',GradientType=0 ); /* IE6-9 */
}
.container .module-content .module-title a {
color:white;
text-decoration:none;
}
.container .module-content .module-description {
background-color:#4272b8;
height: 50px;
padding:25px;
margin:0;
color: white;
}
<div class="container"><!-- this is a 600x400 pixel box with an image for a background -->
<div class="module-content"><!-- this is a 100px height div positioned absolutely and at the bottom with overflow hidden, when the container is hovered, the overflow becomes visible and height is 150px -->
<div class="module-title"><h2><a href="/about/">About</a></h2></div><!-- this heading is the current link and is always visible -->
<div class="module-description"><p>text</p></div><!-- this text is only visible when the container is hovered -->
</div>
</div>
如下图所示,我只能编辑标题文本(带或不带链接)、段落文本和容器背景。 内容的定位由 CSS 覆盖完成。
我想也许我可以把 H2 <a href></a> 做成一个块,这样它就覆盖了整个容器,但是它填满了“关于”文本的位置(它将它移动到顶部,我希望它出现在底部)。
所以我想也许我可以使用 content 的 ::before 或 ::after 之类的伪类来使容器 DIV 成为可点击的链接...
这可能吗?如果没有,我还能如何实现我所追求的?
【问题讨论】:
-
伪元素不是 DOM 的一部分,它们不可点击。
标签: javascript html css pseudo-element