Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
97
rated 0 times [  102] [ 5]  / answers: 1 / hits: 12080  / 4 Years ago, sun, september 6, 2020, 12:00:00

I have like to use tailwind css to position an image over another and I wonder how this can actually be done using mainly tailwind utility classes.


Now I am using:


style="top: 200px; left: 260px;"

Though it works but I have like to use tailwind classes such as


class="top-200 left-260"

I tried a couple of tailwind classes but I could not get it to work.


<div class="relative">
<div>
<img
class="absolute mt-5 ml-0"
src="@/assets/floor_image.jpg"
width="600"
/>
</div>
<div>
<img
src="@/assets/blue_golf.png"
style="top: 200px; left: 260px;"
class="cursor-pointer absolute"
/>
</div>
</div>

More From » css

 Answers
11

You could remove all the other divs and keep just the relatively positioned parent div with the 2 absolute positioned images both set to top: 0 and left: 0 then give the second image a margin on top and left to position it staggered over the other one.


Tailwind preset classes go pretty high into the rem values for margin but if you need something more specific that TW does not come pre-packaged with you can always extend the default theme to add what you need.




<link href=https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css rel=stylesheet />
<div class=relative>

<img class=absolute top-0 left-0 src=https://picsum.photos/536/354 alt=Workplace width=600 />

<img class=cursor-pointer absolute top-0 left-0 mt-32 ml-40 hover:shadow-outline src=https://picsum.photos/535/354 width=600 />

</div>




[#2731] Wednesday, September 2, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayaw

Total Points: 749
Total Questions: 88
Total Answers: 86

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
tayaw questions
Thu, Mar 3, 22, 00:00, 2 Years ago
Fri, May 7, 21, 00:00, 3 Years ago
Wed, Oct 7, 20, 00:00, 4 Years ago
;