- How TO — Tabs
- London
- Paris
- Tokyo
- Create Toggleable Tabs
- Example
- London
- Paris
- Tokyo
- Example
- Example
- Fade in Tabs:
- Example
- Show a tab by default
- Example
- Close a tab
- Example
- London
- 15 CSS Tabs
- Related Articles
- Author
- Links
- Made with
- About a code
- Nav Tab
- Author
- Links
- Made with
- About a code
- CSS Tab
- Author
- Links
- Made with
- About a code
- Tabs Widget. No JS!
- Author
- Links
- Made with
- About a code
- Tabs
- Author
- Links
- Made with
- About a code
- Pure CSS Tab Module
- Author
- Links
- Made with
- About a code
- Simple Pure CSS Tabs
- Author
- Links
- Made with
- About a code
- Pure CSS Tabs
- Author
- Links
- Made with
- About a code
- CSS Tabs
- Author
- Links
- Made with
- About a code
- Pure CSS Tabs With Indicator
- Author
- Links
- Made with
- About a code
- Animated Transition Tabs
- Author
- Links
- Made with
- About a code
- Pure CSS Color Tabs
- Author
- Links
- Made with
- About a code
- CSS Only Tabs
- Author
- Links
- Made with
- About a code
- CSS3 Tabs
- Author
- Links
- Made with
- About a code
- Tab Controls Using HTML And CSS
- Author
- W3.CSS Navigation Tabs
- Paris
- Tokyo
- Tabbed Navigation
- Example
- London
- Paris
- Tokyo
- Example
- Example
- JavaScript Explained
- Closable Tabs
- London
- Paris
- Tokyo
- Example
- London
- Active/Current Tab
- Example
- Vertical Tabs
- Example
- Animated Tab Content
- Example
- Tabbed Image Gallery
- Example
- Tabs in a Grid
- Как сделать адаптивные табы (вкладки) на css без использования скриптов
- Адаптивные вкладки (табы) на чистом css и без скриптов
- HTML код для табов с использованием css3 по пунктам
- CSS стили для табов с использованием css3 по пунктам
- Как заставить это работать
- Делаем наши табы адаптивными
- автор: Роман Довгаль
How TO — Tabs
Tabs are perfect for single page web applications, or for web pages capable of displaying different subjects:
London
London is the capital city of England.
Paris
Paris is the capital of France.
Tokyo
Tokyo is the capital of Japan.
Create Toggleable Tabs
Step 1) Add HTML:
Example
London
London is the capital city of England.
Paris
Paris is the capital of France.
Tokyo
Tokyo is the capital of Japan.
Create buttons to open specific tab content. All elements with class=»tabcontent» are hidden by default (with CSS & JS). When the user clicks on a button — it will open the tab content that «matches» this button.
Step 2) Add CSS:
Style the buttons and the tab content:
Example
/* Style the tab */
.tab overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
>
/* Style the buttons that are used to open the tab content */
.tab button background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
>
/* Change background color of buttons on hover */
.tab button:hover background-color: #ddd;
>
/* Create an active/current tablink class */
.tab button.active background-color: #ccc;
>
/* Style the tab content */
.tabcontent display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
>
Step 3) Add JavaScript:
Example
function openCity(evt, cityName) <
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with and hide them
tabcontent = document.getElementsByClassName(«tabcontent»);
for (i = 0; i < tabcontent.length; i++) tabcontent[i].style.display = "none";
>
// Get all elements with and remove the class «active»
tablinks = document.getElementsByClassName(«tablinks»);
for (i = 0; i < tablinks.length; i++) tablinks[i].className = tablinks[i].className.replace(" active", "");
>
// Show the current tab, and add an «active» class to the button that opened the tab
document.getElementById(cityName).style.display = «block»;
evt.currentTarget.className += » active»;
>
Fade in Tabs:
If you want to fade in the tab content, add the following CSS:
Example
.tabcontent <
animation: fadeEffect 1s; /* Fading effect takes 1 second */
>
/* Go from zero to full opacity */
@keyframes fadeEffect from
to
>
Show a tab by default
To open a specific tab on page load, use JavaScript to «click» on the specified tab button:
Example
Close a tab
If you want to close a specific tab, use JavaScript to hide the tab with a click of a button:
Example
London
London is the capital city of England.
x
Tip: Also check out How To — Vertical Tabs.
15 CSS Tabs
Collection of free HTML and pure CSS tabs. Update of December 2019 collection. 3 new items.
Related Articles
Author
Links
Made with
About a code
Nav Tab
Navigation tabs for two forms.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
CSS Tab
Compatible browsers: Chrome, Firefox, Opera, Safari
Author
Links
Made with
About a code
Tabs Widget. No JS!
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Tabs
The + selector selects the next adjacent element. Historically this has been cool for styling labels. With CSS grid, an element can be next to another in markup, but somewhere totally different in display. This pen uses a simple input[type=»radio»]:checked selector combined with a lot of + ‘s to style different pages of an imaginary microsite.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Pure CSS Tab Module
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Simple Pure CSS Tabs
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Pure CSS Tabs
Radio version of tabs. Requirements: not rely on specific IDs for CSS (the CSS shouldn’t need to know specific IDs), flexible for any number of unkown tabs 2, accessible. Caveats: since these are checkboxes the tabs not tab-able, need to use arrow keys.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
CSS Tabs
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Pure CSS Tabs With Indicator
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Animated Transition Tabs
Animated transition tabs with checkboxes.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Pure CSS Color Tabs
No label pure CSS color tabs.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
CSS Only Tabs
Material Design CSS only tabs.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
CSS3 Tabs
Responsive pure CSS3 tabs by Sorax.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
Links
Made with
About a code
Tab Controls Using HTML And CSS
Clicking on the labels is effectively the same as clicking on the input boxes. The radio inputs are hidden with CSS. When a radio is selected, their curious tab content neighbors show up. That’s it! The only drawback is you won’t be able to style the selected tab without resorting to some JS, but that shouldn’t be a very big deal.
Compatible browsers: Chrome, Edge, Firefox, Opera, Safari
Author
W3.CSS Navigation Tabs
It is the most populous city in the United Kingdom, with a metropolitan area of over 9 million inhabitants.
Paris
Paris is the capital of France.
The Paris area is one of the largest population centers in Europe, with more than 12 million inhabitants.
Tokyo
Tokyo is the capital of Japan.
It is the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.
Tabbed Navigation
Tabbed navigation is a way to navigate around a website.
Normally, tabbed navigation uses navigation buttons (tabs) arranged together with the selected tab highlighted.
This example uses elements with the same class name («city» in our example) , and changes the style between display:none and display:block to hide and display different content:
Example
London
London is the capital of England.
And some clickable buttons to open the tabbed content:
Example
And a JavaScript to do the job:
Example
function openCity(cityName) <
var i;
var x = document.getElementsByClassName(«city»);
for (i = 0; i < x.length; i++) <
x[i].style.display = «none»;
>
document.getElementById(cityName).style.display = «block»;
>
JavaScript Explained
The openCity() function is called when the user clicks on one of the buttons in the menu.
The function hides all elements with the class name «city» (display=»none»), and displays the element with the given city name (display=»block»);
Closable Tabs
London
London is the capital city of England.
Paris
Paris is the capital of France.
Tokyo
Tokyo is the capital of Japan.
To close a tab, add onclick=»this.parentElement.style.display=’none'» to an element inside the tab container:
Example
London
London is the capital city of England.
Active/Current Tab
To highlight the current tab/page the user is on, use JavaScript and add a color class to the active link. In the example below, we have added a «tablink» class to each link. That way, it is easy to get all links that is associated with tabs, and give the current tab link a «w3-red» class, to highlight it:
Example
function openCity(evt, cityName) <
var i, x, tablinks;
x = document.getElementsByClassName(«city»);
for (i = 0; i < x.length; i++) <
x[i].style.display = «none»;
>
tablinks = document.getElementsByClassName(«tablink»);
for (i = 0; i < x.length; i++) <
tablinks[i].className = tablinks[i].className.replace(» w3-red», «»);
>
document.getElementById(cityName).style.display = «block»;
evt.currentTarget.className += » w3-red»;
>
Vertical Tabs
Example
Animated Tab Content
Use any of the w3-animate-classes to fade, zoom or slide in tab content:
Example
Tabbed Image Gallery
×
×
×
×
Example
×
Tabs in a Grid
Using tabs in a third column layout. Note that we add a bottom border to the active tab, instead of a background color:
Как сделать адаптивные табы (вкладки) на css без использования скриптов
Добрый вечер! Сегодня я вам расскажу, каким образом можно сделать табы (вкладки) на чистом css3 без какого-либо использования jquery или других скриптов. Как вы уже знаете, чем меньше вы будете использовать скриптов, тем лучше для вашего сайта, и тем быстрее он будет работать. А скорость сайта сегодня один из самых важных показателей его ранжирования в поисковых системах.
Адаптивные вкладки (табы) на чистом css и без скриптов
Сегодня табы есть практически на любом сайте. Они необходимы для того, чтобы отображать несколько областей контента без перехода пользователя на другие страницы. Например, на одном из моих проектов по разработке интернет-магазина на Joomla было добавление двух табов, которые будут отображать по 3 товара двух типов: “хиты продаж” и “последние”. Принято решение делать их на чистом css без перезагрузки сайта ненужными скриптами.
HTML код для табов с использованием css3 по пунктам
1. В первую очередь нам необходимо создать div с классом “tabs”.
2. Добавляем непосредственно кнопки-переключали с именем “tabs”, при нажатии на которые они будут включать содержимое наших табов.
3. Добавляем их название через label
4. Под кнопками, которые мы с Вами сделали в пунктах 1-3, мы добавляем уже непосредственно контент, который нам нужно выводить. В моем случае это три последних товара и три лучших товара.
Каждый блок у нас имеет класс tab-content и идентификаторы tab-content-1 и tab-content-2.
Итоговый HTML наших будущих табов
На этом мы закончили с написанием нашего html. Согласитесь, ничего сложного тут не было. Итак, идем дальше.
CSS стили для табов с использованием css3 по пунктам
Теперь самое интересное и сложное. Нам нужно наши табы сделать табами, которые будут переключаться при клике 🙂
Так как у нас будет два таба, то нам нужно назначить им такую ширину, чтобы они помещались на экране и не вылазили за его черту. Для этого мы прописываем ширину 50%. Если у вас будет другое число табов, то и ширину рассчитывайте отталкиваясь от их числа.
Также, обратите внимание, что по умолчанию, мы делаем наши кнопки-переключатели невидимыми
.tabs < max-width: 90%; float: none; list-style: none; padding: 0; margin: 75px auto; border-bottom: 4px solid #ccc; >.tabs:after < content: ''; display: table; clear: both; >.tabs input[type=radio] < display:none; >.tabs label p < padding: 5px; margin-right: 0; >.tabs label < display: block; float: left; width: 50%; color: #ccc; font-size: 30px; font-weight: normal; text-decoration: none; text-align: center; line-height: 2; cursor: pointer; box-shadow: inset 0 4px #ccc; border-bottom: 4px solid #ccc; -webkit-transition: all 0.5s; /* Safari 3.1 to 6.0 */ transition: all 0.5s; >.tabs label span < display: none; >.tabs label:hover < color: #3498db; box-shadow: inset 0 4px #3498db; border-bottom: 4px solid #3498db; >.tab-content
Как заставить это работать
Добавляем следующий css код
.tabs [id^=»tab»]:checked + label < background: #FFF; box-shadow: inset 0 4px #3498db; border-bottom: 4px solid #3498db; color: #3498db; >#tab-first:checked ~ #tab-content-1, #tab-second:checked ~ #tab-content-2
Строками выше мы добавляем особы стиль для активного таба используя :checked + label
Далее мы уже проверяем, какой наш переключатель имеет статус checked и отображаем содержимое, которое у нас прикреплено за ним, используя его id.
#tab-first:checked ~ #tab-content-1 – данная строка говорит о том, что нам нужно отобразить контент, который имеет id=”tab-content-1″, если tab-first имеет статус checked.
Делаем наши табы адаптивными
@media (min-width: 768px) < .tabs p < padding: 5px; margin-right: 10px; >.tabs < max-width: 750px; margin: 50px auto; >>
Ну вот по сути и все. Наши табы готовы :). Вы их можете менять как угодно, добавлять-удалять. Спасибо за внимание 🙂
автор: Роман Довгаль
С 2010 года я занимаюсь интернет маркетингом. Сюда входит и SEO, и SMM, и SMO, и, собственно маркетинговое продвижение не только сайтов, а проектов в комплексе 🙂
Для меня каждый проект – это отдельная жизнь. Своя целевая аудитория, свои методы продвижения, свои показатели результативности 🙂