Tumblr 的逐像素箭头

发布于 2024-12-11 05:02:36 字数 428 浏览 0 评论 0原文

如果您查看这里:

http://www.tumblr .com/explore

您会注意到“探索”菜单项上方的背景框和小三角形。我非常喜欢 Tumblr 的设计,所以我一直在努力从中学习。当我使用 Chrome 方便的开发人员工具时,我看到,对于这个小三角形,他们是逐像素“绘制”的。它们每像素高 6 个 div。第一个是 11 像素宽,第二个是 9 像素,第三个是 7 ......

这在我的脑海中引发了各种小信号,但我才刚刚进入 Web 开发,所以我想我应该问了解更多的人关于它。

那么,各位专业人士,使用 HTML 元素而不是使用图像进行逐像素设计的优点和缺点是什么?

If you check out here:

http://www.tumblr.com/explore

You'll notice the background box and little triangle over the "explore" menu item. I absolutely love Tumblr's design, so I've been trying to learn what I can from it. When I used Chrome's handy developer's tools, I saw that, for the little triangle, they "drew" it pixel by pixel. They have 6 divs a pixel tall. The first is 11 pixels wide, the second is 9, the third 7...

This raises all sorts of little flags in my head, but I've only just gotten into web development, so I figured I would ask people who know more about it.

So, all you pros out there, what are the pros and cons of doing a design pixel by pixel with HTML elements instead of using an image?

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

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

发布评论

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

评论(2

江南月 2024-12-18 05:02:36

优点是它在各个浏览器中都是相同的,甚至是 IE6,并且它不会对背景图像方法发出额外的 HTTP 请求。

当然,缺点是 HTML 和 CSS 权重增加、语义减少以及代码看起来更混乱。即使使用图像,更好的替代方案是使用伪元素,其形状看起来像三角形。它不会破坏干净的代码或语义。

The advantages are that it will be identical across browsers, even IE6, and it doesn't make an extra HTTP request for the background image method.

The drawback, of course, is an increased HTML and CSS weight, decreased semantics, and a messier-looking code. A better alternative, even to using an image, would be to use a pseudo-element, shaped to look like a triangle. It wouldn't take away from a clean code, or semantics.

故笙诉离歌 2024-12-18 05:02:36

虽然正如其他人指出的那样,这确实在 IE6 中实现了透明度,但这并不是很有说服力,因为您始终可以为此应用程序使用透明的 GIF。

我想说,这个 hack 是为了减少对服务器的一次调用。这有两个主要好处:

  • 即时可见性。如果渲染图像所需的所有信息都在 CSS 和 HTML 中,则可以尽快渲染。没有额外的网络调用。
  • 走出关键路径。该页面有很多文件需要加载。由于浏览器限制与服务器的并发连接数,因此您可以从启动过程中删除的任何文件都将缩短加载时间。

另一种方法是使用包含透明 PNG 的数据 URL。更好的是它不依赖于 hack,但更糟糕的是 IE6 和 IE7 不支持它。更常见的做法是将页面使用的所有图像捆绑在精灵图像中,并使用带有 background-position 的 CSS 背景来裁剪出精确的图像。这样做的缺点是仍然需要网络调用,但如果您不需要 IE6 或 IE7,则可以与数据 URL 捆绑在一起。

当然,缺点是这是一种黑客行为,不是正确的做事方式。

总结:

优点

  • 快速渲染
  • 无需网络调用
  • 改进页面加载时间
  • 跨浏览器支持

缺点

  • 这不是您应该做的事情。

我个人很喜欢它,如果有必要的话我完全会做类似的事情。

While this does achieve transparency in IE6 as others point out, this is not very convincing since you could always use a transparent GIF for this application.

I would say that this hack is here to have one less call to the server. This has two main benefits:

  • Instant visibility. If all the information you need to render the image is in the CSS and HTML, it can render as soon as possible. There is no additional network call.
  • Getting out of the critical path. This page has a lot of files to load. Since browsers limit the number of concurrent connections to a server, any file you can remove from the startup process will improve load time.

An alternative would be to use a data URL holding a transparent PNG. This is better in that it doesn't depend on a hack but worse in that IE6 and IE7 can't support it. A more common practice is to bundle all images used by the page in a sprite image and use CSS backgrounds with background-position to crop out the exact image. This has the disadvantage of still requiring a network call but could be bundled with a data URL if you don't need IE6 or IE7.

The disadvantage of course is that this is a hack and isn't the right way of doing things.

In summary:

PROS

  • Fast rendering
  • No network call needed
  • Improved page load time
  • Cross browser support

CONS

  • It's just not how you're supposed to do things.

I personally love it and would totally do something like it if I had to.

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