tfhall4
tfhall4

Reputation: 47

Aligning Div inside another Div

You can visit the site I am working on here. Currently, I am working on making the site relative. I am adjusting the CSS for a resolution with a width less than 820px. This involves adjusting the menu from this pic of navigation at wide resolution

to this pic of navigation at narrow resolution. As you can see, I have outlined my divs with a red border to demonstrate the problem. I want to the menu bar to sink to the bottom of its parent div. However, setting it to bottom: 0 nothing changes. How can I get the div class="nav" to sink to the bottom of div class="header" at a resolution of less than 820px?

Here is my HTML

<div class="header">
        <div id="narrow-logo"><a href="#"><img src="Images/pantry logo.png" width="536" height="348"></a></div>
        <div class="nav">
                <ul>
                    <li class="link"><a href="#">HOME</a></li>
                    <li class="link"><a href="#">MENU</a></li>
                    <li id="logo"><a href="#"><img src="Images/pantry logo.png" width="536" height="348"></a></li>
                    <li class="link"><a href="#">CONTACT</a></li>
                    <li class="link"><a href="#">ABOUT</a></li>
                </ul>        
           </div>
      </div>

And my CSS

.header {
    width: 960px;
    height: 150px;
    margin: 0 auto;
    text-align: center;
    position: relative;
    padding: 100px 0px 0px 0px;
}

.header div#narrow-logo {
    display: none;
}

.nav ul li {
    display: inline-block;
        vertical-align: middle;
    margin-right: 70px;
}

#logo a img {
    max-width: 250px;
    height: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%,-50%);
    transform: translate(-50%,-50%);
}

#logo { 
    width: 250px; 
    position: relative;
}

@media screen and (max-width: 1080px) {
.header {
    width: 700px;
    height: 125px;
    padding: 75px 0px 0px 0px;
}

#logo a img {
    max-width: 180px;
}

#logo { 
    width: 180px; 
}

@media screen and (max-width: 820px) {
.header {
    border: 2px solid red;
    width: 475px;
    padding: 0;
    margin-top: 40px;
    height: 200px;
}

.header div#narrow-logo {
    border: 2px solid red;
    display: inherit;
    position: absolute;
    left: 50%;
    -webkit-transform: translate(-50%);
    transform: translate(-50%);
}

.header div#narrow-logo a img {
    width: 200px;
    height: auto;
}

.nav {
    border: 2px solid red;
    bottom: 0px;
}

.nav ul li {
    margin-right: 25px; 
}

.nav ul li:nth-child(3) {
    display: none;
}

#logo a img {
    display: none;
}

#logo { 
    width: 0; 
}

I know that is a lot of code and I apologize. I just wanted to make sure I included all positioning attributes that could be causing my issue. Let me know if I can clarify anything, and I appreciate your time and advice.

Upvotes: 2

Views: 102

Answers (3)

Davion
Davion

Reputation: 911

For bottom:0; to work, your class="nav" has to have absolute positioning.

CSS:

.nav {
position: absolute;
bottom: 0;

Upvotes: 0

Binita Lama
Binita Lama

Reputation: 1278

Adding position value will resolve your issue.Please update your css in the following section.

@media screen and (max-width: 820px) {
.nav {
border: 2px solid red;
bottom: 0px;
position:absolute;
left:16%;
}
}

Upvotes: 0

Kelderic
Kelderic

Reputation: 6697

For bottom:0 to work, you need the element that it's being applied to to be absolutely positioned. You also need, in this case, to have it's parent relatively positioned. Try this:

.nav ul li {
    display: inline-block;
    margin-right: 70px;
    position:absolute;
    bottom:0;
}

Upvotes: 1

Related Questions