通过多个元素的连续梯度

发布于 2025-02-10 22:02:49 字数 2727 浏览 2 评论 0原文

我正在尝试创建一个由四个菜单项组成的Circle/Pie Nav。总菜单应具有带有四种主要颜色的渐变。菜单项需要独立,因为它们具有悬停效果。

我希望梯度在所有元素上无缝显示。

这是应该的样子:

这是一个片段,可以向您展示我到目前为止所做的事情。如您所见,将梯度应用于每个元素与出现均匀的元素。

另外,当尝试使用线性或径向梯度时,我无法创建此二次类型梯度,每个部分是主要颜色,然后逐渐淡入下一节。

任何帮助都将受到赞赏。

ul {
  margin: 100px auto;
  padding: 0;
  position: relative;
  width: 20em;
  height: 20em;
  border-radius: 100%;
  transform: rotate(45deg);
  background: gray;
}

ul a {
  position: absolute;
  list-style: none;
  width: 10em;
  height: 10em;
  color: #fff;
  text-align: center;
  line-height: 5em;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  transition: all 0.5s ease;
  border-left: 1px solid white;
  border-top: 1px solid white;
  transition: 0.5s;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  background: linear-gradient(
    49deg,
    #6a3fc5 0%,
    #f44336 25%,
    #009688 50%,
    #ffc107 100%
  );
}
ul a:hover {
  cursor: pointer;
}
ul li {
  transform: rotate(-45deg);
}

ul a:nth-child(1):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, -10px);
}
ul a:nth-child(2):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, -10px);
}
ul a:nth-child(3):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, 10px);
}
ul a:nth-child(4):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, 10px);
}

ul a:nth-child(1) {
  top: 0;
  left: 0;

  border-top-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(2) {
  top: 0em;
  left: 10em;
  border-top-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(3) {
  top: 10em;a
  left: 0;
  border-bottom-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(4) {
  top: 10em;
  left: 10em;
  border-bottom-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
<ul class="menu">
    <a href="/"><li class="item">Targeting</li></a>
   <a href="/"><li class="item">Optimization</li></a>
   <a href="/"><li class="item">Enablement</li></a>
   <a href="/"><li class="item">Measurement</li></a>
  </ul>

I'm trying to create a circle/pie nav that consists of four menu items. The overall menu should have a gradient with four main colors. The menu items need to be independent as they have hover effects.

I would like the gradient to display seamlessly over all the elements.

Here is what it should look like:

enter image description here

Here is a snippet to show you what I've done so far. As you can see, the gradient is applied to each element vs appearing uniform.

Also, when trying to use a linear or radial gradient, I haven't been able to create this quadrent-type gradient where each section is the primary color and then fades into the next section.

Any help is appreciated.

ul {
  margin: 100px auto;
  padding: 0;
  position: relative;
  width: 20em;
  height: 20em;
  border-radius: 100%;
  transform: rotate(45deg);
  background: gray;
}

ul a {
  position: absolute;
  list-style: none;
  width: 10em;
  height: 10em;
  color: #fff;
  text-align: center;
  line-height: 5em;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  transition: all 0.5s ease;
  border-left: 1px solid white;
  border-top: 1px solid white;
  transition: 0.5s;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  background: linear-gradient(
    49deg,
    #6a3fc5 0%,
    #f44336 25%,
    #009688 50%,
    #ffc107 100%
  );
}
ul a:hover {
  cursor: pointer;
}
ul li {
  transform: rotate(-45deg);
}

ul a:nth-child(1):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, -10px);
}
ul a:nth-child(2):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, -10px);
}
ul a:nth-child(3):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, 10px);
}
ul a:nth-child(4):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, 10px);
}

