Table of Contents
Basic Horizontal Split (Two Equal Vertical Panels)
Vertical Split (Top and Bottom Halves)
Adding Responsive Behavior
Optional: Fixed Sidebar with Main Content
Key Tips
Home Web Front-end CSS Tutorial How to create a split-screen layout with CSS

How to create a split-screen layout with CSS

Aug 11, 2025 pm 10:59 PM
css 分屏布局

Using CSS to create a split screen layout can be implemented through Flexbox. First, set the container to display: flex and set the height to 100vh. Through flex: 1, the child elements are divided equally. The horizontal layout is only possible by default. Vertical layout needs to be set flex-direction: column. In conjunction with media query @media (max-width: 768px) to achieve the mobile stacking responsive effect. If you need to fix the sidebar, set a fixed width for it. Use flex: 1 to adapt to the remaining space in the main content area. It is also recommended to use box-sizing: border-box globally to avoid padding affecting the layout, and ultimately achieve a simple and responsive split screen design.

How to create a split-screen layout with CSS

Creating a split-screen layout with CSS is straightforward and useful for designs that require two equal sections—like portfolios, login/signup pages, or comparison views. Here's how to do it effectively.

Basic Horizontal Split (Two Equal Vertical Panels)

This layout divides the screen into two side-by-side sections, each taking up half the width.

 .split-screen {
  display: flex;
  height: 100vh; /* Full viewport height */
}

.left, .right {
  flex: 1; /* Each takes 50% width */
  padding: 20px;
}

.left {
  background-color: #e0e0e0;
}

.right {
  background-color: #c0c0c0;
}
 <div class="split-screen">
  <div class="left">Left Panel</div>
  <div class="right">Right Panel</div>
</div>
  • display: flex on the container enables horizontal alignment.
  • flex: 1 ensures both panels grow equally to fill the space.
  • height: 100vh makes the layout fill the entire screen height.

Vertical Split (Top and Bottom Halves)

If you want one section on top and one on the bottom, use a column flex layout.

 .split-screen-vertical {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.top, .bottom {
  flex: 1;
  padding: 20px;
}

.top {
  background-color: #a0d8f1;
}

.bottom {
  background-color: #f1a0a0;
}
 <div class="split-screen-vertical">
  <div class="top">Top Panel</div>
  <div class="bottom">Bottom Panel</div>
</div>
  • flex-direction: column stacks children vertically.
  • Again, flex: 1 gives each section 50% of the height.

Adding Responsive Behavior

To make the layout mobile-friendly, you can switch to stacked panels on small screens.

 @media (max-width: 768px) {
  .split-screen {
    flex-direction: column;
  }
}

Now on screens narrower than 768px, the two panels will stack vertically instead of sitting side by side.

Optional: Fixed Sidebar with Main Content

Sometimes you want one panel fixed-width (like a sidebar), and the other flexible.

 .sidebar-layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 300px; /* Fixed width */
  background-color: #333;
  color: white;
}

.main-content {
  flex: 1; /* Takes remaining space */
  background-color: #f9f9f9;
  padding: 20px;
}

This is useful for dashboards or navigation-heavy interfaces.

Key Tips

  • Use box-sizing: border-box globally to avoid padding affecting layout width.
  • Consider adding overflow: auto if content might exceed panel size.
  • You can add borders or margins between panels using gap (in flex or grid) or padding with nested divs.

Basically, with flexbox , split-screen layouts are simple and responsive. Just pick your direction, set the flex properties, and adjust for mobile if needed.

The above is the detailed content of How to create a split-screen layout with CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1543
276
How to use vw and vh units in CSS How to use vw and vh units in CSS Aug 07, 2025 pm 11:44 PM

vw and vh units achieve responsive design by associating element sizes with viewport width and height; 1vw is equal to 1% of viewport width, and 1vh is equal to 1% of viewport height; commonly used in full screen area, responsive fonts and elastic spacing; 1. Use 100vh or better 100dvh in the full screen area to avoid the influence of the mobile browser address bar; 2. Responsive fonts can be limited with 5vw and combined with clamp (1.5rem, 3vw, 3rem) to limit the minimum and maximum size; 3. Elastic spacing such as width:80vw, margin:5vhauto, padding:2vh3vw, can make the layout adaptable; pay attention to mobile device compatibility, accessibility and fixed width content conflicts, and it is recommended to give priority to using dvh first;

