Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Using HTML5 and CSS How to place one element in front of another elemen

In an HTML5 page I would like to put one element exactly in front of another so that it completely covers the one which is behind.
So in the HTML code I have put in the code window I would like the user to see only the the element which is in front. I would like to achieve this without using absolute positioning.

In WPF application, using XAML I can achieve this very easily. So if have a Grid Cell and put a a button in it and then put another button in the same cell. The second button completely overlaps the first button. I would like to achieve the same kind of thing in HTML5 and would appreciate guidance on how to achieve this.
At the moment on my page red and green button are displayed one above another. I would like the green button to completely overlap red button.

To clarify my question I am putting a XAML example with HTML code.
<div>
    <input type="button" height="90" style="width:400px; background-color: red;" value="I am in behind" />
</div> 
<div>
    <input type="button" height="90" style="width:400px; background-color: green;" value="I am in front" />
</div> 


// In the WPF XAML example Button two will completely overlap button one. 


<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"></RowDefinition>
            <RowDefinition Height="1*"></RowDefinition>
        </Grid.RowDefinitions>

       
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" ></ColumnDefinition>
                <ColumnDefinition Width="1*" ></ColumnDefinition>
                
            </Grid.ColumnDefinitions>
<Button Name="One" Grid.Row="0" Grid.Column="0" ></Button>
<Button Name="Two" Grid.Row="0" Grid.Column="0" ></Button>
</Grid>

Open in new window

* WPFHTMLCSS

Avatar of undefined
Last Comment
Julian Hansen
SOLUTION
Avatar of SniperCode Sheva
SniperCode Sheva

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of FaheemAhmadGul

ASKER

Many thanks. I am very grateful. Both solutions were helpful, but as Julina's solution was more thorough with a working a example, I found it more helpful. I was away from my desk hence some delay in accepting the solutions.
Thank you very much again.
I would like to achieve this without using absolute positioning.
Just pointing out the first solution uses absolute positioning

Otherwise you are most welcome.
Avatar of FaheemAhmadGul

ASKER

Thank you Julian. I realise that now. The first solution did not fully answer my question. Many thanks again for you kind help.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

You are welcome.
HTML
HTML

HTML (HyperText Markup Language) is the main markup language for creating web pages and other information to be displayed in a web browser, providing both the structure and content for what is sent from a web server through the use of tags. The current implementation of the HTML specification is HTML5.

62K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo