Using <img1 />
as an HTML tag is not valid. To uniquely select elements, it is recommended to define a class
or id
for each element. If you prefer not to use a class
or an id
, you can create Custom Attributes with a prefix of data-
. However, it is not possible to define custom HTML elements.
For example, you can define classes for img
tags like this:
<img src="" class="img1" />
<img src="" class="img2" />
Then, you can write CSS rules for each class:
.img1 {
/* Styles for .img1 */
}
.img2 {
/* Styles for .img2 */
}
If you have common properties for multiple classes, you can group them using commas and then redefine unique properties for each class:
.img1, .img2 {
padding-left: 15pt;
/* Other common properties */
}
.img2 {
/* Unique properties for .img2 */
}
If you prefer not to assign classes to individual img
tags, you can use pseudo-classes like :nth-of-type
or :nth-child
to select specific elements within a container element:
For instance, if you wrap the img
tags inside a div
with a class
of .container
:
<div class="container">
<img src="" />
<img src="" />
</div>
You can then apply styles to each img
tag based on their position within the container:
.container img:nth-of-type(1) {
/* Styles for first img tag inside .container */
}
.container img:nth-of-type(2) {
/* Styles for second img tag inside .container */
}
It is important to consider specificity when using these selectors. If you are unfamiliar with specificity, you can learn more here.