Web Front-end
HTML Tutorial
What is Flexible Layout? Basic application of flexible layout flex (with code)What is Flexible Layout? Basic application of flexible layout flex (with code)
What is elastic layout? Flexible layout (flex), as the name suggests, is a layout method. Nowadays, basically all browsers support flexible layout. So, what this article will share with you next is the basic application of flexible layout flex.
How to apply elastic layout, the code is as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
div{
border: 1px solid #ccc;
box-sizing: border-box;
}
.box{
height:20vh;
display: flex;
}
.box div{
flex: 1;
}
.box div:last-child{
flex: 2;
}
</style>
</head>
<body>
<div>
<div>Document1</div>
<div>Document2</div>
<div>Document3</div>
<div>Document4</div>
<div>Document5</div>
</div>
</body>
</html>The running results are as follows:

Container settings
flex has 6 properties that can be set:
flex-direction:row (main axis from left to right, default) / row-reverse ( Main axis from right to left) / column (main axis from top to bottom) / column-reverse (main axis from bottom to top) Determine the direction of the main axis
flex-wrap:nowrap (default, no line wrap) / wrap (line wrap) ) / wrap-reverse (line wrap, first line below) determines the wrapping method when the items cannot be arranged on one axis
flex-flow: It is the abbreviation mode of the above two properties. The default value: flex-flow :row nowrap.
justify-content: flex-start (default, left-aligned) / flex-end (right-aligned) / center (center) / space-between (justified at both ends, equal spacing between items) /
space-around (the space between each item is equal, so the space between items is twice as large as the price between the item and the border); determines the alignment of the items on the main axis. space-between/around is useful when adaptively adjusting spacing
align-items: flex-start (alignment of the starting point of the cross axis) / flex-end (alignment of the end point of the cross axis) / center (alignment of the end point of the cross axis) Midpoint alignment)/baseline (baseline alignment of the first line of text of the item)/stretch (default value, if the item does not set a height or is set to auto, the item will fill the height of the entire container). Define the alignment of items on the cross axis
align-content: flex-start (aligned with the starting point of the cross axis) / flex-end (aligned with the end point of the cross axis) / center (aligned with the center of the cross axis) Point alignment) /
space-between (aligned with both ends of the cross axis, the intervals between the axes are evenly distributed) /space-around (the intervals on both sides of the axis are equal, so the spacing between the axes is ratio The distance between the axis and the border is doubled)
/ stretch (default value, the axis occupies the entire cross axis). Define the alignment of multiple axes. If the project has its own axis, this property will not work.
Project property settings
order: Define the order of items, The smaller the number, the higher it is arranged. The default is 0.
flex-grow: Defines the magnification ratio of the item. The default is 0. By default, the item will not be enlarged even if there is remaining space. The direction of scaling is the direction of flex-direction.
flex-shrink: Define the shrinkage ratio of the item. The default is 1. When there is insufficient space, the item will shrink. A value of 0 means no scaling. The direction of scaling is the direction of flex-direction.
flex-basis: Defines the main axis space (main size) occupied by the project before allocating excess space. The browser does not calculate whether there is excess space on the main axis based on this attribute. The default value is auto, which is the original size of the project. size. flex-basis: 80px; the width (direction is row) is set to 80px;
flex: is the abbreviation of the above three properties, the default value is 0 1 auto. There are two shortcut values: auto (1 1 auto ) and none (0 0 auto)
align-self: This attribute allows the alignment of delayed items to be different from other items, and overrides the attribute value of align-items. The default value is auto, which means inheriting the align-items attribute of the parent element, or stretch if there is no parent element.
align-self: auto/flex-start/flex-end/center/baseline/stretch flex-basis: The difference between the value 0 and auto (default): the former does not calculate the entire item, and then The other is calculated ignoring the content, so if the layout requires the percentage configuration of each item, flex-basis should be set to 0.
Related recommendations:
Introduction to flexible layout (Flex) in HTML (with code)
The above is the detailed content of What is Flexible Layout? Basic application of flexible layout flex (with code). For more information, please follow other related articles on the PHP Chinese website!
The Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AMThe future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.
HTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AMThe roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.
The Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AMThe future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.
HTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AMThe roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.
HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AMHTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.
HTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AMHTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.
From Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AMHTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.
Understanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AMWebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool





