如何使 CSS 半透明的两个形状看起来像一个?

流行音乐

问题

像这样
我用 CSS 绘制了 2 个重叠的图形。
因为它是半透明的,所以重叠的部分很突出。
我想在悬停时使它像这样半透明,但是我们可以做一些诸如合成数字之类的事情吗?

(我也介意transition两个数字的结尾是不同的..)


我试过的

我认为重叠部分可以用 删除overflow: hidden;,但它不适用于对:: before角切割部分丢失的 &元素。


中心放置问题

我想以这种方式将标签中的字母集中对齐。 这边走


代码

html { font-size: 62.5%; }
body { background-color: #c6d2dd; }
header { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; font: inherit; vertical-align: baseline; background: transparent; box-sizing: border-box; }   /*  reset  */

header ul {
 list-style: none;
 display: flex;
 align-items: center;
 flex-wrap: wrap;
 overflow: hidden;
 width: 100%;
 margin-bottom: -1px;
}
header li {
 font-size: 1.5rem;
 height: 4.5rem;
 padding-left: .4rem;
}
header li:first-child {
 padding-left: 1.5rem;
}
header li:last-child {
 padding-right: .5rem;
}
header li > a {
 text-decoration: none;
 display: block;
 padding: 1rem 2rem;
 height: 100%;
 color: #fff;
 outline: none;
 transition: background-color 0.2s ease-out, border-color 0.2s ease-out;
 position: relative;
 border-radius: 9px 5px 0 0;
}

/*  from here  */
header li > a:hover {    /*  The rectangular part on the right side  */
 background-color: rgba(255, 255, 255, 0.4);
 border-color: rgba(255, 255, 255, 0.4);
 transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
 box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.4);
}
header li > a:hover::before {    /*  Part of oblique cut on the left side  */
 background-color: rgba(255, 255, 255, 0.4);
 border-color: rgba(255, 255, 255, 0.4);
 transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
 box-shadow: -2px 2px 2px rgba(0, 0, 0, 0.2);
}
header li > a::before {    /*  Part of oblique cut on the left side  */
 content: '';
 position: absolute;
 z-index: 1;
 top: 0;
 left: -.4rem;
 bottom: 0;
 width: 1rem;
 transition: background-color 0.3s ease-in;
 transform: skew(-15deg);
 border-radius: 5px 0 0 0;
}

.current a {    /*  add from here  */
  border: 1px solid #fff;
  border-bottom-width: 0;
  z-index: 3;
  background-color: #9bacbb;
  pointer-events: none;
  margin-bottom: -3px;
}
.current a::before {
  border: 1px solid #fff;
  background-color: #9bacbb;
  margin: -1px 0 -3px -1px;
  z-index: 3;
  left: -.5rem;
}
.current a::after {
  content: '';
  position: absolute;
  z-index: 3;
  top: 0;
  left: -.4rem;
  bottom: 0;
  width: 1rem;
  transform: skew(-15deg);
  border-radius: 5px 0 0 0;
  margin-bottom: -3px;
  background-color: #9bacbb;
}

.content {
  display: flex;
  margin: 0 1rem 1rem 1rem;
  width: 100vw;
  height: 61.9rem;
  position: relative;
  background: #9bacbb;
  border: 1px solid #fff;
  border-radius: 5px;
  box-shadow: 0 -2px 3px -2px rgba(0, 0, 0, 0.5);
}
<header>
 <nav>
  <ul>
   <li class="111">
    <a href="#">
     111
    </a>
   </li>
   <li class="222">
    <a href="#">
     222
    </a>
   </li>
   <li class="333">
    <a href="#">
     333
    </a>
   </li>
   <li class="444">
    <a href="#">
     444
    </a>
   </li>
   <li class="current">
    <a href="#">
     555
    </a>
   </li>
  </ul>
 </nav>
</header>

<div class="content">    <!--  add  -->
  Hello world
</div>

陪伴阿菲

我只会用一个元素来做这件事。诀窍是倾斜并隐藏右侧的溢出部分:

检查代码注释

