


How to achieve adaptive height layout with 2:5:3 scale using CSS Flexbox?
Apr 04, 2025 pm 11:06 PMEasily build adaptive and highly layouts with 2:5:3 scale with CSS Flexbox
This article describes how to use the CSS elastic box model (Flexbox) to create a container with the precise height proportion of the three child elements inside it being 2:5:3, and can be automatically adjusted according to the screen size, always maintaining the proportion and filling the parent container height.
We need a container containing three child elements, and the height ratio of these three child elements must be maintained at 2:5:3, and can be perfectly adapted at various screen resolutions. Flexbox layouts can easily achieve this.
The key is to set display: flex
and flex-direction: column
properties of the parent container, which makes the child elements arranged vertically. Then, use the flex
attribute to set the proportion of space occupied by each child element: flex: 2
, flex: 5
, and flex: 3
respectively representing the child element occupying 2 parts, 5 parts and 3 parts of the height of the parent container. The parent container height is automatically adjusted according to the content to ensure that the child elements are proportional correctly and adaptive. For vertical centering, we used align-items: center
.
The following code snippet demonstrates the implementation:
.container { display: flex; flex-direction: column; align-items: center; /* vertical center*/ height: 100vh; /* It occupies full viewport height, can be modified according to actual conditions*/ } .item1 { flex: 2; } .item2 { flex: 5; } .item3 { flex: 3; }
To show the effect more intuitively, we provide a complete HTML example:
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Flexbox Layout</title> <style> .container { height: 100vh; width: 100px; background: #000; display: flex; flex-direction: column; align-items: center; } .item1 { flex: 2; background: pink; } .item2 { flex: 5; background-color: blue; } .item3 { flex: 3; background-color: cadetblue; } </style> <div class="container"> <div class="item1"></div> <div class="item2"></div> <div class="item3"></div> </div>
This code creates a highly adaptive layout with a ratio of 2:5:3. The parent container height is set to 100vh
so that it occupies the viewport height, which you can adjust according to actual needs.
The above is the detailed content of How to achieve adaptive height layout with 2:5:3 scale using CSS Flexbox?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Ordinary investors can discover potential tokens by tracking "smart money", which are high-profit addresses, and paying attention to their trends can provide leading indicators. 1. Use tools such as Nansen and Arkham Intelligence to analyze the data on the chain to view the buying and holdings of smart money; 2. Use Dune Analytics to obtain community-created dashboards to monitor the flow of funds; 3. Follow platforms such as Lookonchain to obtain real-time intelligence. Recently, Cangming Money is planning to re-polize LRT track, DePIN project, modular ecosystem and RWA protocol. For example, a certain LRT protocol has obtained a large amount of early deposits, a certain DePIN project has been accumulated continuously, a certain game public chain has been supported by the industry treasury, and a certain RWA protocol has attracted institutions to enter.

DAI is suitable for users who attach importance to the concept of decentralization, actively participate in the DeFi ecosystem, need cross-chain asset liquidity, and pursue asset transparency and autonomy. 1. Supporters of the decentralization concept trust smart contracts and community governance; 2. DeFi users can be used for lending, pledge, and liquidity mining; 3. Cross-chain users can achieve flexible transfer of multi-chain assets; 4. Governance participants can influence system decisions through voting. Its main scenarios include decentralized lending, asset hedging, liquidity mining, cross-border payments and community governance. At the same time, it is necessary to pay attention to system risks, mortgage fluctuations risks and technical threshold issues.

To create responsive images using CSS, it can be mainly achieved through the following methods: 1. Use max-width:100% and height:auto to allow the image to adapt to the container width while maintaining the proportion; 2. Use HTML's srcset and sizes attributes to intelligently load the image sources adapted to different screens; 3. Use object-fit and object-position to control image cropping and focus display. Together, these methods ensure that the images are presented clearly and beautifully on different devices.

The coordinated rise of Bitcoin, Chainlink and RWA marks the shift toward institutional narrative dominance in the crypto market. Bitcoin, as a macro hedging asset allocated by institutions, provides a stable foundation for the market; Chainlink has become a key bridge connecting the reality and the digital world through oracle and cross-chain technology; RWA provides a compliance path for traditional capital entry. The three jointly built a complete logical closed loop of institutional entry: 1) allocate BTC to stabilize the balance sheet; 2) expand on-chain asset management through RWA; 3) rely on Chainlink to build underlying infrastructure, indicating that the market has entered a new stage driven by real demand.

Is DAI suitable for long-term holding? The answer depends on individual needs and risk preferences. 1. DAI is a decentralized stablecoin, generated by excessive collateral for crypto assets, suitable for users who pursue censorship resistance and transparency; 2. Its stability is slightly inferior to USDC, and may experience slight deansal due to collateral fluctuations; 3. Applicable to lending, pledge and governance scenarios in the DeFi ecosystem; 4. Pay attention to the upgrade and governance risks of MakerDAO system. If you pursue high stability and compliance guarantees, it is recommended to choose USDC; if you attach importance to the concept of decentralization and actively participate in DeFi applications, DAI has long-term value. The combination of the two can also improve the security and flexibility of asset allocation.

The role of Ethereum smart contract is to realize decentralized, automated and transparent protocol execution. Its core functions include: 1. As the core logic layer of DApp, it supports token issuance, DeFi, NFT and other functions; 2. Automatically execute contracts through code to reduce the risks of human intervention and fraud; 3. Build a DeFi ecosystem so that users can directly conduct financial operations such as lending and transactions; 4. Create and manage digital assets to ensure uniqueness and verifiability; 5. Improve the transparency and security of supply chain and identity verification; 6. Support DAO governance and realize decentralized decision-making.

opacity is an attribute in CSS that controls the overall transparency of an element, with values ranging from 0 (fully transparent) to 1 (fully opaque). 1. It is often used for the image hover fade effect, and enhances the interactive experience by setting the opacity transition; 2. Making a background mask layer to improve text readability; 3. Visual feedback of control buttons or icons in the disabled state. Note that it affects all child elements, unlike rgba, which only affects the specified color part. Smooth animation can be achieved with transition, but frequent use may affect performance. It is recommended to use it in combination with will-change or transform. Rational application of opacity can enhance page hierarchy and interactivity, but it should avoid interfering with users.

The value of stablecoins is usually pegged to the US dollar 1:1, but it will fluctuate slightly due to factors such as market supply and demand, investor confidence and reserve assets. For example, USDT fell to $0.87 in 2018, and USDC fell to around $0.87 in 2023 due to the Silicon Valley banking crisis. The anchoring mechanism of stablecoins mainly includes: 1. fiat currency reserve type (such as USDT, USDC), which relies on the issuer's reserves; 2. cryptocurrency mortgage type (such as DAI), which maintains stability by over-collateralizing other cryptocurrencies; 3. Algorithmic stablecoins (such as UST), which relies on algorithms to adjust supply, but have higher risks. Common trading platforms recommendations include: 1. Binance, providing rich trading products and strong liquidity; 2. OKX,
