几段强大的响应式 CSS 代码

实现响应式图像CSS

img {
max-width: 100%;
}

响应式导航菜单

CSS // 宽度小于960px 就隐藏变成下来式菜单,其实这样也不好看,最起码默认显示一两个就更好。
nav select {
display: none;
}

@media (max-width: 960px) {
nav ul { display: none; }
nav select { display: inline-block; }
}

响应式表格

HTML code

First Name Last Name Job Title
James Matman Chief Sandwich Eater
The Tick Crimefighter Sorta

CSS code

/*
适用于桌面PC和笔记本
*/
table {
width: 100%;
border-collapse: collapse;
}
/* Zebra striping */
tr:nth-of-type(odd) {
background: #eee;
}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}

自适应CSS
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {

/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {
display: block;
}

/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}

tr { border: 1px solid #ccc; }

td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}

td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}

/*
Label the data
*/
td:nth-of-type(1):before { content: "First Name"; }
td:nth-of-type(2):before { content: "Last Name"; }
td:nth-of-type(3):before { content: "Job Title"; }
td:nth-of-type(4):before { content: "Favorite Color"; }
td:nth-of-type(5):before { content: "Wars of Trek?"; }
td:nth-of-type(6):before { content: "Porn Name"; }
td:nth-of-type(7):before { content: "Date of Birth"; }
td:nth-of-type(8):before { content: "Dream Vacation City"; }
td:nth-of-type(9):before { content: "GPA"; }
td:nth-of-type(10):before { content: "Arbitrary Data"; }
}

对于IE这垃圾货的兼容问题可以使用 CSS3-mediaqueries.js 和下面的html code

/* Or an external stylesheet or whatever */

响应式HTML5视频
video {
max-width: 100%;
height: auto;
}

响应式YouTube and Vimeo 视频 Html and CSS

 

CSS 代码:
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px; height: 0; overflow: hidden;
}

.video-container iframe,
.video-container object,
.video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

Via http://css-tricks.com/responsive-data-tables
http://css-tricks.com/convert-menu-to-dropdown

发表评论或回复

*选项为必填项,您的电子邮件地址不会被公开。

*
*