mysql游标少循环

In the previous article we learned the basics of the Less mixin guards and loops. We saw that once we’ve gained a clear understanding of their structure we can use them properly. Now, we’ll explore how this knowledge can be put to practice by examining some real world examples.

在上一篇文章中,我们了解了Less mixin保护和循环的基础。 我们看到,一旦对它们的结构有了清楚的了解,就可以正确使用它们。 现在,我们将通过研究一些实际示例来探索如何将这些知识付诸实践。

创建警报框 (Creating Alert Boxes)

The first example is to create an alert box with four variations. We’ll create a mixin guard that transforms a regular div into a differently styled alert box – depending on the argument (the type of alert box) we pass to the mixin. First, we need to define some variables:

第一个示例是创建具有四个变体的警报框。 我们将创建一个mixin防护,将常规div转换为样式不同的警报框-取决于传递给mixin的参数(警报框的类型)。 首先,我们需要定义一些变量:

@color_info: #00a8e6;
@color_success: #8cc14c;
@color_warning: #faa732;
@color_error: #da314b;

These are four color variables, which we’re going to use for the four variants of our alert box. Now, let’s add the needed mixin guards:

这是四个颜色变量,我们将在警报框的四个变体中使用它们。 现在,让我们添加所需的mixin防护:

.alert(@mode) when (@mode = 'info'){
background-color: @color_info;
border: thin solid darken(@color_info, 15%);
}
...
.alert(@mode) {
width: 300px;
padding: 25px;
color: #fff;
text-shadow: 0.5px 0.5px #000;
}

The first part of the above code creates a conditional statement, which, if the @mode parameter is equal to "info", will use the @color_info variable to set both the background color of the alert box and the color for its border. We use the darken() function to make the border color 15% darker than the background color.

上面的代码的第一部分创建了一个条件语句,如果@mode参数等于“ info”,则该条件语句将使用@color_info变量设置警报框的背景颜色及其边框的颜色。 我们使用darken()函数使边框颜色比背景颜色深15%。

We need to repeat the same pattern for the rest three variants. We do that by copying and pasting the first variant. For each variant we use the appropriate color variable and change the word "info" to "success", "warning", and "error" respectively.

对于其余三个变体,我们需要重复相同的模式。 我们通过复制和粘贴第一个变体来做到这一点。 对于每种变体,我们使用适当的颜色变量,并将单词“ info”分别更改为“ success”,“ warning”和“ error”。

Finally, at the end, we put the styles that are common for all alert boxes. We set the text color to white and apply a subtle text shadow effect to it for better contrast.

最后,最后,我们放置所有警报框通用的样式。 我们将文本颜色设置为白色,并对它应用微妙的文本阴影效果以获得更好的对比度。

Now, to use the mixin we need to put it like so .alert('success'), inside a CSS rule for the div. Et voila. We can see a nice alert box with green background.

现在,要使用mixin,我们需要将它像.alert('success')这样.alert('success') divCSS规则中。 等等 。 我们可以看到一个带有绿色背景的漂亮警报框。

Depending on our needs, we can use different colors for our alert boxes – by changing the values of the color variables – and still keeping the mixin semantic.

根据我们的需要,我们可以为警报框使用不同的颜色-通过更改颜色变量的值-并仍然保留mixin语义。

See the Pen Mastering Less Guards and Loops #1 by SitePoint (@SitePoint) on CodePen.

请参阅CodePen上SitePoint ( @SitePoint ) 编写的Pen Mastering Less Guards and Loops#1 。

创建响应式网格 (Creating Responsive Grids)

One of the most valuable uses of Less loops is for creating a responsive grid system. Let’s see how this can be done. Let’s explore the following code:

Less循环最有价值的用途之一是创建响应式网格系统。 让我们看看如何做到这一点。 让我们探索以下代码:

@breakpoint-small : 480px;
@breakpoint-medium: 768px;
@breakpoint-large : 960px;
.grid(@breakpoint; @columns; @index: 1) when (@index =< @columns) {
.col-@{breakpoint}-1-@{index} {
width: 100% / @index;
}
.grid(breakpoint; @columns; (@index + 1));
}

First, we have set three variables for different breakpoints. Then, we create the actual mixin. To output the needed CSS classes, we need two things – the breakpoint and the number of the columns for our grid. We set those as parameters in our mixin. Next, we create the pattern for the CSS rule. We want a pattern that tells us the actual width of a column.

首先,我们为不同的断点设置了三个变量。 然后,我们创建实际的mixin。 要输出所需CSS类,我们需要两件事–断点和网格的列数。 我们将这些设置为我们的mixin中的参数。 接下来,我们为CSS规则创建模式。 我们需要一种模式来告诉我们列的实际宽度。

Many frameworks define a column width by using the number of default columns (most often there are 12 default columns) that span. For example, for creating three equal columns they use .col-4 class for each column. But this can be confusing and not a sensible naming convention. It looks like they may want to create four columns instead of one. So, we’ll use a different approach, which I consider more natural. We’ll define our columns like this: col-1-3. This tell us that the column width is one third of the container’s width, which makes much more sense, at least for me.

