Home > Web Front-end > HTML Tutorial > How to anchor an element to the correct position in a responsive image?

How to anchor an element to the correct position in a responsive image?

PHPz
Release: 2023-09-22 18:09:06
forward
1106 people have browsed it

How to anchor an element to the correct position in a responsive image?

Placing anchors at the right location on responsive images has become more important these days. Because we encounter many advertisements in our daily life, if the anchor is not placed correctly under the responsive image, it will make it more difficult for users to understand the web page.

We use CSS and HTML to anchor elements to the correct position on the responsive image. Before we dive into this article to understand better, let’s take a quick look at anchors and image tags in HTML.

Anchor tags in HTML

Through its href attribute, the HTML element (or anchor element) generates a hyperlink to a web page, file, email address, location on the same page, or any other content that can be addressed by a URL.

Each should contain text describing the final destination of the link. When focus is on the element, pressing Enter activates the href attribute if it exists.

grammar

The following is the syntax of anchor tags in HTML

<a href = "link"> Link Name </a>
Copy after login

HTML How to anchor an element to the correct position in a responsive image? tag

To insert an image into a web page or website, use the HTML How to anchor an element to the correct position in a responsive image? tag. In modern websites, images are linked to web pages using the How to anchor an element to the correct position in a responsive image? element, which contains the space for the image. This prevents websites from adding images directly to web pages.

grammar

The following is the syntax of the img tag

<img src="" alt=""    style="max-width:90%" height="">
Copy after login

To learn more about anchoring elements to the correct location on a responsive image, check out the following examples

Example

Below we use CSS to anchor the element to the correct position on the responsive image.

<!DOCTYPE html>
<html>
   <body>
      <style>
         .tutorial {
            display: flex;
            width: 60%;
            margin: auto;
         }
         .type {
            text-align: center;
         }
         .tutorial img {
            max-width: 90%;
            display: block;
         }
      </style>
      <div class="tutorial">
         <div class="type">
            <img  src="https://www.tutorialspoint.com/java/images/java-mini-logo.jpg" alt="How to anchor an element to the correct position in a responsive image?" >
            <a href="https://www.tutorialspoint.com/java/index.htm">Java Tutorial</a>
         </div>
         <div class="type">
            <img  src="https://www.tutorialspoint.com/html/images/html-mini-logo.jpg" alt="How to anchor an element to the correct position in a responsive image?" >
            <a href="https://www.tutorialspoint.com/html/index.htm">HTML Tutorial</a>
         </div>
      </div>
   </body>
</html>
Copy after login

When the script is executed, it will generate an output containing the image uploaded to the web page and the corresponding hyperlink appended to the bottom of the response image.

Example

Consider the following example where we place the anchor point of an element at the correct location on a responsive image.

<!DOCTYPE html>
<html>
   <body>
      <style>
         #tutorial{
            float:left;
            position: relative; 
         }
         #tutorial img {
            max-width: 100%;
            display: inline-block;
         }
         a.link1{
            height:15%;
            width:15%;
            position: absolute;
            top:60%; left:10%;
            display:block;
            background:#00FF00 ;
         }
         a.link2{
            height:15%;
            width:15%;
            position: absolute;
            top:50%;
            left:76%;
            display: block;
            background:#FF0000;
         }
      </style>
      <div id="tutorial">
         <div>
            <img  src="https://www.math-english.com/media/dices/two-dices2.png" alt="How to anchor an element to the correct position in a responsive image?" >
         </div>
         <a href="https://www.tutorialspoint.com/html/index.htm" class="link1">HTML</a>
         <a href="https://www.tutorialspoint.com/java/index.htm" class="link2">JAVA</a>
      </div>
   </body>
</html>
Copy after login

When you run the above script, an output window will pop up showing the image uploaded on the web page and the hyperlinks attached to both sides of the image, with CSS applied to the hyperlinks.

The above is the detailed content of How to anchor an element to the correct position in a responsive image?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template