国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Case 1. Contour box
HTML:
CSS:
Case 2. Simple old-style layout
Case 3. Adaptive layout with content orchestration function
Conclusion
FAQs about CSS table Properties
Home Technology peripherals It Industry Layout Secret Weapon #1: The CSS Table Property

Layout Secret Weapon #1: The CSS Table Property

Feb 20, 2025 am 09:32 AM

CSS display: table Attributes: A powerful tool to solve layout problems

Core points:

  • CSS's table attributes are powerful, can solve multiple layout problems and are compatible with all modern browsers. It allows HTML elements to function like table elements, providing a common solution to complex layout and alignment problems.
  • CSS table Properties can be used to create contour boxes, simple old-style layouts, and adaptive layouts with content orchestration. It is especially useful in responsive designs, allowing elements to resize and position according to the user's screen size.
  • Although the CSS table attribute has many advantages, it also has some limitations. It has less flexibility in creating complex layouts compared to other display properties and does not work well with certain CSS properties such as float and position. However, in many cases, the advantages of using the table attribute outweigh its disadvantages.

Layout Secret Weapon #1: The CSS Table Property

At present, Flexbox may be a popular new technology for layout construction. Flexbox’s amazing ability to adapt to available space has left many people looking forward to its possibilities. However, it doesn't solve all layout issues, and there are some issues with its compatibility with older browsers. Flexbox does not currently have a common polyfill (a fallback solution for older browsers) - I only know a polyfill for the 2009 version of IE: Flexie. In many cases, I found that using the often overlooked CSS table display properties can find a simpler solution. These CSS properties are widely supported by all relevant browsers (note that this excludes IE6 and IE7) and can gracefully solve some major and minor layout difficulties.

If you are not completely familiar with this technique, changing the display attribute of a DIV can make it behave like a table or table element.

Wait, use tables to layout? Isn't this good?

One of the hottest web design topics in the early 21st century was the debate about using HTML table code as a layout tool. That's a hack, and it's still a bad practice.

Instead, we use HTML that makes perfect sense here (i.e., DIV, SECTION, HEADER, etc.), just borrowing some useful table representation knowledge from CSS. This is exactly what CSS is designed for, so don't think it's a hack or patch. It's not.

Usage

display: table-cell

In the following example, click the button at the top and you can change the

attribute of the three colored DIVs from display to block: table-cell

[CodePen sample link - replace with actual CodePen link]

You can see how DIVs are arranged horizontally without any

properties, and you can also access some typical table rules (like float). vertical-align

If you need some spacing, note that the classic CSS margin attribute has no effect on the table cell: instead, use border-spacing (it must be applied to container table elements). If you want to use these rules, you can find some comment lines in Codepen.

This technique is very useful for solving many problems that are difficult to solve with other methods.

I have picked out three simple cases, where table display attributes are very valuable.

But first let's look at them:

display attribute Represented as
table, inline-table
display 屬性 呈現(xiàn)為
table, inline-table table
table-column col
table-column-group colgroup
table-row-group tbody
table-header-group thead
table-footer-group tfoot
table-row tr
table-cell td
table-caption caption
table-column col
table-column-group colgroup
table-row-group tbody
table-header-group thead
table-footer-group tfoot
table-row tr
table-cell td
table-caption caption

For a truly comprehensive guide to forms and CSS, check out CSS Tricks: [CSS Tricks' Form Guide Link - Replace with the Actual Link]

Case 1. Contour box

I think this is one of the most common problems I deal with: there are some floating boxes with unknown content and you have to make them all have the same height.

I know that Flexbox can easily solve this problem, but table rules can do it too.

Simply apply the display: table (or table-row) property to the container and the display: table-cell property to the internal box. Note that you want to delete any float attributes (otherwise the table-cell attributes will not take effect).

HTML:

<div id="wrapper">
    <div id="div1"></div>
    <div id="div2"></div>
    <div id="div3"></div>
</div>

CSS:

#wrapper {
    display: table;
}
#wrapper div {
    display: table-cell;
}

[CodePen sample link - replace with actual CodePen link]

Case 2. Simple old-style layout

This is a rather outdated example, but I think you might need to deal with it, like I did recently.

A few months ago, I received a graphic layout that was very similar to the following scheme. It needs to be compatible with IE8, and I found the best way to do this is to use CSS table rules:

[CodePen sample link - replace with actual CodePen link]

Case 3. Adaptive layout with content orchestration function

The previous example leads us to a new topic: Is it possible to build an adaptive layout using CSS table rules?

This is not only possible, but we can also perform some content orchestration tasks.

We have seen how to change the display property of two divs from block to table-cell to change their arrangement from vertical to horizontal.

