<!DOCTYPE html>
<html>
<head>
<style>
image {
border: 5px solid red;
}
</style>
</head>
<body>
<image src="https://www.w3schools.com/howto/img_snow.jpg" alt="Snow">
</body>
</html>
border not applying in HTML custom image tag. is possible to fix?
border not applying in HTML custom image tag. is possible to fix? i want image tag with border not changing <img> tag.
3
Answers
You could add an id that way you won’t change the border of all img, just the one with the id.
If you want to use a custom tag like instead of for your image element and set a custom attribute for the source, you can do so using HTML5’s Custom Elements (also known as Web Components). Custom Elements allow you to define your own custom HTML elements with custom behavior. Here’s how you can create a custom element:
In this code, we define a CustomImage class that extends HTMLElement. When a custom-image element is added to the DOM, the connectedCallback method is called. Inside this method, we read the custom-src attribute and create an element with the specified source. We then append the element to the custom element.
If you really wants to do this you can with web components custom element
https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements
This will attach the real
img
tag to the shadow root.Because the
img
tag is in shadow root you cannot modify the style from outside and need to change the style from theCustomImage
classBut because web component tag name must include
-
you can’t useimage
as the tag name instead usecustom-image