Use Anchor title instead of image title - php

If I have an image in an anchor, how can I make the title of the anchor appear, and not that of the image element?
I know I could remove the title attribute with javascript, but I'm hoping there is a simpler solution.
For example
<a title="Anchor Title"><img title="Image Title" /></a>
If you hover over the link, it will display "Image Title".
What I've Tried
With CSS, I thought maybe I could change the z-indexes to push the anchor to the front, or maybe I could display the anchor as a block and give it the width and height of the image. This did not work. See JSFiddle here.
I was hoping to find a solution with CSS or maybe HTML.
The reason I want to do this is is that I'm working with Wordpress, spitting out posts and thumbnails. I want the thumbnails to link to a certain page, and I want to have a universal title for the link, but it is taking the title from the individual thumbnails. Here's the Wordpress/PHP code:
<a href="<?php the_permalink(); ?>" title="Click to see Featured Stories">
<?php the_post_thumbnail(); ?>
</a>

Pass an empty string in the title attribute in the $attr array in the thumbnail:
<?php the_post_thumbnail('thumbnail', array('title' => '')); ?>

This offers a general solution, disregarding WordPress. CSS prevents the title to show up.
HTML:
<a title="Anchor Title">
<img title="Image Title" src="http://codepen.io/images/logo.png" />
</a>
With CSS:
a {
display: inline-block;
}
img {
pointer-events: none;
}
Result
See CodePen example

Just put a transparent <span> over the image, with transparent background and desired title attribute.
Markup
<a href="#">
<img title="Image Title" />
<span title="Div Title"></span>
</a>​
CSS
img { width:50px;height:50px;background:blue; }
a, img { position:absolute; }
a { z-index:4;display:block;width:50px;height:50px; }
img { z-index:2; }
​span{
top:0;
left:0;
position:absolute;
width:50px;
height:50px;
display:block;
z-index:100;
background-color:transparent;
}​
I just forked your fiddle, works in Chrome at least.

I think removing the img title attribute is the simplest solution of all.

http://jsfiddle.net/hnmuj/
CSS:
#foo {
position:relative;
display:block;
}
#foo span {
position:absolute;
width:100%;
height:100%;
z-index:1;
top:0;
left:0;
display:block;
}
​
HTML:
<a title="Anchor Title" id="foo">
<span></span>
<img title="Image Title" />
</a>​

Related

IMG title edit using CSS but identifying by PHP call

I currently have an info image in a table.
When I hover over the icon it displays the artist description in the tool tip because i have it set up to do so.
<img src='images/info.png' width="20" height="20" title="<?php echo $artist['description']; ?>">
This is my CSS
img[title="<?php echo $artist['description']; ?>"]{
border-radius:50%;
background-color: red;}
It doesnt work. Is there anything I can do?

Trying to align my embed photo gallery (coming from tinymce editor) at center of my modal div

Im using tinymce to insert news into a website.
I inserting a embed code that corresponds to a photo gallery in tinymce html editor. (Im using an online photo sharing service for my images gallery.)
This service give me a "embed code" and when I insert in my tinymce html editor I get this in my html: (my embed tag becomes a object tag)
<p>
<object style="height: 350px; width: 460px;" width="460" height="350"
align="middle"
data="http://flash.picturetrail.com/pflicks/3/spflick.swf"
type="application/x-shockwave-flash">
<param name="src" value="http://flash.picturetrail.com/pflicks/3/spflick.swf" />
<param name="quality" value="high" /><param name="flashvars" value="ql=2&
src1=http://pic20.picturetrail.com:80/VOL1566/13680586/flicks/1/9035174" />
<param name="wmode" value="transparent" /><param name="allowscriptaccess" value="sameDomain" />
</object>
</p>
And now Im trying to align my photo gallery at center of my modal div, but Im not having sucess doing this.
Because I also need to float:left my photo gallery because if my paragraph text is too small my photogallery is coming to stick my paragraph text and I dont want that.
I want always a margin-top of 20px below my news image with .img class.
Do you know how can I solve this?
This is my fiddle with full example: http://jsfiddle.net/65z7w3z3/
This is how I show my textarea content in website;
echo '<p>'.$result_read_textarea['content_textarea'].'</p>';
My Html:
<div class="modal">
<h2>Title of my first news</h2>
<span id="date">15/08/2014</span><br />
<img class="img" src=""/>
<p>my first paragraph</p>
<embed src="http://flash.picturetrail.com/pflicks/3/spflick.swf"
quality="high" FlashVars="ql=2&src1=http://pic20.picturetrail.com:80/VOL1566/13680586/flicks/1/9035174" wmode="transparent" bgcolor="" width="460" height="350" name="Acrobat Cube" align="middle" allowScriptAccess="sameDomain" style="height:350px;width:460px" type="application/x-shockwave-flash">
</embed>
<div id="pdfs">
<h3>Links:</h3>
<ul class="links">
<li> Link 1</li>
<li> Link 2</li>
<li> Link 3</li>
</ul>
</div>
<span class="close">Back</span>
</div>
This is because are floating the element. Remove the float. Also add a clear div to help with your layout too. The clear div will stop it floating up with your other elements.
DEMO http://jsfiddle.net/david321312312231/65z7w3z3/1/
CSS Update
.clearfix {
clear: both;
width: 100%;
display: block;
}
#pdfs, embed
{
margin:20px auto;
clear:both;
width:100%;
}
HTML Update
// html code
<div class="clearfix"></div>
<embed // more html code
You need to create a wrapper div around the embed tag and align that to center:
<div class="wrapper" style="width: 460px; margin: 0px auto;">...</div>
http://jsfiddle.net/65z7w3z3/2/
Create a tag around your Gallery then style it.
HTML Gallery Section:
<div class="photogallery">
<embed src="http://flash.picturetrail.com/pflicks/3/spflick.swf"
quality="high" FlashVars="ql=2&src1=http://pic20.picturetrail.com:80/VOL1566/13680586/flicks/1/9035174" wmode="transparent" bgcolor="" width="460" height="350" name="Acrobat Cube" align="middle" allowScriptAccess="sameDomain" style="height:350px;width:460px" type="application/x-shockwave-flash">
</embed>
</div>
CSS for Photo Gallery:
.photogallery {
width: 400px;
margin: auto;
}

Wordpress Functions - How to use Replace String func. to add some code

