Домой / Рецепты CSS / Создание одностраничного (адаптивного) сайта из вкладок (табов) на чистом CSS
Создание одностраничного (адаптивного) сайта из вкладок (табов) на чистом CSS

Создание одностраничного (адаптивного) сайта из вкладок (табов) на чистом CSS

Отличный и в тоже время оригинальный пример создания сайта из вкладок (табов) с помощью CSS. Такой одностраничный сайт подойдет для сайта-визитки или для простого информационного сайта. Имеет адаптивный дизайн.

 

Демо

HTML

<meta content='width=device-width, minimum-scale=0.81, maximum-scale=0.81, minimal-ui' name='viewport'>
<div class='content'>
 <div class='tabs-v'>
 <input checked id='rad1' name='rad' type='radio'>
 <label data-text='Home' for='rad1'></label>
 <input id='rad2' name='rad' type='radio'>
 <label data-text='About' for='rad2'></label>
 <input id='rad3' name='rad' type='radio'>
 <label data-text='Work' for='rad3'></label>
 <input id='rad4' name='rad' type='radio'>
 <label data-text='Contact' for='rad4'></label>
 <div class='tab-c'>
 <div class='card'>
 <h1>Home</h1>
 <p>The lysine contingency - it's intended to prevent the spread of the animals is case they ever got off the island. Dr. Wu inserted a gene that makes a single faulty enzyme in protein metabolism. The animals can't manufacture the amino acid lysine. Unless they're continually supplied with lysine by us, they'll slip into a coma and die.</p>
 </div>
 </div>
 <div class='tab-c'>
 <div class='card'>
 <h1>About</h1>
 <p>Yeah, I like animals better than people sometimes... Especially dogs. Dogs are the best. Every time you come home, they act like they haven't seen you in a year. And the good thing about dogs... is they got different dogs for different people. Like pit bulls. The dog of dogs. Pit bull can be the right man's best friend... or the wrong man's worst enemy. You going to give me a dog for a pet, give me a pit bull. Give me... Raoul. Right, Omar? Give me Raoul.</p>
 </div>
 </div>
 <div class='tab-c'>
 <div class='card'>
 <h1>Work</h1>
 <p>Your bones don't break, mine do. That's clear. Your cells react to bacteria and viruses differently than mine. You don't get sick, I do. That's also clear. But for some reason, you and I react the exact same way to water. We swallow it too fast, we choke. We get some in our lungs, we drown. However unreal it may seem, we are connected, you and I. We're on the same curve, just on opposite ends. Your bones don't break, mine do. That's clear. Your cells react to bacteria and viruses differently than mine. You don't get sick, I do. That's also clear. But for some reason, you and I react the exact same way to water. We swallow it too fast, we choke. We get some in our lungs, we drown. However unreal it may seem, we are connected, you and I. We're on the same curve, just on opposite ends.</p>
 </div>
 </div>
 <div class='tab-c'>
 <div class='card'>
 <h1>Contact</h1>
 <p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee. The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
 </div>
 </div>
 </div>
</div>

CSS

