473,379 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

4 common methods to overlap 2 images in CSS? any more method? (orelse use a program)

It seems like there are only 4 methods to overlap 2 images using CSS?

There are two images, each with its own URL. Using CSS, there seems to
be 2 ways to overlap them (the task is actually to put a "play button"
image with size 50 x 50 on top of the bigger image which is a video
thumbnail size 200 x 150).

1) Use <div><img ><img ></divwith the play button as the second
image and displayed relatively positioned to overlap the first image.
The div better have enough width so that the second img won't wrap to
the next line.

2) use a div that is relatively positioned without modifying the top
and left value. enclose the video thumbnail image inside of it first,
and then enclose the play button image which is absolute positioned
with some top and left value. Now the 2nd image is absolutely
positioned relative to the outer div.

3) and 4) are suggested by someone

3) use negative margin. this is very similar to (1). will try that
as relative positioning have problem on both IE 6 and 7 (pls see post
http://groups.google.com/group/comp....89f1d55?hl=en#
)

4) use an image that has a background. looks like that's very
possible, but somehow is it true that we cannot easily size the 2
images and position them easily. (for example, how do you position
the play button on the video thumbnail?) one easy method might be to
make them the same size, and with the top image have a lot of
transparent area to achieve the top margin and left margin for the top
image.

Or else, use a PHP program or something similar that can do GD or
ImageMagick, and overlap the smaller image onto the other image, and
then return the resulting image as a single image.

Any other method possible? The PHP method probably works the simplest
for HTML and CSS design coz the final image is really a single image,
but it would take up a lot of CPU time on the servers. Thanks very
much for your help!
Aug 22 '08 #1
5 10847

liketofindoutwhy wrote:
It seems like there are only 4 methods to overlap 2 images using CSS?
I never counted, but there are indeed multiple ways, probably several
more than 4.
There are two images, each with its own URL. Using CSS, there seems to
be 2 ways to overlap them (the task is actually to put a "play button"
image with size 50 x 50 on top of the bigger image which is a video
thumbnail size 200 x 150).
Piece of cake, really.
4) use an image that has a background.
This one get my vote. One way to do it:

div {
background: #fff url(img1.png);
color: #000;
width: 200px;
height: 150px;
text-align: center;
}
img {
margin-top: 50px;
}

<div><img src="img2.png" width="50" height="50" alt="Play"></div>
is it true that we cannot easily size the 2
images and position them easily.
You cannot resize a background image, at least not at this time. Make
the containing div the same dimensions as the background image. If the
background isn't the size you need, resize it in a graphics editor first.

Positioning the foreground image is easy peasy.
(for example, how do you position
the play button on the video thumbnail?)
This is a case where absolute positioning might be useful, but you can
do it just as easily without, just using margin on the <imgor even
padding on the containing <div>

--
Berg
Aug 22 '08 #2
On Aug 22, 4:02*pm, Bergamot <berga...@visi.comwrote:
This one get my vote. One way to do it:

div {
* background: #fff url(img1.png);
* color: #000;
* width: 200px;
* height: 150px;
* text-align: center;}

img {
* margin-top: 50px;

}

<div><img src="img2.png" width="50" height="50" alt="Play"></div>
i see... one reason this has problem is that if a link a wrapped
around the final result, IE won't take the whole thing as the link.
the play button is excluded from the link. some more info on
http://groups.google.com/group/comp....89f1d55?hl=en#
Aug 22 '08 #3

liketofindoutwhy wrote:
On Aug 22, 4:02 pm, Bergamot <berga...@visi.comwrote:
>>
<div><img src="img2.png" width="50" height="50" alt="Play"></div>

one reason this has problem is that if a link a wrapped
around the final result, IE won't take the whole thing as the link.
Sure it will, if you apply the right rules. You had the right idea in
your other post (with the span display:block), you just applied them
kind of backwards.

Put the <aelement in there and make it display:block. You might need
to add a couple more rules, but that should make the inline <afill the
parent div.

--
Berg
Aug 23 '08 #4
On Aug 22, 8:02 pm, Bergamot <berga...@visi.comwrote:
liketofindoutwhy wrote:
On Aug 22, 4:02 pm, Bergamot <berga...@visi.comwrote:
<div><img src="img2.png" width="50" height="50" alt="Play"></div>
one reason this has problem is that if a link a wrapped
around the final result, IE won't take the whole thing as the link.

Sure it will, if you apply the right rules. You had the right idea in
your other post (with the span display:block), you just applied them
kind of backwards.

Put the <aelement in there and make it display:block. You might need
to add a couple more rules, but that should make the inline <afill the
parent div.
now, could it be an IE bug, as IE clearly shows the target link on the
status line of IE, but clicking that play button has no effect.

I don't quite see how right now it is backward... and put the <a>
element there? I thought it is already there.... you mean change <a>
to display:block? i thought in reality, <ais not displayed but is
just to indicate a link. i am sorry, do you think you can give an
example?
Aug 24 '08 #5

liketofindoutwhy wrote:
On Aug 22, 8:02 pm, Bergamot <berga...@visi.comwrote:
>liketofindoutwhy wrote:
On Aug 22, 4:02 pm, Bergamot <berga...@visi.comwrote:
><div><img src="img2.png" width="50" height="50" alt="Play"></div>
one reason this has problem is that if a link a wrapped
around the final result, IE won't take the whole thing as the link.

Put the <aelement in there and make it display:block.

now, could it be an IE bug, as IE clearly shows the target link on the
status line of IE, but clicking that play button has no effect.
IE has lots of bugs, among which is how it handles replaced elements
like <img>, and switching elements from inline to block.
i thought in reality, <ais not displayed but is
just to indicate a link.
Not sure what you mean by that. <ais an inline element, so it is
display:inline by default.
http://www.w3.org/TR/CSS21/visuren.html#display-prop

There is a lot more info on that page about inline and block elements,
among other things.
i am sorry, do you think you can give an
example?
Didn't somebody else already give you a working solution?

--
Berg
Aug 26 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
9
by: Mike Meyer | last post by:
Another thread pointed out a couple of methods that would be nice to have on Python collections: find and inject. These are taken from <URL:...
23
by: George | last post by:
Is there a way to customize the open file common dialog? I am trying to modify the button text so I can create a delete file common dialog. I need the same functionality of the open file common...
7
by: Byron | last post by:
I have several user controls that have a few methods in common, such LoadFromForm() which populates an object from controls on the form. I want to call that method from the form in which the...
5
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. ...
8
by: Arno R | last post by:
Hi all. When I need to search for pictures, I always have too choose thumbnail-view manually. Is it possible to open the common dialog in thumbnail-view programmatically? Example ?? At the...
4
by: Christopera | last post by:
Hello, I have built a site that uses two divs, one verticle, and one horizontal as graphic style for the ite. The problem I am having is that if the browser is resized very small the divs are...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.