拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 使用z-index时调整影像大小的问题

使用z-index时调整影像大小的问题

白鹭 - 2022-01-25 1994 0 0

当我没有指定我的部分的位置时,手机影像完全遵循指定的宽度。

这是 - width: 60%;

使用 z-index 时调整影像大小的问题

使用 z-index 时调整影像大小的问题



但是当我申请前两个部分时position由于手机影像变得太大,所以没有应用。z-indexwidth: 60%;

使用 z-index 时调整影像大小的问题

使用 z-index 时调整影像大小的问题



HTML & CSS 代码:

body {
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
}

#title {
    background-color: #ff4c68;
    color: #FFFFFF;
}

h1 {
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 3.5rem;
    Line-height: 1.5;
}

h2 {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 2rem;
}

h3 {
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
}

.container-fluid {
    padding: 3% 15% 7%;
}

p {
    font-family: "Ubuntu";
    color: #8f8f8f;
}


/* Navigation Bar */

.navbar-brand {
    font-family: "Ubuntu";
    font-size: 2.5rem;
}

.navbar {
    padding-bottom: 4.5em;
}

.nav-item {
    padding: 0 18px;
}

.nav-link {
    font-size: 1.2rem;
    font-family: "Montserrat";
    font-weight: 100;
}


/* Download buttons */

.download-button {
    margin: 5% 3% 5% 0;
}


/* Title image */

.title-image {
    width: 60%;
    transform: rotate(25deg);
    position: absolute;
}


/* feature section  */

#features {
    padding: 7% 15%;
    background-color: #FFFFFF;
    position: relative;
    z-index: 1;
}

.feature-box {
    text-align: center;
    padding: 5%;
}

.icon {
    margin-bottom: 1rem;
    color: #ef8172;
}

.icon:hover {
    color: #ff4c68;
}


/* testimonials */

#testimonials {
    text-align: center;
    background-color: #ef8172;
    color: #fff;
}

.carousel-item {
    padding: 7% 15%;
}

.testimonial-image {
    width: 10%;
    border-radius: 100%;
    margin: 20px;
}


/* Press */

#press {
    background-color: #ef8172;
    text-align: center;
    padding-bottom: 3%;
}

.press-logo {
    width: 15%;
    padding: 20px 20px 50px;
}


/* Pricing  */

#pricing {
    padding: 100px;
    text-align: center;
}

.pricing-col {
    padding: 3% 2%;
}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>TinDog</title>

    <!-- Bootstap css  -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

    <!-- CSS Stylesheets  -->
    <link rel="stylesheet" href="css/styles.css">

    <!-- Google fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800&family=Ubuntu:wght@500&display=swap" rel="stylesheet">
    <!-- Bootstrap scripts  -->
    <script src="jquery-3.5.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7 zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG 2QOK9T ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>



    <!-- font awesome  -->
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg p" crossorigin="anonymous" />


</head>

