Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use CSS to style multiple images differently?

I am basically styling a long essay with various images scattered throughout. I would like the first image to "float: left" and the second one to "float: right". I know that I can style the images like this:

img {
float: left;
}

This makes each image have the same style. How do I style each image differently? I tried to put each image in a different div class, so that I could style them differently, but it didn't work.

I also understand, that I could style each image in the html tag, like this:

<img src="ABCD.png" alt="Raoul Hausmann's ABCD" align="left" height="300px">

I keep hearing that it is best to keep style in the external style sheet (CSS), separate from the html. Is this a case where inline styling is necessary?

like image 600
cphil Avatar asked Dec 29 '14 23:12

cphil


People also ask

How do I overlay multiple images in CSS?

If the parent element is position:relative, you can overlay images with display:absolute, Then inside this parent element you can continue to layer images by z-index, z-index will give view priority to the highest index, just like layer levels. this will allow you to have as many images over each other as you need.

Can images be styled using CSS?

Using CSS to style images allows you to uniformly specify how images should appear across your website with only a few rulesets.

How do you blend two images in CSS?

Background blend mode with two images It's as easy as adding two background images in the CSS declaration. The next choice is to have a background color (or not). If you do not want a background color, this can be removed and the images will blend together depending on the blend mode that you choose.


1 Answers

You can give each image a class or id that will help you to define different css for each image like

<img src="" class="image1">
<img src="" class="image2">

in css file you can define

.image1
{
width:200px;
height:200px;
}
.image2
{
width:300px;
height:300px;
}
like image 120
priya786 Avatar answered Oct 05 '22 06:10

priya786