css 当我滑下车窗时,旋转木马向上移动

im9ewurl  于 2022-11-26  发布在  其他
关注(0)|答案(1)|浏览(125)

我正在做我的一个个人项目,我正在使用HTML和CSS为一家餐厅设计一个网站......我有一个旋转木马的代码,我试图将它与我的网站集成......但我面临着旋转木马的问题......当我滑下我的窗口......旋转木马也往往向上移动,并不坚持它的原始位置......我应该如何解决这个问题....这是我所有个人项目中的第一个。如果这个社区的Maven或成员能在这个学习过程中帮助我,并帮助我完成这个项目,我将非常高兴和高兴.... This is the project这是我的index.html。Carousel的代码位于最后一节,注解为“Carousel Starts”

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Restaurant Page</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <nav>
      <div class="navigation container">
        <div class="logo_container">
          <img src="images/logo.png" alt="logo" />
        </div>
        <div class="allmenus">
          <ul>
           <li class="menu">Home</li>
            <li class="menu" >About Us</li> 
           <li class="menu" >Our Services</li>
          </ul>
       
      </div>
    </nav>
    <script
      src="https://kit.fontawesome.com/8b6347e91f.js"
      crossorigin="anonymous"
    ></script>
    <!--First Section-->
    <div class="container" >
      <div class="first">
        <div class="first_image">
          <img src="images/hero_image.png" alt="Vegetables" />
        </div>
        <div class="first_content">
          <div class="tag">50% Off On All Products</div>
          <h1>Enjoy Your Delicious Food</h1>
          <p>
            Make reservations, hours, and locations front-and-center, and
            prominently get your order within few minutes of getting placed
          </p>
          <button class="explore">Order Now</button>
        </div>
      </div>

      <section class="second_section" >
        <div class="feature">
          <img src="images/discount 1.png" />
          <div class="feature_content">
            <h1>Discount Voucher</h1>
            <p>Get a discount voucher worth Rs.100 on yout first order</p>
          </div>
        </div>

        <div class="feature">
          <img src="images/fresh.png" />
          <div class="feature_content">
            <h1>Fresh Healthy Food</h1>
            <p>Get a discount voucher worth Rs.100 on yout first order</p>
          </div>
        </div>
        <div class="feature">
          <img src="images/delivery.png" />
          <div class="feature_content">
            <h1>Instant delivery</h1>
            <p>Get a discount voucher worth Rs.100 on yout first order</p>
          </div>
        </div>
      </section>
    </div>

    <!--Popular Dishes  -->

    <div class="container dishes" >
      <h1 class="popdishes">Our Popular Dishes</h1>

      <div class="subcontainer">
        <div class="section">
        
          <img class="dish" src="images/dish-3.png" alt="">
          
           <h2 class="recipe">Chicken Leg Piece</h2>
            <div class="priceandbutton">
              <span>$15</span>
              <button class="addtocart">Add To Cart</button>
            </div>
        </div>
        <div class="section">
          
              <img class="dish" src="images/dish-1.png" alt="">
             
              <h2 class="recipe">Burger</h2>
              <div class="priceandbutton">
                <span>$20</span>
                <button class="addtocart">Add To Cart</button>
              </div>
        </div>

        <div class="section">
         
                <img class="dish" src="images/dish-2.png" alt="">
                
                <h2 class="recipe">Chicken Nuggets</h2>
                
                <div class="priceandbutton">
                  <span>$12</span>
                  <button class="addtocart">Add To Cart</button>
                </div>
             
        </div>
      </div>
    <!-- Second SubContainer Starts-->
      <div class="subcontainer">

        <div class="section">
         
          <img class="dish" src="images/dish-4.png" alt="">
          
          <h2 class="recipe">Pizza</h2>
          
          <div class="priceandbutton">
            <span>$12</span>
            <button class="addtocart">Add To Cart</button>
          </div>
       
        </div>
     

      
        <div class="section">
        
          <img class="dish" src="images/dish-5.png" alt="">
          
           <h2 class="recipe">Chocolate Cookies</h2>
            <div class="priceandbutton">
              <span>$15</span>
              <button class="addtocart">Add To Cart</button>
            </div>
        </div>
        <div class="section">
          
              <img class="dish" src="images/dish-6.png" alt="">
             
              <h2 class="recipe">Broasted</h2>
              <div class="priceandbutton">
                <span>$20</span>
                <button class="addtocart">Add To Cart</button>
              </div>
        </div>
      </div>

      <!-- Third SubContainer Starts-->

      <div class="subcontainer">

        <div class="section">
         
          <img class="dish" src="images/menu-33 new.jpg" alt="">
          
          <h2 class="recipe">Crepes</h2>
          
          <div class="priceandbutton">
            <span>$12</span>
            <button class="addtocart">Add To Cart</button>
          </div>
       
        </div>
     

      
        <div class="section">
        
          <img class="dish" src="images/menu-44.jpg" alt="">
          
           <h2 class="recipe">Waffles</h2>
            <div class="priceandbutton">
              <span>$15</span>
              <button class="addtocart">Add To Cart</button>
            </div>
        </div>
        <div class="section">
          
              <img class="dish" src="images/menu-55.jpg" alt="">
             
              <h2 class="recipe">Pasteries</h2>
              <div class="priceandbutton">
                <span>$20</span>
                <button class="addtocart">Add To Cart</button>
              </div>
        </div>
      </div>
    </div>

    <!-- Carousel Starts -->
  <div class="container">
    <div class="mycarousel" >
      <input type="radio" name="position" checked />
      <input type="radio" name="position" />
      <input type="radio" name="position" />
      <input type="radio" name="position" />
      <input type="radio" name="position" />
      <main id="carousel">
        <div class="item" >
          <div class="reviews">
          <img class="reviewimages" src="images/pic-1.png">
          <div class="content">
            <h1>John Doe</h1>
            <p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
          </div>
    </div>
        </div>
        <div class="item">
         <div class="reviews">
          <img class="reviewimages" src="images/pic-2.png">
          <div class="content">
            <h1>John Doe</h1>
            <p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
          </div>
    </div>
        </div>
        <div class="item">
         <div class="reviews" >
          <img class="reviewimages"       src="images/pic-1.png">
            <div class="content">
              <h1>John Doe</h1>
              <p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
            </div>
          </div>
        </div>
        <div class="item">
         <div class="reviews">
          <img class="reviewimages" src="images/pic-1.png">
          <div class="content">
            <h1>John Doe</h1>
            <p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
          </div>
    </div>
        </div>
        <div class="item">
         <div class="reviews">
          <img class="reviewimages" src="images/pic-1.png">
          <div class="content">
            <h1>John Doe</h1>
            <p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
          </div>
    </div>
        </div>
        <main>
    </div>
  </div>
  </body>