许多框架通过使用跨越的默认列数(通常有12个默认列)来定义列宽。 例如,要创建三个相等的列,它们对每个列使用.col-4类。 但这可能会造成混淆,而不是明智的命名约定。 看起来他们可能想要创建四列而不是一列。 因此,我们将使用另一种方法,我认为这种方法更自然。 我们将定义这样的列: col-1-3 。 这告诉我们列宽是容器宽度的三分之一,这更有意义,至少对我而言。

To apply this pattern in our mixin, we just need to use the @screen_size and the @index variables, and also, to divide the @index by 100% for the width property. Lastly, we add the mixin itself, which will increment the @index by 1.

要在我们的mixin中应用此模式,我们只需要使用@screen_size@index变量,并且还要将width属性的@index除以100%。 最后,我们添加mixin本身,这将使@index增加1。

And now, let’s see how easy we can create different CSS classes for our grid:

现在,让我们看看为网格创建不同CSS类有多么容易:

.grid(all, 4);
@media only screen and (min-width: @breakpoint-small) {
.grid(small, 4);
}
@media only screen and (min-width: @breakpoint-medium) {
.grid(medium, 4);
}
@media only screen and (min-width: @breakpoint-large) {
.grid(large, 4);
}

The first appearance of the .grid() mixin creates column classes applicable for all screen sizes. In the next three, we use media queries to generate column classes for our small, medium and large breakpoints. Let’s check the compiled output:

.grid() mixin的首次出现会创建适用于all屏幕尺寸的列类。 在接下来的三个中,我们使用媒体查询为smallmediumlarge断点生成列类。 让我们检查编译后的输出:

.col-all-1-1 {
width: 100%;
}
.col-all-1-2 {
width: 50%;
}
.col-all-1-3 {
width: 33.33333333%;
}
.col-all-1-4 {
width: 25%;
}
@media only screen and (min-width: 480px) {
.col-small-1-1 {
width: 100%;
}
...
}
@media only screen and (min-width: 768px) {
.col-medium-1-1 {
width: 100%;
}
...
}
@media only screen and (min-width: 960px) {
.col-large-1-1 {
width: 100%;
}
...
}

Nice and useful CSS classes created on the fly. Thanks Less.

动态创建的漂亮而有用CSS类。 谢谢少。

为您的Sprite图片生成CSS (Generating CSS for Your Sprite Images)

Imagine that we have a nice sprite image, which contains many icons. To make this sprite work, we need to write a lot of CSS – a separate rule for each icon, with the icons name and different background position. Doing this manually can be time consuming, especially if the image contains too many icons. In such a case, a Less loop is the ideal candidate for the job. Let’s explore how to create it:

想象一下,我们有一个漂亮的精灵图像,其中包含许多图标。 为了使此精灵有效,我们需要编写大量CSS –每个图标都有单独的规则,并带有图标名称和不同的背景位置。 手动执行此操作可能很耗时,尤其是在图像包含太多图标的情况下。 在这种情况下,Less循环是该工作的理想人选。 让我们探讨如何创建它:

@icons: tag flag filter sort sort-asc sort-desc;
.sprites(@length; @index: 1) when (@index =< @length) {
@name: extract(@icons, @index);
.icon-@{name} {
background-position: 0 (@index * 32px);
}
.sprites(@length; (@index + 1));
}
.sprites(length(@icons));

We create the mixin with parameter @length, and @index set to 1. Then, we instruct the loop to iterate until the @index is equal to or lesser than the list’s length. Inside the loop’s body, we use the extract() function to get the name for each individual icon. Next, we create the desired CSS rule by using the @name and @index variables. And finally, we put the mixin itself to make the loop working.

我们使用参数@length@index设置为1来创建mixin。然后,指示循环进行迭代,直到@index等于或小于列表的长度。 在循环体内,我们使用extract()函数获取每个图标的名称。 接下来,我们使用@name@index变量创建所需CSS规则。 最后,我们将mixin本身放入循环中。

Now, the only effort required from us is to put the names of the icons in a list, which the loop will use – as this is done in the first line of the above code.

现在,我们唯一需要做的就是将图标的名称放在一个列表中,循环将使用该列表–这是在上面代码的第一行中完成的。

To use the mixin, we just need to provide the length of the list, which we easily do by using the length() function. We don’t want to count the number of icons manually, right? :)

要使用mixin,我们只需要提供列表的长度即可,我们可以使用length()函数轻松地做到这一点。 我们不想手动计算图标的数量,对吗? :)

And here is the code generated by our mixin:

这是我们的mixin生成的代码:

.icon-tag {
background-position: 0 32px;
}
.icon-flag {
background-position: 0 64px;
}
...
}
.icon-sort-desc {
background-position: 0 192px;
}

摘要 (Summary)

I hope you’ve enjoyed the examples and have found them useful. Lots of things can be done with Less mixins and guards, and this article only scratches the surface. You now, hopefully, know the basic scheme and should be able to confidently experiment with your own ideas.

希望您喜欢这些示例并发现它们有用。 使用更少的mixin和Guards可以完成很多事情,并且本文仅涉及表面内容。 希望您现在了解基本方案,并且应该能够自信地尝试自己的想法。

