How to add image in css with the help of class or id? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to add image in css with the help of class or id?

image should be in left or right but not a background as all uses background-image not this just like in html we give <img> tag like that but the use of this in a class or id ?

19th Feb 2017, 5:16 PM
akash yadav
akash yadav - avatar
4 Answers
+ 1
css has 3 main things "selectors" (not sure what they are called lol) are accessed like header {} nav ol li {} then classes, class="css-label" .css-label {} .generalClassName {} or an id <div id="main">... #main {} #picture {} ect. for the whole img thing... do <img src... alt.... class="myPic"/> then in styles .myPic { height: 50%; width:50%; float:left; others... } hope this helps.
19th Feb 2017, 6:54 PM
Michael Szczepanski
Michael Szczepanski - avatar
+ 1
With: <img src="picture.url" id="myPicID" class="myClass" alt="description"> ... you can target it by "selecting" it ( selector is the right word ;) ) by different ways: img { /* rules targets all <img> elements */ } #myPic { /* target all id 'myPic' ( but they're supposed to be unique ^^ ) */ } .myClass { /* target all elements with class 'myClass' */ } And you can combine them: img.myClass { /* target only <img> with class 'myClass' */ } ... as well as associate parent and children in the selector: div.myStyle img.myClass { /* will target all <img> with class 'myClass', which are childs ( contained in ) of all <div> with class 'myStyle' */ } Also, a lot of css selector operators exists, now with Css3, to make accurates rules ;) However, handling complex css selectors, require to good understanding too how priorities, inherits, and so on works in the "Cascading Style Sheet" context, as order of rules are not the only criterion to decide overwriting or not a property ^^
19th Feb 2017, 10:40 PM
visph
visph - avatar
0
thank you so much!
23rd Feb 2017, 3:16 AM
akash yadav
akash yadav - avatar
0
thnx ol fr help n keep sharing knwoledge fr free thnk u!
23rd Feb 2017, 3:17 AM
akash yadav
akash yadav - avatar