tfhall4
tfhall4

Reputation: 47

Positioning divs inside other divs

This is what I am trying to code. I am at a loss as to how to get everything positioned within the center of the page. I have to header coded (without hover and other interactions, but I'll handle that later) but the center part is giving me trouble. First, I am not sure why my 'div id="captionbar' is not visible. Secondly, I can't figure out why the border around 'div class="container"' seems to be ignoring the height attribute (600 px) I've given it and merely conforming to the height of the slider (400 px) I have created.

*EDIT* I had typed 'heigth: 600px' by mistake. So now it is bhaving as expected. But the other issues still remain - namely the missing 'div id="captionbar"

I am also not sure how to create the right column within the 'div class=container' with the two boxes to hold content. I know this is rather vague and much to ask, but I'm in an interactive design class at university where the prof. is requiring this homepage to be coded in a week's time and all he offered in the way of teaching were some basic online tutorials. Also, it has to be responsive - so I'm thinking that's way too much to ask of graphic design students who know nothing of code, so any help is greatly appreciated!

Here is my full HTML

<!doctype html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<meta charset="UTF-8">
<title>The Pantry</title>
<link rel="stylesheet" href="reset.css"/>
<link rel="stylesheet" href="stylesheet.css"/>
</head>
<body>
    <div class="header">
        <div class="nav">
            <ul>
                <li><a href="#">HOME</a></li>
                <li><a href="#">MENU</a></li>
                <li id="logo"><a href="#"><img src="Images/pantry logo.png" width="536" height="348"/></a></li>
                <li><a href="#">CONTACT</a></li>
                <li id="last"><a href="#">ABOUT</a></li>
            </ul>        
       </div>
  </div><!--end header-->

<div id="container">
    <div id="slider">
        <figure>
            <img src="Images/hungarian-goulash_10-20-13_1_ca.jpg" width="600" height="400" alt="Hungarian Sausage Goulash"/>
            <img src="Images/G-lasagne-al-forno.jpg" width="600" height="400" alt="Lasagne al Forno"/>
            <img src="Images/5357829-svickova.jpg" width="600" height="400" alt="Svickova"/>
            <img src="Images/pork shoulder.jpg" width="600" height="400" alt="Pork Shoulder with Dumplings"/>
            <img src="Images/hungarian-goulash_10-20-13_1_ca.jpg" width="600" height="400" alt="Hungarian Sausage Goulash"/>
        </figure>

        <div id="captionbar">
            <h1>Test 123</h1>
        </div>

    </div><!--end slider-->

    <div id="menu ad">

    </div><!--end menu ad-->

    <div id="hours">

    </div><!--end hours-->
</div><!--end container-->

<footer>

</footer>

And my CSS

@charset "UTF-8";

body {
    background: #f8f8f1;
    line-height: 1.5;
}

/*header*/


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

div ul li {
    display: inline-block;
    font-family: "Montserrat", "Helvetica", sans-serif;
    font-size: 18px;
    color: #4f4d4b;
    text-decoration: none;
    list-style: none;
    vertical-align: middle;
}

.nav ul li {
    margin-right: 70px
}

.nav ul li:nth-child(5) {
    margin: 0;
}

div ul li a {
    list-style: none;
    text-decoration: none;
    color: #4f4d4b;
}

.nav ul li a:visited {
    text-decoration: none;
    color: #4f4d4b;
}


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

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

/*End Header*/

/*Container*/

    div.container {
    margin: 0 auto;
    position: relative;
    width: 936px;
    height: 600px;
    padding: 10px;
    border: 2px solid #b9aea3;
    }

/*slider*/

@-webkit-keyframes slidy {
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}

div#slider { position: relative; overflow: hidden; width: 80%; max-width: 600px; height: auto; max-height: 400px;
margin: 0 auto}
div#slider figure { 
  position: relative;
  width: 500%;
  margin: 0;
  left: 0;
  font-size: 0;
  animation: 20s slidy infinite; 
  margin: 0; top: 0; left: 0;
  -webkit-animation: 20s slidy ease-in-out infinite;
  animation: 20s slidy ease-in-out infinite; 
 }

 /*slider captions*/

 #captionbar {
     position: relative;
     max-width: 600 px;
     height: 60px;
     background: #f9f4df;
     margin-top: 5px;
 }

Please visit the site here to see what is happening.

Thanks for your help.

Upvotes: 0

Views: 91

Answers (1)

GajendraSinghParihar
GajendraSinghParihar

Reputation: 9131

Check this lab Demo

Check the code here

You have to change below Css

div.container {
    margin: auto 0;
    position: relative;
    width: 960px;
    height: 438px;     /* heigth is what you have written */
    border: 10px solid red;
}

div#slider { 
   position: relative; 
   overflow: hidden; 
   width: 80%; 
   max-width: 600px; 
   height: auto; 
  /* max-height: 460px; */   /*Remove this */
    margin: 0 auto    /* to make the slider content center*/
}

EDIT 1

Please use below code for you #slider

#div#slider {
  margin: auto;
  position: relative;
  overflow: hidden;
  width: 80%;
  max-width: 600px;
}

Note that we also removed float: left;

Upvotes: 1

Related Questions