</html>

这是我的css文件

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html,
body {
  line-height: 1.4;
  font-weight: 300;
  font-family: "Roboto", sans-serif;
}
nav {
  box-shadow: 5px 5px 5px rgba(1, 1, 1, 0.05);
  background-color: white;
  position: sticky;
  top: 0;
  margin-bottom: 32px;
  padding: 10px;
}
.navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: rgba(28, 22, 22, 0.414);
  font-weight: bolder;
  font-size: large;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}
ul {
  text-align: right;
  display: flex;
  font-family: Helvetica, sans-serif;
  font-weight: bolder;
  list-style: none;
}
li {
  padding: 0 20px;
  margin-top: 30px;
}
li:hover {
  color: #134a7a;
  text-decoration: underline;
}
.logo_container {
  margin-left: 15px;
}
/* First Section */
.first {
  display: flex;
  gap: 100px;
  justify-content: center;
  align-items: center;
}
.first_content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.tag {
  background-color: #134a7a;
  align-self: flex-start;
  padding: 5px 10px;
  color: white;
}
.first_content h1 {
  font-size: 72px;
  line-height: 1.2;
  font-weight: 500;
}
button {
  padding: 10px 15px;
  color: white;
  font-weight: 500;
  font-size: 22px;
  background: crimson;
  border: none;
  border-radius: 30px;
  align-self: flex-start;
  width: 250px;
}
button:hover {
  transition: 0.2s ease-in-out;
  background:#e5eaee;
  color: #134a7a;
  font-weight: 500;
}
.second_section {
  display: flex;
  flex-direction: row;
  gap: 20px;
  margin-top: 100px;
  justify-content: center;
}