html { font-size: 62.5%; }
body { background-color: #c6d2dd; }
header { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; font: inherit; vertical-align: baseline; background: transparent; box-sizing: border-box; }   /*  reset  */

header ul {
 list-style: none;
 display: flex;
 align-items: center;
 flex-wrap: wrap;
 overflow: hidden;
 width: 100%;
 margin-bottom: -1px;
}
header li {
 font-size: 1.5rem;
 height: 4.5rem;
 padding-left: .4rem;
}
header li:first-child {
 padding-left: 1.5rem;
}
header li:last-child {
 padding-right: .5rem;
}
header li > a {
 text-decoration: none;
 display: block;
 padding: 1rem 1rem 1rem 3rem; /*changed the padding*/
 margin-left:-2rem; /*create the overlap*/
 height: 100%;
 color: #fff;
 outline: none;
 transition: background-color 0.2s ease-out, border-color 0.2s ease-out;
 position: relative;
 border-radius: 9px 5px 0 0;
 overflow:hidden; /*hide the overflow*/
 /*increase the z-index*/
 position:relative;
 z-index:2;
}

/*  from here  */
header li > a:hover {    /*  The rectangular part on the right side  */
 transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
 box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.4);
 /*remove border and background from here*/
}
header li > a:hover::before {    /*  Part of oblique cut on the left side  */
 background-color: rgba(255, 255, 255, 0.4);
 border-color: rgba(255, 255, 255, 0.4);
 transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
 box-shadow: -2px 2px 2px rgba(0, 0, 0, 0.2);
}
header li > a::before {    /*  Part of oblique cut on the left side  */
 content: '';
 position: absolute;
 z-index: -1;
 top: 0;
 left: 0;
 bottom: 0;
 right:0; /*make right:0*/
 transition: background-color 0.3s ease-in;
 transform: skew(-15deg);
 transform-origin:bottom right; /*change the origin*/
 border-radius: 5px 0 0 0;
}

.current a {   
  pointer-events: none;
  margin-bottom: -3px;
  border-right: 1px solid #fff;
}
.current a::before {
  border: 1px solid #fff;
  background-color: #9bacbb;
}


.content {
  display: flex;
  margin: 0 1rem 1rem 1rem;
  width: 100vw;
  height: 61.9rem;
  position: relative;
  background: #9bacbb;
  border: 1px solid #fff;
  border-radius: 5px;
  box-shadow: 0 -2px 3px -2px rgba(0, 0, 0, 0.5);
}
<header>
 <nav>
  <ul>
   <li class="111">
    <a href="#">
     111
    </a>
   </li>
   <li class="222">
    <a href="#">
     222
    </a>
   </li>
   <li class="333">
    <a href="#">
     333
    </a>
   </li>
   <li class="444">
    <a href="#">
     444
    </a>
   </li>
   <li class="current">
    <a href="#">
     555
    </a>
   </li>
  </ul>
 </nav>
</header>
<div class="content">    <!--  add  -->
  Hello world
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用CSS将两个div重叠/重叠,使其看起来像文本气泡?

来自分类Dev

如何使用CSS将两个div叠加/叠加,使其看起来像文本气泡?

来自分类Dev

如何在CSS中设置菜单样式以使其看起来像一个按钮

来自分类Dev

html/css,使按钮看起来像一个 div

来自分类Dev

如何使烧瓶wtforms SelectField看起来像一个下拉列表?

来自分类Dev

如何创建一个看起来像电话按钮的按钮

来自分类Dev

如何使烧瓶wtforms SelectField看起来像一个下拉列表?

来自分类Dev

如何创建一个看起来像计时器的圆形进度条?

来自分类Dev

如何使 QPlainTextEdit 看起来像一个 .txt 文件?

来自分类Dev

如何使 Radio Widget 看起来像一个按钮

来自分类Dev

Bootstrap CSS 没有正确加载,看起来像一个典型的 HTML/CSS 下拉菜单

来自分类Dev

如何制作一个其构造函数看起来像内置类的构造函数的类?

来自分类Dev

如何将json结构更改为看起来像另一个json结构

