Transparent PNG and link compatibility problem

Tell us what’s happening:
So I am going to try and explain this as easy as I can, this is only my second day doing all of this. So I’m just trying to make a simple one page website for my music that I make. I have a png image with my artist name and a transparent background. The image is pretty big. I want to make it so the transparent part isn’t taking up so much of the page, but when I do by setting the position to absolute and moving it where I want to be, the links below aren’t allowed to be clicked. I imagine because the transparent area of the image is overlapping with the text. Was wondering how I can make it possible for the transparent part not to interfere with the links, if I even could. I can see that the “Instagram” text isn’t overlapped because I can highlight the text but the other three are covered by the transparent part of the image

Sorry that was a lot, thank you to whoever even reads this haha

  **Your code so far**
<head>

    <style>          

        .center {

          display: block;

          margin-left: auto;

         margin-right: auto;

         

        }

        body{

            background-color: rgb(255, 255, 255);

            color: black;

            font-family: 'Oswald', sans-serif;

            text-align: center;

            font-size: 40px;

        }

        h2 {

            font-size: 30px;

            font-weight: 500;

            font-family: sans-serif;

        }

        h3 {

            margin-left: auto;

            font-size: 20px;

            font-family: sans-serif;

            font-weight: 400;

        }

       

    </style>

</head>

<body>

    <h1><img style="position: absolute; left: 650px; top: -200px;" src="3.15.18 nurture text.png" alt="NURTURE" width="600" height="600" class="center"></h1>

    <br>

    <br>

    <br>

    <p> <a href="https://www.traktrain.com/nurture/">Buy Beats</a> <br>

        Soundcloud<br>

        Twitter<br>

        Instagram

     </p>

    <img src="mfnftrans.png" alt="MFNF" class="center" width="400" height="400">

   

    <h2>Contact</h2>

   

    <h3><form id="fcf-form-id" class="fcf-form-class" method="post" action="action.php">

            <label for="Name" class="fcf-label">Your name</label>

            <div class="fcf-input-group">

                <input type="text" id="Name" name="Name" class="fcf-form-control" required>

            </div>

        <div class="fcf-form-group">

            <label for="Email" class="fcf-label">Email address</label>

            <div class="fcf-input-group">

                <input type="email" id="Email" name="Email" class="fcf-form-control" required>

            </div>

        <div class="fcf-form-group">

            <label for="Message" class="fcf-label">Your message</label>

            <div class="fcf-input-group">

                <textarea id="Message" name="Message" class="fcf-form-control" rows="6" maxlength="3000" required></textarea>

            </div>

        </div>

        <div class="fcf-form-group">

            <button type="submit" id="fcf-button" class="fcf-btn fcf-btn-primary fcf-btn-lg fcf-btn-block">Send</button>

        </div>

    </h3>

   

</body>
  **Your browser information:**

Chrome

1 Like

It sounds like the image should be cropped. But we can’t tell what the image looks like because you have linked to a local image and not one stored on a server.

If you use CodeSandbox they allow you to upload images so you can post a working example.


You can use z-index to position the links on top of the image (if they are only over the transparent part). Give the main link container position: relative and then a positive z-index

.some-container {
  position: relative;
  z-index: 10;
}

However, using position absolute is rarely the correct choice. It is used for very specific cases and not just normal positioning of page elements.

Thank you very much!

I agree with @lasjorg. I’m actually experiencing the same problem where I am trying to add an image with an irregular border. When I create it in Photoshop I can easily use transparency to get the appearance of an irregular border, but the html and CSS still see the object as a box since although you can’t “see” anything, there is still information there about the size and shape of the non-visible area.

Best answer: find a program that will let you crop the image as an irregular shape, then import it. Then let me know which program you used because I as of yet haven’t found one that let’s me do it.

Second best answer: use z-index to place the buttons above the image. As for using position absolute, don’t be afraid of using it. @lasjorg is correct in that it can create some problems with responsive design, but I’ve found those usually go away if I use a parent container with relative position to get the positioning correct on the x, y axis of the page and then just use position relative for the z-index.

@trrapp12 You can’t do that, elements don’t work that way. Everything is a box.

Okay. Well thanks for setting me straight then.

As for the positioning.

The way position absolute is used here sounds like an escape hatch which is never how you want to use it. Sure if you have to take the element out of normal flow it does work, but images that are not meant to overlap other elements shouldn’t be positioned so they overlap. It is just creating a new problem instead of fixing the actual problem.

And thanks for the post @E715 . As you can see I’m learning too, these types of questions and forums are as much a help to the rest of us and they are to the people asking the question.

One thing that comes to mind is the pointer-events property. Rather than worrying about layering the image behind the links, you could remove the pointer event and the hover/click events should fall through to the links instead of the image.

1 Like

That is definitely also an option. But I do worry that part of the image that isn’t transparent might overlap in some cases (depending on the screen width). So making sure the stacking is correct might be needed.

1 Like

Absolutely, thank you for your input as well!

Thank you for your input!

I am writing down all of the things related to PNG and link compatibility -

