Solved

CSS Adding rel="lightbox" to all Image hyperlinks?

Posted on 2013-01-11
7
393 Views
Last Modified: 2013-01-14
Hi All

I'm slowly getting better with CSS, so bear with me :(

When I'm adding image hyperlinks to my website articles, I simply drop to the code and add rel="lightbox" into the URL so that it uses the lightbox image transition when the images are clicked {example}

before
<a href="/KB/Media/0000742/00001.jpg"><img src="/KB/Media/0000742/00001s.jpg" width="550" height="421" alt="_vti_inf.html" /></a>
after
<a href="/KB/Media/0000742/00001.jpg" rel="lightbox"><img src="/KB/Media/0000742/00001s.jpg" width="550" height="421" alt="_vti_inf.html" /></a>


Can I not just add something to my CSS so that if the link is an image, add the rel="ligthbox" automatically? If so, what and where?

Pete
0
Comment
Question by:Pete Long
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 30

Accepted Solution

by:
LZ1 earned 500 total points
ID: 38767288
CSS doesn't work like that. It's a static language.

You could use some jquery to add it though.

$(''a img[src$=".jpg"]'').attr('rel', 'lightbox')

Open in new window

0
 
LVL 57

Author Comment

by:Pete Long
ID: 38767310
Yikes - I'm a network engineer! , where do I put that? and I'm assuming I would also need..

$(''a img[src$=".png"]'').attr('rel', 'lightbox')

Would that go in my CSS, or am I Waaay out of my depth here?

Pete
0
 
LVL 30

Expert Comment

by:LZ1
ID: 38767334
It's not too bad Pete. First do you know if your loading jQuery in your page?
If not add this  just before the closing </body> tag.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(''a img[src$=".jpg"]'').attr('rel', 'lightbox')
</script>

Open in new window


If you already have jquery on your page, then just add the 2nd part.

Do you have a live URL you could share?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 57

Author Comment

by:Pete Long
ID: 38767338
I Don't think I am http://www.petenetlive.com/KB/Article/0000742.htm

Would it not be more efficient for me to load something into my JS folder on the root of the site and reference that - or is that a stupid question?
0
 
LVL 30

Expert Comment

by:LZ1
ID: 38767388
Not a stupid question. I see your loading prototype.js. In that case, you can't use what I've given you.

Try this instead.

$$('a[href$=.jpg], a[href$=.png].each(function(
link.writeAttribute('rel','lightbox');
}

Open in new window


I'm not very good with Prototype, but this will hopefully get you started.
0
 
LVL 57

Author Comment

by:Pete Long
ID: 38767466
Tried - the first graphic has a manual rel in the link, the rest of the graphics I've removed it, they have stopped working

http://www.petenetlive.com/KB/Article/0000742.htm
0
 
LVL 57

Author Closing Comment

by:Pete Long
ID: 38773767
Unfortunately I can't really implement this, but as no other experts were forthcoming, Ill close and accept this as a workable solution.

Thanks for your efforts


Pete
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't get js code to execute 8 36
Wordpress Responsive Web design and iPads 11 35
type of website 13 48
wordpress 4.7.4, theme 8 36
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question