excedent the just hide to How the div?

huangapple go评论94阅读模式
英文:

How to hide just the excedent of the div?

问题

在我的网站上,我有一个 div 元素(圆圈),它使用位置属性来放置在图像中的特定位置,但是这个圆圈占用了右侧多余的空间,导致视图宽度增加,如何只隐藏圆圈的多余部分?

我不想将圆圈移到其他位置,只想隐藏多余的部分。

.floating-circles .big-circle {
  position: absolute;
  z-index: 1;
  right: calc((-35vw / 2) + 9%);
  bottom: calc((-35vw / 2) + 14%);
  overflow: hidden;
  overflow-x: hidden;
  width: 35vw;
  height: 35vw;
  border-radius: 50%;
  background: rgb(146, 28, 205);
  background: linear-gradient(45deg, rgba(146, 28, 205, 1) 0%, rgba(153, 26, 177, 1) 40%, rgba(48, 35, 174, 1) 80%, rgba(48, 35, 174, 1) 100%);
}
<div class="floating-circles">
  <div class="small-circle"></div>
  <div class="big-circle"></div>
  <!-- big-circle 是导致问题的圆圈 -->
</div>

完整项目代码可在GitHub 上查看

英文:

Im my site, i have a div (the circle) that use position to be in that position in image, but the circle is ocupping an excedent space in the right who is forcing the view width to grow, how to hide just the excedent part of the circle?

I don't want to move the circle for another position, just hide the excedent.

excedent the just hide to How the div?

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-css -->

.floating-circles .big-circle {
  position: absolute;
  z-index: 1;
  right: calc((-35vw / 2) + 9%);
  bottom: calc((-35vw / 2) + 14%);
  overflow: hidden;
  overflow-x: hidden;
  width: 35vw;
  height: 35vw;
  border-radius: 50%;
  background: rgb(146, 28, 205);
  background: linear-gradient(45deg, rgba(146, 28, 205, 1) 0%, rgba(153, 26, 177, 1) 40%, rgba(48, 35, 174, 1) 80%, rgba(48, 35, 174, 1) 100%);
}

<!-- language: lang-html -->

&lt;div class=&quot;floating-circles&quot;&gt;
  &lt;div class=&quot;small-circle&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;big-circle&quot;&gt;&lt;/div&gt;
  &lt;!-- The big-circle is the circle causing the bug --&gt;
&lt;/div&gt;

<!-- end snippet -->

Full project code here in github

答案1

得分: 3

你可以防止 body 溢出内容:

body {
  overflow-x: hidden;
}

或者使用一个 clip-path,将主要框之外的所有内容“剪切掉”:

.floating-circles {
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 0);
  /* 或者 clip-path: inset(0) */
  /* 感谢 @TemaniAfif 的建议! */
}

试一试:

<div class="floating-circles">
  <div class="big-circle"></div>
</div>
英文:

You can either prevents body from overflowing:

body {
  overflow-x: hidden;
}

...or use a clip-path that "cuts" everything outside of the main box:

.floating-circles {
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 0);
  /* or clip-path: inset(0) */
  /* Thanks @TemaniAfif for the suggestion! */
}

Try it:

<!-- begin snippet: js hide: true -->

<!-- language: lang-css -->

.floating-circles {
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 0);
}


/* Demo only */

.floating-circles {
  position: relative;
  top: 4em;
  height: 200px;
  width: 500px;
  background: #ddd;
}

.floating-circles .big-circle {
  position: absolute;
  right: -25px;
  bottom: -40px;
  width: 125px;
  height: 125px;
  border-radius: 50%;
  background: linear-gradient(45deg, rgba(146, 28, 205, 1) 0%, rgba(153, 26, 177, 1) 40%, rgba(48, 35, 174, 1) 80%, rgba(48, 35, 174, 1) 100%);
}

<!-- language: lang-html -->

&lt;div class=&quot;floating-circles&quot;&gt;
  &lt;div class=&quot;big-circle&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月29日 06:43:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76353860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定