sass中循环结构

举报
陈业贵 发表于 2021/12/15 00:09:49 2021/12/15
6.1k+ 0 0
【摘要】 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>...
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		/*ul
		{
			li
			{
				width: 100%;
				height: 50px;
				border: 1px solid red;
				font-size: 20px;
				background: red;
				/*这下面是less的写法:
			&:nth-child(5)
			{
				background:yellow;
			}
			&:nth-child(6)
			{
				background:red;
			}
			&:nth-child(7)
			{
				background:blue;
			}
			&:nth-child(8)
			{
				background:black;
			}
			}
			}
			*/
		/*less编译后的css文件*/
		/*
ul li {
  width: 100%;
  height: 50px;
  border: 1px solid red;
  font-size: 20px;
  background: red;
}
ul li:nth-child(5) {
  background: yellow;
}
ul li:nth-child(6) {
  background: red;
}
ul li:nth-child(7) {
  background: blue;
}
ul li:nth-child(8) {
  background: black;
}

		 */
		
/*ul{
  li{
    width: 100%;
    height: 50px;
    border: 1px solid #000;
    font-size: 20px;
    color: #fff;
    background: red;
    @for $i from 5 through 8
    {
    	$i:5;
    	&:nth-child(#{$i})
    	{
    		background: red;
    	}
    	$i:$i+1;
    }
}}*/
/*编译后的css文件*/
/*

ul li {
  width: 100%;
  height: 50px;
  border: 1px solid #000;
  font-size: 20px;
  color: #fff;
  background: red;
}
ul li:nth-child(5) {
  background: red;
}
ul li:nth-child(5) {
  background: red;
}
ul li:nth-child(5) {
  background: red;
}
ul li:nth-child(5) {
  background: red;
}

 */
/*ul{
  li{
    width: 100%;
    height: 50px;
    border: 1px solid #000;
    font-size: 20px;
    color: #fff;
    background: red;
    @for $i from 5 to 8
    {
    	$i:5;
    	&:nth-child(#{$i})
    	{
    		background: red;
    	}
    	$i:$i+1;
    }
}}*/
/*编译后的css文件*/
/*
ul li {
  width: 100%;
  height: 50px;
  border: 1px solid #000;
  font-size: 20px;
  color: #fff;
  background: red;
}
ul li:nth-child(5) {
  background: red;
}
ul li:nth-child(5) {
  background: red;
}
ul li:nth-child(5) {
  background: red;
}

 */
/*ul{
  li{
    width: 100%;
    height: 50px;
    border: 1px solid #000;
    font-size: 20px;
    color: #fff;
    background: red;
    
    	$i:5;
    	@while($i<=8)
    	{
    	&:nth-child(#{$i})
    	{
    		background: red;
    	}
    	$i:$i+1;
    }
    }*/
    /*编译后的css文件*/
    /*ul li {
  width: 100%;
  height: 50px;
  border: 1px solid #000;
  font-size: 20px;
  color: #fff;
  background: red;
}
ul li:nth-child(5) {
  background: red;
}
ul li:nth-child(6) {
  background: red;
}
ul li:nth-child(7) {
  background: red;
}
ul li:nth-child(8) {
  background: red;
}*/
	</style>
</head>
<body>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
</ul>
<!--2.for循环
    @for $i from 起始整数 through 结束整数{}
    @for $i from 起始整数 to 结束整数{}
    两者的区别 through包头包尾, to包头不包尾

    3.while循环
    @while(条件语句){}
    */-->
</body>
</html>

  
 

文章来源: blog.csdn.net,作者:贵哥的编程之路(陈业贵),版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/qq_37805832/article/details/108091551

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。