What are the virtual currency trading apps?_The top ten recommended official virtual currency trading apps in 2025 What are the virtual currency trading apps?_The top ten recommended official virtual currency trading apps in 2025 Aug 08, 2025 pm 06:42 PM

1. Binance is known for its huge transaction volume and rich trading pairs. It provides diversified trading models and perfect ecosystems. It also ensures the security of user assets through SAFU funds and multiple security technologies and attaches great importance to compliant operations; 2. OKX Ouyi provides a wide range of digital asset trading services and unified trading account models, actively deploys the Web3 field, and improves transaction security and experience through strict risk control and user education; 3. gate.io Sesame opens the door and has good currency speed and rich currency, provides diversified trading tools and value-added services, adopts multiple security verification mechanisms and adheres to the transparency of asset reserves to enhance user trust; 4. Huobi provides one-stop digital asset services with deep industry accumulation, with strong transaction depth and

How to use the filter property in CSS How to use the filter property in CSS Aug 11, 2025 pm 05:29 PM

TheCSSfilterpropertyallowsvisualeffectslikeblur,brightness,andgrayscaletobeapplieddirectlytoHTMLelements.1)Usethesyntaxfilter:filter-function(value)toapplyeffects.2)Combinemultiplefilterswithspaceseparation,e.g.,blur(2px)brightness(70%).3)Commonfunct

How to use CSS selectors effectively How to use CSS selectors effectively Aug 11, 2025 am 11:12 AM

When using CSS selectors, low-specific selectors should be used first to avoid excessive limitations; 1. Understand the specificity level and use them reasonably in the order of type, class, and ID; 2. Use multi-purpose class names to improve reusability and maintainability; 3. Use attributes and pseudo-class selectors to avoid performance problems; 4. Keep the selector short and clear scope; 5. Use BEM and other naming specifications to improve structural clarity; 6. Avoid the abuse of tag selectors and:nth-child, and give priority to the use of tool classes or modular CSS to ensure that the style is controllable for a long time.

How to create a vertical line with CSS How to create a vertical line with CSS Aug 11, 2025 pm 12:49 PM

Use a div with border to quickly create vertical lines, and define styles and heights by setting border-left and height; 2. Use ::before or ::after pseudo-elements to add vertical lines without additional HTML tags, suitable for decorative separation; 3. In Flexbox layout, by setting the width and background color of the divider class, adaptive vertical dividers between elastic containers can be achieved; 4. In CSSGrid, insert vertical lines as independent columns (such as autowidth columns) into grid layout, which is suitable for responsive design; the most appropriate method should be selected according to the specific layout needs to ensure that the structure is simple and easy to maintain.

css mix-blend-mode example css mix-blend-mode example Aug 08, 2025 pm 12:59 PM

The mix-blend-mode attribute is used to control the mixing effect of element content and background. 1. Multiply can achieve the overlapping of text and background images; 2. Screen brightens the image and is suitable for dark backgrounds; 3. Overlay enhances contrast, combining multiply and screen features; 4. Difference creates a strong contrast, which is suitable for creative design; it is necessary to ensure that elements overlap and the correct z-index stacking order, and combined with isolation:isolate, the mixing range can be limited, and rich visual effects can be achieved by adjusting colors and modes.

How to change the list style in CSS How to change the list style in CSS Aug 17, 2025 am 10:04 AM

To change the CSS list style, first use list-style-type to change the bullet or numbering style. 1. Use list-style-type to set the bullet of ul to disc, circle or square, and the number of ol is decimal, lower-alpha, upper-alpha, lower-roman or upper-roman. 2. Remove the tag completely with list-style:none. 3. Use list-style-image:url('bullet.png') to replace it with a custom image. 4. Use list-style-position:in

How to prevent a line break in CSS How to prevent a line break in CSS Aug 08, 2025 pm 05:14 PM

Usewhite-space:nowraptopreventtextfrombreakingontomultiplelines,ensuringcontentstaysonasingleline;2.Applythispropertytoinline,inline-block,orflexitems,whereflex-wrap:nowrappreventsitemwrappingandwhite-space:nowrappreventsinternaltextwrapping;3.Forspe

See all articles