In addition, elements with table-header-group attributes are placed at the top of the table layout. Again, the table-footer-group element will be placed at the bottom, and so on. This can be unexpectedly useful when reformatting responsive layouts.

In the pen below, the title element swaps its position with the navigation element when the window is resized, just change its display attribute to table-header-group.

HTML:

<div id="wrapper">
    <nav></nav>
    <header></header>
    <div id="banner2"></div>
    <footer></footer>
</div>

CSS:

#wrapper, header {
    display: block; /* 我們實際上不需要此規(guī)則,因為它默認為此值 */
}

@media (min-width: 48em) {
    #wrapper {
        display: table;
    }
    header {
        display: table-header-group;
    }
}

footer and #banner2 divs also have similar behaviors.

This is a layout plan: the default mobile version on the left, and the desktop version on the right:

Layout Secret Weapon #1: The CSS Table Property

This is a running demonstration:

[CodePen sample link - replace with actual CodePen link]

More information about this argument can also be viewed:

  • CSS stacking using display:table
  • Anti-hero of CSS layout—"display:table"

Conclusion

CSS table Display properties are an underestimated and valuable solution to the size and layout challenges.

While I personally may not choose to use them to build complex layouts, they certainly solve many of the challenges related to the layout part.

FAQs about CSS table Properties

(Frequently asked questions about the CSS table attributes should be added here. The content is similar to the original text, but the wording needs to be adjusted to avoid duplication.)

Please note that all the above CodePen links need to be replaced with the actual CodePen link. I can't access and create a CodePen directly.

The above is the detailed content of Layout Secret Weapon #1: The CSS Table Property. 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)

The Developer's Shortcut To Your Udemy-like Platform The Developer's Shortcut To Your Udemy-like Platform Jun 17, 2025 pm 04:43 PM

When developing learning platforms similar to Udemy, the focus isn't only on content quality. Just as important is how that content is delivered. This is because modern educational platforms rely on media that is accessible, fast, and easy to digest.

Cost Effective Reseller Platforms for Buying SSL Certificates Cost Effective Reseller Platforms for Buying SSL Certificates Jun 25, 2025 am 08:28 AM

In a world where online trust is non-negotiable, SSL certificates have become essential for every website. The market size of SSL certification was valued at USD 5.6 Billion in 2024 and is still growing strongly, fueled by surging e-commerce business

5 Best Payment Gateways for SaaS: Your Ultimate Guide 5 Best Payment Gateways for SaaS: Your Ultimate Guide Jun 29, 2025 am 08:28 AM

A payment gateway is a crucial component of the payment process, enabling businesses to accept payments online. It acts as a bridge between the customer and the merchant, securely transferring payment information and facilitating transactions. For

New study claims AI 'understands' emotion better than us — especially in emotionally charged situations New study claims AI 'understands' emotion better than us — especially in emotionally charged situations Jul 03, 2025 pm 05:48 PM

In what seems like yet another setback for a domain where we believed humans would always surpass machines, researchers now propose that AI comprehends emotions better than we do.Researchers have discovered that artificial intelligence demonstrates a

Hurricanes and sandstorms can be forecast 5,000 times faster thanks to new Microsoft AI model Hurricanes and sandstorms can be forecast 5,000 times faster thanks to new Microsoft AI model Jul 05, 2025 am 12:44 AM

A new artificial intelligence (AI) model has demonstrated the ability to predict major weather events more quickly and with greater precision than several of the most widely used global forecasting systems.This model, named Aurora, has been trained u

Your devices feed AI assistants and harvest personal data even if they’re asleep. Here's how to know what you're sharing. Your devices feed AI assistants and harvest personal data even if they’re asleep. Here's how to know what you're sharing. Jul 05, 2025 am 01:12 AM

Like it or not, artificial intelligence has become part of daily life. Many devices — including electric razors and toothbrushes — have become AI-powered," using machine learning algorithms to track how a person uses the device, how the devi

Would outsourcing everything to AI cost us our ability to think for ourselves? Would outsourcing everything to AI cost us our ability to think for ourselves? Jul 03, 2025 pm 05:47 PM

Artificial intelligence (AI) began as a quest to simulate the human brain.Is it now in the process of transforming the human brain's role in daily life?The Industrial Revolution reduced reliance on manual labor. As someone who researches the applicat

Advanced AI models generate up to 50 times more CO₂ emissions than more common LLMs when answering the same questions Advanced AI models generate up to 50 times more CO₂ emissions than more common LLMs when answering the same questions Jul 06, 2025 am 12:37 AM

The more precisely we attempt to make AI models function, the greater their carbon emissions become — with certain prompts generating up to 50 times more carbon dioxide than others, according to a recent study.Reasoning models like Anthropic's Claude

See all articles