html - 点击显示跨度

标签 html css

我试图将跨度隐藏在另一个跨度下,当有人点击最上面的跨度时,它应该消失并显示其下方的内容。

我的 HTML:

<span id="couponCode" style="display:inline-block;border:2px dashed;padding:5px;margin:5px;background:#EE4000;color:white;height:20px;text-align:center;">{{ i.couponCode }}</span><span class="cTs">Click to see code</span>

我的 CSS:

.cTs
{
    left :0px;
    padding:10px;
    height:50px;
    color:white;
    width: 100px;
    position: relative;
    background: black;  
}

但我无法将其定位在第一个跨度上...而是它出现在第一个跨度的右侧...有人可以帮助我吗...

最佳答案

将元素包装在 position: relative; 容器中,然后将 position: absolute;topleft< 一起使用 内部元素的值

div {
    position: relative;
}

div span {
    position: absolute;
    top: 0;
}

div span:nth-of-type(1) {
    z-index: 1;    
}

div span:nth-of-type(2) {
    top: 10px;
    left: 25px;
}

Demo

使用 onclick事件

关于html - 点击显示跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16890548/

相关文章:

html - 选择下拉列表可能到 "Drop-Up"

jquery - 回溯代码问题(DIV 背景)

php - Codeigniter 网址重定向

javascript - 元素移除后的 jQuery 焦点

html - 着色中断命令

javascript - 如何禁用鼠标拖动单击任何图像?

html - 当我将鼠标悬停在元素上时显示 sibling

html - #footer 背景纯色不适用于容器

php - HTML 下载链接失败的可能原因是什么?

html - 居中图像