?
Solved

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

Posted on 2013-01-11
7
Medium Priority
?
409 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 1500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
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.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 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