3分钟13行代码搭建sass版移动端网格系统_html/css_WEB-ITnose
一般来说,网格系统分为container、row及column三大部分,而container一般是负责内容居中的,这对pc端比较合适,而大移动端是真的不太需要,所以直接砍掉,那么就剩下row和column了。
上代码:
@mixin row() { width: 100%; display: flex;}@mixin col($num, $total: 1) { // 如果$total为默认的1,则表示等分的$num分之一 // 否则计算$num/$total @if $total == 1 { width: 100% / $num; } @else { width: percentage($num / $total); }}
如何使用:
.row{ @include row;}// col的命名规范为col-占的格子数-总的格子数.col-1-2{ @include col(2);}.col-1-3{ @include col(1, 3);}.col-2-3{ @include col(2, 3);}.col-1-4{ @include col(4);}.col-3-4{ @include col(3, 4);}.col-2-5{ @include col(2,5);}
最后,扩展成一个百搭可控制的网格系统:
@charset "UTF-8";//-----------------------------------------------------// grid system//-----------------------------------------------------$gridFlex: false !default;$gridRowClearfix: false !default; // 如果采用float,子元素清除浮动使用clearfix或overflow$gridClass: false !default;// row@mixin row() { width: 100%; @if $gridFlex { display: flex; } @else if $gridRowClearfix{ @extend %clearfix; } @else { overflow: hidden; }}// col@mixin col($num, $total: 1) { @if not $gridFlex { float: left; } // 如果$total为默认的1,则表示等分的$num分之一 // 否则计算$num/$total @if $total == 1 { width: 100% / $num; } @else { width: percentage($num / $total); }}// 是否开启class@if $gridClass { .row{ @include row; } .col-1-2{ @include col(2); } .col-1-3{ @include col(1, 3); } .col-2-3{ @include col(2, 3); } .col-1-4{ @include col(4); } .col-3-4{ @include col(3, 4); } .col-1-5{ @include col(5); } .col-2-5{ @include col(2, 5); } .col-3-5{ @include col(3, 5); } .col-4-5{ @include col(4, 5); }}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to distinguish between closing tabs and closing entire browser using JavaScript on your browser? During the daily use of the browser, users may...