I had previously used a bit of code I found to add "rel = shadowbox" to my links in Wordpress (Which works like a charm).
/*
Plugin Name: Add shadowbox
*/
define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true);
function addlightboxrel_replace($string) {
$pattern = '/<a(.*?)href="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?)>/i';
$replacement = '<a$1href="$2.$3" rel=\'shadowbox\'$4>';
return preg_replace($pattern, $replacement, $string);
}
add_filter('the_content', 'addlightboxrel_replace');
I had to use a separate plugin to add some gallery images. This plugin however didn't wrap the thumbnail image in an "a" tag (and there's no option to do such). So rather than edit the plugin, I am trying to use the same replace idea to add a link around the image.
I don't quite understand the first replace code, so I'm sure I'm missing something. I'm also trying to replace more than one line of code, so I'm not sure if that's where it's breaking. This is what I have:
define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true);
function addlink_replace($string) {
$pattern = '/<ul class="slides"(.*?)><li(.*?)><img(.*?)src=(.*?)><(.*?)li><(.*?)ul>/i';
$replacement = '<ul class="slides"$1><li$2><a src="$4"><img$3src=$4></a><$5li><$6ul>';
return preg_replace($pattern, $replacement, $string);
}
add_filter('the_content', 'addlink_replace');
This is the current code being spit out by the plugin:
<ul class="slides" style="width: 600%; transition-duration: 0s; transform: translate3d(0px, 0px, 0px);">
<li style="float: left; display: block; width: 100px;">
<img width="110" height="110" class="slider-247 slide-243" alt="" src="http://carerforklifts.com/wp-content/uploads/2014/04/F16H-1-110x110.jpg" draggable="false">
</li>
</ul>
And I would like to wrap a "a" tag around the image, using the current images URL for the a tag's src. (If possible I need to remove that "-110x100" bit at the end of the jpg.
<ul class="slides" style="width: 600%; transition-duration: 0s; transform: translate3d(0px, 0px, 0px);">
<li style="float: left; display: block; width: 100px;">
<a src="http://carerforklifts.com/wp-content/uploads/2014/04/F16H-1.jpg">
<img width="110" height="110" class="slider-247 slide-243" alt="" src="http://carerforklifts.com/wp-content/uploads/2014/04/F16H-1-110x110.jpg" draggable="false">
</a>
</li>
</ul>
Currently working on this site if that helps: http://www.carerforklifts.com/f16-h/
The regex you have isn't going to match properly, it's missing several things. I've changed and simplified it a bit, so if the structure of the unordered list isn't the same every time you may need to modify this. Here is the regex updated in the function:
function addlink_replace($string) {
$pattern = '/<ul(.*?)class="slides"(.*?)<img(.*?)src="(.*?)"(.*?)>(.*?)<\/ul>/is';
$replacement = '<ul$1class="slides"$2<img$3src="$4"$5>$6</ul>';
return preg_replace($pattern, $replacement, $string);
}
Basically this will match any unordered list that has the class slides, followed by anything up to an image tag, it will capture anything before the source attribute, it will capture the image source itself, anything in the image tag after the source attribute, then anything up to the closing tag of the unordered list.
The replacement will be the same string, but with the anchor tag around the image with the href attribute the same as the image src.
I made a sample output of this on regex101, there is a detailed explanation in the right side column of what it's matching.

position close button inside a image

I'm trying to put an anchor in the top-right of an image.
This is my view:
<div class="table">
<tr>
<?php foreach ($q as $row)
{
$var = $row->path;
$info = pathinfo($var);
echo '<td><a href="#" style= "position:relative">
<img src="'.base_url().'images/thumbs/'.$info['basename'].'"/>
</a>'.anchor('gallery/remove_photo/'.$row->id,'<i class="icon-remove"></i>','class="close"').'</td>';
}?>
</tr>
</div>
I've tried by set the position relative and the postion of the anchor absolute but it now works. I forgot to say that i'm using bootstrap 3
Why not just use an image map?
http://www.w3schools.com/tags/tag_map.asp
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
There are even some decent online tools to find the coordinates if needed like this one.
http://www.image-maps.com/
To position something absolutely (which is what you want to do), it has to have container that also has positioning set to position itself against. Sounds complex, but it's not really.
If you set your container to position:relative (meaning keep it in the flow of the document where it would normally be), then you can set descendant elements to position: absolute.
So, in your case, if you wrap your image and button in a div and set the div to position: relative, you can set the button to position: absolute like this:
<div style="position: relative;">
<img src="yourimagename.jpg" alt="">
<button style="position: absolute; top: 0; right: 0; z-index: 1;">&times</button>
</div

limit number of images in a row?

i have a set of images that i want to show where they are saved into my database as linked, where each images has its thumbs, now i have used limit inquery to show a small number of images where the user needs to go next to show the other, my question is that how can i arrange those images where 4 images in a row and 3 columns
HTML:
<div id="image_container">
<img src="" alt="" />
<img src="" alt="" />
<img src="" alt="" />
<img src="" alt="" />
...
</div>
CSS:
#image_container { width:440px; overflow:hidden; }
#image_container img { width:100px; margin:5px; float:left; display:inline; }
You may need to adjust the sizes; this is the general concept though.
If the images all have the same width then make the container only wide enough for 4 images and float the images left
Otherwise loop through the images and use the modulus operator to test for which image in the row you are on. If you are on an image that should be the first in the row you can clear the floats on that image.

Categories