0

Q1

How can I centre the text <h1>Welcome to Liam Docherty's Digital Portfolio</h1> in line with the navigation bar text?

Q2

How can I make a <DIV> to represent a background image?

I dont want to make section 1 the background image for various reasons this is why I want to make a <DIV> it's own background image. I tried to to use the HTML div class="hero"></div> with the CSS below. However, nothing happens.

.hero {
      background-image: url("https://static.pexels.com/photos/48727/pexels-photo-48727.jpeg");
      background-attachment: fixed;
    }

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">Welcome to 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="hero"></div>

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

    </section>
    <section id="section2" class="section2">


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

    </section>

    <section id="contact-me" class="contact_section section3">

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

    </section>
    <script   src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="   crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<footer>
    <div class="page">
        <h1 class="footer">Copyright © 2017 Liam Docherty's Site. All rights reserved.</h1>
    </div>
 </footer>     
</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;
    }
    nav-title {
        display: block;
        margin: 0 auto; /*auto will do the centering trick*/
        width: 80%; /*or any width*/
        position: relative;
    }
    .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:
    }
    h1{
      font-size: 14pt;
      margin:0;
      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>

2 Answers2

0

To take your second question first - the hero element as you have it does not have any height - that's why the image does not show. If you would like the image to display as a background on the full height, you could add these elements to your .hero style: position:absolute; height:100%; width:100%;

When I copy and paste your code into a plain file, the navigation does not display expanded, so it's hard to answer question 1. The text in the H1 is already centered against the page itself. If you can provide a URL or codepen, it will be easier to answer this bit.

Jonny Perl
  • 133
  • 6
  • Hi, thanks for your help. Here is my codepen. I have also tested your answer for Q2 and it works thanks a lot! –  Mar 15 '17 at 11:33
  • If I use CSS it should look like this `.title { font-family:'Roboto', sans-serif; color:white; font-size:10pt; text-align:center; }` –  Mar 15 '17 at 11:56
0

Q2: The reason why nothing happens is because by default any DIV height and width are 0px, so you have to explicitly mention the hight and the width. If you want the hero image to be 100% of the height and 100% of the width, I would recommend using vw(viewport width) and vh(viewport height values)for that in your CSS, where 100vw means 100% of the viewport width (same logic for height). Like here:

.hero {
  background-image: url("https://static.pexels.com/photos/48727/pexels-photo-48727.jpeg");
  background-attachment: fixed;
  position: fixed;
  width: 100%;
  width: 100vw;
  height: 100%;
  height: 100vh;
}

values in percentages are for backwards compatibility.

Q1: Put the h1 inside if a div and center it:

<div>
  <h1>Welcome to Liam Docherty's Digital Portfolio</h1>
</div>

CSS:

div{
 display: block;
 margin: 0 auto; /*auto will do the centering trick*/
 width: 80%; /*or any width*/
 position: relative;
}

The div has to be outside of the nav container.

margarita
  • 884
  • 1
  • 10
  • 21
  • Hi, thanks for the feedback. I have tested your answer and it works thanks! Any ideas about the other question Q1?? –  Mar 15 '17 at 11:35
  • Can you provide the picture of what kind of alignment you want? – margarita Mar 15 '17 at 11:36
  • Just Q1 was my last question, if your happy to do it add it to your answer and I'll vote it as the answer. My Q1 was how can I centre the text

    Welcome to Liam Docherty's Digital Portfolio

    in line with the navigation bar text?"
    –  Mar 15 '17 at 11:40
  • I will be able to do that once i see the picture of what exactly you want it to look like. – margarita Mar 15 '17 at 11:42
  • http://codepen.io/ldocherty1/pen/WRJaXO. Here is an example where the text is in line with the navigation bar and in the centre. Thats how I want to look like. –  Mar 15 '17 at 11:45
  • Where would I place the HTML of the H1 within my nav bar HTML code? –  Mar 15 '17 at 12:01
  • Do you need to place it inside of nav? – margarita Mar 15 '17 at 12:05
  • Because it is h1, it is usually bad practice to put it inside nav. I would place it right after nav element. – margarita Mar 15 '17 at 12:05
  • Correct. If I call it "DIV" doesn't it also affect the other "DIV" within my code? –  Mar 15 '17 at 12:06
  • yes, div is every div in your code, so you should give it a class. – margarita Mar 15 '17 at 12:07
  • Doesn't seem to work I'll update my code in the post and can you point me out in the right direction please? –  Mar 15 '17 at 12:23
  • First of all, delete the – margarita Mar 15 '17 at 12:48
  • [example](http://i1126.photobucket.com/albums/l611/ldocherty1/Screen%20Shot%202017-03-15%20at%2017.25.21_zpsjipjrwcy.png) the orange box is where I want the text to be placed. Sorry if I didn't explain myself properly. –  Mar 15 '17 at 17:47
  • What do you want it to look like on mobile then? – margarita Mar 16 '17 at 11:24