Css -- about setting the "collapse" value for visibility

Source: Internet
Author: User

1. It may have been usedvisibilityThousands of times, the most commonvisibleAndhiddenUsed to display or hide elements.

The third rarely used value iscollapseIn addition to the differences in table rows and columnshiddenIs equivalent.

Next let's take a look at the table elements,collapseBut the premise is thattableOfborder-collapseSetseparateIt will be effective!

The following is a demo:

The main () code is as follows:

 
 
Fruits Vegetables Rocks
Apple Celery Granite
Orange Cabbage Flint

2. The js file is as follows:

var btns = document.getElementsByTagName('button'),    rows = document.getElementsByTagName('tr');btns[0].addEventListener('click', function () {  rows[1].className = 'vc';}, false);btns[1].addEventListener('click', function () {  rows[1].className = 'vh';}, false);btns[2].addEventListener('click', function () {  rows[1].className = '';}, false);

3. the css file is as follows:

body {  text-align: center;  padding-top: 20px;  font-family: Arial, sans-serif;}table {  border-collapse: separate;  border-spacing: 5px;  border: solid 1px black;  width: 500px;  margin: 0 auto;}th, td {  text-align: center;  border: solid 1px black;  padding: 10px;}.vc {  visibility: collapse;}.vh {  visibility: hidden;}button {  margin-top: 5px;}

The default output is:

When you click COLLAPSE ROW1, the following information is displayed:

When you click HIDE ROW1, the following information is displayed:

Although collapse has the feature of hidden, the form of expression is very different from that of hidden. Now you can make a choice based on your own needs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.