Solved

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

Posted on 2013-01-11
7
390 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

820 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