.feature {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 15px;
  height: 165px;
  background-color: #134a7a;
  color: azure;
}

.feature:hover {
  transition: 0.2s ease-in-out;
  background-color: azure;
  color:#134a7a;
}
.dishes{
  background-color: #e5eaee;
  margin-top: 20px;
  height:1250px;
  margin-bottom: 20px;;
}

.dishes .subcontainer {
  display: flex;
  flex-direction: row;
  justify-content: space-evenly;
  gap: 25px;
}

.recipe{
  font-weight: 300;
}

.section {
  width: 350px;
  height: 350px;
  background: white;
  padding-top: 32px;
  margin-top: 25px;
}
.section{
  display:flex;
  flex-direction:column;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
h1.popdishes {
  padding-top: 20px;
  color:#134a7a;
  text-align: center;
}
.priceandbutton {
  display: flex;
  flex-direction: row;
  gap:10px
}
span {
    padding-top: 5px;
    font-weight: 400;
    color:#134a7a;
    font-size: 30px;
}
.addtocart{
  padding: 10px 15px;
  color: white;
  font-weight: 500;
  font-size: 22px;
  background:#134a7a;
  border: none;
  border-radius: 30px;
  align-self: flex-start;
  width: 200px;
}
.addtocart:hover {
  background:#e5eaee;
  color: #134a7a;
  font-weight: 500;
  transition: 0.2s ease-in-out;
}

.reviewimages{
  height:150px; 
  width:170px;
  border-radius:50%;
}
.reviews{
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  padding:20px
}
.content{
  text-align:center
}

.mycarousel{
  height: 600px;
  margin: 0;
  display: grid;
  grid-template-rows: 500px 100px;
  grid-template-columns: 1fr 30px 30px 30px 30px 30px 1fr;
  align-items: center;
  justify-items: center;
  background-color: #134a7a;
}

main#carousel {
  grid-row: 1 / 2;
  grid-column: 1 / 8;
  width: 100vw;
  height: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transform-style: preserve-3d;
  perspective: 600px;
  --items: 5;
  --middle: 3;
  --position: 1;
  pointer-events: none;
  
}

div.item {
  position: absolute;
  width: 300px;
  height: 400px;
  background-color: coral;
  --r: calc(var(--position) - var(--offset));
  --abs: max(calc(var(--r) * -1), var(--r));
  transition: all 0.25s linear;
  transform: rotateY(calc(-10deg * var(--r)))
    translateX(calc(-300px * var(--r)));
  z-index: calc((var(--position) - var(--abs)));
  overflow: hidden;
  
}

div.item:nth-of-type(1) {
  --offset: 1;
 
}
div.item:nth-of-type(2) {
  --offset: 2;
  
}
div.item:nth-of-type(3) {
  --offset: 3;
  
}
div.item:nth-of-type(4) {
  --offset: 4;
  
}
div.item:nth-of-type(5) {
  --offset: 5;
  
}

input:nth-of-type(1) {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
}
input:nth-of-type(1):checked ~ main#carousel {
  --position: 1;
}

input:nth-of-type(2) {
  grid-column: 3 / 4;
  grid-row: 2 / 3;
}
input:nth-of-type(2):checked ~ main#carousel {
  --position: 2;
}

