Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

My elements in a menu seem to have no width?

Tags: height width ease

My elements in a menu seem to have no width?

Problem

see this codepen for a demo

EDIT of course, hard coding a Width for an element is no solution. It should be just the size of the actual title.

HTML


css

/** the newsfeed and footer */
nav {
    width: 100%;
    height: 20px;
    position: relative;
}

.navfake {
    width: 100%;
    height: 100%;
    background: green;
    z-index: 10;
    position: relative;
}

.singleelement {
    display: inline-block;
    height: 60px;
    text-align: center;
}

.container {
    position: absolute;
    top: 0px;
    -webkit-transition: all .8s ease;
    -moz-transition: all .8s ease;
    -ms-transition: all .8s ease;
    -o-transition: all .8s ease;
    transition: all .8s ease;
    height: 200px;
}

.titlepicture {
    position: absolute;
    width: 100%;
    background-color: red;
    z-index: 10;
    height: 100px;
    overflow: hidden;
}

.container:hover {
    top: -80px;
}

.container:hover .titlepicture {
    height: 100px;
    z-index: 10;

}

.title {
    z-index: 555;
    position: relative;
    height: 20px;
    width: 100%;
}

.footer {
    position: relative;
    z-index: 1000;
    background-color: white;
}
Problem courtesy of: Toskan

Solution

The trick was to replace position absolute with position relative

HTML


CSS

/** the newsfeed and footer */
nav {
    width: 100%;
    height: 20px;
}

.navfake {
    width: 100%;
    height: 100%;
    background: green;
    z-index: 10;
    position: relative;
}

.singleelement {
    display: inline-block;
    height: 60px;
    text-align: center;
    position: relative;
}

.container {
    top: -20px;
    position: relative;                 /**changed*/
    -webkit-transition: all .8s ease;
    -moz-transition: all .8s ease;
    -ms-transition: all .8s ease;
    -o-transition: all .8s ease;
    transition: all .8s ease;
    height: 200px;
}

.titlepicture {
    position: absolute;
    background-color: red;
    z-index: 10;
    height: 100px;
    overflow: hidden;
}

.container:hover {
    top: -80px;
}

.container:hover .titlepicture {
    height: 100px;
    z-index: 10;

}

.title {
    z-index: 555;
    position: relative;
    height: 20px;
    width: 100%;
}

.footer {
    position: relative;
    z-index: 1000;
    background-color: white;
}
Solution courtesy of: Toskan

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

My elements in a menu seem to have no width?

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×