手写笔设置中的url()函数有什么作用? [英] What does url() function do in Stylus setup?

查看:90
本文介绍了手写笔设置中的url()函数有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注此处有关Stylus官方文档的文档并想知道url()函数在其中的示例代码中的作用.特别是,我想知道应该在项目/文件中编写代码的位置...例如,如果在Node.js/Express应用程序的app.js(或server.js)文件中定义代码,则会触发错误:str is not defined,因为很明显我没有在文件中定义str变量.

I've been following the documentation here over official Stylus docs and wonder what the url() function does in the example code there. Especially, I would like to know where I should write the code in my projects/files... For example, if I define it in app.js (or server.js) file in my Node.js/Express application, it triggers an error: str is not defined, since it's obvious that I don't define str variable in my file.

但是,我首先不了解str变量是什么以及它来自何处.

However, I don't understand what the str variable is and where it does come from in the first place.

我认为url()函数是一个包装器,当实际的手写笔代码在其手写笔文件之一(例如style.styl)中找到url()时将执行该包装器,但除此之外,我没有得到它有什么用,什么时候我定义它,什么时候不需要.

I think that the url() function is a wrapper that is to be executed when the actual Stylus code finds url() in one of its Stylus files (like style.styl), but beyond that, I don't get what it does nor when I define it and when I don't need to.

有人在这里澄清吗?

我使用Express 3.5.1和Stylus 0.44.

I use Express 3.5.1 and Stylus 0.44.

推荐答案

它可帮助您将图像转换为样式表中正确的base-64数据,而不是将其链接为外部资源.

It helps you turn an image into base-64 data that goes right in the stylesheet, instead of linking to the image as an external resource.

此处

如果将其设置为选项,它将替换样式表中的默认url()行为.

It replaces the default url() behavior in your stylesheet if you set it up as an option.

那样,当您说:

.someElement
   background-image url('someImage.png')

手写笔代替链接图像文件,而是将图像转换为base-64字符串并将其内联为输出样式

instead of linking to the image file, stylus converts the image to a base-64 string and inlines it into the output style

这篇关于手写笔设置中的url()函数有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