less简单学习使用


一、如何使用

官网:https://lesscss.org

在这里插入图片描述

安装使用有多种方式,介绍简单的两种:
1、npm安装:npm install -g less
2、普通h5下载less.js引用
下载地址:https://cdn.jsdelivr.net/npm/less

二、简单使用

1.dome示例

废话不多说,直接上代码
html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<link rel="stylesheet/less" type="text/css" href="styles.less" />
<script src="./js/less.js" ></script>
		<title>测试</title>
	</head>
	<body>
		<div class="container">
			<header></header>
			<section></section>
			<footer></footer>
		</div>
	</body>
</html>

css:【style.less】

//变量
//伪类
//嵌套
//伪元素
//媒体查询

//外面定义变量,里面可以直接用
@width:600px;
@color: red;

.container{
	width: @width;
	height: 800px;
	background:@color;
	header{
		height:100px;
		background: green;
	}
	
	//子元素样式可以直接写在父样式里面
	section{
		height: 400px;
		background: skyblue;
		&:hover{
			background: blue;
		}
		
		//在元素前面加元素。content:内容
		&::before{
			content: '11';
			position: absolute;
			width: 100px;
			height: 100px;
			background: yellow;
		}
		
		//在元素后面加元素。content:内容
		&::after{
			content: url(img/20230202015430200.ico);
			position: absolute;
			left: 100px;
			width: 200px;
			height: 200px;
			background: red;
		}
		
		//媒体查询,窗口宽度小于300背景改成红色
		@media screen and (max-width:300px){
			background: red;
		}
	}
	
	footer{
		height: 200px;
		background: black;
	}
}

目录结构示例
在这里插入图片描述


总结

参考链接:
https://www.runoob.com/bootstrap/bootstrap-v2-less.html
https://www.bilibili.com/video/BV1i54y1U7zY/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值