.tabs-v {
 float: left;
 display: inline-block;
 width: 4rem;
 height: 100%;
}
.tabs-v, .tabs-v * {
 box-sizing: border-box;
 -webkit-tap-highlight-color: transparent;
}
.tabs-v > input[type="radio"] {
 -webkit-appearance: none;
 -moz-appearance: none;
 -ms-appearance: none;
 -o-appearance: none;
 appearance: none;
 display: none;
}
.tabs-v > input[type="radio"]:checked + label {
 background: white;
 background-image: -moz-linear-gradient(left, #ffffff 0%, #ffffff 50%, #333333 50%, #333333 100%, #333333 100%);
 background-image: -webkit-linear-gradient(left, #ffffff 0%, #ffffff 50%, #333333 50%, #333333 100%, #333333 100%);
 background-image: linear-gradient(to right, #ffffff 0%, #ffffff 50%, #333333 50%, #333333 100%, #333333 100%);
 background-size: 200% 200%;
 background-position: 0;
}
.tabs-v > input[type="radio"]:checked + label:before {
 -moz-transform: translate(0, -50%);
 -ms-transform: translate(0, -50%);
 -webkit-transform: translate(0, -50%);
 transform: translate(0, -50%);
 -moz-transform: translate3d(0, -50%, 0);
 -ms-transform: translate3d(0, -50%, 0);
 -webkit-transform: translate3d(0, -50%, 0);
 transform: translate3d(0, -50%, 0);
 -moz-transition: -moz-transform 0.35s;
 -o-transition: -o-transform 0.35s;
 -webkit-transition: -webkit-transform 0.35s;
 transition: transform 0.35s;
}
.tabs-v > input[type="radio"]:checked + label:after {
 color: #333333;
}
.tabs-v > label {
 border: none;
 padding: 0;
 background: none;
 outline: none;
 border-radius: 0;
 -moz-transition: background-position 0.25s, box-shadow 0.25s;
 -o-transition: background-position 0.25s, box-shadow 0.25s;
 -webkit-transition: background-position 0.25s, box-shadow 0.25s;
 transition: background-position 0.25s, box-shadow 0.25s;
 position: relative;
 float: left;
 display: inline-block;
 width: 100%;
 height: 25%;
 text-align: center;
 line-height: 25vh;
 margin: 0;
 background: #333333;
 background-image: -moz-linear-gradient(left, #ffffff 0%, #ffffff 50%, #333333 50%, #333333 100%, #333333 100%);
 background-image: -webkit-linear-gradient(left, #ffffff 0%, #ffffff 50%, #333333 50%, #333333 100%, #333333 100%);
 background-image: linear-gradient(to right, #ffffff 0%, #ffffff 50%, #333333 50%, #333333 100%, #333333 100%);
 background-size: 200% 200%;
 background-position: 100%;
 box-shadow: inset 0px 1px 0 white, inset -1px 0 0px 0px white;
}
.tabs-v > label:first-of-type {
 box-shadow: inset -1px 0 0px 0px white;
}
.tabs-v > label:after {
 content: attr(data-text);
 position: absolute;
 top: 50%;
 left: 50%;
 display: inline-block;
 width: 100%;
 color: white;
 text-align: center;
 -moz-transform: translate(-50%, -50%);
 -ms-transform: translate(-50%, -50%);
 -webkit-transform: translate(-50%, -50%);
 transform: translate(-50%, -50%);
 -moz-transform: translate3d(-50%, -50%, 0);
 -ms-transform: translate3d(-50%, -50%, 0);
 -webkit-transform: translate3d(-50%, -50%, 0);
 transform: translate3d(-50%, -50%, 0);
 -moz-transition: color 0.25s;
 -o-transition: color 0.25s;
 -webkit-transition: color 0.25s;
 transition: color 0.25s;
}
.tabs-v > label:before {
 content: '';
 position: absolute;
 left: 100%;
 top: 50%;
 display: inline-block;
 width: 0;
 height: 0;
 border-top: solid 1rem transparent;
 border-bottom: solid 1rem transparent;
 border-right: solid 1.5rem transparent;
 border-left: solid 1.5rem;
 border-left-color: white;
 -moz-transform: translate(-5.5rem, -50%);
 -ms-transform: translate(-5.5rem, -50%);
 -webkit-transform: translate(-5.5rem, -50%);
 transform: translate(-5.5rem, -50%);
 -moz-transform: translate3d(-5.5rem, -50%, 0);
 -ms-transform: translate3d(-5.5rem, -50%, 0);
 -webkit-transform: translate3d(-5.5rem, -50%, 0);
 transform: translate3d(-5.5rem, -50%, 0);
 -moz-transition: -moz-transform 0.2s;
 -o-transition: -o-transform 0.2s;
 -webkit-transition: -webkit-transform 0.2s;
 transition: transform 0.2s;
}
.tabs-v > .tab-c {
 position: fixed;
 display: inline-block;
 width: 100%;
 height: 100%;
 left: 4rem;
 text-align: center;
 -moz-transition: -moz-transform 0.5s;
 -o-transition: -o-transform 0.5s;
 -webkit-transition: -webkit-transform 0.5s;
 transition: transform 0.5s;
}
.tabs-v > .tab-c > .card {
 position: absolute;
 left: 50%;
 top: 50%;
 display: inline-block;
 width: 70%;
 max-height: 80%;
 overflow-x: hidden;
 overflow-y: auto;
 padding: 2rem;
 box-shadow: 0 0 0 1px white;
 color: white;
 -webkit-overflow-scrolling: touch;
 -moz-transform: translate(-50%, -50%) translate(-1.5rem, 0);
 -ms-transform: translate(-50%, -50%) translate(-1.5rem, 0);
 -webkit-transform: translate(-50%, -50%) translate(-1.5rem, 0);
 transform: translate(-50%, -50%) translate(-1.5rem, 0);
 -moz-transform: translate3d(-50%, -50%, 0) translate3d(-1.5rem, 0, 0);
 -ms-transform: translate3d(-50%, -50%, 0) translate3d(-1.5rem, 0, 0);
 -webkit-transform: translate3d(-50%, -50%, 0) translate3d(-1.5rem, 0, 0);
 transform: translate3d(-50%, -50%, 0) translate3d(-1.5rem, 0, 0);
}
.tabs-v > .tab-c > .card > h1 {
 margin-top: 0;
}
.tabs-v > input[type="radio"]:nth-of-type(1):checked ~ .tab-c:nth-of-type(1) {
 -moz-transform: translate(0, 0%);
 -ms-transform: translate(0, 0%);
 -webkit-transform: translate(0, 0%);
 transform: translate(0, 0%);
 -moz-transform: translate3d(0, 0%, 0);
 -ms-transform: translate3d(0, 0%, 0);
 -webkit-transform: translate3d(0, 0%, 0);
 transform: translate3d(0, 0%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(1):checked ~ .tab-c:nth-of-type(2) {
 -moz-transform: translate(0, 100%);
 -ms-transform: translate(0, 100%);
 -webkit-transform: translate(0, 100%);
 transform: translate(0, 100%);
 -moz-transform: translate3d(0, 100%, 0);
 -ms-transform: translate3d(0, 100%, 0);
 -webkit-transform: translate3d(0, 100%, 0);
 transform: translate3d(0, 100%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(1):checked ~ .tab-c:nth-of-type(3) {
 -moz-transform: translate(0, 200%);
 -ms-transform: translate(0, 200%);
 -webkit-transform: translate(0, 200%);
 transform: translate(0, 200%);
 -moz-transform: translate3d(0, 200%, 0);
 -ms-transform: translate3d(0, 200%, 0);
 -webkit-transform: translate3d(0, 200%, 0);
 transform: translate3d(0, 200%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(1):checked ~ .tab-c:nth-of-type(4) {
 -moz-transform: translate(0, 300%);
 -ms-transform: translate(0, 300%);
 -webkit-transform: translate(0, 300%);
 transform: translate(0, 300%);
 -moz-transform: translate3d(0, 300%, 0);
 -ms-transform: translate3d(0, 300%, 0);
 -webkit-transform: translate3d(0, 300%, 0);
 transform: translate3d(0, 300%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(2):checked ~ .tab-c:nth-of-type(1) {
 -moz-transform: translate(0, -100%);
 -ms-transform: translate(0, -100%);
 -webkit-transform: translate(0, -100%);
 transform: translate(0, -100%);
 -moz-transform: translate3d(0, -100%, 0);
 -ms-transform: translate3d(0, -100%, 0);
 -webkit-transform: translate3d(0, -100%, 0);
 transform: translate3d(0, -100%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(2):checked ~ .tab-c:nth-of-type(2) {
 -moz-transform: translate(0, 0%);
 -ms-transform: translate(0, 0%);
 -webkit-transform: translate(0, 0%);
 transform: translate(0, 0%);
 -moz-transform: translate3d(0, 0%, 0);
 -ms-transform: translate3d(0, 0%, 0);
 -webkit-transform: translate3d(0, 0%, 0);
 transform: translate3d(0, 0%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(2):checked ~ .tab-c:nth-of-type(3) {
 -moz-transform: translate(0, 100%);
 -ms-transform: translate(0, 100%);
 -webkit-transform: translate(0, 100%);
 transform: translate(0, 100%);
 -moz-transform: translate3d(0, 100%, 0);
 -ms-transform: translate3d(0, 100%, 0);
 -webkit-transform: translate3d(0, 100%, 0);
 transform: translate3d(0, 100%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(2):checked ~ .tab-c:nth-of-type(4) {
 -moz-transform: translate(0, 200%);
 -ms-transform: translate(0, 200%);
 -webkit-transform: translate(0, 200%);
 transform: translate(0, 200%);
 -moz-transform: translate3d(0, 200%, 0);
 -ms-transform: translate3d(0, 200%, 0);
 -webkit-transform: translate3d(0, 200%, 0);
 transform: translate3d(0, 200%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(3):checked ~ .tab-c:nth-of-type(1) {
 -moz-transform: translate(0, -200%);
 -ms-transform: translate(0, -200%);
 -webkit-transform: translate(0, -200%);
 transform: translate(0, -200%);
 -moz-transform: translate3d(0, -200%, 0);
 -ms-transform: translate3d(0, -200%, 0);
 -webkit-transform: translate3d(0, -200%, 0);
 transform: translate3d(0, -200%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(3):checked ~ .tab-c:nth-of-type(2) {
 -moz-transform: translate(0, -100%);
 -ms-transform: translate(0, -100%);
 -webkit-transform: translate(0, -100%);
 transform: translate(0, -100%);
 -moz-transform: translate3d(0, -100%, 0);
 -ms-transform: translate3d(0, -100%, 0);
 -webkit-transform: translate3d(0, -100%, 0);
 transform: translate3d(0, -100%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(3):checked ~ .tab-c:nth-of-type(3) {
 -moz-transform: translate(0, 0%);
 -ms-transform: translate(0, 0%);
 -webkit-transform: translate(0, 0%);
 transform: translate(0, 0%);
 -moz-transform: translate3d(0, 0%, 0);
 -ms-transform: translate3d(0, 0%, 0);
 -webkit-transform: translate3d(0, 0%, 0);
 transform: translate3d(0, 0%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(3):checked ~ .tab-c:nth-of-type(4) {
 -moz-transform: translate(0, 100%);
 -ms-transform: translate(0, 100%);
 -webkit-transform: translate(0, 100%);
 transform: translate(0, 100%);
 -moz-transform: translate3d(0, 100%, 0);
 -ms-transform: translate3d(0, 100%, 0);
 -webkit-transform: translate3d(0, 100%, 0);
 transform: translate3d(0, 100%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(4):checked ~ .tab-c:nth-of-type(1) {
 -moz-transform: translate(0, -300%);
 -ms-transform: translate(0, -300%);
 -webkit-transform: translate(0, -300%);
 transform: translate(0, -300%);
 -moz-transform: translate3d(0, -300%, 0);
 -ms-transform: translate3d(0, -300%, 0);
 -webkit-transform: translate3d(0, -300%, 0);
 transform: translate3d(0, -300%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(4):checked ~ .tab-c:nth-of-type(2) {
 -moz-transform: translate(0, -200%);
 -ms-transform: translate(0, -200%);
 -webkit-transform: translate(0, -200%);
 transform: translate(0, -200%);
 -moz-transform: translate3d(0, -200%, 0);
 -ms-transform: translate3d(0, -200%, 0);
 -webkit-transform: translate3d(0, -200%, 0);
 transform: translate3d(0, -200%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(4):checked ~ .tab-c:nth-of-type(3) {
 -moz-transform: translate(0, -100%);
 -ms-transform: translate(0, -100%);
 -webkit-transform: translate(0, -100%);
 transform: translate(0, -100%);
 -moz-transform: translate3d(0, -100%, 0);
 -ms-transform: translate3d(0, -100%, 0);
 -webkit-transform: translate3d(0, -100%, 0);
 transform: translate3d(0, -100%, 0);
}
.tabs-v > input[type="radio"]:nth-of-type(4):checked ~ .tab-c:nth-of-type(4) {
 -moz-transform: translate(0, 0%);
 -ms-transform: translate(0, 0%);
 -webkit-transform: translate(0, 0%);
 transform: translate(0, 0%);
 -moz-transform: translate3d(0, 0%, 0);
 -ms-transform: translate3d(0, 0%, 0);
 -webkit-transform: translate3d(0, 0%, 0);
 transform: translate3d(0, 0%, 0);
}

::-webkit-scrollbar {
 width: 14px;
}

::-webkit-scrollbar-thumb {
 background: rgba(255, 255, 255, 0.5);
 box-shadow: inset 0 0 0 4px #333333;
}

.content {
 position: relative;
 float: left;
 display: inline-block;
 width: 100%;
 height: 100%;
}

html, body {
 width: 100%;
 height: 100%;
 margin: 0;
 padding: 0;
 font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
 background: #333333;
 overflow: hidden;
 scrollbar-face-color: white;
 scrollbar-base-color: #FFF;
 scrollbar-track-color: #333333;
 scrollbar-arrow-color: #333333;
 scrollbar-shadow-color: #333333;
}

Отличный и в тоже время оригинальный пример создания сайта из вкладок (табов) с помощью CSS. Такой одностраничный сайт подойдет для сайта-визитки или для простого информационного сайта. Имеет адаптивный дизайн.   HTML <meta content='width=device-width, minimum-scale=0.81, maximum-scale=0.81, minimal-ui' name='viewport'> <div class='content'> <div class='tabs-v'> <input checked id='rad1' name='rad' type='radio'> <label data-text='Home' for='rad1'></label> <input id='rad2' name='rad' type='radio'> <label data-text='About' for='rad2'></label> <input id='rad3' name='rad' type='radio'> <label data-text='Work' for='rad3'></label> <input id='rad4' name='rad' type='radio'> <label data-text='Contact' for='rad4'></label> <div class='tab-c'> <div class='card'> <h1>Home</h1> <p>The lysine contingency - it's intended to prevent the spread of the animals is case they ever got off the island. Dr.…

Обзор

Проголосуйте за урок

Оценка

Итог : Уважаемые читатели! Если вам понравилась статья не поленитесь проголосовать и оставить комментарий, ведь так я смогу понять полезность уроков и статей, и улучшить их качество в будущем. Заранее спасибо!

Рейтинг: 4.68 ( 5 голосов )
100

Оставить комментарий

Ваш email не будет опубликован.

*