[英]Appending text to link title on hover?
So I'm working on my portfolio website. 所以我正在我的投资组合网站上。 One of the columns has four divs, each with a button inside () that leads to a different page (Resume, Portfolio, Contact, etc).
列中的一个包含四个div,每个div中的()内都有一个按钮,可转到另一个页面(“简历”,“投资组合”,“联系人”等)。 What I'm trying to figure out is how to create a selector of sorts using { and }.
我想弄清楚的是如何使用{和}创建排序选择器。 I really like the look of brackets around each link, so for instance when you hover over Resume, it would change from Resume to { Resume }.
我真的很喜欢每个链接周围的括号外观,例如,当您将鼠标悬停在Resume上时,它会从Resume更改为{Resume}。 I've been messing with CSS for awhile and got a nice 1s transition on the color, but I have no idea how to get this selector idea of mine to work.
我已经弄乱CSS一段时间了,并且在颜色上得到了不错的1s转换,但是我不知道如何使我的选择器想法起作用。 I've been attempting to use JS/jQuery to prepend and append { and } to each on hover, but I can't seem to make it work.
我一直在尝试使用JS / jQuery将{和}附加和附加到悬停时,但是我似乎无法使其工作。 My JS is definitely on the beginner side, and I haven't seen anything from google searches that helps with this.
我的JS绝对是初学者,并且我还没有从Google搜索中看到任何有助于此的东西。
Here's the code for the column in question: 这是相关列的代码:
<div class="col-xs-12 col-sm-3 col-lg-4">
<div class="resume button links marginTop"><a href="resume.html" class="btn">Resume</a></div>
<div class="portfolio links button"> <a href="portfolio.html" class="btn">Portfolio</a></div>
<div class="photography links button"><a href="photography.html" class="btn">Photography</a></div>
<div class="contact links button"><a href="mailto:me@me.me" class="btn">Contact</a></div>
</div>
And my JS: 而我的JS:
$(function() {
$('.links').hover(function(){
var text = (this).text();
$(this).text = "{ " + text + " }";
});});
I'm sure I'm messing up either the HTML or JS (or both), but I can't seem to figure it out. 我确定我搞砸了HTML或JS(或两者),但似乎无法弄清楚。 Any help would be great!
任何帮助将是巨大的!
PS: While I'm asking, should I be using a list (UL?) for my links vs. separate divs like I have currently in the column? PS:当我问的时候,我应该在链接中使用列表(UL?),还是在列中使用单独的div? The links are vertically oriented.
链接是垂直定向的。
CSS only solution: (EDIT: braces placed within the link not around it) 仅CSS解决方案:(编辑:括号放在链接中而不是其周围)
.links:hover a:before { content: '{'; } .links:hover a:after { content: '}'; }
<div class="col-xs-12 col-sm-3 col-lg-4"> <div class="resume button links marginTop"><a href="resume.html" class="btn">Resume</a></div> <div class="portfolio links button"> <a href="portfolio.html" class="btn">Portfolio</a></div> <div class="photography links button"><a href="photography.html" class="btn">Photography</a></div> <div class="contact links button"><a href="mailto:me@me.me" class="btn">Contact</a></div> </div>
With brackets inside <a>
: 在
<a>
带有括号:
a { display: block; } a span { opacity: 0; } a:hover span { opacity: 1; }
<a href="#"><span>{</span>Resume<span>}</span></a> <a href="#"><span>{</span>Portfolio<span>}</span></a> <a href="#"><span>{</span>Photography<span>}</span></a> <a href="#"><span>{</span>Contact<span>}</span></a>
But I like @mwl's solution with :before
and :after
cause in this case you won't be able to select brackets with mouse. 但是我喜欢@mwl的
:before
和:after
解决方案,因为在这种情况下,您将无法使用鼠标选择方括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.