来自分类Dev

uGet看起来像一个Linux应用程序。它如何在Windows上运行?

来自分类Dev

css 问题使其看起来像是合并了两个网格单元格(行)

来自分类Dev

如何使背景看起来像CSS3中的图像?

来自分类Dev

如何“转义”一个看起来与它来自的文件不同的字符串?

来自分类Dev

我构建了一个iOS软件来解析网站。但是该网站看起来像xhtml。object-c如何解析它?

来自分类Dev

问:控制器当前2秒钟,如何使其看起来像只有一个过渡?

来自分类Dev

javascript 如何循环浏览我的字符串的字符,使其看起来像一个仅使用 javascript 的选取框

来自分类Dev

如何降低 Cupertino Sliver Navigation bar 的高度,使其看起来像一个带有可滚动主体的普通 Cupertino Navigation Bar

来自分类Dev

悬停一个div时如何一次执行两个CSS动画?

来自分类Dev

创建一个看起来像两个条形的渐变背景

来自分类Dev

如何使用CSS和Jquery通过一个按钮获得两个结果

来自分类Dev

如何通过CSS或CSS3在一个div标签上形成两个边框?

来自分类Dev

如何使“ <input type =“ file” />”看起来像是CSS的链接?

来自分类Dev

如何使CSS转换看起来3D?

来自分类Dev

如何调整 CSS 使关闭按钮看起来正确?

来自分类Dev

CSS-Grid:如何左对齐2个,中间一个大,右边两个?

Related 相关文章

  1. 1

    如何使用CSS将两个div重叠/重叠,使其看起来像文本气泡?

  2. 2

    如何使用CSS将两个div叠加/叠加,使其看起来像文本气泡?

  3. 3

    如何在CSS中设置菜单样式以使其看起来像一个按钮

  4. 4

    html/css,使按钮看起来像一个 div

  5. 5

    如何使烧瓶wtforms SelectField看起来像一个下拉列表?

  6. 6

    如何创建一个看起来像电话按钮的按钮

  7. 7

    如何使烧瓶wtforms SelectField看起来像一个下拉列表?

  8. 8

    如何创建一个看起来像计时器的圆形进度条?

  9. 9

    如何使 QPlainTextEdit 看起来像一个 .txt 文件?

  10. 10

    如何使 Radio Widget 看起来像一个按钮

  11. 11

    Bootstrap CSS 没有正确加载,看起来像一个典型的 HTML/CSS 下拉菜单

  12. 12

    如何制作一个其构造函数看起来像内置类的构造函数的类?

  13. 13

    如何将json结构更改为看起来像另一个json结构

  14. 14

    uGet看起来像一个Linux应用程序。它如何在Windows上运行?

  15. 15

    css 问题使其看起来像是合并了两个网格单元格(行)

  16. 16

    如何使背景看起来像CSS3中的图像?

  17. 17

    如何“转义”一个看起来与它来自的文件不同的字符串?

  18. 18

    我构建了一个iOS软件来解析网站。但是该网站看起来像xhtml。object-c如何解析它?

  19. 19

    问:控制器当前2秒钟,如何使其看起来像只有一个过渡?

  20. 20

    javascript 如何循环浏览我的字符串的字符,使其看起来像一个仅使用 javascript 的选取框

  21. 21

    如何降低 Cupertino Sliver Navigation bar 的高度,使其看起来像一个带有可滚动主体的普通 Cupertino Navigation Bar

  22. 22

    悬停一个div时如何一次执行两个CSS动画?

  23. 23

    创建一个看起来像两个条形的渐变背景

  24. 24

    如何使用CSS和Jquery通过一个按钮获得两个结果

  25. 25

    如何通过CSS或CSS3在一个div标签上形成两个边框?

  26. 26

    如何使“ <input type =“ file” />”看起来像是CSS的链接?

  27. 27

    如何使CSS转换看起来3D?

  28. 28

    如何调整 CSS 使关闭按钮看起来正确?

  29. 29

    CSS-Grid:如何左对齐2个,中间一个大,右边两个?

热门标签

归档