45 度角 + Box Shadow - 只使用 CSS

发布于 2024-09-30 18:00:02 字数 320 浏览 3 评论 0原文

我需要仅使用 CSS 重新创建以下设计:

image

您在图片是网站容器的顶部 - “链接”是主菜单的一部分。

就目前而言,我已经创建了容器,但我不确定如何在不使用图像的情况下在导航上进行倾斜。

郑重声明:我不想使用图像,因为倾斜上的框阴影与浏览器渲染的框阴影匹配的可能性很小,尤其是在使用多个浏览器时。

我正在思考具有白色背景和盒子阴影的定位和旋转 div 的思路,但我还无法构建它。

有什么想法吗?

I need to recreate the following design using only CSS:

image

What you're seeing in the picture is the top of a website container - the "links" are part of the main menu.

As it stands, I've created the container but I'm not sure how to go about making the slant on the navigation without using an image.

For the record: I'd rather not use an image as the chances of the box shadow on the slant matching up with box shadow rendered by the browser are slim-to-none, especially when it comes to multiple browsers.

I was thinking along the lines of a positioned and rotated div with a white background and a box shadow, but I haven't been able to build it yet.

Any ideas?

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

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

发布评论

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

评论(4

云柯 2024-10-07 18:00:03

有一种东西叫做砂纸< /a> 可以帮助您转换元素,即使在 IE 中也是如此!

.myDiv {
    -sand-transform: rotate(45deg);
}

您只需将其插入您的网站即可。

您也可以使用 CSS3 转换,您在问题中提到过:“除了 CSS 之外什么都不用。”

为此,您可以使用:

 .myDiv {
    -webkit-transform: rotate(45deg); 
    -moz-transform: rotate(45deg);  
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=5); /*for IE*/
}

感谢 Josh 和 Robert 提供的 Opera 等效项:

-o-transform: rotate(45deg);

Internet Explorer 将在任何应用了过滤器的文本上放置 ClearType。但是您可以在主元素内添加空的额外元素,并对这个额外元素应用过滤器。这样ClearType就不会被破坏并且可以达到相同的结果。

There is something called Sandpaper that can help you to transform your elements, even in IE!

.myDiv {
    -sand-transform: rotate(45deg);
}

You can just plug it into your site and you're set.

Also you can use CSS3 transforms, which you asked about in your question: "Using nothing but CSS."

To do this you'd use:

 .myDiv {
    -webkit-transform: rotate(45deg); 
    -moz-transform: rotate(45deg);  
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=5); /*for IE*/
}

And thanks to Josh and Robert for the Opera equivalent:

-o-transform: rotate(45deg);

Internet Explorer will drop ClearType on any text that has a filter applied to it. But you can add empty extra element inside the main one and apply filter to this extra element. After this ClearType will be not ruined and the same result can be achieved.

明媚如初 2024-10-07 18:00:03

对于旋转,您需要:

-moz-transform:rotate(45deg);
-webkit-transform:rotate(45deg);

请记住,旋转是 CSS3 属性,因此您不会在所有浏览器中获得相同的行为。与其仅用图像进行倾斜,不如重新创建整个轮廓可能会更好。我会用以下方法来处理它:

  1. 标题部分,其中有倾斜、阴影、菜单背景和内容顶部的填充,与您的屏幕截图非常相似。
  2. 可以用阴影重复整个内容的图像。
  3. 页脚部分。

您还可以使用外部库来尝试重新创建 CSS3 属性,但图像可能是最简单的方法,因为您知道它们将如何呈现。

For rotation, you're looking for:

-moz-transform:rotate(45deg);
-webkit-transform:rotate(45deg);

Keep in mind, that the rotation is a CSS3 attribute, so you're not going to get the same behavior across all browsers. Rather than making just the slant with an image, it would probably be better to recreate the whole outline. I'd approach it with:

  1. The header section, which would have the slant, shadow, the menu background and the padding at the top of the content, pretty much like your screenshot there.
  2. An image that can repeat-y down the entire body of content with a shadow.
  3. The footer section.

You can also use external libraries to attempt to recreate CSS3 attributes, but images may be the easiest way as you know how they'll render.

从此见与不见 2024-10-07 18:00:03

我认为您可以使用 http://nicolasgallagher.com/pure-css- 中的技术voice-bubbles/demo/

这是一个非常好的汇编,也是使用 CSS 的灵感。享受。

PS:它比 CSS3 转换更安全。

I think you can use the techniques from http://nicolasgallagher.com/pure-css-speech-bubbles/demo/

This is a really nice compilation and inspiration for using CSS. Enjoy.

PS: it is safer than CSS3 transforms.

错々过的事 2024-10-07 18:00:03

旋转似乎没有必要。我会尝试使用 CSS 三角形效果。

我假设您的链接位于 ul 中,因此您的 css 可以选择 ul:before 并将其设置为正确的形状。

我不知道 box-shadow 会发生什么,但它可能值得一试,并且可能会更容易在 IE 中对齐,而无需求助于 JavaScript。

Rotation seems unnecessary. I would try using a CSS triangle effect.

I'm going to assume your links are in a ul so your css could select ul:before and make it into the correct shape.

I don't know what will happen with the box-shadow but it might be worth a shot, and will probably be easier to align in IE without resorting to JavaScript.

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