Absolute + float example.
by Joshua Powell
HTML
<div class="wrapper">
<div class="float"></div>
<div class="inline"></div>
<div class="block"></div>
</div>
<div class="btnFrame">
<span class="btn1">Click for float view</span><br /><br />
<span class="btn2">Click for inline-block + absolute view</span>
<span class="btn3">Click for block view</span>
</div>
CSS
.wrapper {
width: 50%;
min-height: 30px;
margin: 0 auto;
background: mediumSeaGreen;
}
.block {
display: none;
background: brown;
height: 4em;
width: 4em;
}
.float {
display: none;
float: right;
background: brown;
height: 3em;
width: 3em;
}
.inline {
display: none;
position: absolute;
top: 0;
left: 50%;
background: brown;
height: 3em;
width: 3em;
}
.btn1 {
display: block;
position: absolute;
bottom: 250px;
left: 25px;
width: 20%;
padding: 5px;
background: #ff9900;
text-align: center;
box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.btn1:active {
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
bottom: 249px;
left: 26px;
}
.btn2 {
display: block;
position: absolute;
bottom: 150px;
left: 25px;
width: 30%;
padding: 5px;
background: #ff9900;
text-align: center;
box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.btn2:active {
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
bottom: 149px;
left: 26px;
}
.btn3 {
display: block;
position: absolute;
bottom: 50px;
left: 25px;
width: 20%;
padding: 5px;
background: #ff9900;
text-align: center;
box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.btn3:active {
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
bottom: 49px;
left: 26px;
}
JavaScript
$('.btn1').on('click', function() {
$('.float').stop(true).slideToggle();
});
$('.btn2').on('click', function() {
$('.inline').stop(true).slideToggle();
});
$('.btn3').on('click', function() {
$('.block').stop(true).slideToggle();
});