аккордеон на чистом css

Аккордеон на чистом CSS + HTML. Табы в виде аккордеона

В данной записи я вам покажу как можно сделать простой аккордеон на чистом CSS и HTML. Мы рассмотрим простой но очень удобный аккордеон, который требует минимум кода для реализации.

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

HTML

Внутри контейнера .ac-container находятся элементы div внутри которых размещаются заголовки табов и контент который находится в каждом из них. Тег input задает кнопку при нажатии на которую будет открываться определенный таб. У каждого input должен быть свой уникальный идентификатор.

<section class="ac-container">
    <div>
        <input id="ac-1" name="accordion-1" type="checkbox" />
        <label for="ac-1">Тестовое название таба 1</label>
        <article class="ac-small">
            <p>Тестовая начинка для таба 1</p>
        </article>
    </div>
    <div>
        <input id="ac-2" name="accordion-1" type="checkbox" />
        <label for="ac-2">Тестовое название таба 2</label>
        <article class="ac-medium">
            <p>Тестовая начинка для таба 2</p>
        </article>
    </div>
    <div>
         <!-- ... -->
    </div>
</section>

CSS

.ac-container{
    width: 400px;
    margin: 10px auto 30px auto;
    text-align: left;
}
.ac-container label{
    font-family: 'Arial Narrow', Arial, sans-serif;
    padding: 5px 20px;
    position: relative;
    z-index: 20;
    display: block;
    height: 30px;
    cursor: pointer;
    color: #777;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
    line-height: 33px;
    font-size: 19px;
    background: #ffffff;
    background: -moz-linear-gradient(top, #ffffff 1%, #eaeaea 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#ffffff), color-stop(100%,#eaeaea));
    background: -webkit-linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    background: -o-linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    background: -ms-linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    background: linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eaeaea',GradientType=0 );
    box-shadow: 
        0px 0px 0px 1px rgba(155,155,155,0.3), 
        1px 0px 0px 0px rgba(255,255,255,0.9) inset, 
        0px 2px 2px rgba(0,0,0,0.1);
}
.ac-container label:hover{
    background: #fff;
}
.ac-container input:checked + label,
.ac-container input:checked + label:hover{
    background: #c6e1ec;
    color: #3d7489;
    text-shadow: 0px 1px 1px rgba(255,255,255, 0.6);
    box-shadow: 
        0px 0px 0px 1px rgba(155,155,155,0.3), 
        0px 2px 2px rgba(0,0,0,0.1);
}
.ac-container label:hover:after,
.ac-container input:checked + label:hover:after{
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    right: 13px;
    top: 7px;
    background: transparent url(../images/arrow_down.png) no-repeat center center;    
}
.ac-container input:checked + label:hover:after{
    background-image: url(../images/arrow_up.png);
}
.ac-container input{
    display: none;
}
.ac-container article{
    background: rgba(255, 255, 255, 0.5);
    margin-top: -1px;
    overflow: hidden;
    height: 0px;
    position: relative;
    z-index: 10;
    -webkit-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    -moz-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    -o-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    -ms-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
}
.ac-container article p{
    font-style: italic;
    color: #777;
    line-height: 23px;
    font-size: 14px;
    padding: 20px;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
}
.ac-container input:checked ~ article{
    -webkit-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
    -moz-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
    -o-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
    -ms-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
    transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
    box-shadow: 0px 0px 0px 1px rgba(155,155,155,0.3);
}
.ac-container input:checked ~ article.ac-small{
    height: 140px;
}
.ac-container input:checked ~ article.ac-medium{
    height: 180px;
}
.ac-container input:checked ~ article.ac-large{
    height: 230px;
}
На этом всё!
Если у вас есть вопросы, пишите их в нашей группе - https://vk.com/progtime
Вы так же можете разместить свой вопрос на нашем форуме, где другие программисты смогут вам помочь в решение вашей задачи - https://vk.com/prog_time
В ней мы делимся своим опытом с другими начинающими программистами, поэтому обязательно ответим на ваш вопрос.
Так же прокачивайте свои навыки на нашем канале - https://www.youtube.com/c/ProgTime

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

avatar
43 Цепочка комментария
0 Ответы по цепочке
0 Последователи
 
Популярнейший комментарий
Цепочка актуального комментария
42 Авторы комментариев
JeffreymaxJeffreymaxtreantincMichaeldusMichaeldus Авторы недавних комментариев
  Подписаться  
новее старее большинство голосов
Уведомление о
JanleF
Гость

First Trusted Rx [url=http://apcialisle.com/#]Cialis[/url] Priligy Et Cialis cialis online Cialis Viagra Venta

JanleF
Гость

Viagra Prix Pharmacie Paris En Dijon [url=https://buyciallisonline.com/#]Cialis[/url] Lasixonline cialis professional Purchase Of Viagra

bemnite
Гость
bemnite

cialis for sale in nz how to get prescription drugs without doctor how can i order viagra online

AlvinCox
Гость
AlvinCox

cheapest cialis on the net http://tadmedz.com generic viagra pills

CharlesGOP
Гость
CharlesGOP

cheap cialis uk online http://cialisxtl.com buy levitra germany

Waltonplort
Гость
Waltonplort

cheap mexico viagra viagra online without prescription cheap viagra levitra

BarryNaW
Гость
BarryNaW

cialis for sale in canada https://edpillsphrm.com viagra buy calgary

Jefferykap
Гость
Jefferykap

best site to order viagra https://www.sildwithdoctorprescription.com is it legal to order viagra online

Marvinerulk
Гость
Marvinerulk

usa viagra cheap info http://zithazi.com – buy zithromax order viagra pfizer

Marvinerulk
Гость
Marvinerulk

wholesale cialis pills http://tadal24ph.com – cialis prices cheap viagra order online

Marvinerulk
Гость
Marvinerulk

generic cialis discount http://alexa24ph.com – generic viagra 100mg buy viagra jelly

Marvinerulk
Гость
Marvinerulk

buy viagra philippines http://hydroxychloroquine24.com – generic plaquenil cialis cheap prices

Marvinerulk
Гость
Marvinerulk

cheap cialis in the uk http://zithazi.com – cheap zithromax cheap viagra canada online

Marvinerulk
Гость
Marvinerulk

best place to buy levitra online http://hydroxychloroquine24.com – buy plaquenil buy generic viagra super active

Marvinerulk
Гость
Marvinerulk

buy cialis super active http://aralenph.com – chloroquine can you really buy viagra online

Marvinerulk
Гость
Marvinerulk

where can i buy real viagra online http://tadal24ph.com – generic cialis order cialis professional

Marvinerulk
Гость
Marvinerulk

viagra buy bangkok http://alexa24ph.com – viagra where is the best place to buy cialis

Marvinerulk
Гость
Marvinerulk

buy viagra online no rx http://tadal24ph.com – cialis coupon order brand name viagra online

AlfredAdvog
Гость
AlfredAdvog

buy viagra
buy viagra safe online

AlfredAdvog
Гость
AlfredAdvog

viagra pills
buy cialis drugstore

AlfredAdvog
Гость
AlfredAdvog

viagra
cheap kamagra/viagra

AlfredAdvog
Гость
AlfredAdvog

cheap viagra
order generic levitra

AlfredAdvog
Гость
AlfredAdvog

viagra help
viagra sale scams

AlfredAdvog
Гость
AlfredAdvog

viagra pills
cheapest cialis pharmacy comparison

AlfredAdvog
Гость
AlfredAdvog

100mg viagra without a doctor prescription
caverta cheap cialis generic viagra

AlfredAdvog
Гость
AlfredAdvog

buy viagra
brand name viagra sale

AlfredAdvog
Гость
AlfredAdvog

buy sildenafil
cialis 20 mg 4 tablet fiyat

AlfredAdvog
Гость
AlfredAdvog

buy viagra
buy cialis professional

DennisLof
Гость
DennisLof

cialis online buy generic cialis
cialis vs viagra

DennisLof
Гость
DennisLof

cialis at a discount price order cialis here
cialis lowest price

DonaldTwill
Гость
DonaldTwill

herbal viagra cheap viagra
generic viagra without subscription

DonaldTwill
Гость
DonaldTwill

side effects of viagra buy viagra
how much is viagra

JosephDiona
Гость
JosephDiona

cialis without doctor prescription cialis tolerance
buy cialis online canadian

JosephDiona
Гость
JosephDiona

cheapest cialis web prices cialis dosages
cialis vs levitra

Thomasreeld
Гость
Thomasreeld

when will generic viagra be available: alternative to viagra viagra super force 100mg 100mg pills

Thomasreeld
Гость
Thomasreeld

natural viagra: directions for use of viagra order cialis for daily use

JohnnieQuabs
Гость
JohnnieQuabs

anti fungal pills without prescription cat antibiotics without pet prescription how to get prescription drugs without doctor onlinepharmacyero.com

JohnnieQuabs
Гость
JohnnieQuabs

pet antibiotics without vet prescription prescription drugs without doctor approval prescription drugs without doctor approval onlinepharmacyero.com

Michaeldus
Гость
Michaeldus

generic cialis tadalafil buy cialis

Michaeldus
Гость
Michaeldus

cialis 20mg price cialis vs viagra

treantinc
Гость
treantinc

cialis 10 mg receta [url=https://bbuycialisss.com/]buy cialis online no prescription[/url] cialis 10 mg sin receta Buy Cialis cialis 10 mg tabletas

Jeffreymax
Гость
Jeffreymax

cialis or viagra: cialis vs viagra

Jeffreymax
Гость
Jeffreymax

free cialis: buy cialis