- This topic is empty.
-
AuthorPosts
-
March 17, 2016 at 6:17 am #239402nicolafwParticipant
Hi,
I want to make the img alt visible by using ::after, but it does not work. It does work for the a-tag, but I cannot make it work for the img-tag. Why?a::after { content: attr(alt); } img::after { content: attr(alt); }
March 17, 2016 at 6:53 am #239409bearheadParticipantI don’t think it is possible to give an
img
a pseudo element. It’s probably because they are self-closing, and can’t contain child elements.To get the alt text to display you’ll probably have to use javascript.
[edit] Thanks for the correction Paulie_D
March 17, 2016 at 7:49 am #239414Paulie_DMemberNo, an image cannot have a pseudo-element (not class).
Either Js or wrap the image and use a pseudo-element on that (using a data-attribute)…
Or you could just use the
title
attribute…you can’t style it (AFAIK) but it is informationalMarch 17, 2016 at 10:08 am #239416nicolafwParticipantThanks, but I need it as a caption. I cannot change the HTML-code. I might find a Java script.
March 17, 2016 at 10:35 am #239417bearheadParticipantWith jquery it should be pretty simple – something like:
http://codepen.io/kvana/pen/PNWEBR
depends a little on your html structure though…
March 17, 2016 at 12:19 pm #239419Paulie_DMemberIf Jquery is a possibility then we can make our own structure
March 18, 2016 at 1:43 am #239444nicolafwParticipantThanks Bearhead. This works fine.
What I get is this:
<a href="...">
<img src="..." alt="alternativ text" />
alternativ text
</a>All I need now is some HTML to be able to positon and style the caption:
<a href="...">
<img src="..." alt="alternativ text" />
<caption>alternativ text</caption>
</a>March 18, 2016 at 3:46 am #239446Paulie_DMember<caption>
is intended to be used with atable
element`so it’s probably not the best choice here.As for positioning…what did you have in mind?
March 18, 2016 at 8:02 am #239463nicolafwParticipantIt can also be a div. I want to positon it below the photo. I can do that by css, but without any tag surrounding it I cannot style it.
Your code did not work unfortunately, it is a jimdo page, there must be some conflict somewhere: http://omfactorynyc.jimdo.com/teachers/
March 18, 2016 at 8:22 am #239464Paulie_DMemberI have no idea what a
jimdo
page is and the link you provided returns an empty page unfortunately.This might be a battle you can’t win without some major retooling of whatever it is you have.
March 18, 2016 at 8:58 am #239467nicolafwParticipantIt cannot be that difficult as the code bearhead provided does work:
$(document).ready(function(){
$('div').each(function(){
var alt = $(this).children('img').attr('alt');
$(this).append(alt);
});
});all I need is a surrounding div-tag for the alt text.
I don’t know how to do that as I don’t know any javascript unfortunatly…March 18, 2016 at 9:05 am #239468Alex ZaworskiParticipantShould do it:
$(document).ready(function(){ $('div').each(function(){ var alt = $(this).children('img').attr('alt'); var wrap = $('<div>'); wrap.append(alt); $(this).append(wrap); }); });
If you need a class on the wrapper that’s easy enough too, you can just change
<div>
to<div class="myclass">
when creating the wrap variable.March 21, 2016 at 2:54 am #239642nicolafwParticipantThis finally worked:
</script><script language="javascript" type="text/javascript"> //<![CDATA[ $(document).ready(function(){ $('div a').each(function(){ var alt = $(this).children('img').attr('alt'); $(this).append('<div class="bildlegende">' + alt + '</div>'); }); }); //]]> </script>
Thanks for all the help…
March 15, 2017 at 8:27 am #252804alexnovelliParticipantI’m using a jQuery image slider plugin in WordPress. It creates itself HTML elements and when I try to use this code, it doesn’t recognize. Apparently don’t have time to this code see the HTML elements created by the plugin. Some help please? Thanks!
March 15, 2017 at 2:40 pm #252828ShikkedielParticipantI think it would be good to start a new topic and add a reduced demo, or in any case a link to the site. Quite impossible to say anything without actually seeing the code.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.