Custom alternative text of the unload the image - html

I have image tag
If the user has disabled the download of pictures or for some reason they did not load properly, then place icons should appear comfortable text, like this:
And yet, there may be an image of circles, transparent in the middle, it means that simply the text under the picture will not post.
What there are ways of making such alternative text - NOT using JS,it test task and it says there is solution wothout JS ?
Property 'alt' - unusable because I must set text with color (Attached image)

Just set the alt attribute to your text and style it using CSS:
<img id="myImage" src="" alt="Some text" />
CSS:
#myImage {
color: red;
}
More information: How to style alt text color?

You can style the alt text displayed on a broken image. Use the color: style on either the image itself or on the image's container (the image will inherit the color).
Demo Fiddle
HTML:
<div class="container">
<img src="notarealimg.jpg" alt="lorem ipsum">
</div>
CSS:
.container{
color: red;
}
img {
width: 100px;
height: 100px;
}

Related

How to pull IMG SRC from one HTML tag into another?

I'm working on a school project and I'm wondering if this is possible:
In one div, I've defined an <img>, which will display.
In the second div, I want the img src to come from the first div.
Is it possible to do this? Preferably without anything besides css/html.
If you don't mind a little JS you can do it inline in your HTML. E.g.
<img id="img1" src="http://cdn.obsidianportal.com/assets/50953/serenity19dc.png" />
<img id="img2" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onload="this.src=document.getElementById('img1').src" />
Here the second image has intially just a placeholder image (1x1 gif) but on load it is replaced by SRC from the first image.
You need JavaScript to copy the src attribute, but you can have two images while defining the URL in one place by defining a background image in CSS:
.is-image {
background: url('http://www.google.com/images/srpr/logo11w.png') no-repeat;
width: 538px;
height: 190px;
}
<div class="is-image"></div>
<div class="is-image"></div>

How to add an image to an anchor tag using CSS?

I want to show an image with the link on the menubar. My code is as below:
The login class in css is as below:
.login{background: url(../img/user.png) no-repeat 6px center;}
But, I am not able to view the image in the browser. If I tried like
Login
then image appears in the background. But I want to use only image and not the text. how can I do that?
You'll have to set dimensions on the a tag, and set it to display: block;.
.login {
background: url(../img/user.png) no-repeat 6px center;
width: 100px;
height: 100px;
display: block;
}
Of course replace dimensions with the correct ones.
Alternatively you could put the image directly into the a tag like so:
<img src="../img/user.png" />
You can use the following:
<img src="../img/user.png" />
EDIT: I forgot to mention this would mean you have to remove the background image from your CSS.
Use the following code:
<img src= {require('../img/image_namer.svg')} />
05 2021
for SEO
Something to keep in mind when adding image wrapped with href element. If it is possible try to use the img inside the href element. This is good for seo. If the image fail to load it will show you the alt text.
Whenever an image is linked, Google will use the text contained in the image's alt attribute as the anchor text. - moz
src: https://moz.com/learn/seo/anchor-text
When you wrap the img with the href element, always include the alt text.
This will act as a Anchor text to your href element.
<a href="#" class="login" title="Login">
<img src="../img/user.png" alt="User profile"/>
</a>

Is it possible to change the size of the alt attribute of an image in CSS

I have an image that I would like to show alt values when displaying images:
HTML:
<div id="demo">
<li><img src="images/cpu.jpg" alt="Over All CPU" /></li>
</div>
CSS:
#demo img { font:italic 100px Georgia, Times, Serif; color: #000; text-shadow: 0px 2px 4px #222; margin:10px 20px; }
Is it possible to make the alt size big? If not, is there a way to put a title to the image when displaying?
The alt property is a property of the image tag, it's not an element by itself. You can't style the alt property its same as src
but you can use the jQuery Tooltip plugin to get this effect
You can use onload() event handler or onmouseover() event handler to display the text on image in whichever style you want.
Is it possible to make the alt size big?
Like said above, there is no way to style the alt. The alt attribute serves two purposes.
If the image fails to load or if the user has images off, it is
shown.
The text in the alt is reported to assistive technology,
such as JAWS, so users can get an equal experience.
If not, is there a way to put a title to the image when displaying?
Can't you simply do:
<figure>
<img src="" alt="Over All CPU">
<figcaption>Your title goes here, which should not be Over All CPU</figcaption>
</figure>
Ref

linking an image and text

I'd like to wrap an html link tag around both and image and a caption, so something like
<img src="...">Caption Text</img>
The caption should go below the image, but I'm not sure of a good way to do that (adding a <br> works, but seems unclean). I'd like to be able to use a styled element, but I can't put a div inside of there.
Try this - DEMO
No need to change your HTML
<a href="link">
<img src="http://lorempixel.com/200/100" />
Caption Text
</a>
CSS
a {
display: inline-block;
text-align: center;
border: 2px solid orange;
}
img {
display: block;
}
You can wrap the caption inside a span
<img src="..."/><span style="display: block;">Caption Text</span>
http://jsfiddle.net/ZgKqF/
Try it this way : <img src="..." alt="Caption Text" />
Then use javascript to display the alt attribute and display with javascript. Look at this for reference Get the "alt" attribute from an image that resides inside an <a> tag
You can make the a behave like a div (in regard to how it can be styled) with
display: block

placing image as div background

How can I place only an image in a div as background image, and add url link to it.
Currenty I'm doing it this way:
<div class="image"><img src="books.png" alt="Test" /></div>
I want to do something like following, but its not working (the image does not appear).
<div class="image"><span class="books"></span></div>
Thanks.
Place the background image in the <a> tag if you want it clickable.
your css:
.image a { display: block;
background: url('image.jpg') no-repeat;
height: 50px; /* obviously use the same dimensions as your image */
width: 50px; /* obviously use the same dimensions as your image */
}
<div class="image"> </div>
or better yet, get rid of the div entirely, and just apply the image class directly to a:
<a class="image" href="example.com"> </a>
It's likely it's because the div is empty. Try something like:
<div class="image"><span class="books"> </span></div>
If it's still not showing, set the "image" class to have a background color too, so that you can see how big the div 'thinks' it is.
If you want an image to be in the background you need to set, the style property "z-index:-1", that way, the image will be in the back of the other elements in the same content div
Does it have to be a DIV?
I am writing the style inside you can use it in css file
<a class="image" style="display:block; width: (image-width); height: (image-height); background: url(image-link)"></a>
this will work...
you can use it like this if you need div..
<div class="image" style="width: (image-width); height: (image-height); background: url(image-link)"></div>