I have - img id="logo" SO I can have my logo on my website, the full code for it being:
<img id="logo" src="nsc/logo2.png" alt="logo" />
How can I link this logo image using <a href=""> ???
I've tried many different ways but they don't work :/
<img id="logo" src="nsc/logo2.png" alt="logo" />
It would be nice to embed in a link tag. :)
<a href="your.html">
<img id="logo" src="nsc/logo2.png" alt="BrandLog" />
</a>
it's clean and no need of javascript :)
It's super simple, just wrap the <img> tag with an anchor tag <a>:
<a href="myUrl.html">
<img id="logo" src="nsc/logo2.png" alt="logo" />
</a>
This will turn the entire image into a link for you :)
For people who want to receive click event on a tag instead of img tag
<a href="/chat" style="background: red; display: inline-block;">
<img src="chat.svg" style="pointer-events: none; display: block;" width=40 height=40>
</a>
On a tag
display: inline-block in a: allows to set a width and height on a tag
On img tag
display: block: help remove extra space below the image
pointer-events: none: ignore click on img, click event will fired on a tag
If you can't wrap the image in a link, an image map should work just as well without requiring JavaScript & without needing to wrap the element.
I add id in img tag like this:
<img id={logo.id} src={logo.url} onError={this.handleImageError} />
Since I am working on React that's why I used JSX in the id and src attribute. onError attribute is used if the image is broken. It gives me an event, So this is how I access the id attribute:
handleImageError = (e) => { console.log(e.target.id) }
Here is the solution for you,
<img id="logo" src="nsc/logo2.png" alt="logo" onClick="window.open('http://yahoo.com');" />
Related
i decided to make redirects with images but i have small problem.
Look at this screen:
https://i.stack.imgur.com/eEnNB.png
This is this item:
<p><div><a title="Home" href="/home"><img src="/icons/home.svg" width="55" height="55" /></a></div></p>
It shows strange rectangle, i dont want to show it. Do you have any ideas?
That outline is an accessibility feature (Which might be added as part of a CSS theme, but hard to know without the full context of the codebase). However, removing it is not a good idea, as it will worsen the experience for people with visibility impairment (Check http://www.outlinenone.com/).
What we can do, however, is make it look better. You have a <div> with a <a> nested in a <p>, it being the reason for the rectangle not encasing the whole icon and instead overlapping on top of it, as it believes it to be an inline element (Ideally, you don't want to use block elements in p tags). Here, you're getting block elements, such as a <div> and an <img> inside of the <p>). So what I recommend is:
Remove <p> and <div>, and leave it only wrapped in the <a>
Add the display: inline-block CSS property to the <a> tag, resulting in:
<a style="display:inline-block;" title="Home" href="/home">
<img src="/icons/home.svg" width="55" height="55" />
</a>
If you want a block element, simply remove the <p> tag:
<div>
<a title="Home" href="/home">
<img src="/icons/home.svg" width="55" height="55" />
</a>
</div>
Without full context it will be difficult to answer but:
Try to set a element display:block or display:inline-block
Try to set IMG width and height as style="width:55px;height:55px"
Add display: inline-block to the <a> tag
<p>
<div>
<a style="display:inline-block" title="Home" href="/home">
<img src="https://media.istockphoto.com/id/1357549139/photo/shot-of-an-adorable-baby-boy-wearing-a-hoody-towel.webp?s=612x612&w=is&k=20&c=MvuPLKqQhs7f6ZIsPf8oTgw08OiCvmmjJNeNdL0FG4M=" width="55" height="55" />
</a>
</div>
</p>
I attend to put a link on an image, who can help me? Is it correct to use a tag inside a figure tag?
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dojo/1.13.8/resources/dojo.min.css" />
<figure class="mar-btm-30">
<a href="" alt="">
<img class="img-responsive image-center" title="" alt="" src="https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png" />
<figcaption class="text-center"><em>Caption</em></figcaption>
</a>
</figure>
You dont need the alt attribute in the a tag but all in all your solution is right. You just need to wrap yor img tag with an a tag.
Not sure why, but none links over the images in my posts works unless it's set to position: absolute;
Summary:
No problems with neither src or href
The pointer cursor does not appear
Nothing happens when clicking on the image
The links works when I set a to position: absolute;, but then everything is misplaced and so on.
I have tried shortening it up to make it easier to debug.
Shorten HTML
<a href="#.jpg">
<img src="#.jpg" alt="Alt text" width="1200" height="800">
</a>
(Shortened) Complete HTML
<div class="clearfix"></div>
<div class="holder blacktext bildeserieholder">
<div class="container">
<div class="row">
<div class="col-md-12 centertext">
<img class="aligncenter size-full wp-image-512" src="#.jpg" alt="text" width="1200" height="800" />
<img class="aligncenter size-full wp-image-513" src="#.jpg" alt="text" width="600" height="900" />
<img class="aligncenter size-full wp-image-514" src="#.jpg" alt="text" width="1200" height="800" />
<img class="aligncenter size-full wp-image-515" src="#.jpg" alt="text" width="1200" height="800" />
<img class="aligncenter size-full wp-image-516" src="#.jpg" alt="text" width="600" height="900" />
</div>
</div>
</div>
</div>
</div>
I have tried:
Using cursor: pointer to the link attribute.
Removing all img classes
Removing all CSS on both images and links in Chrome Inspect Element
It's hard to find out where I have done something wrong, so I would really recommend checking out the page: http://goo.gl/DqXAlC
Maybe not relevant, but I will add this information anyways regarding what I am using:
Wordpress
Bootstrap
Types (custom posts etc plugin)
The images are being uploaded with Types within each posts in a WYSIWYG editor called "bildeserie". In my single PHP I have the following which echos the images:
<?php echo(types_render_field( "bildeserie", array( 'raw' => true) )); ?>
Do you have a working solution or any ideas?
Note: The problem is with the images below the header and all the text.
Solutions:
.holder img {
pointer-events: none;
}
The above is disabling the link on the image, commenting it out will make everything work.
Second solution:
a {
display:inline-block;
}
That also fixes your problem (by expanding the link to the dimensions of the image).
I would imagine that the img has a size and the link does not have a size unless set to absolute. If the a doesn't have a size, you aren't clicking on the a you are clicking on the img, give the a a size and see what happens
You should disable this line in your style.css file:
.holder img {
pointer-events: none;
}
I am trying to create a link section in a HTML document. I have a couple links containing images. The code is here: http://jsfiddle.net/u6Tmt/. As you can see after the SO image there is a little black bar which looks almost like an underscore. What is causing this black bar to appear and how do I get rid of it?
In case you don't know what I'm talking about, here is an image to help:
Also here is another copy of the code:
<div id="links">
<a href="http://stackoverflow.com/users/1916721/cabellicar123">
<img src="http://cdn.sstatic.net/stackoverflow/img/favicon.ico" alt="stack overflow">
</a>
<a href="https://github.com/cabellicar123">
<img src="https://assets-cdn.github.com/favicon.ico" alt="github">
</a>
</div>
The bar is the default underline of hyperlinks.
Add this rule to your CSS stylesheet to get rid of it
DIV#links A { text-decoration: none; }
I wouldnt have thought it an issue but if you change
<img src="image URL" alt="stack overflow">
to
<img src="image URL" alt="stack overflow"/>
and remove all spaces in the
<A>
your fiddle fixes
Edit: This & cobra_fast's answer
There seems to be a space in your first a-tag and the hyperlink is underlining it. When you use the a-tags with images, put it on the same line and it seems to work:
<div id="links">
<img src="https://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico" alt="stack overflow">
<img src="https://web.archive.org/web/20190109105720/https://assets-cdn.github.com/favicon.ico" alt="github">
</div>
It seems like a simple problem but whatever i did i couldn't solve it. I post a link about what i am talking. http://www.olmasigereken.com/demo/?view=listen&artist=ibrahim+ferrer&track=dos+gardenias
If you look at page codes you will see that order of items is red arrow artistname dash(-) trackname twitter and facebook links. However the output is not like that. I want to put everything on one line with correct order which is red image artistname dash trackname twitter and facebook links.
Note: When you click it if you don't see anything please refresh the page.
<li>
<img src="img/track_arrow.gif" alt="" />
<div class="singer">
<?php echo $a[artistname]?>
</div>
-
<div class="song">
<?php echo $a[trackname]?>
</div>
<div class="fav">
<a target="_blank" href="#" /><img src="img/twit.gif" alt="share on twitter" /></a>
<a target="_blank" href="#"> <img src="img/face.gif" alt="share on facebook" /> </a>
</div>
<br />
</li>
The floating left of links inside is causing conflict. If you remove the float: left as seen in the following screenshot, I think you will get what you want...
You need to set some css propertys like
.ikinciSol ul li {
widht: 375px;
}
.fav{
float: right;
}
Hope this may helpful to you.
try this to put each element between li balises and use the css attributewith ul element: list-style-type:none;