html - 在菜单栏中为 Logo 创建切口

标签 html css

我有一个关于使用 CSS 在菜单中间剪切的问题。 让我解释更多: 我有一个两边都有三个“li”项的菜单,我想在菜单中间放一个 Logo 并为其创建一个切口,如下所示:

enter image description here

关于如何获得它,我首先想到的是将菜单分为两部分 - 左侧和右侧。之后使用“剪辑路径”尝试修改左侧菜单的末尾和右侧菜单的开始并使用“position:absolute”,在切口中间放置一个 Logo ,但我不确定这个解决方案。 enter image description here

也许您可以提出更好的建议?

Logo 是透明的,背景图像应该在 Logo 下方可见,因为菜单位于图像之上。

设计截图: enter image description here

最佳答案

我想了解有关径向渐变的更多信息,因此这里可能是您问题的解决方案。

:root {
  --background-cutout: 30px;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-image: linear-gradient(-130deg, lightblue, red);
}

nav {
  height: 30px;
  width: 100%;
  display: flex;
}

nav > div:not(.middle) {
  flex: 1 1 auto;
  background: cyan;
}

nav > div.middle {
  width: calc(var(--background-cutout) * 2);
  background-image:
    radial-gradient(circle at bottom, transparent 20px, aqua 21px); /* creates the "hole */
    
  display: flex;
  justify-content: center; /* place .circle in center */
  align-content: end; /* place .circle in the bottom */
}

nav > div.middle > .circle {
  height: var(--background-cutout);
  width: var(--background-cutout);
  border-radius: 50%;
  box-sizing: border-box; /* only needed because I used a border */
  border: 5px solid aqua;
  transform: translateY(50%);
}
<body>

<nav>
  <div class="left"></div>
  <div class="middle">
    <div class="circle"></div>
  </div>
  <div class="right"></div>
</nav>

</body>

关于html - 在菜单栏中为 Logo 创建切口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59151363/

相关文章:

javascript - 创建具有特定坐标的 div

css - 为什么这在 Firefox、Chrome 和 IE 中的工作方式不同?

html - 如何使用 HTML 和 CSS 制作简单的计时器图像幻灯片

Android 浏览器不使用 Cell-ID 通过 HTML5 API 进行地理定位(仅 GPS)

jquery - -webkit-transform 旋转和位置绝对左侧

css - 不带空格 "a>b"和带空格 "a > b"的 CSS 子选择器有什么区别?

css - 自动高度在 FF 和 Chrome 中不起作用

jquery - Div发生溢出时创建.....

html - 在 IE7 中正确对齐一行上的两个 div

java - 离开页面时运行java函数(HTML)