ul a:nth-child(1) {
  top: 0;
  left: 0;

  border-top-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(2) {
  top: 0em;
  left: 10em;
  border-top-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(3) {
  top: 10em;a
  left: 0;
  border-bottom-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(4) {
  top: 10em;
  left: 10em;
  border-bottom-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
<ul class="menu">
    <a href="/"><li class="item">Targeting</li></a>
   <a href="/"><li class="item">Optimization</li></a>
   <a href="/"><li class="item">Enablement</li></a>
   <a href="/"><li class="item">Measurement</li></a>
  </ul>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋意浓 2025-02-17 22:02:49
.circle {
  width: 300px;
  height: 300px;
  background: conic-gradient(#81408e, #c84955, #f05435, #b58835, #7fbd37, #3baf75, #00a4b2, #3770a2, #81408e);
  border-radius: 50%;
  filter: blur(15px);
}

.circle-container {
  width: 300px; 
  height: 300px;
  border-radius: 50%;
  overflow: hidden;
}
<div class="circle-container">
   <div class="circle"></div>
</div>

.circle {
  width: 300px;
  height: 300px;
  background: conic-gradient(#81408e, #c84955, #f05435, #b58835, #7fbd37, #3baf75, #00a4b2, #3770a2, #81408e);
  border-radius: 50%;
  filter: blur(15px);
}

.circle-container {
  width: 300px; 
  height: 300px;
  border-radius: 50%;
  overflow: hidden;
}
<div class="circle-container">
   <div class="circle"></div>
</div>

月亮坠入山谷 2025-02-17 22:02:49

好吧,我认为,而不是在“ ul a”上使用背景,而应仅在“ ul”上使用梯度如下:

ul {
  margin: 100px auto;
  padding: 0;
  position: relative;
  width: 20em;
  height: 20em;
  border-radius: 100%;
  transform: rotate(45deg);
  background: gray;
}

ul a {
  position: absolute;
  list-style: none;
  width: 10em;
  height: 10em;
  color: #fff;
  text-align: center;
  line-height: 5em;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  transition: all 0.5s ease;
  border-left: 1px solid white;
  border-top: 1px solid white;
  transition: 0.5s;
  
}

ul {
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  background: linear-gradient(
    49deg,
    #6a3fc5 0%,
    #f44336 25%,
    #009688 50%,
    #ffc107 100%
  );
}
ul a:hover {
  cursor: pointer;
}
ul li {
  transform: rotate(-45deg);
}

ul a:nth-child(1):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, -10px);
}
ul a:nth-child(2):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, -10px);
}
ul a:nth-child(3):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, 10px);
}
ul a:nth-child(4):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, 10px);
}

ul a:nth-child(1) {
  top: 0;
  left: 0;

  border-top-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(2) {
  top: 0em;
  left: 10em;
  border-top-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(3) {
  top: 10em;a
  left: 0;
  border-bottom-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(4) {
  top: 10em;
  left: 10em;
  border-bottom-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
<ul class="menu">
    <a href="/"><li class="item">Targeting</li></a>
   <a href="/"><li class="item">Optimization</li></a>
   <a href="/"><li class="item">Enablement</li></a>
   <a href="/"><li class="item">Measurement</li></a>
  </ul>

Well I think, instead of using background on "ul a" you should use the gradient only on the "ul" like below:

ul {
  margin: 100px auto;
  padding: 0;
  position: relative;
  width: 20em;
  height: 20em;
  border-radius: 100%;
  transform: rotate(45deg);
  background: gray;
}

ul a {
  position: absolute;
  list-style: none;
  width: 10em;
  height: 10em;
  color: #fff;
  text-align: center;
  line-height: 5em;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  transition: all 0.5s ease;
  border-left: 1px solid white;
  border-top: 1px solid white;
  transition: 0.5s;
  
}

ul {
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  background: linear-gradient(
    49deg,
    #6a3fc5 0%,
    #f44336 25%,
    #009688 50%,
    #ffc107 100%
  );
}
ul a:hover {
  cursor: pointer;
}
ul li {
  transform: rotate(-45deg);
}

ul a:nth-child(1):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, -10px);
}
ul a:nth-child(2):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, -10px);
}
ul a:nth-child(3):hover {
  background: #999;
  z-index: 19;
  transform: translate(-10px, 10px);
}
ul a:nth-child(4):hover {
  background: #999;
  z-index: 19;
  transform: translate(10px, 10px);
}

