One of the major problems people facing while designing HTML layouts using CSS is the overlapping issue. CSS positioning lets you position an HTML object anywhere you like. You can locate an object anywhere you like but it involves great care. By using the CSS positioning attributes like absolute, fixed or relative you often come across a problem where on object overlaps another or blocks the view of another section. In order to bring one div section on front or back of another you will need to use z-index property of CSS. Just like in Adobe Photoshop CS5, z-index lets you to send an element to back or bring it to front. In todays' tutorial we will aim at explaining this property briefly and with clarity.
DEMO: If you carefully observe the floating sharing widget towards your left, you will find that as soon as you reach the footer/bottom of this blog, it hides behind the footer. We applied z-index to so that the widget remains on front near the post body but goes to back as soon as it touches the lower section of the page.
What is z-index?
z-index is a number which can be either positive or negative. The default z-index value is Zero. The object with the highest z-index value appears on top, followed by the next the element with second highest z-index value and the element with lowest z-index will appear behind all others. If two elements have similar z-index value the web browser will layer them in the order they appear in the HTML code.
W3schools says:
The z-index property specifies the stack order of an element.
An element with greater stack order is always in front of an element with a lower stack order
How it works?
You may find the following tool important in understanding how it works. z-index only works on positioned elements like (position:absolute, position:relative, or position:fixed). In our case in order to push the floating widget to back and keep footer on front we gave the sharing widget a value smaller than the footer.
For Sharing widget we kept it default. We did not added any code to it. The default z-index value is always 0. But for the footer we used:
position:relative;
z-index:9999;
9999 is the maximum value I choose for the object that I want to appear above all. I used the same concept for the sticky bar above. You may set position to absolute if you don't know what to choose else you will choose position parameters depending upon your requirement.
Take a look at the following example: Below five elements have different stack order
A z-index:150;
B z-index:30;
C z-index not set
D z-index:-30;
The order in which they will appear is:
1. A
2. B
3. C
4. D
D will appear behind all four elements while A will appear on top of all. C has not z-index set so by default the value assigned to it is zero.
What should you do now?
Check the elements on your blog or website and see which elements is blocking the view of others and which elements should appear on top of others. Inside the style code for each just add position and z-index properties to them accordingly to make things look neat and clean.
Need Help?
If you need my help in finding the codes then feel confident to post your query in the comment box below. Today's post was meant to help most of you this important yet simple problem that would make your blog design look even better. I will be sharing such CSS tips in order to help you with designing basics. I do humbly apologies for not posting frequently after 6th June onwards you will find a flood of exciting posts every day. Till tomorrow take good care of your loved ones and yourself. Peace and blessings pals. : )
Filed Under: CSS and HTMLTricks, Web Designing
If you don't want to get yourself into Serious Technical Trouble while editing your Blog Template then just sit back and relax and let us do the Job for you at a fairly reasonable cost. Submit your order details by Clicking Here »









19 comments:
Thanks for this great post.
I have searched a lot before on this problem and now its on mbt
Hey mohemed i need your help please how can i show the facebook comment without opening the post this is my blog http://damnlolpicture.blogspot.co.uk/
Thanks
hey interesting technical post....keep it up...Killer Ways Use By Google to Detecct Invalid clicks Activity
@probloggerstricks
nah...try not copy all of Mohammad's style my friend :(
@Gratitudewhat u mean
Thanks for another beautiful post. I am learning many things day by day just following your articles.
I blog @ Manidipa's Kitchen
So Nice Info For Z-index ..Its Clearly
nice information...thanks for the post
Awesome Blogging Tips
Nice tutorial bro :)
Your knowledge about HTML is surely too immense.
Thanks and keep us updating like this :)
Wow this is cool
http://www.technosupers.com
Technosupers
How to use dotted line for headings in post as u r using ? and i am using same template u r using plz reply soon.
Thank you !
Wow i got it :D
http://facebookjokers.blogspot.com
TechNosupers
This is my school. I, learning everything here! Thank you to whoever make all this post. LetraMania0919
I am really glad that most of your found it helpful. Thanks for the warm feedback. :)
@supreme
Please read this post and once you know what to do remove the codes form the facebook comment plugin code.
http://www.mybloggertricks.com/2011/01/how-to-show-and-hide-widgets-in-blogger.html
@admin
Please read http://www.mybloggertricks.com/2009/11/change-heading-style-in-blogger.html
Your contents are progressing with days keep it up guys.
Web Development
Nice Post pal :D
How To Make A Contact Form For Blogger
I am so grateful to read this such a wonderful post. Thank you for discussing this great topic. I really admire the writer for allotting their time for this impressive article. Thank you.
Web developer
This so helpful for me..
Click Here To add Comment
Your feedback is always appreciated. We will try to reply to your queries as soon as time allows.
Note:
1. To add HTML CODE in comments then please use our HTML Encoder
2. You can always Test the tutorial on our HTML Editor
3. No cheesy/spam Comments tolerated Spam comments will be deleted immediately upon our review.
Regards,
Mohammad