همه مقالات ارسال شده در سایت ما، بر اساس تاریخ آخرین به روز رسانی مرتب شده اند. برای مجموعه‌های انتخاب‌شده، کاوش را امتحان کنید.

例如,这是营销网站的常见布局,可能包含一行三项内容,通常包括图片、商品名,以及一些文字来描述商品的某些特性。在小屏设备上,您希望这些内容能够整齐地堆叠,并随着屏幕尺寸的增大而展开。 通过使用 Flexbox 实现此效果,您无需在屏幕大小调整时使用媒体查询来调整这些元素的位置。 flex 简写表示: flex: <flex-grow> <flex-shrink> <flex-basis> 。 如果您希望框在换行时拉伸并填充空白,请将

借助 aspect-ratio 属性,当您调整卡片大小时,绿色视觉块会保持 16 x 9 的宽高比。我们会遵循 aspect-ratio: 16 / 9 的宽高比。 如需在不使用此属性的情况下保持 16 x 9 的宽高比,您需要使用 padding-top 黑客 并为其设置 56.25% 内边距,以设置宽高比。我们很快就会推出一个用于此目的的属性,以避免使用此 hack 和计算百分比。您可以使用 1 / 1 的宽高比制作正方形图片,也可以使用 2 / 1 的宽高比制作 2 比 1

This demo uses container queries to create an intrinsic, responsive card. The card goes from a single-column layout at more narrow sizes to a two-column layout when it is at wider sizes. To create the container, first set containment on the parent:

A centering technique that only aligns content and doesn't change their size during the process. See the full article for many more details about this technique and when it's efficient. Full article · Video on YouTube · Source on Github

A centering technique where an element pushes equally from all edges of a flex container. Best for quick centering for single items only. See the full article for many more details about this technique and when it's efficient. Full article · Video on

Unlike the deconstructed pancake, this example does not wrap its children when the screen size changes. Commonly referred to as a sticky footer, this layout is used for both websites and apps, across mobile applications (the footer is commonly a

In this demo, you are setting the width using clamp() like so: width: clamp(<min>, <actual>, <max>). This sets an absolute min and max size, and an actual size. With values, that can look like: The minimum size here is 23ch or 23

For this seventh example, combine some of the concepts you've already learned about to create a responsive layout with automatically-placed and flexible children. Pretty neat. The key terms to remember here are repeat, auto-(fit|fill), and minmax(),

For this classic holy grail layout, there is a header, footer, left sidebar, right sidebar, and main content. It's similar to the previous layout, but now with sidebars! To write this entire grid using a single line of code, use the grid-template

A centering technique that puts the content in the center via equal padding around all its sides. See the full article for many more details about this technique and when it's efficient. Full article · Video on YouTube · Source on Github

The main point demonstrated here is the use of justify-content: space-between, which places the first and last child elements at the edges of their bounding box, with the remaining space evenly distributed between the elements. For these cards, they

Use place-items: center to center an element within its parent. This enables the content to be perfectly centered within the parent, regardless of intrinsic size.