Sunday, March 29, 2015

Positioning with CSS

Hi again,
#menu1{          /*this is a grandpa*/
    background-color: white;
    position: relative;/*this is for the logo balls to refer to this bar in positioning*/
    height: 15em;
}
#menu_pos{    /*this is a parent*/
    position: absolute;
    left: 50%;   
    top: 50%;/*at a certain position through relative to grandpa*/
    height: 3em;
...
}
.menu{            /*this is a child*/
    display: inline-block;
    position: relative;
    top: 5%; /*this is relative to the parent, not grandpa! Even though grandpa is relative!*/
    /*another note: this top positioning depends on the parent having a 'height'! I.e. if "height: 3em;" was commented in the parent then "top: 5%;" here will be ignored*/
    width: 7em;   
    height: 3em;
}