Web Front-end
CSS Tutorial
css code to realize the mutual exchange of rows and columns of the tableThis article introduces to you the css code for realizing the exchange of rows and columns of tables. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<!DOCTYPE html>
<html>
<head>
<title>行列互换</title>
<meta charset="UTF-8">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<style type="text/css">
table {
border: 1px solid #ccc;
font-size: 14px;
}
table th {
background: orange;
color: #fff;
padding: 10px;
}
table td {
padding: 10px;
}
table.vertical {
-webkit-writing-mode: vertical-lr;
-moz-writing-mode: vertical-lr;
-ms-writing-mode: tb-lr;
writing-mode: vertical-lr;
}
table.vertical th,
table.vertical td {
width: 100px;
height: 14px;
}
table.vertical p {
-webkit-writing-mode: horizontal-tb;
-moz-writing-mode: horizontal-tb;
-ms-writing-mode: lr-tb;
writing-mode: horizontal-tb;
}
</style>
<script type="text/javascript">
var flag = false;
//注:多次点击后,内面文字会包裹多层p,尚无好的解决方法
function test() {
if(!flag) {
$('table').addClass('vertical').find('th, td').wrapInner('<p>');
// $('table').addClass('vertical');//数字会变垂直,不能用
} else {
$('table').removeClass('vertical');
}
flag = !flag;
}
</script>
</head>
<body>
<table>
<tr>
<tr>
<th>列1</th>
<th>列2</th>
<th>列3</th>
<th>列4</th>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
<tr>
<td>数据1-1</td>
<td>数据1-2</td>
<td>数据1-3</td>
<td>数据1-4</td>
</tr>
<tr>
<td>数据2-1</td>
<td>数据2-2</td>
<td>数据2-3</td>
<td>数据2-4</td>
</tr>
<tr>
<td>数据3-1</td>
<td>数据3-2</td>
<td>数据3-3</td>
<td>数据3-4</td>
</tr>
</table>
<input type="button" onclick="test()" value="行列转置" />
</body>
</html>Related recommendations:
Positioning problem in css: Absolute Positioning, relative positioning, fixed and static
How to use css to cover another image when the mouse moves in and out? (Example)
The above is the detailed content of css code to realize the mutual exchange of rows and columns of the table. For more information, please follow other related articles on the PHP Chinese website!
Explain the concept of BEM (Block Element Modifier) naming convention in CSSJul 24, 2025 am 04:06 AMBEM is a CSS naming specification that improves code readability, reduces conflicts and facilitates maintenance. 1.Block is a separate component, such as .btn; 2.Element is an integral part of Block, such as .nav\_\_link; 3.Modifier represents a state or variant, such as .btn--large. The naming formats are .block, .block\_\_element, .block--modifier or .block\_\_element--modifier respectively. Using BEM can avoid class name conflicts, improve maintainability, and facilitate team collaboration. Notes include: avoiding too deep levels, using Modifier reasonably,
Explain CSS specificity and how it is calculatedJul 24, 2025 am 04:03 AMCSS refers to the weighting mechanism used by the browser to determine which style rules are preferred. When multiple rules act on the same element, a high-weight rule takes effect. For example, #mainp is more specific than p, and will cover the color blue. The calculation method is based on the selector type and is divided into four levels: a is the number of inline styles, b is the number of ID selectors, c is the number of classes, attributes, and pseudo-classes, and d is the number of elements and pseudo-elements. Compare bit by bit when comparing, and compare a→b→c→d in sequence like a phone number. Common misunderstandings include abuse!important, over-necking selectors, dependency ID selectors, etc. It is recommended to use clear structure and unified class name naming to reduce conflicts, and you can check the style coverage through the developer tool and adjust the selector rights.
How to create a custom cursor with CSS?Jul 24, 2025 am 04:03 AMThere are four ways to customize mouse pointers using CSS: 1. Use the cursor attribute to set built-in styles, such as pointer, text, etc.; 2. Specify the custom picture as the cursor through url() and set alternate styles; 3. Add coordinate values after url() to adjust the hot spot position of the cursor; 4. Use JavaScript to hide the native cursor and use elements to simulate dynamic effects. Each method is suitable for different scenarios, and needs to pay attention to compatibility, performance and user experience details.
What is the difference between `id` and `class` selectors?Jul 24, 2025 am 03:56 AMThe role of id and class in CSS is different, and the usage scenarios are also different. 1.id is a unique identifier, used for style design of a single unique element, such as #main-content; 2.class can be reused and is suitable for multiple elements to apply the same style, such as .button; 3.id's selector priority is higher than class, which will affect style overwrite; 4. id is used in HTML, class is used in class, 5. id is used in CSS, and class is used in class. 6. It is recommended to avoid excessive use of id for style design, because it is not easy to cover; 7.
How do you center an element horizontally and vertically with CSS?Jul 24, 2025 am 03:55 AMTo center elements horizontally and vertically, the most common methods include using Flexbox, Grid and absolute positioning to match transform. 1. Use Flexbox: Set the container to flex layout, and set it to center through justify-content and align-items, which is suitable for modern browsers and is simple and efficient; 2. Use Grid: Use display:grid and place-items:center to achieve centering, which is concise and clear; 3. Absolute positioning and transform: suitable for old browsers, set it to 50% by left and top and use transform to move half of its width and height back to achieve centering. It is commonly used
How to change the font color in CSS?Jul 24, 2025 am 03:51 AMTo change the text color in a web page, use the color attribute of CSS. This property controls the foreground color of the text and supports color name, hexadecimal value, RGB or HSL format, such as: p{color:red;} or h1{color:#00ff00;}, which can be applied to label selector, class or ID; commonly used methods include: 1. Color name (such as red); 2. Hexadecimal (such as #ff0000); 3. RGB (such as rgb(255,0,0)); 4. HSL (such as hsl(0,100%,50%)); If the color does not take effect during debugging, it may be overwritten by other rules, insufficient contrast or wrong format. It is recommended to use browser developer tools to check and debug in real time to ensure the effect
Explain techniques for image replacement using CSSJul 24, 2025 am 03:49 AMImagereplacementinCSSinvolveshidingrealtextanddisplayinganimageorstyledversioninstead,ensuringaccessibilityandSEObenefitswhileallowingvisualcustomization.1.Theclassicmethodusestext-indenttomovetextoff-screenwhileshowingabackgroundimage,requiringsetel
What are CSS Logical Properties and Values?Jul 24, 2025 am 03:48 AMCSSLogicalProperties and Values provides a layout based on writing mode, using inline, block, start, end and other logical directions to replace the traditional left, right, top, bottom. 1. It enables the style to automatically adapt to LTR, RTL and vertical layout without additional adjustments; 2. Common attributes include margin-inline-start, padding-block-end, inline-size and block-size; 3. Applicable to international websites, component library development and responsive design; 4. Be careful about compatibility when using it, and some browsers may need to fall


Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.






