Home Web Front-end CSS Tutorial How to use the CSS attribute border-collapse to solve the table border problem

How to use the CSS attribute border-collapse to solve the table border problem

Sep 13, 2018 am 11:43 AM

When we are laying out the page, in addition to pictures and text, the most used table is the table. For many people, the border of the table is quite annoying. I personally hate seeing it with multiple layers. The table with borders is extremely ugly. Do you know how to set the border of the table? Today I will talk to you about the border-collapse attribute in CSS. This attribute is very practical, but many people don’t know it yet. Come and take a look. Generally we write a table, which is written in the following way, give the table border and the style you want. The code is as follows:

HTML part:

<table class="aa">
   <thead>
    <tr>
     <th>序号</th>
     <th>姓名</th>
     <th>性别</th>
     <th>年龄</th>
    </tr>
   </thead>
   <tbody>
    <tr>
     <td>1</td>
     <td>张晗</td>
     <td>男</td>
     <td>23</td>
    </tr>
    <tr>
     <td>2</td>
     <td>陆颖</td>
     <td>女</td>
     <td>20</td>
    </tr>
    <tr>
     <td>3</td>
     <td>郝婷婷</td>
     <td>女</td>
     <td>19</td>
    </tr>
   </tbody>
  </table>
Copy after login

CSS part:

.aa{border: 1px solid #ccc;width:30%;text-align: center;border-collapse: collapse;}
.aa th,.aa td{border: 1px solid #ccc;padding: 10px;}
Copy after login

Look, the effect is like this:

How to use the CSS attribute border-collapse to solve the table border problem##It It does not conform to our understanding of the table. How come there are so many border lines? Generally, we only need the outer border and the part shared by the cells, and do not need to have a border for each cell. So how to remove these extra borders? Next is the focus of today. The border-collapse in the CSS attribute can help us remove excess borders.

First let’s take a look at the border-collapse attribute value description. It has two values. Separate is the default value. The borders are separated and not merged. Collapse borders are merged. If they are adjacent, they share a border. Let's add this attribute to the table just now.

.aa{border: 1px solid #ccc;width:30%;text-align: center;border-collapse: collapse;}
Copy after login

Picture:

How to use the CSS attribute border-collapse to solve the table border problem

see it? When we apply border-collapse: collapse to the table, the table borders merge and become much more beautiful. You can use this attribute in future work, it is very useful. It is recommended that friends try it themselves, especially beginners. I hope this article can help you!

The above is the detailed content of How to use the CSS attribute border-collapse to solve the table border problem. 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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

How to make custom borders in Microsoft Word How to make custom borders in Microsoft Word Nov 18, 2023 pm 11:17 PM

Want to make the front page of your school project look exciting? Nothing makes it stand out from other submissions like a nice, elegant border on the homepage of your workbook. However, the standard single-line borders in Microsoft Word have become very obvious and boring. Therefore, we show you the steps to create and use custom borders in Microsoft Word documents. How to Make Custom Borders in Microsoft Word Creating custom borders is very easy. However, you will need a boundary. Step 1 – Download Custom Borders There are tons of free borders on the internet. We have downloaded a border like this. Step 1 – Search the Internet for custom borders. Alternatively, you can go to clipping

Popular science on how to set excel borders Popular science on how to set excel borders Mar 20, 2024 am 10:30 AM

It is not uncommon for Excel to appear in our daily work and life. Whether it is the production of employee information, salary tables, or student enrollment information and transcripts, Excel is a relatively easy-to-use tool. When printing Excel, you need to set borders to meet printing requirements. In this article, the editor will introduce you to several ways to set Excel borders. Method 1. Use the function tab button. This should be a method often used by everyone. It is convenient and fast. The specific operation: select the cell area B2:H10 where you need to add a border, click the [Start] tab - [Border] drop-down on the right Button-[All Frames] to complete adding frames. Method 2. Select the cell area B2:H10 where you want to add a border.

How to use CSS to animate the border of an element How to use CSS to animate the border of an element Nov 21, 2023 pm 02:26 PM

How to use CSS to achieve element border animation effects Introduction: In web design, in order to increase the user's visual experience and the attractiveness of the page, some animation effects are often used to make page elements more vivid and interesting. Among them, border animation is a very common effect, which can make the element border change, flicker or flow dynamically. This article will introduce how to use CSS to animate the border of elements and provide specific code examples. 1. Realize the border color change animation To realize the border color change animation effect, you can

How to add borders to images using PHP How to add borders to images using PHP Aug 26, 2023 am 10:12 AM

How to use PHP to add borders to pictures In web development and image processing, it is often necessary to add borders to pictures to improve the beauty and visibility of the pictures. This article will introduce how to add borders to images using PHP, with code examples. First, we need to make sure that PHP's GD library is installed on the server. The GD library is an open source library for image processing that can be used to create, manipulate and output images. Most servers have the GD library installed by default, but if it is not installed, you can manage the work through the PHP extension.

Tips for achieving gradient border effect using CSS properties Tips for achieving gradient border effect using CSS properties Nov 18, 2023 pm 02:53 PM

The technique of realizing the gradient border effect using CSS properties requires specific code examples. In web design, the border is an important element that can bring richer visual effects to the page. And if you can achieve a gradient effect on the border, it will further increase the appeal of the page. This article will introduce some techniques for using CSS properties to achieve gradient border effects, and provide specific code examples. Use the "border-image" attribute to implement gradient borders&lt;style&gt;.gradient-

Tips for implementing border animation effects using CSS properties Tips for implementing border animation effects using CSS properties Nov 18, 2023 pm 01:26 PM

Techniques for implementing border animation effects using CSS properties require specific code examples. With the continuous development of Web technology, the requirements for page design are becoming higher and higher. In page design, animation effects are one of the important means to attract users' attention. Among them, border animation effects can add vitality and vitality to the page. This article will introduce some techniques for using CSS properties to help you achieve various border animation effects. 1. Use the transition attribute to achieve transition effects. The transition attribute can define the elements in different states.

How to use vue3 table component How to use vue3 table component May 12, 2023 pm 09:40 PM

Basic table Before developing the table component, first think about what style of API to use. Because the author uses element in production work, the styles of the previous components are similar to element, but this time I do not plan to use the element style. , I plan to change it and display it directly: We expect users to use it like this: constdataList=[{id:1,name:'"JavaEE Enterprise Application Practice"',author:'dev1ce',price:'10.22',desc:&# 3

See all articles