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

LVL 1
FaheemAhmadGulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SniperCode ShevaCommented:
try this code :

<div style="z-index:1; position:absolute;">
    <input type="button" height="90" style="width:400px; background-color: red;" value="I am in behind" />
</div> 
<div style="z-index:2; position:absolute;">
    <input type="button" height="90" style="width:400px; background-color: green;" value="I am in front" />
</div> 

Open in new window

0
Julian HansenCommented:
Why not just hide the first element

.elementId {
   display: none;
}

Open in new window

0
Julian HansenCommented:
Working sample
CSS
<style type="text/css">
.buttons div:first-child {
  display: none;
}
</style>

Open in new window

HTML
<div class="buttons">
  <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> 
</div>

Open in new window


Working sample here
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

FaheemAhmadGulAuthor Commented:
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.
0
Julian HansenCommented:
I would like to achieve this without using absolute positioning.
Just pointing out the first solution uses absolute positioning

Otherwise you are most welcome.
0
FaheemAhmadGulAuthor Commented:
Thank you Julian. I realise that now. The first solution did not fully answer my question. Many thanks again for you kind help.
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WPF

From novice to tech pro — start learning today.