How to make Tag not suffer a tag attribute whose tag is housed?

Asked

Viewed 37 times

-3

How do I get one tag from another? Ex.:

<div>
    <img src="...">
    <a href="...">...</a>
    <a href="...">...</a>
    <a href="...">...</a>
</div>

In case I want to put an attribute in the <div> to make a square with a color, but I want the image to be left of the square and not inside. What I do?

  • if the image is to be outside the div and to the left, why not put it outside the div then? can put both inside another div and use display to position as you wish

1 answer

0


You have to use the property position: absolute in the div/element you want to leave somewhere else and define how much of the top/bottom/left/right the element will be.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div style="background-color: red; margin-left: 50%; text-align: center; width: 500px; height: 200px">
                Q1
                <div style="position: absolute; right: 50%; text-align: center; top: 8px; background-color: blue; width: 500px; height: 200px;">
                    <img src="https://www.w3schools.com/w3images/mac.jpg" width="500px" height="200px"/>
                </div>
    </div>
</body>
</html>

  • and where is the solution for image? your answer does not demonstrate how to solve the problem

  • edited @Ricardopontual

Browser other questions tagged

You are not signed in. Login or sign up in order to post.