Home > Web Front-end > HTML Tutorial > Two tables in one html set two styles but apply the same_html/css_WEB-ITnose

Two tables in one html set two styles but apply the same_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:16:39
Original
1565 people have browsed it

代码如下:




表格






  
    
    
  
  
    
    
  
这个表格是绿色边框 这个表格是绿色边框
这个表格是绿色边框 这个表格是绿色边框



  
  
    
    
  
  
    
    
  
这个表格是红色边框 这个表格是红色边框
这个表格是红色边框 这个表格是红色边框




这是效果图:


回复讨论(解决方案)





无标题文档





  
    
    
  
  
    
    
  
这个表格是绿色边框 这个表格是绿色边框
这个表格是绿色边框 这个表格是绿色边框





td>This table has a red border


;This table has a red border


;



Understand the usage of CSS compound selector. Take a look at the two pieces of code above.

#dc table tr td,#dc table tr th{border: 1px solid #0F0;}#cd table tr td,#cd table tr th{border: 1px solid #F00;}
Copy after login
#dc tr,th,td {
border: 1px solid #0F0;
}

#cd table tr,th,td {

border: 1px solid #F00;
}
Your two selectors actually select 3 each, one is #dc tr, one is th and one is td

CSS code?1234567#dc table tr td,# dc table tr th{border: 1px solid #0F0;}#cd table tr td,#cd table tr th{border: 1px solid #F00;}

Understand the usage of CSS compound selector. Take a look at the two pieces of code above.

The first one means that the td element and the th element contained under the tr element under the table element with id dc share a statement {border: 1px solid #0f0;

The second one means the same as the first one It's the same, but the ID is different. Do you understand me correctly?
What you want to tell me is that my compound selector is written incorrectly? #dc tr,td,th{border......} Is this incorrect?

Well, I have figured it out. It is indeed a writing error. The compound selector under the same ID needs to be written like this: #dc th, #dc td {border...} is correct. Special thanks to 2nd floor and 3rd floor. Correction from my friend! Thank you also, friend on the 1st floor, haha, but your code treats the symptoms but not the root cause. You just write the first table as th and the second table as td. Although the table effect is achieved, the first table is all Header, it’s not the final result I want

Well, I figured it out. It’s indeed a writing error. The compound selector under the same ID needs to be written like this: #dc th, #dc td {border… ...} is correct. Special thanks to friends on the 2nd and 3rd floors for their corrections! Thank you also, friend on the 1st floor, haha, but your code treats the symptoms but not the root cause. You just write the first table as th and the second table as td. Although the table effect is achieved, the first table is all Header, it’s not the final result I want

You’re welcome hehe

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template