Fortunately, there are plenty of hacks and workarounds designed to “fix” IE’s PNG image-display problem. Unfortunately , every currently available solution requires the use of Microsoft’s proprietary AlphaImageLoader transparency filter1. Thus, if you need to display translucent PNG images in IE, the solution will inevitably involve the `AlphaIm

General Method

The general implementation of the AlphaImageLoader transparency filter requires three steps:

Step 1. Include an IE-specific stylesheet via [conditional]ageLoader` filter until more sophisticated techniques are developed.[comments]:

<!--[if lt IE 7]>
	<link rel="stylesheet" type="text/css" href="http://domain.tld/path/ie-specific.css" />
<![endif]-->

Step 2. Within the same directory as the IE-specific stylesheet, upload a [transparent GIF file]2 and [this .htc file], provided by TwinHelix Designs which contains an excellent implementation of the required AlphaImageLoader function.

Step 3. Finally, add the following “custom extension” to your “ ie-specific.css ” CSS file:

.png { behavior: url(http://domain.tld/path/png.htc); }

Once in place, this method will enable IE (versions 5.5+/Win) to display transparent PNGs for any PNG images associated with the “ .png ” class. This method works great for designs containing multiple PNGs as the behavior is applied to all .png -classed images — inline or background — regardless of name or location. For designs using only a few PNG images, the next method is equally effective, and doesn’t require any external files.

Simpler Method

This method replaces the external “ png.htc ” and transparent GIF files with a small chunk of invalid CSS:

.png {
	cursor: pointer;
	background: none;
	/* filter applies only to IE5+/Win */
	filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='fixed', src='http://domain.tld/path/image.png');
}
.png[class] {
	/* [class] applies to non-IE browsers */
	background: url(http://domain.tld/path/image.png) no-repeat;
}
* html .png a {
	/* make links clickable in IE */
	position: relative;
	z-index: 999;
}

Once in place, this chunk of CSS enables IE (versions 5.5+/Win) to display transparent PNGs for any PNG images associated with the “ .png ” class.

To use this code for background images, edit the image path/name to match your own and ensure that the .png class is included in the markup. For inline images, the second code block (i.e., .png[class] ) may not be necessary. Here are a few more potentially useful considerations:

  • For best practice, include this code via [conditional comment] in an IE-specific stylesheet.
  • Alternatively, you may want to use the * html filter to keep the rules from interfering with other browsers (may affect performance).
  • This method will not work for background images that have been positioned in any way or set to repeat in any direction. Basically, I have used this PNG and link compatibility on best payroll software Kolkata where various types of PNG related things.
  • If the target PNG images fail to display properly, try replacing the sizingMethod='fixed' parameter with either sizingMethod='crop' or sizingMethod='scale' .
  • The last code block (i.e., * html .png a ) is required only if there are links within the target element.

Alternate Method

An alternate approach to displaying transparent PNGs in IE involves placing the following code directly into your CSS file:

* html img,
* html .png {
position:relative;
behavior: expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')",
this.src = "transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')",
this.runtimeStyle.backgroundImage = "none")),this.pngSet=true)
);
}

Of course, you will probably want to include this code via [conditional comment] and an IE-specific stylesheet:

<!--[if lte IE 6]>
	<link rel="stylesheet" type="text/css" href="http://domain.tld/path/png_fix.css" />
<![endif]—->

A few notes should you decide to go this route:

  • Invalid CSS
  • Works well only for statically displayed images.
  • Requires a transparent 1px-square GIF image.
  • Non-repeating backgrounds should be sized to “crop”, others should be sized to “scale”.
  • As-is, this CSS expression is very resource-intensive, so…
  • USe this.runtimeStyle.behavior="none" to ensure the function is executed only once.

JavaScript Method

There are several JavaScript techniques for applying the AlphaImageLoader transparency filter to target PNGs. One of the more popular methods is the [SuperSleight method]. SuperSleight solves many of the problems typically associated with previously discussed methods:

  • Valid CSS — requires no special CSS.
  • Unobtrusive functionality — exclusively targets deficient versions of IE.
  • Improved performance — the function can be executed throughout the entire document or only in specified page regions.
  • Clickable links, focusable forms — optional automatic application of position: relative to links and form fields.
  • Automatic sizing method — detects background images set to no-repeat and sets the scaleMode to crop rather than scale .
  • Applied to new content — automatically applied to any newly added content, such as that loaded via Ajax requests.
  • Replaces previous versions — works with both inline and background images, replacing the need for both sleight and bgsleight.
  • Web Standards — complete separation of structure, presentation, and behavior.

The downside to this method is that JavaScript must be available in order for it to work. Other than that, the technique is nearly perfect, addressing nearly all of the shortcomings of previous methods. To use this method, [download the Supersleight script] and a [transparent GIF], upload the files to your server, and include the function via [conditional comment]:

<!--[if lte IE 6]>
	<script type="text/javascript" src="http://domain.tld/path/supersleight.js"></script>
<![endif]-->

…and that’s all there is to it. No need to mess with class names, alternate images, or specific attributes. Supersleight does all the work by traversing the DOM and applying the required filters via pattern matching. Completely unobtrusive and awesome.

Hope this article helps everyone properly.