Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the fixed width three-column layout in CSS

Shulou Source: shulou.com Published: 2022-06-03 14:25:38 11月14日 Update

This article is about how to use a fixed-width three-column layout in CSS. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Fixed width three-column layout

This is very basic, and we can understand it by looking directly at the code:

Header aside

Main

Content-aside

Footer # header {width: 980px; height: 90px; margin: 0 auto; background: # f60;} # body {width: 980px; margin: 0 auto;} # aside {float: left; width: 240px; background: # ccc;} # content {margin-left: 240px;} # main {float: left; width: 540px; background: pink;} # content-aside {float: left; width: 200px; background: orange;} # footer {width: 980px; height: 90px; margin: 0 auto Background: # 08f;}

Example: realization of equal width and equal spacing layout of three-column pictures

Each picture block floats to the left, with a width of 30% and a left margin of 2.5%:

100% = (2.5% 30%) + (2.5% 30%) + (2.5% 30%) + 2.5%

Equal width layout of three-column images * {margin: 0; padding: 0;} img {display: block; width: 30%; margin: 2.5% 002.5%; float: left;}

Width: 30%; represents 30% of the width of the parent element.

Height: 30%; if the specific height of the parent element is not set, then the height has no effect.

To achieve a responsive square, you can use the unit vw (Viewport Width):

.square {width: 30%; height: 30vW; background: url ("byd.jpg") no-repeat scroll center 0 transparent; background-size: 100% 100%; margin: 2.5% 00 2.5%; float: left;}

It is important to note, however, that lower-version IE and lower-version Android/iOS browsers do not support viewport units.

Or use JS to set height according to width to ensure compatibility:

$(document) .ready (function () {$("img"). Height ($("img"). Width ();}); $(window) .resize (function () {$("img"). Height ($("img"). Width ();})

Percentage layout can also be seen as a responsive layout.

The simple and practical percentage layout is very suitable for the layout of mobile WAP pages:

Min-width:320px; max-width:980px; width:100%; overflow-x: hidden; margin: 0 auto

The minimum width 320px, the maximum width 980px, automatically adapts the width between 320px and 980px, looks OK.

In

The tag only needs to set the percentage value of the width attribute, such as width= "40%", not the height attribute, so that the image can be scaled to the original scale.

The blocks in the container can also be arranged as a percentage, such as 60% on the left and 40% on the right.

Thank you for reading! This is the end of the article on "how to use the fixed-width three-column layout in CSS". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Layout width picture percentage solid practical element content unit attribute more version article good maximum minimum no between code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Shulou Tech Info Apple Microsoft