I have an image that I’m trying to display inline with a donate button, but I’d like it to overlap the div it’s contained in.
Currently, the image just won’t show; the box it’s surrounded in has display:table in it:
When I block display:inline in Firebug, the image shows, but above the donate button.
The code I’m using (based on suggestions and usings W3 Schools) is:
<div style="background: url('https://nationalcdp.org/wp-content/uploads/2014/09
/feature-me.png') no-repeat 50% 50%; background-position: center center; background-
attachment: absolute!important; width: 133px; height: 116px; display:inline;
overflow:visible;"></div>
<a href="https://nationalcdp.org/wp-content/plugins/stripe_payment_terminal/terminal
/index.php" class="spt_newpay_button buttondesign28">Donate!</a>
Here is the effect I mocked up in Photoshop that I’m trying to achieve:
The avatar and the arrow is just one image called “feature-me.png”. But I’m just unsure how to accomplish what I’d like. There is nothing in the spt_newpay_button class other than just different color options for the button.
I’m really hoping this can be achieved without using jquery, and just using CSS.
Any guidance would be greatly appreciated!
Thanks!
2
Answers
Try this piece of code directly in your page:
Your original code didn’t make it clear what the button is made out of, or if the banner text was part of a background or actual text. You also refer to a CLASS within your example code, which isn’t detailed.
I hosted the two temporary images (out box and button) on one of my domains just so you could see it working, replace them for your own code as necessary.
So I created the code above basically using 3x separate images and in element styling just to show you one clean way of achieving what you needed.
Simply remove out any images you wish to recreate with text and pure styles etc.
you will see that it only uses 1 DIV layer that has the style POSITION:Relative – this sets the layer relative to whatever else is on your page. The two inner elements are image elements [One of them surrounded in an HREF link to provide the button action.]
Both these elements use style POSITION:Absolute which anchors to the start of the outer DIV at position x=0. Then its just a case of setting the LEFT style value to move both img elements to the right of its parent DIV.
These two IMG elements will stay in place with the parent, where ever the parent is placed in your main page.
There’s other ways to achieve the same, but with no extra info about your page – this works fine.
You can achieve what you’re trying to achieve quite easily without the hassle of creating another
<div>
. Currently, this is the code which generates theDonate
button and thefeature-me
image inside your website:You will need to remove this line of code from the code above:
<div style="background: url('https://nationalcdp.org/wp-content/uploads/2014/09/feature-me.png') no-repeat 50% 50%; background-position: center center; background-attachment: absolute!important; width: 133px; height: 116px; display:inline; overflow:visible;"></div>
and replace it with this code:<img src="https://nationalcdp.org/wp-content/uploads/2014/09/feature-me.png" id="sideimage">
. The final code will look like this:Next, you will have to add these styles to the bottom of your stylesheet:
You can adjust the
margin-left
,margin-top
and thewidth
properties assigned to the CSS ofimg#sideimage
as per your liking. Hopefully, this will resolve the issue which you’re facing.