实现CSS Sidenav和内容

时间:2015-10-08 06:12:48

标签: html css css3 materialize

我正在使用Materialize CSS设计我的投资组合并现在遇到一些问题。我的网站现在寻找的截图是这样的:

enter image description here

正如您所看到的,关于部分位于导航下方,这是我的问题。我希望它向右移动,以便可以看到它。我现在的代码是:

<!DOCTYPE html>
<html>
  <head>
    <!--Import Font awesome Icon Font-->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <!--Import materialize.css-->
    <link type="text/css" rel="stylesheet" href="css/materialize.css"  media="screen,projection"/>
    <link type="text/css" rel="stylesheet" href="css/style.css" />
    <!--Let browser know website is optimized for mobile-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  </head>
  <body>
    <header>
      <ul id="staggered-list" class="side-nav fixed grey darken-4 blue-grey-text text-lighten-4 go">
        <br />
        <div style="text-align:center;" id="profilepic">
          <img src="./images/robertsoriano.jpg" alt="" class="circle responsive-img" width="200"> <br />
          Robert Soriano
        </div>
        <br /> <br />
        <li><a  class="grey-text text-lighten-2" href="#"><i class="fa fa-user fa-2x fa-fw"></i>Home</a></li>
        <li><a id="links" class="pink-text lighten-2" href="#"><i class="fa fa-terminal fa-2x fa-fw"></i>Projects</a></li>
        <li><a id="links" class="green-text text-lighten-2" href="#"><i class="fa fa-bar-chart fa-2x fa-fw"></i>Skills</a></li>
        <li><a id="links" class="yellow-text text-lighten-2" href="#"><i class="fa fa-graduation-cap fa-2x fa-fw"></i>Education</a></li>
        <li><a id="links"class="blue-text text-lighten-2" href="#"><i class="fa fa-code fa-2x fa-fw"></i>Source Codes</a></li>
      </ul>
    </header>
    <main>
      <div class="section">
        <div class="container">
          <div class="row">
            <div class="col s12 m9">
              <h1 class="header center-on-small-only">About</h1>
              <h4 class ="light red-text text-lighten-4 center-on-small-only">Learn about the Material Design and our Project Team.</h4>
            </div>
          </div>
        </div>
      </div>
    </main>
    <!--Import jQuery before materialize.js-->
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/materialize.min.js"></script>
    <script>
      $(document).ready(function() {
      Materialize.fadeInImage('#profilepic');
      Materialize.showStaggeredList('#staggered-list');
      });

    </script>
  </body>
</html>

的style.css

body {
    background-image: url("../images/small_steps.png");
    background-color: #cccccc;
}

.go a:before,
.go a:after {
    display: inline-block;
    opacity: 0;
    -webkit-transition: -webkit-transform 0.3s, opacity 0.2s;
    -moz-transition: -moz-transform 0.3s, opacity 0.2s;
    transition: transform 0.3s, opacity 0.2s;
}

.go a:before {
    margin-right: 10px;
    content: '[';
    -webkit-transform: translate(20px);
    -moz-transform: translate(20px);
    transform: translate(20px);
}

.go a:after {
    margin-left: 10px;
    content: ']';
    -webkit-transform: translate(-20px);
    -moz-transform: translate(-20px);
    transform: translate(-20px);
}

.go a:hover:before,
.go a:hover:after,
.go a:focus:before,
.go a:focus:after {
    opacity: 1;
    -webkit-transform: translate(0px);
    -moz-transform: translate(0px);
    transform: translate(0px);
}

小提琴:https://jsfiddle.net/ugwwxk64/

任何帮助都会非常感激。谢谢。

3 个答案:

答案 0 :(得分:8)

仅当屏幕高于991px时才会发生重叠。因此,您需要为特定屏幕大小的main元素指定一些填充。

@media (min-width: 991px) {
  main {
    padding-left: 120px;
  }
}

Updated JSfiddle

答案 1 :(得分:1)

试试这个:

<div class="row">

    <div class="col s2">
        <ul id="staggered-list" class="side-nav fixed grey darken-4 blue-grey-text text-lighten-4 go">
    <br />
    <div style="text-align:center;" id="profilepic">
      <img src="./images/robertsoriano.jpg" alt="" class="circle responsive-img" width="200"> <br />
      Robert Soriano
    </div>
    <br /> <br />
    <li><a  class="grey-text text-lighten-2" href="#"><i class="fa fa-user fa-2x fa-fw"></i>Home</a></li>
    <li><a id="links" class="pink-text lighten-2" href="#"><i class="fa fa-terminal fa-2x fa-fw"></i>Projects</a></li>
    <li><a id="links" class="green-text text-lighten-2" href="#"><i class="fa fa-bar-chart fa-2x fa-fw"></i>Skills</a></li>
    <li><a id="links" class="yellow-text text-lighten-2" href="#"><i class="fa fa-graduation-cap fa-2x fa-fw"></i>Education</a></li>
    <li><a id="links"class="blue-text text-lighten-2" href="#"><i class="fa fa-code fa-2x fa-fw"></i>Source Codes</a></li>
  </ul>
    </div>

    <div class="col s10"> 

一些内容......

答案 2 :(得分:1)

我已更新它:https://jsfiddle.net/ugwwxk64/24/

这是我在您的代码中包含的代码:

<style>
    body
    {
        padding-left: 240px;
    }
    @media only screen and (max-width : 992px) 
    {
     body 
     {
        padding-left: 0;
     }
    }
</style>

MaterialiseCSS的sideNav的默认宽度为240px。因此,我添加了padding-left:240px;在体内说从左边移动内容240px。然后,如果屏幕大小小于991px,则@media only屏幕和(max-width:992px)隐藏会将padding-left重写为0。 :)