>  기사  >  웹 프론트엔드  >  매우 아름답고 실용적인 CSS 스타일 테이블 4개를 공유하세요.

매우 아름답고 실용적인 CSS 스타일 테이블 4개를 공유하세요.

黄舟
黄舟원래의
2017-07-26 09:24:3416716검색

1. 단일 픽셀 테두리 CSS 테이블

매우 일반적으로 사용되는 테이블 스타일입니다.


소스 코드:

<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style>

<!-- Table goes in the document BODY -->
<table class="gridtable">
<tr>
	<th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
</tr>
<tr>
	<td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
</tr>
<tr>
	<td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
</tr>
</table>

2. 배경 이미지가 포함된 CSS 스타일 테이블

은 위와 유사하지만 각 그리드에 추가 배경 이미지가 있습니다.

cell-blue.jpg

cell-grey.jpg

1. 위 두 사진을 다운로드하고 이름을 cell-blue.jpg 및 cell-grey.jpg

2.로 지정하세요. 아래 코드를 원하는 위치에 복사하고, 이미지 URL을 수정하는 것을 잊지 마세요

<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.imagetable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #999999;
	border-collapse: collapse;
}
table.imagetable th {
	background:#b5cfd2 url(&#39;cell-blue.jpg&#39;);
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #999999;
}
table.imagetable td {
	background:#dcddc0 url(&#39;cell-grey.jpg&#39;);
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #999999;
}
</style>

<!-- Table goes in the document BODY -->
<table class="imagetable">
<tr>
	<th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
</tr>
<tr>
	<td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
</tr>
<tr>
	<td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
</tr>
</table>

3. 전체 행의 색상을 자동으로 변경하는 CSS 스타일 테이블(JS 필요)

이 CSS 스타일 테이블은 각 행의 색상을 자동으로 전환합니다. row, 이는 대규모 테이블을 자주 업데이트해야 할 때 유용합니다.


코드:

<!-- Javascript goes in the document HEAD -->
<script type="text/javascript">
function altRows(id){
	if(document.getElementsByTagName){  
		
		var table = document.getElementById(id);  
		var rows = table.getElementsByTagName("tr"); 
		 
		for(i = 0; i < rows.length; i++){          
			if(i % 2 == 0){
				rows[i].className = "evenrowcolor";
			}else{
				rows[i].className = "oddrowcolor";
			}      
		}
	}
}

window.onload=function(){
	altRows(&#39;alternatecolor&#39;);
}
</script>


<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.altrowstable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #a9c6c9;
	border-collapse: collapse;
}
table.altrowstable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
table.altrowstable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
.oddrowcolor{
	background-color:#d4e3e5;
}
.evenrowcolor{
	background-color:#c3dde0;
}
</style>


<!-- Table goes in the document BODY -->
<table class="altrowstable" id="alternatecolor">
<tr>
	<th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
</tr>
<tr>
	<td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
</tr>
<tr>
	<td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
</tr>
</tr>
<tr>
	<td>Text 3A</td><td>Text 3B</td><td>Text 3C</td>
</tr>
<tr>
	<td>Text 4A</td><td>Text 4B</td><td>Text 4C</td>
</tr>
<tr>
	<td>Text 5A</td><td>Text 5B</td><td>Text 5C</td>
</tr>
</table>

<!--  The table code can be found here: http://www.textfixer/resources/css-tables.php#css-table03 -->

4. 마우스 오버로 강조된 CSS 스타일 테이블(JS 필요)

순수한 CSS 표시 테이블 강조 표시는 IE에서 문제가 있으므로 여기에서는 강조 표시를 사용합니다. 블로그는 js 사용을 제한하므로 가까운 시일 내에 블로그를 내 웹 호스트로 이전할 예정입니다.


한 가지 주의할 점은 그리드의 배경색을 정의하지 않는 것입니다.

<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.hovertable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #999999;
	border-collapse: collapse;
}
table.hovertable th {
	background-color:#c3dde0;
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
table.hovertable tr {
	background-color:#d4e3e5;
}
table.hovertable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
</style>

<!-- Table goes in the document BODY -->
<table class="hovertable">
<tr>
	<th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
</tr>
<tr onmouseover="this.style.backgroundColor=&#39;#ffff66&#39;;" onmouseout="this.style.backgroundColor=&#39;#d4e3e5&#39;;">
	<td>Item 1A</td><td>Item 1B</td><td>Item 1C</td>
</tr>
<tr onmouseover="this.style.backgroundColor=&#39;#ffff66&#39;;" onmouseout="this.style.backgroundColor=&#39;#d4e3e5&#39;;">
	<td>Item 2A</td><td>Item 2B</td><td>Item 2C</td>
</tr>
<tr onmouseover="this.style.backgroundColor=&#39;#ffff66&#39;;" onmouseout="this.style.backgroundColor=&#39;#d4e3e5&#39;;">
	<td>Item 3A</td><td>Item 3B</td><td>Item 3C</td>
</tr>
<tr onmouseover="this.style.backgroundColor=&#39;#ffff66&#39;;" onmouseout="this.style.backgroundColor=&#39;#d4e3e5&#39;;">
	<td>Item 4A</td><td>Item 4B</td><td>Item 4C</td>
</tr>
<tr onmouseover="this.style.backgroundColor=&#39;#ffff66&#39;;" onmouseout="this.style.backgroundColor=&#39;#d4e3e5&#39;;">
	<td>Item 5A</td><td>Item 5B</td><td>Item 5C</td>
</tr>
</table>

가장 일반적인 CSS 스타일 테이블이 여기에 있습니다. 모두에게 도움이 되기를 바랍니다

위 내용은 매우 아름답고 실용적인 CSS 스타일 테이블 4개를 공유하세요.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.