Carousel(图像滑块)与响应式菜单冲突

时间:2018-03-24 19:30:17

标签: javascript jquery html css

您好亲爱的开发者社区, 我几天前开始编程。我开始为艺术家制作一个主页。

我有一个响应式菜单,当屏幕变小时,会使用按钮转换为下拉菜单。它还具有滚动效果。 添加轮播(图像滑块)时:菜单栏会出现乱码。 我制作了截图,以解决问题:

问题1

enter image description here

菜单栏向右侧移位。应该填写屏幕顶部

问题2

enter image description here

当屏幕变小时,条形图向底部移位
我希望有人可以帮助我解决这个问题。
代码:

html, body {
      margin: 0;
      padding: 0;
      width: 100%;
}
 
body {
      font-family: "Helvetica Neue",sans-serif;
      font-weight: lighter;
}
 
header {
      width: 100%;
      height: 100vh;
      background-color: #111
      background: url(bilder/acrylic/63.jpg) no-repeat 50% 50%;
      background-size: cover;
}
 
.content {
      width: 94%;
      margin: 4em auto;
      font-size: 20px;
      line-height: 30px;
      text-align: justify;
}
 
.logo {
      line-height: 40px;
      position: fixed;
      float: left;
      margin: 16px 46px;
      color: #fff;
      font-weight: bold;
      font-size: 20px;
      letter-spacing: 2px;
      height:40px;
}
 
nav {
      position: fixed;
      width: 100%;
      line-height: 60px;
}
 
nav ul {
      line-height: 40px;
      list-style: none;
      background: rgba(0, 0, 0, 0);
      overflow: hidden;
      color: #fff;
      padding: 0;
      text-align: right;
      margin: 0;
      padding-right: 40px;
      transition: 1s;
}
 
nav.black ul {
      background: #111; opacity: 50%
}
 
nav ul li {
      display: inline-block;
      padding: 16px 40px;;
}
 