翻译自: https://www.sitepoint.com/mastering-less-guards-and-loops/

mysql游标少循环

mysql游标少循环_掌握更少的后卫和循环相关推荐

  1. shell脚本for循环_了解Shell脚本中的for循环

    shell脚本for循环 Continuing on from our previous tutorials, let's understand the for loop in shell scrip ...

  2. 的 while循环_十八、Python图解while循环

    人生苦短,要学Python Python中循环有while循环和for循环,接下来将介绍Python中的while循环和for循环. while循环 语法格式 # while语句用于循环执行程序,也就 ...

  3. 跳出多重循环_代码里的俄罗斯套娃 | 07 多重循环

    点击上方 蓝字 关注我们 前情提要:刚上二年级的小红正在学习九九乘法表,老师说明天上课时要抽查,但她总是记不熟,你能写个程序帮帮她吗? 是不是想到了我们上一期学的For循环遍历,刚好可以用上.但好像又 ...

  4. 企业网站建设要多少钱_用更少的钱建设优质网站的9个想法

    我们都知道网络工作会多么艰苦. 对于胆小的人来说,这不是一个任务,通常需要一年或一年以上的学习才能真正掌握. 随着我们时代的发展,我们已经看到了出色的想法和创新,将在线社区引向了开源和共享. 网站的建 ...

  5. mysql 游标 导出数据库_数据库 游标for

    SQLServer游标(Cursor)简介和使用说明 游标(Cursor)是处理数据的一种方法,为了查看或者处理结果集中的数据,游标提供了在结果集中一次以行或者多行前进或向后浏览数据的能力.我们可以把 ...

  6. django中的for循环_深入了解 JavaScript 中的 for 循环

    在ECMAScript5(简称 ES5)中,有三种 for 循环,分别是: 简单for循环 for-in forEach 在2015年6月份发布的ECMAScript6(简称 ES6)中,新增了一种循 ...

  7. vba循环通过键盘某个按键按下退出循环_[VBA]For Next与Do Loop循环

    " 在黑夜中前行,行也寂寞,停也寂寞 " (更文的时候,正好最近发生许多事,算是做个自我安慰吧) 作为VBA的基本语句,For Next和Do Loop都是很早进入初学者学习的循环 ...

  8. map for循环_阿里面试问我hashMap的循环姿势有哪几种?

    hashMap 应该是java程序员工作中用得比较多的一个键值对处理的数据的类型了.这种数据类型一般都会有增删查的方法,今天我们就来看看它的循环方法以前写过一篇关于ArrayList的循环效率问题&l ...

  9. python并发循环_在Python中模拟一个并发循环?

    在Python中模拟一个并发循环? 我需要模拟Python程序中的并发循环.不幸的是,以下简单的代码不起作用:list_of_ints = [ 1, 2, 3 ]iterator = list_of_ ...

  10. java 暂停循环_在用于暂停线程时,循环Thread.Sleep()会不会对性能造成影响?...

    有(或者已经有)很多关于使用 Thread.Sleep() 方法的好坏的讨论 . 据我所知,它主要用于调试目的 . 现在我想知道:用于我的特定目的是不是很糟糕,也就是说,不断循环它以便能够暂停/恢复线 ...

最新文章

  1. 自定义GridView分页模板
  2. 模拟运维中产品上线流程
  3. ASM 磁盘、目录的管理
  4. C#写的windows应用程序打包
  5. 内附PPT下载 | 阿里云资深技术专家 陈长城:一站式数据管理DMS及最新解决方案解读
  6. Logistic分类函数
  7. 接口并发如何模仿用户点击率和提交率_洞察| 五大法则揭秘!在抖音如何打造“爆款”?...
  8. PHP获取当前脚本内存占用情况
  9. Charles工具基本使用详解
  10. 直通串口线和交叉串口线
  11. android8临时root,Android8.0怎么root,刷supersu无穷重启
  12. 洞察科技,感知未来:人工智能将如何改变学术搜索?
  13. javaWeb(1)———基础
  14. 残差连接(skip connect)/(residual connections)
  15. 论文阅读5 Cv-CapsNet:Complex-Valued Capsule Network
  16. 闭区间上连续函数的性质
  17. jquery徽章_城市需要能够获得数字徽章
  18. Vue_01_组件的使用
  19. laravel如何实现请求图片或文件需用户验证
  20. quartz-深度解析

热门文章

  1. android 判断 飞行模式,Android 设置飞行模式,判断是否是飞行模式
  2. 网易严选(html+css+js)
  3. 学云计算需要准备哪些知识?
  4. 海洋地球物理探测方法综述(二)
  5. JS indexOf 用法
  6. MySQL 文本类型,存储大小
  7. java opts xmn_tomcat设置JAVA_OPTS
  8. vue项目中使用思维导图mindmap
  9. java自动回复_java实现自动回复聊天机器人
  10. 计算机管理里面删打印机就卡住了,打印机任务无法删除怎么办-解决打印机任务无法删除的方法 - 河东软件园...