input:nth-of-type(3) {
  grid-column: 4 /5;
  grid-row: 2 / 3;
}
input:nth-of-type(3):checked ~ main#carousel {
  --position: 3;
}

input:nth-of-type(4) {
  grid-column: 5 / 6;
  grid-row: 2 / 3;
}
input:nth-of-type(4):checked ~ main#carousel {
  --position: 4;
}

input:nth-of-type(5) {
  grid-column: 6 / 7;
  grid-row: 2 / 3;
}
input:nth-of-type(5):checked ~ main#carousel {
  --position: 5;
}
.reviewimages{
  height:150px; 
  width:170px;
  border-radius:50%;
  border:5px solid black;
}
.content h1{
  color:#134a7a;
}
.reviews{
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  padding:20px
}
.content{
  text-align:center
}

.mycarousel{
  height: 600px;
  margin: 0;
  display: grid;
  grid-template-rows: 500px 100px;
  grid-template-columns: 1fr 30px 30px 30px 30px 30px 1fr;
  align-items: center;
  justify-items: center;
}

main#carousel {
  grid-row: 1 / 2;
  grid-column: 1 / 8;
  width: 100vw;
  height: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transform-style: preserve-3d;
  perspective: 600px;
  --items: 5;
  --middle: 3;
  --position: 1;
  pointer-events: none;
}

div.item {
  position: absolute;
  width: 300px;
  height: 400px;
  background-color: coral;
  --r: calc(var(--position) - var(--offset));
  --abs: max(calc(var(--r) * -1), var(--r));
  transition: all 0.25s linear;
  transform: rotateY(calc(-10deg * var(--r)))
    translateX(calc(-300px * var(--r)));
  z-index: calc((var(--position) - var(--abs)));

}

div.item:nth-of-type(1) {
  --offset: 1;
  background-color: #e5eaee;
   
}
div.item:nth-of-type(2) {
  --offset: 2;
  background-color: #e5eaee;
  
}
div.item:nth-of-type(3) {
  --offset: 3;
  background-color: #e5eaee;
 

}
div.item:nth-of-type(4) {
  --offset: 4;
  background-color: #e5eaee;
  
}
div.item:nth-of-type(5) {
  --offset: 5;
  background-color: #e5eaee;
 
}

input:nth-of-type(1) {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
}
input:nth-of-type(1):checked ~ main#carousel {
  --position: 1;
}

input:nth-of-type(2) {
  grid-column: 3 / 4;
  grid-row: 2 / 3;
}
input:nth-of-type(2):checked ~ main#carousel {
  --position: 2;
}

input:nth-of-type(3) {
  grid-column: 4 /5;
  grid-row: 2 / 3;
}
input:nth-of-type(3):checked ~ main#carousel {
  --position: 3;
}

input:nth-of-type(4) {
  grid-column: 5 / 6;
  grid-row: 2 / 3;
}
input:nth-of-type(4):checked ~ main#carousel {
  --position: 4;
}

input:nth-of-type(5) {
  grid-column: 6 / 7;
  grid-row: 2 / 3;
}
input:nth-of-type(5):checked ~ main#carousel {
  --position: 5;
}
e4eetjau

e4eetjau1#

尝试添加justify-content: space-around;,使其保持与页面相同的宽度:

.mycarousel {
    height: 600px;
    margin: 0;
    display: grid;
    grid-template-rows: 500px 100px;
    grid-template-columns: 1fr 30px 30px 30px 30px 30px 1fr;
    align-items: center;
    justify-items: center;
    justify-content: space-around;
}

对于幻灯片部分,我看到它在导航栏上,你可以通过在导航栏上添加一个z-index: 1;来解决它。

nav {
    box-shadow: 5px 5px 5px rgb(1 1 1 / 5%);
    background-color: white;
    position: sticky;
    top: 0;
    margin-bottom: 32px;
    padding: 10px;
    z-index: 1;
}

相关问题