0

Q1

How I can put an image in the center over a background image?

I'm trying to put the image <div class="shape"></div> over the image <div class="hero"></div> within the center. What coding can I add to move it up and down to my needs?

Q2

Below the <div class="shape"></div> image I want to put a rectangle shape box below within the center. Within this CSS what code do I need to add to for me to move the shape up and down. Furthermore, within the CSS would I use height:; & width:; to change the height/width of the box?

HTML

 <body>
        <nav class="navbar navbar-default navbar-fixed-top"> 
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"><img src="http://placehold.it/60x60" alt="Your Brand Name"></a>
                    <h1 class="nav-title">Liam Docherty's Digital Portfolio</h1>
                </div>
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                            <li><a href="#">Home</a>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">About Me <span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">Action</a>
                                    </li>
                                    <li><a href="#section3">Contact</a>
                                    </li>
                                    <li><a href="#">Something else here</a>
                                    </li>
                                    <li><a href="#">Separated link</a>
                                    </li>
                                    <li><a href="#">One more separated link</a>
                                    </li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Units <span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">Action</a>
                                    </li>
                                    <li><a href="#">Another action</a>
                                    </li>
                                    <li><a href="#">Something else here</a>
                                    </li>

                                    <li><a href="#">Separated link</a>
                                    </li>

                                    <li><a href="#">One more separated link</a>
                                    </li>
                                </ul>
                            </li>
                            <li><a href="#">Clients</a>
                            </li>
                            <li><a href="#contact-me">Contact Me</a>
                            </li>
                        </ul>
                      </div><!-- /.navbar-collapse -->
                    </div><!-- /.container-fluid -->
        </nav>


    <section id="section1" class="section1">
      <div class="shape"></div>
      <div class="hero"></div>


      <a href="#section2"><i class="fa fa-angle-down" style="font-size:100px;"></i></a>

    </section>

</body>

CSS

<style>
    body {
      margin: 0;
      padding: 0;
    }
    .navbar.navbar-default {
      background-color: #4D5061;
      height: 10vh;
      z-index: 100;
    }
    .navbar.navbar-default ul {
      list-style-type: none;
      text-align: right;
    }
    .navbar.navbar-default ul li {
      display: inline-block;
    }
    .dropdown-menu li { 
        text-align:center 
    }
    .dropdown .dropdown-menu {
      background-color: #4D5061;
    }
    .dropdown .dropdown-menu a {
      color: white;
    }
    .navbar.navbar-default ul li a {
      display: inline-block;
      padding: 3.5vh 8px 4px;
      color: white;
      text-decoration: none;
      font-size: 14pt;
      font-family: 'Roboto', sans-serif;
    }
    .navbar.navbar-default ul li:after {
      content: '';
      position: absolute;
      right: 50%;
      bottom: 0;
      left: 50%;
      height: 3px;
      background-color: #FFFFFF;
      border-radius: 9px;
      transition: all .2s;
    }
    .navbar.navbar-default ul li a:hover {
      color: white;
    }
    .nav.navbar-nav,
    .nav.navbar-nav>li {
      float: none;
    }
    .navbar.navbar-default ul li:hover:after {
      right: 0;
      left: 0;
    }
    .nav>li>a:hover {
    background-color: rgba(17, 17, 17, 0.2);
    }
    #logo {
      padding-top: 2vh;
      padding-left: 20px;
      float: left;
    }
    .shape {
      content:url(http://i1126.photobucket.com/albums/l611/ldocherty1/IMG_0730_zpsiz4dqc47.jpg);
      border-radius: 25px;
      background:darkgrey;
      color:white;
      padding:3px;
      margin:50px auto 0 auto;
      width:150px;
      height:150px;
    }
    .hero {
      background-image: url("https://static.pexels.com/photos/48727/pexels-photo-48727.jpeg");
      background-attachment: fixed;
      position:absolute;
      width: 100%;
      width: 100vw;
      height: 100%;
      height: 70vh;
    }
    section {
      position: relative;
      height: 95vh;
    }
    .section1 {
      height: 100vh;
      text-align: center;
      color: white;
    }
    .section2 {
      //height: 95vh;
      background-color: #11B5E4;
      text-align: center;
      color: white;
    }
    .section3 {
      //height: 95vh;
      background-color: #EDF7F6;
      text-align: center;
      color: white;
    }
    .fa-angle-down {
      color: #4D5061;
      position: absolute;
      bottom: 0px;
    }
    .fa-angle-up {
      color: #4D5061;
      position: absolute;
      bottom: 0px;
    }
    .footer {
      height: 5vh;
      background-color: #4D5061;
      text-align: center;
      padding:0;
      right:0;
      bottom:0;
      left:0:
    }
    .nav-title {
      font-size: 14pt;
      margin:0;
      top: 32px;
      left: 50px;
      width: 100%;
      position: absolute;
      text-align: center;
      color: white;
      font-family: 'Roboto', sans-serif;
    }
    .navbar.navbar-default ul.dropdown-menu li,
    .navbar.navbar-default ul.dropdown-menu li a {
      position: relative;
      display: block;
    }
    </style>
Johannes
  • 64,305
  • 18
  • 73
  • 130
  • Any ideas anyone? –  Mar 16 '17 at 20:08
  • http://i1126.photobucket.com/albums/l611/ldocherty1/Slide1_zpsz1p6xxos.jpg Does this help explain what I'm trying to do? Here is an example. –  Mar 16 '17 at 20:36
  • Possible duplicate of [How to overlay one div over another div](http://stackoverflow.com/questions/2941189/how-to-overlay-one-div-over-another-div) – Rob Mar 16 '17 at 21:25
  • 1
    Next time please try and reduce the code down to just what is needed to demonstrate your issue. Do we really need all the nav code for this issue? – Jon P Mar 16 '17 at 23:07

1 Answers1

2

To put one DIV over another DIV you put the one that should appear on top (= the child) INTO the other one (= the parent element), for example

<div class="x1"><div class="x2">...content...</div></div>

The most important CSS settings for these are:

div.x1 {
  position: relative;
}
div.x2 {
  position: absolute;
  top: 30px;
  left: 50px;
  width: 100px;
  height: 50px;
}

All the px values above are completely random, they depend on your actual situation - adjust them as you need it. But you do need these or similar parameters for the second div.

Also an additional rectangle could handled the same way (like div.x2).

In addition you can assign a background (can be only a color value) to those absolutely positioned DIVs to actually cover what is behind them.

Addition after comment, concerning the codepen:

  • You did it the other way in HTML - shape has to be inside hero

  • CSS: absolute/relative: other way around.

For the rest, look at the code in http://codepen.io/anon/pen/JWONgz

Johannes
  • 64,305
  • 18
  • 73
  • 130
  • Hi, thanks for your feedback and time. http://codepen.io/ldocherty1/pen/yMPbwp Where has my background picture gone of the macbook? I'm trying to put the photo of me over the macbook. I'll award that the answer after this is sorted. After the photo of me is over the background pic how could I move it down? –  Mar 16 '17 at 22:50
  • 1
    see the addition to my answer – Johannes Mar 16 '17 at 23:03