nav ul li a {
      text-decoration: none;
      color: #fff;
      font-size: 16px;
      text-transform: uppercase;
      margin: 0 10px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before {
  transition: all .5s;
}
nav ul li a:hover {
  color: #555;
}

 
.menu-icon {
      line-height: 40px;
      width: 100%;
      background: #111;
      text-align: right;
      box-sizing: border-box;
      padding: 15px 24px;
      cursor: pointer;
      color: #fff;
      display: none;
}
 
@media(max-width: 786px) {
 
      .logo {
            position: fixed;
            top: 0;
            margin-top: 16px;
      }
 
      nav ul {
            max-height: 0px;
            background: #111;
      }
 
      nav.black ul {
            background: #111;
      }
 
      .showing {
            max-height: 34em;
      }
 
      nav ul li {
            box-sizing: border-box;
            width: 100%;
            padding: 24px;
            text-align: center;
      }
 
      .menu-icon {
            display: block;
      }
 
}


nav.shift ul li a {
  position:relative;
  z-index: 1;
}
nav.shift ul li a:hover {
  color: #777;
}
nav.shift ul li a:after {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  margin: auto;
  width: 100%;
  height: 1px;
  content: '.';
  color: transparent;
  background: ;
  visibility: none;
  opacity: 0;
  z-index: -1;
}
nav.shift ul li a:hover:after {
  opacity: 1;
  visibility: visible;
  height: 100%;
}

.img {
  min-height: 15%;
}
<!DOCTYPE html>
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Viktoria Nagel</title>
      <link rel="stylesheet" href="css.css">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
      <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
</head>

<body>


<!-- IMAGE SLIDER -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
               
                <div class="carousel-inner">
                    <div class="item active">
                        <img src="https://imgur.com/J5AvznH" alt="First slide">
                        <div class="carousel-caption">
                            <h3>
                                Acrylic</h3>
                            <p>
                                Wildlife, Stillife</p>
                        </div>
                    </div>
                    <div class="item">
                        <img src="https://imgur.com/buAVgjt" alt="Second slide">
                        <div class="carousel-caption">
                            <h3>
                                Pencil</h3>
                            <p>
                                Portrait, Nude</p>
                        </div>
                    </div>
                    <div class="item">
                        <img src="https://imgur.com/IysG1mL" alt="Third slide">
                        <div class="carousel-caption">
                            <h3>
                                Pottery</h3>
                            <p>
                                Vases, Bowls</p>
                        </div>
                    </div>
                </div>
                
            </div>
            <div class="main-text hidden-xs">
                <div class="col-md-12 text-center">
                    <h1>
                        Viktoria Nagel</h1>
                    <h3>
                        Master of Fine Art</h3>
                    
            </div>
        </div>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

<!--END SLIDER -->

<!--MENU-->

<div class="wrapper">
            <header>

                  <nav class="shift">

                        <div class="menu-icon">
                              <i class="fa fa-bars fa-2x"></i>
                        </div>

                        <div class="logo">
                              <img src="vnlogow.png" height="50px">
                        </div>

                        <div class="menu">

                              <ul>
                        <li><a href="index.html">Home</a></li>
                        <li><a href="index.html">About</a></li>
					    <li><a href="gallery.html">Gallery</a></li>
					    <li><a href="contact.html">Contact</a></li>
                              </ul>
                        </div>
                  </nav>

            </header>

<!-- End MENU-->

            <div class="content">
            	
            	<div container>
            	<div class="img">
            	<img src="bilder/acrylic/01.jpg" 
            	width="20%"
				style="float: left; padding: 25px 10px 1000px 0px" 
            	
            	 > 
            	 </div>


            	<p>

Dear viewer, 
My name is Viktoria Nagel.<br> I was born in Russia in 1969, although my roots go back to Germany.
<br>
My family and I have been working in the beautiful town of Lorch in southern Germany since 1996. This is where we have found our home and we lead happy lives here.
 <br>
It was only after we settled down in Lorch that my painting hobby became my pure and all-consuming passion. After a few years of practice, accumulating experience through my own experimentation, I was ready to exhibit my artwork. I was overwhelmed by the positive response and demand for my work, which has since enabled me to transform my hobby into a career. I have been working as an independent and freelance artist with "VN-Arts" since 2010.
 <br>
I am enthusiastic about sharing my knowledge and skill, so I also offer painting and pottery courses.
 <br><br>
In my relatively short, full-time art career, I am grateful to have met with encouraging successes, for example:
<br><br>
<b>2009</b> Finalist "International Art Competition X-Power Gallery" Beverly Hills, USA
<br><br>
<b>2010</b> Finalist "International Art Competition X-Power Gallery" Taipei/Taiwan
<br><br>
<b>2010</b> First place at "Russian Art Week" Moscow (international Exhibition and Contemporary Art Competition)
<br><br>
<b>2011</b> Art and X-Power Gallery Exhibition in New York GP DEVA USA
<br><br>
<b>2011</b> Forth Open Art 2011. Artist from Europe in Baden-Baden.
<br><br>
My specialities include acrylic painting and the photorealistic rendering of people, nature and animals.
 <br>
With every work my goal is to capture, on canvas, the beauty and emotion of my subject and, in the most beautiful way possible, to serve this to the viewer.
 <br>
My wish is that you would thoroughly enjoy and have fun as you view my artworks, and I greatly look forward to your feedback.
 <br>
Kind regards,
V. Nagel
                  </p>
              </div>
            </div>
      </div>

      <!---Script Menu-->

      <script type="text/javascript">

      // Menu-toggle button

      $(document).ready(function() {
            $(".menu-icon").on("click", function() {
                  $("nav ul").toggleClass("showing");
            });
      });

      // Scrolling Effect

      $(window).on("scroll", function() {
            if($(window).scrollTop()) {
                  $('nav').addClass('black');
            }

            else {
                  $('nav').removeClass('black');
            }
      })


      </script>

</body>

</html>

非常感谢提前!

问候,艾迪。

1 个答案:

答案 0 :(得分:0)

请现在看看你的问题解决了。复制并过去到您的HTML页面

    <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Viktoria Nagel</title>
    <link rel="stylesheet" href="css.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <style>
        html, body {
          margin: 0;
          padding: 0;
          width: 100%;
    }

    body {
          font-family: "Helvetica Neue",sans-serif;
          font-weight: lighter;
    }

    header {
          width: 100%;
          height: 100vh;
          background-color: #111
          background: url(bilder/acrylic/63.jpg) no-repeat 50% 50%;
          background-size: cover;
    }

    .content {
          width: 94%;
          margin: 4em auto;
          font-size: 20px;
          line-height: 30px;
          text-align: justify;
    }

    .logo {
          line-height: 40px;
          position: fixed;
          float: left;
          margin: 16px 46px;
          color: #fff;
          font-weight: bold;
          font-size: 20px;
          letter-spacing: 2px;
          height:40px;
    }

    nav {
          position: fixed;
          width: 100%;
          line-height: 60px;
          left: 0;
    }

    nav ul {
          line-height: 40px;
          list-style: none;
          background: rgba(0, 0, 0, 0);
          overflow: hidden;
          color: #fff;
          padding: 0;
          text-align: right;
          margin: 0;
          padding-right: 40px;
          transition: 1s;
    }

    nav.black ul {
          background: #111; opacity: 50%
    }

    nav ul li {
          display: inline-block;
          padding: 16px 40px;;
    }

    nav ul li a {
          text-decoration: none;
          color: #fff;
          font-size: 16px;
          text-transform: uppercase;
          margin: 0 10px;
    }
    nav ul li a,
    nav ul li a:after,
    nav ul li a:before {
      transition: all .5s;
    }
    nav ul li a:hover {
      color: #555;
    }


    .menu-icon {
          line-height: 40px;
          width: 100%;
          background: #111;
          text-align: right;
          box-sizing: border-box;
          padding: 15px 24px;
          cursor: pointer;
          color: #fff;
          display: none;
    }

    @media(max-width: 786px) {

          .logo {
                position: fixed;
                top: 0;
                margin-top: 16px;
          }

          nav ul {
                max-height: 0px;
                background: #111;
          }

          nav.black ul {
                background: #111;
          }

          .showing {
                max-height: 34em;
          }

          nav ul li {
                box-sizing: border-box;
                width: 100%;
                padding: 24px;
                text-align: center;
          }

          .menu-icon {
                display: block;
          }

    }


    nav.shift ul li a {
      position:relative;
      z-index: 1;
    }
    nav.shift ul li a:hover {
      color: #777;
    }
    nav.shift ul li a:after {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      margin: auto;
      width: 100%;
      height: 1px;
      content: '.';
      color: transparent;
      background: ;
      visibility: none;
      opacity: 0;
      z-index: -1;
    }
    nav.shift ul li a:hover:after {
      opacity: 1;
      visibility: visible;
      height: 100%;
    }

    .img {
      min-height: 15%;
    }
    </style>
</head>

<body>


    <!-- IMAGE SLIDER -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

    <div class="container">
        <div class="row">

            <div class="wrapper">
                <header>

                    <nav class="shift">

                        <div class="menu-icon">
                            <i class="fa fa-bars fa-2x"></i>
                        </div>

                        <div class="logo">
                            <img src="vnlogow.png" height="50px">
                        </div>

                        <div class="menu">

                            <ul>
                                <li><a href="index.html">Home</a></li>
                                <li><a href="index.html">About</a></li>
                                <li><a href="gallery.html">Gallery</a></li>
                                <li><a href="contact.html">Contact</a></li>
                            </ul>
                        </div>
                    </nav>

                </header>

                <div class="content">

                    <div class="container">
                        <div class="img">
                            <img src="bilder/acrylic/01.jpg" width="20%" style="float: left; padding: 25px 10px 1000px 0px">
                        </div>


                        <p>

                            Dear viewer, My name is Viktoria Nagel.<br> I was born in Russia in 1969, although my roots go back to Germany.
                            <br> My family and I have been working in the beautiful town of Lorch in southern Germany since 1996. This is where we have found our home and we lead happy lives here.
                            <br> It was only after we settled down in Lorch that my painting hobby became my pure and all-consuming passion. After a few years of practice, accumulating experience through my own experimentation, I was ready to exhibit
                            my artwork. I was overwhelmed by the positive response and demand for my work, which has since enabled me to transform my hobby into a career. I have been working as an independent and freelance artist with "VN-Arts" since
                            2010.
                            <br> I am enthusiastic about sharing my knowledge and skill, so I also offer painting and pottery courses.
                            <br><br> In my relatively short, full-time art career, I am grateful to have met with encouraging successes, for example:
                            <br><br>
                            <b>2009</b> Finalist "International Art Competition X-Power Gallery" Beverly Hills, USA
                            <br><br>
                            <b>2010</b> Finalist "International Art Competition X-Power Gallery" Taipei/Taiwan
                            <br><br>
                            <b>2010</b> First place at "Russian Art Week" Moscow (international Exhibition and Contemporary Art Competition)
                            <br><br>
                            <b>2011</b> Art and X-Power Gallery Exhibition in New York GP DEVA USA
                            <br><br>
                            <b>2011</b> Forth Open Art 2011. Artist from Europe in Baden-Baden.
                            <br><br> My specialities include acrylic painting and the photorealistic rendering of people, nature and animals.
                            <br> With every work my goal is to capture, on canvas, the beauty and emotion of my subject and, in the most beautiful way possible, to serve this to the viewer.
                            <br> My wish is that you would thoroughly enjoy and have fun as you view my artworks, and I greatly look forward to your feedback.
                            <br> Kind regards, V. Nagel
                        </p>
                         <div class="col-md-12">
                <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">

                    <div class="carousel-inner">
                        <div class="item active">
                            <img src="http://via.placeholder.com/1000x350" alt="First slide">
                            <div class="carousel-caption">
                                <h3>
                                    Acrylic</h3>
                                <p>
                                    Wildlife, Stillife</p>
                            </div>
                        </div>
                        <div class="item">
                            <img src="http://via.placeholder.com/1000x350" alt="Second slide">
                            <div class="carousel-caption">
                                <h3>
                                    Pencil</h3>
                                <p>
                                    Portrait, Nude</p>
                            </div>
                        </div>
                        <div class="item">
                            <img src="http://via.placeholder.com/1000x350" alt="Third slide">
                            <div class="carousel-caption">
                                <h3>
                                    Pottery</h3>
                                <p>
                                    Vases, Bowls</p>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="main-text hidden-xs">
                    <div class="col-md-12 text-center">
                        <h1>
                            Viktoria Nagel</h1>
                        <h3>
                            Master of Fine Art</h3>

                    </div>
                </div>
            </div>

                    </div>
                </div>
            </div>

            <!---Script Menu-->
            <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
            <!-- Include all compiled plugins (below), or include individual files as needed -->
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
            <script type="text/javascript">
                // Menu-toggle button

                  $(document).ready(function() {
                        $(".menu-icon").on("click", function() {
                              $("nav ul").toggleClass("showing");
                        });
                  });

                  // Scrolling Effect

                  $(window).on("scroll", function() {
                        if($(window).scrollTop()) {
                              $('nav').addClass('black');
                        }

                        else {
                              $('nav').removeClass('black');
                        }
                  })
            </script>

</body>

</html>