ul a:nth-child(1) {
  top: 0;
  left: 0;

  border-top-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(2) {
  top: 0em;
  left: 10em;
  border-top-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(3) {
  top: 10em;a
  left: 0;
  border-bottom-left-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
ul a:nth-child(4) {
  top: 10em;
  left: 10em;
  border-bottom-right-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
<ul class="menu">
    <a href="/"><li class="item">Targeting</li></a>
   <a href="/"><li class="item">Optimization</li></a>
   <a href="/"><li class="item">Enablement</li></a>
   <a href="/"><li class="item">Measurement</li></a>
  </ul>

倦话 2025-02-17 22:02:49

您可以使用评论中讨论的圆锥梯度或图像本身,也可以在包含要构成梯度的所有元素的元素上使用模糊,并具有使用溢出隐藏的父级div 在具有高边框半径的模糊元件上。然后将其放在您的交互式悬停层下,这可以是您已经拥有的东西,但是以透明的背景开始,因此梯度通过显示。.

我建议将您要模糊的容器比容器大一点隐藏溢流,以防止白色羽化在圆的外边缘。

我还建议您使用元素上的SVG十字架,如果您想更接近原始设计,而不是边界。

在此示例中,我使用网格放置将某些元素互相强制,而无需绝对定位,但绝对定位元素也会起作用。

.wrapper {
  position: relative;
  width: 20em;
  height: 20em;
  margin: 50px;
  display: grid;
}

.cross {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  pointer-events: none
}

.menu {
  position: relative;
  z-index: 2;
  grid-row: 1/2;
  grid-column: 1/2;
  position: relative;
  width: 20em;
  height: 20em;
  transform: rotate(45deg);
  padding: 0;
  margin: 0;
}

.item {
  position: absolute;
  width: 10em;
  height: 10em;
  color: #fff;
  transition: all 0.5s ease;
  transition: 0.5s;
  display: flex;
  overflow: hidden;
  text-transform: uppercase
}

.item, .item:hover {
  text-decoration: none
}

.item:nth-child(1) {
  top: 0;
  left: 0;
  border-top-left-radius: 100%;
}

.item:nth-child(2) {
  top: 0em;
  left: 10em;
  border-top-right-radius: 100%;
}

.item:nth-child(3) {
  top: 10em;
  left: 0;
  border-bottom-left-radius: 100%;
}

.item:nth-child(4) {
  top: 10em;
  left: 10em;
  border-bottom-right-radius: 100%;
}

.item span {
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-family: 'Oswald', sans-serif;
  font-size: 1.2rem;
  width: 100%;
  height: 100%;
}

.item:nth-child(2) span {
  justify-content: flex-start;
}

.item:nth-child(3) span {
  justify-content: flex-end;
}

.item:nth-child(1) span {
  position: relative;
  top: 1.5em;
  left: 1.5em
}

.item:nth-child(4) span {
  position: relative;
  top: -.75em;
  right: .75em
}

.item:nth-child(1):hover {
  background: #999;
  transform: translate(-10px, -10px);
}

.item:nth-child(2):hover {
  background: #999;
  transform: translate(10px, -10px);
}

.item:nth-child(3):hover {
  background: #999;
  transform: translate(-10px, 10px);
}

.item:nth-child(4):hover {
  background: #999;
  transform: translate(10px, 10px);
}

.gradient-concealer {
  height: 20em;
  width: 20em;
  border-radius: 99999px;
  overflow: hidden;
  position: relative;
  top: 0;
  left: 0;
  transform: rotate(45deg);
  transform-origin: center;
  grid-row: 1/2;
  grid-column: 1/2
}

.gradient {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  background: #fff;
  filter: blur(30px);
  height: 24em;
  width: 24em;
  position: relative;
  top: -2em;
  left: -2em
}

.purple {
  background-color: #ca61df;
  background: radial-gradient(circle, rgba(202, 97, 223, 1) 11%, rgba(143, 97, 223, 1) 47%);
}

.red {
  background-color: #ff5932;
}

.blue {
  background-color: #16c5d3;
  background: radial-gradient(circle, rgba(25, 205, 219, 1) 18%, rgba(29, 166, 177, 1) 47%);
}

.green {
  background-color: #90d33c;
}
<div class="wrapper">
  <div class="menu">
    <a href="/" class="item">
      <span>targeting</span>
    </a>
    <a href="/" class="item">
      <span>optimization</span>
    </a>
    <a href="/" class="item">
      <span>enablement</span>
    </a>
    <a href="/" class="item">
      <span>measurement</span>
    </a>
  </div>
  <div class="cross">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="2" stroke="#fff">
        <line vector-effect="non-scaling-stroke" x1="19" y1="5" x2="5" y2="19" />
        <line vector-effect="non-scaling-stroke" x1="5" y1="5" x2="19" y2="19" />
    </svg>
  </div>
  <div class="gradient-concealer">
    <div class="gradient">
      <div class="purple"></div>
      <div class="red"></div>
      <div class="blue"></div>
      <div class="green"></div>
    </div>
  </div>
</div>

You can use conic gradient or the image itself as discussed in the comments or you can use a blur on an element that contains all of the elements you want to form the gradient and have a parent div that uses overflow-hidden on the blurred element with a high border radius. Then place that under your interactive hover layer which can be what you already have but with a transparent background to begin with so the gradient shows through..

I would recommend making the container you are going to blur be a bit larger than the container that will hide the overflow to prevent white feathering at the outer edges of the circle.

I'd also recommend using an SVG cross positioned absolutely over the elements instead of borders if you want to get closer to your original design.

In this example I'm using grid for placement to force some elements on top of one another without absolute positioning but absolute positioning the elements would work just as well.

.wrapper {
  position: relative;
  width: 20em;
  height: 20em;
  margin: 50px;
  display: grid;
}

.cross {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  pointer-events: none
}

.menu {
  position: relative;
  z-index: 2;
  grid-row: 1/2;
  grid-column: 1/2;
  position: relative;
  width: 20em;
  height: 20em;
  transform: rotate(45deg);
  padding: 0;
  margin: 0;
}

.item {
  position: absolute;
  width: 10em;
  height: 10em;
  color: #fff;
  transition: all 0.5s ease;
  transition: 0.5s;
  display: flex;
  overflow: hidden;
  text-transform: uppercase
}

.item, .item:hover {
  text-decoration: none
}

.item:nth-child(1) {
  top: 0;
  left: 0;
  border-top-left-radius: 100%;
}

.item:nth-child(2) {
  top: 0em;
  left: 10em;
  border-top-right-radius: 100%;
}

.item:nth-child(3) {
  top: 10em;
  left: 0;
  border-bottom-left-radius: 100%;
}

.item:nth-child(4) {
  top: 10em;
  left: 10em;
  border-bottom-right-radius: 100%;
}

.item span {
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-family: 'Oswald', sans-serif;
  font-size: 1.2rem;
  width: 100%;
  height: 100%;
}

.item:nth-child(2) span {
  justify-content: flex-start;
}

.item:nth-child(3) span {
  justify-content: flex-end;
}

.item:nth-child(1) span {
  position: relative;
  top: 1.5em;
  left: 1.5em
}

.item:nth-child(4) span {
  position: relative;
  top: -.75em;
  right: .75em
}

.item:nth-child(1):hover {
  background: #999;
  transform: translate(-10px, -10px);
}

.item:nth-child(2):hover {
  background: #999;
  transform: translate(10px, -10px);
}

.item:nth-child(3):hover {
  background: #999;
  transform: translate(-10px, 10px);
}

.item:nth-child(4):hover {
  background: #999;
  transform: translate(10px, 10px);
}

.gradient-concealer {
  height: 20em;
  width: 20em;
  border-radius: 99999px;
  overflow: hidden;
  position: relative;
  top: 0;
  left: 0;
  transform: rotate(45deg);
  transform-origin: center;
  grid-row: 1/2;
  grid-column: 1/2
}

.gradient {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  background: #fff;
  filter: blur(30px);
  height: 24em;
  width: 24em;
  position: relative;
  top: -2em;
  left: -2em
}

.purple {
  background-color: #ca61df;
  background: radial-gradient(circle, rgba(202, 97, 223, 1) 11%, rgba(143, 97, 223, 1) 47%);
}

.red {
  background-color: #ff5932;
}

.blue {
  background-color: #16c5d3;
  background: radial-gradient(circle, rgba(25, 205, 219, 1) 18%, rgba(29, 166, 177, 1) 47%);
}

.green {
  background-color: #90d33c;
}
<div class="wrapper">
  <div class="menu">
    <a href="/" class="item">
      <span>targeting</span>
    </a>
    <a href="/" class="item">
      <span>optimization</span>
    </a>
    <a href="/" class="item">
      <span>enablement</span>
    </a>
    <a href="/" class="item">
      <span>measurement</span>
    </a>
  </div>
  <div class="cross">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="2" stroke="#fff">
        <line vector-effect="non-scaling-stroke" x1="19" y1="5" x2="5" y2="19" />
        <line vector-effect="non-scaling-stroke" x1="5" y1="5" x2="19" y2="19" />
    </svg>
  </div>
  <div class="gradient-concealer">
    <div class="gradient">
      <div class="purple"></div>
      <div class="red"></div>
      <div class="blue"></div>
      <div class="green"></div>
    </div>
  </div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文