css 我怎样才能建立一个六边形的旋转木马指标?

h5qlskok  于 2023-04-13  发布在  其他
关注(0)|答案(2)|浏览(118)

我必须为我的网站建设六边形旋转木马指标。我需要像这样的形象。
因此,使用此代码,当carousel处于活动状态时,它会查找工作。它是全红色背景。
但是当它不活动的时候,我有一个正方形在六边形里面,你能帮我,使它在六边形里面不活动,我可以看到六边形的形状吗?
谢谢大家提前干杯!

#section-testimonials .carousel-indicators {
  bottom: 15px !important;
  margin-bottom: unset !important;
}

#section-testimonials .carousel .carousel-indicators button {
  display: inline-block;
  background-color: transparent;
  /* set background color to transparent */
  background-clip: unset;
  border: 4px solid red;
  width: 10px;
  height: 10px;
  opacity: 1;
  -webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

#section-testimonials .carousel .carousel-indicators button.active {
  background-color: red;
  border-color: red;
}
<body>
  <section id="section-testimonials">
    <div id="carouselTestimonialsIndicators" class="carousel slide">
      <div class="carousel-indicators">
        <button type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1">
        </button>
        <button type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide-to="1" aria-label="Slide 2">
        </button>
        <button type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
      </div>
      <div class="carousel-inner">
        <div class="carousel-item active px-md-3">

          <div class="comment-slider">
            <p class="fs-6-mobile">“Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
              book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
              recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ”

            </p>
          </div>

        </div>

        <div class="carousel-item px-md-3">

          <div class="comment-slider">
            <p class="fs-6-mobile">“Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
              book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
              recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ”

            </p>
          </div>

        </div>
        <!-- <div class="carousel-item">
            <img src="..." class="d-block w-100" alt="...">
        </div> -->
      </div>
      <button class="carousel-control-prev" type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide="prev">
        <span class="carousel-control-prev-icon d-none" aria-hidden="true"></span>
        <span class="visually-hidden">Previous</span>
    </button>
      <button class="carousel-control-next" type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide="next">
        <span class="carousel-control-next-icon d-none" aria-hidden="true"></span>
        <span class="visually-hidden">Next</span>
    </button>
    </div>
  </section>
dzjeubhm

dzjeubhm1#

让我试着用猜测来回答这个问题,因为我不完全明白你的意思。
你可以使用css的clip-path,它的工作原理是从它所应用的元素中剪切一些东西,在这个例子中是一个六边形。你的实际对象不会改变形状。
你的实际对象仍然是一个带有4px实心边框的盒子。
当这个形状有.active类的时候,你可以用边框和背景色来给它上色。
虽然它有类不活动的背景没有背景颜色指定的css,这就是为什么它显示一个白色的方块.
如果你想要一个带红色边框的白色六边形,你可以尝试使用伪元素,像这样的东西可能会奏效:

#section-testimonials .carousel-indicators {
  bottom: 15px !important;
  margin-bottom: unset !important;
}

#section-testimonials .carousel .carousel-indicators button {
  display: inline-block;
  background-color: red;
  /* set background color to transparent */
  background-clip: unset;
  width: 18px;
  height: 18px;
  opacity: 1;
  -webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  overflow: hidden;
  position: relative;
  border:none;
}

#section-testimonials .carousel .carousel-indicators button.active {
  background-color: red;
  border-color: red;
}

#section-testimonials .carousel .carousel-indicators button:before {
  display: block;
  background: white;
  width: 14px;
  position: absolute;
  top: 2px;
  left: 2px;
  height: 14px;
  content: "";
  -webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

#section-testimonials .carousel .carousel-indicators button.active:before {
  background: red;
}
<body>
  <section id="section-testimonials">
    <div id="carouselTestimonialsIndicators" class="carousel slide">
      <div class="carousel-indicators">
        <button type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1">
        </button>
        <button type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide-to="1" aria-label="Slide 2">
        </button>
        <button type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
      </div>
      <div class="carousel-inner">
        <div class="carousel-item active px-md-3">

          <div class="comment-slider">
            <p class="fs-6-mobile">“Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
              book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
              recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ”

            </p>
          </div>

        </div>

        <div class="carousel-item px-md-3">

          <div class="comment-slider">
            <p class="fs-6-mobile">“Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
              book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
              recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. ”

            </p>
          </div>

        </div>
        <!-- <div class="carousel-item">
            <img src="..." class="d-block w-100" alt="...">
        </div> -->
      </div>
      <button class="carousel-control-prev" type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide="prev">
        <span class="carousel-control-prev-icon d-none" aria-hidden="true"></span>
        <span class="visually-hidden">Previous</span>
    </button>
      <button class="carousel-control-next" type="button" data-bs-target="#carouselTestimonialsIndicators" data-bs-slide="next">
        <span class="carousel-control-next-icon d-none" aria-hidden="true"></span>
        <span class="visually-hidden">Next</span>
    </button>
    </div>
  </section>
wydwbb8l

wydwbb8l2#

我在photoshop中做了六边形指示器并导出svg。我用于ol.carousel-indicators liol.carousel-indicators li.activebackground属性和一些css。

.carousel-item p{
font-size:50px;
background-color: #d4d3d3;
height:100vh;
display:flex !important;
justify-content:center;
align-items:center ;
padding-bottom:1.5em !important;

}
.carousel-inner{
  width: 80vw;
  height:90vh;
}

ol.carousel-indicators li {
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 1067 1067'%3E%3Cdefs%3E%3Cstyle%3E .cls-1 %7B fill: %23fff; stroke: %23030303; stroke-width: 4.68px; fill-rule: evenodd; %7D %3C/style%3E%3C/defs%3E%3Cpath id='Polygon_1' data-name='Polygon 1' class='cls-1' d='M707.25,209L881,517.5,707.25,826H359.75L186,517.5,359.75,209h347.5Z'/%3E%3C/svg%3E%0A") no-repeat;
display: block;
box-sizing: border-box;
width: 64px;
height: 64px;

}

ol.carousel-indicators li.active {

background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 1067 1067'%3E%3Cdefs%3E%3Cstyle%3E .cls-1 %7B fill: %23ee0a2a; stroke: %23030303; stroke-width: 4.68px; fill-rule: evenodd; %7D %3C/style%3E%3C/defs%3E%3Cpath id='Polygon_1' data-name='Polygon 1' class='cls-1' d='M702.75,206L872,518.5,702.75,831H364.25L195,518.5,364.25,206h338.5Z'/%3E%3C/svg%3E ") no-repeat;
display: block;
box-sizing: border-box;
width: 64px;
height: 64px;
}

.carousel-control-prev-icon {
 background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23000' viewBox='0 0 8 8'%3E%3Cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E") !important;
}

.carousel-control-next-icon {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23000' viewBox='0 0 8 8'%3E%3Cpath d='M2.75 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3E%3C/svg%3E") !important;
}
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <link rel="stylesheet" href="/style.css">
  </head>
  <body>
    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
          <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
          <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
          <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
          <li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
        </ol>
        <div class="carousel-inner">
          <div class="carousel-item active">
            <p  class="d-block w-100 " alt="...">Text-1</p>
          </div>
          <div class="carousel-item">
            <p class="d-block w-100" alt="...">Text-2</p>
          </div>
          <div class="carousel-item">
            <p class="d-block w-100" alt="...">Text-3</p>
          </div>
          <div class="carousel-item">
            <p class="d-block w-100" alt="...">Text-4</p>
          </div>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
          <span class="carousel-control-prev-icon" aria-hidden="true"></span>
          <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>

相关问题