HTML高亮标签悬停
HTML Highlighting Tags On Hover
给定以下html
:
This is a test to
<cpos data-idcpos="10" data-comment="1">
highlight only this portion of text
</cpos> and not this
我的任务是只突出cpos
部分。我能够突出自己的div
类,但对如何做到这一点有点困惑。我使用javascript
和css
样式
任何帮助都会很感激。谢谢!
无需javascript,只需使用css:hover
cpos:hover{
background:yellow;
}
This is a test to<cpos data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this
如果我有多个具有不同id的
cpos
标签,并且想要在悬停时突出显示单个
用#
简单地定位每个单独的id
#MyId:hover{
background:yellow;
}
This is a test to<cpos data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this
This is a test to<cpos id="MyId" data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this
还有,你能告诉我如何使用javascirpt吗?
使用onmouseover
和onmouseout
事件
This is a test to<cpos data-idcpos="10" data-comment="1" onmouseover="this.style.background='yellow'" onmouseout="this.style.background=''"> highlight only this portion of text </cpos> and not this
是否有一种方法来做它类似于你的javascript的例子,但是不改变cpos标签属性?
是的,遍历它们并以编程方式附加
var elements = document.getElementsByTagName('cpos');
for(var i = 0; i < elements.length; i++){
elements[i].onmouseover = function(){
this.style.background = 'yellow';
}
elements[i].onmouseout = function(){
this.style.background = '';
}
}
This is a test to
<cpos data-idcpos="10" data-comment="1">
highlight only this portion of text
</cpos>and not this This is a test to
<cpos data-idcpos="10" data-comment="1">
highlight only this portion of text
</cpos>and not this This is a test to
<cpos data-idcpos="10" data-comment="1">
highlight only this portion of text
</cpos>and not this
你可以使用CSS。使用class
.
.highlight:hover{ //Use HOVER
background-color:yellow;
}
HTML: This is a test to<cpos class="highlight" data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this
: hover您要做的是为cpos分配一个类,在其他情况下,您甚至可以使用SPAN这是件大事……结束
对于您的代码,添加类如下:This is a test to<cpos class="highlight" data-idcpos="10" data-comment="1"> highlight only this portion of text </cpos> and not this
在CSS .hightlight:hover{
background-color: yellow;
}
我做了一个很好的高亮动画的例子。使用CSS:不需要javascript
CSS:
html, body {
height: 100%;
}
body {
background: #2c3e50;
display: flex;
}
.card {
width: 350px;
padding: 30px;
background: #1abc9c;
margin: auto;
transition: .3s ease;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}
.card:hover {
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.8);
transform: translateY(-10px) scale(1.02);
}
.card:hover .entry-title {
background-position: -100% 0;
}
.entry-title {
background: linear-gradient(to right, rgba(255, 255, 255, 0) 50%, #16a085 50%);
background-size: 200%;
background-position: 0 0;
display: inline;
transition: .5s ease-in-out;
font-family: raleway, arial, sans-serif;
text-transform: uppercase;
}
.entry-title cpos {
color: white;
text-decoration: none;
}
<div class="card">
<h1 class="entry-title">
<cpos><a>This text will be highlighted when hovered</a></cpos>
</h1>
</div>
在JSfiddle上:http://jsfiddle.net/ebramatef/Lfd98v9m/
相关文章:
- 悬停时以矩形突出显示整个标签区域
- Chart.js条形图标签在悬停时被隐藏
- 如何使Highcharts中的渲染标签始终可见,并且相对于单击或悬停的点仍然可见
- jQuery悬停淡出p个标签,再淡出另一个标签
- 在每个条形图的中间添加文本标签&鼠标悬停事件
- 将鼠标悬停在切片上时更改d3.js饼图标签的颜色
- marquee标签不适用于谷歌铬悬停效果
- Chart.js-悬停弹出-添加带值的标签-不起作用
- Highcharts 单个水平堆叠条形图,始终显示数据名称(标签)和 %-年龄,并在鼠标悬停时显示数据编号和系列名称
- 半圆形圆环饼图,饼图上有标签(数据名称)和年龄百分比..和鼠标悬停上的数据编号
- 如何刷新 qtip 标签以在悬停时显示特定按钮的新标签
- 如何在 Arbor js 中将鼠标悬停在节点上时显示节点的标签
- 我在 标签中设置了背景图像,现在我想使用内联 CSS 在鼠标悬停事件上更改图像
- 我的 h1 标签链接在悬停时会显示一个下划线,我没有添加
- 离开悬停后如何将P标签保持在上一个位置
- 使用 ajax 将鼠标悬停时更改标签文本
- 高图表在类别标签悬停时显示工具提示
- 当我将鼠标悬停在动态创建的行上时,行中的选择元素(标签)选项无法正确下拉.火狐问题
- 如何使onClick执行与将鼠标悬停在
- 标签上相同的操作
- HTM如何使用悬停标签