MAWStudios

Modification Forums => Coding Help => Topic started by: MoonWolf63 on September 12, 2024, 10:58:48 AM

Title: How to fix my ad code
Post by: MoonWolf63 on September 12, 2024, 10:58:48 AM
So I'm trying to create an ad for my game and what I want it to do is when a user hovers over the image banner, it will fade the image out and fade in a gif that I made. All it does is fade out the image. Another weird part is that theres this odd huge border for it. I just want it centered and without the huge margin.

<style>
.hover-img .animated {
    transition: opacity 0.5s ease-in-out;
}

.hover-img:hover .static {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.hover-img:hover .animated {
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}
</style>

<a href="https://mawstudios.com/index.php/mawbreaker/" class="hover-img">
    <img src="https://www.mawstudios.com/wp-content/uploads/2022/01/mawad-1-e1643755590654.png" alt="Static Image" class="static">
    <img src="https://www.mawstudios.com/wp-content/uploads/2023/02/ezgif.com-gif-maker.gif" alt="Animated Image" class="animated" style="opacity:0;">
</a>

image_2024-09-12_115731234.png
Title: Re: How to fix my ad code
Post by: Kyle on September 12, 2024, 11:09:38 AM
To fix your issue:


Here's an updated version of the CSS to try:
.hover-img {
    display: inline-block;
    position: relative;
}

.hover-img .static, .hover-img .animated {
    position: absolute;
    top: 0; left: 0;
}

.hover-img .animated {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.hover-img:hover .static {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.hover-img:hover .animated {
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}
Title: Re: How to fix my ad code
Post by: MoonWolf63 on September 12, 2024, 11:33:59 AM
Ok so I tried that and now the ad doesn't show up at all
Title: Re: How to fix my ad code
Post by: Kyle on September 12, 2024, 11:36:01 AM
If the ad isn't showing up at all after the changes, it could be due to the position: absolute causing both images to overlap or not display correctly. Try adding specific dimensions to the container and images:
<style>
.hover-img {
    display: inline-block;
    position: relative;
    width: 300px; /* Set the width for your ad */
    height: 200px; /* Set the height for your ad */
    overflow: hidden; /* Prevent overflow */
}

.hover-img .static, .hover-img .animated {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.hover-img .animated {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.hover-img:hover .static {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.hover-img:hover .animated {
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}
</style>

<a href="https://mawstudios.com/index.php/mawbreaker/" class="hover-img">
    <img src="https://www.mawstudios.com/wp-content/uploads/2022/01/mawad-1-e1643755590654.png" alt="Static Image" class="static">
    <img src="https://www.mawstudios.com/wp-content/uploads/2023/02/ezgif.com-gif-maker.gif" alt="Animated Image" class="animated">
</a>
Title: Re: How to fix my ad code
Post by: MoonWolf63 on September 12, 2024, 11:38:27 AM
:D It's finally fixed.
Title: Re: How to fix my ad code
Post by: Heidi on September 12, 2024, 12:40:54 PM
This isn't fixed, it's off-centered. It looks horrible.
Title: Re: How to fix my ad code
Post by: MoonWolf63 on September 12, 2024, 01:43:17 PM
Quote from: Heidi on September 12, 2024, 12:40:54 PMThis isn't fixed, it's off-centered. It looks horrible.
Eh, maybe the very bottom one, but, the top one is perfect as its just under the title and date.
Title: Re: How to fix my ad code
Post by: Jadedacat1976 on September 13, 2024, 10:23:49 PM
Yeah so on mobile it looks horrible. It's too big for the screen.
Title: Re: How to fix my ad code
Post by: MoonWolf63 on September 17, 2024, 12:49:05 PM
Quote from: Jadedacat1976 on September 13, 2024, 10:23:49 PMYeah so on mobile it looks horrible. It's too big for the screen.
Did I fix it?
Title: Re: How to fix my ad code
Post by: Jadedacat1976 on September 17, 2024, 12:50:46 PM
Quote from: MoonWolf63 on September 17, 2024, 12:49:05 PM
Quote from: Jadedacat1976 on September 13, 2024, 10:23:49 PMYeah so on mobile it looks horrible. It's too big for the screen.
Did I fix it?
No, it's less but it's still fucked.