<body>

    <section id="title">

        <div class="container-fluid">

            <!-- Nav Bar -->
            <nav class="navbar navbar-expand-lg navbar-dark">
                <a class="navbar-brand" href=""> tindog</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ms-auto">
                        <li class="nav-item">
                            <a class="nav-link" href="">Contact</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="">Pricing</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="">Download</a>
                        </li>
                    </ul>
                </div>
            </nav>



            <!-- Title -->

            <div class="row">
                <div class="col-md-6">
                    <h1>Meet new and interesting dogs nearby.</h1>
                    <button type="button" class="btn btn-dark btn-lg download-button"><i class="fab fa-apple"></i> Download</button>
                    <button type="button" class="btn btn-outline-light btn-lg download-button"><i class="fab fa-google-play"></i> Download</button>
                </div>

                <div class="col-md-6">
                    <img class="title-image" src="images/iphone6.png" alt="iphone-mockup">
                </div>
            </div>
        </div>
    </section>


    <!-- Features -->

    <section id="features">
        <div class="row">
            <div class="feature-box col-md-4">
                <i class="icon fas fa-check-circle fa-5x"></i>
                <h3>Easy to use.</h3>
                <p>So easy to use, even your dog could do it.</p>
            </div>
            <div class=" feature-box col-md-4">
                <i class="icon fas fa-bullseye fa-5x"></i>
                <h3>Elite Clientele</h3>
                <p>We have all the dogs, the greatest dogs.</p>
            </div>
            <div class=" feature-box col-md-4">
                <i class="icon fas fa-heart fa-5x"></i>
                <h3>Guaranteed to work.</h3>
                <p>Find the love of your dog's life or your money back.</p>
            </div>
        </div>

    </section>


    <!-- Testimonials -->

    <section id="testimonials">
        <div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel" data-bs-interval="3000">
            <div class="carousel-inner">
                <div class="carousel-item active">
                    <h2>I no longer have to sniff other dogs for love. I've found the hottest Corgi on TinDog. Woof.</h2>
                    <img class="testimonial-image" src="images/dog-img.jpg" alt="dog-profile">
                    <em>Pebbles, New York</em>
                </div>
                <div class="carousel-item">
                    <h2 class="testimonial-text">My dog used to be so lonely, but with TinDog's help, they've found the love of their life. I think.</h2>
                    <img class="testimonial-image" src="images/lady-img.jpg" alt="lady-profile">
                    <em>Beverly, Illinois</em>
                </div>
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
              <span class="carousel-control-prev-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Previous</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
              <span class="carousel-control-next-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Next</span>
            </button>
        </div>





    </section>


    <!-- Press -->

    <section id="press">
        <img class="press-logo" src="images/techcrunch.png" alt="tc-logo">
        <img class="press-logo" src="images/tnw.png" alt="tnw-logo">
        <img class="press-logo" src="images/bizinsider.png" alt="biz-insider-logo">
        <img class="press-logo" src="images/mashable.png" alt="mashable-logo">

    </section>


    <!-- Pricing -->

    <section id="pricing">

        <h2>A Plan for Every Dog's Needs</h2>
        <p>Simple and affordable price plans for your and your dog.</p>
        <div class="row ">
            <div class="pricing-col col-lg-4 col-md-6">
                <div class="card">
                    <div class="card-header">
                        <h3>Chihuahua</h3>
                    </div>
                    <div class="card-body">
                        <h2>Free</h2>
                        <p>5 Matches Per Day</p>
                        <p>10 Messages Per Day</p>
                        <p>Unlimited App Usage</p>
                        <div class="d-grid col-6 mx-auto">
                            <button type="button" class="btn btn-lg  btn-outline-dark">Sign Up</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="pricing-col col-lg-4 col-md-6">
                <div class="card">
                    <div class="card-header">
                        <h3>Labrador</h3>
                    </div>
                    <div class="card-body">
                        <h2>$49 / mo</h2>
                        <p>Unlimited Matches</p>
                        <p>Unlimited Messages</p>
                        <p>Unlimited App Usage</p>
                        <div class="d-grid col-6 mx-auto">
                            <button type="button" class="btn btn-lg  btn-dark">Sign Up</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="pricing-col col-lg-4 col-md-12">
                <div class="card">
                    <div class="card-header">
                        <h3>Mastiff</h3>
                    </div>
                    <div class="card-body">
                        <h2>$99 / mo</h2>
                        <p>Pirority Listing</p>
                        <p>Unlimited Matches</p>
                        <p>Unlimited Messages</p>
                        <p>Unlimited App Usage</p>
                        <div class="d-grid col-6 mx-auto">
                            <button type="button" class="btn btn-lg  btn-dark">Sign Up</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>


    <!-- Call to Action -->

    <section id="cta">

        <h3>Find the True Love of Your Dog's Life Today.</h3>
        <button type="button">Download</button>
        <button type="button">Download</button>

    </section>


    <!-- Footer -->

    <footer id="footer">

        <p>? Copyright 2018 TinDog</p>

    </footer>


</body>

</html>



我希望最终结果是这样的:

使用 z-index 时调整影像大小的问题



手机图片:

使用 z-index 时调整影像大小的问题

uj5u.com热心网友回复:

嘿伙计,我真的不知道这是否是正确的做法,但它似乎作业得很好。我所做的是将宽度更改为最大宽度,使其从 60% 变为 18%。它看起来不错,就像上课一样。然后,当您将其切换到平板计算机或移动设备时,我让@media 功能将其改回 60%,这样它就不会一直缩小并且看起来很奇怪。idk,如果我解释正确但这里是代码:

    .title-image {
      max-width: 18%;
      transform: rotate(25deg);
      position: absolute;
      right: 22%;
      }

      @media (max-width: 991px) {
       .title-image {
       position: static;
       transform: rotate(0deg);
       max-width: 60%;
        }
         }
    

我和你一样是一个完整的初学者,但我希望这对你有所帮助。

uj5u.com热心网友回复:

你只需要设定position你的第一部分来实作这一点,如果你设定title'sposition: relative;z-index: -1;,你就不需要在你的.title-image班级上设定位置。请参阅下面的片段(整页)以供参考。

这是片段的结果: 使用 z-index 时调整影像大小的问题

body {
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
}

#title {
  background-color: #ff4c68;
  color: #FFFFFF;
  height: 90%;
  max-height: 900px;
  display: flex;
  justify-content: space-evenly;
  padding-inline: 10%;
  position: relative;
  z-index: -1;
}

h1 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 800;
  font-size: 3.5rem;
  Line-height: 1.5;
}

h2 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 2rem;
}

h3 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
}

.container-fluid {
  padding: 3% 15% 7%;
}

p {
  font-family: "Ubuntu";
  color: #8f8f8f;
}


/* Navigation Bar */

.navbar-brand {
  font-family: "Ubuntu";
  font-size: 2.5rem;
}

.navbar {
  padding-bottom: 4.5em;
  margin-bottom: 3rem;
}

.nav-item {
  padding: 0 18px;
}

.nav-link {
  font-size: 1.2rem;
  font-family: "Montserrat";
  font-weight: 100;
}


/* Download buttons */

.download-button {
  margin: 5% 3% 5% 0;
}


/* Title image */

.title-image {
  width: 70%;
  transform: rotate(25deg);
}


/* feature section  */

#features {
  padding: 7% 15%;
  background-color: #FFFFFF;
}

.feature-box {
  text-align: center;
  padding: 5%;
}

.icon {
  margin-bottom: 1rem;
  color: #ef8172;
}

.icon:hover {
  color: #ff4c68;
}
							
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *