weranda
@weranda

Как сделать табы (начальный вид только с помощью стилей)?

Приветствую

Есть код (CodePen):
<div class="tabs">
    <div class="item">
        <div class="title">item1</div>
        <div class="content">content1</div>
    </div>
    <div class="item">
        <div class="title">item2</div>
        <div class="content">content2</div>
    </div>
    <div class="item">
        <div class="title">item3</div>
        <div class="content">content3</div>
    </div>
    <div class="item">
        <div class="title">item4</div>
        <div class="content">content4</div>
    </div>
    <div class="item">
        <div class="title">item5</div>
        <div class="content">content5</div>
    </div>
</div>

Можно ли из этого HTML без изменения структуры и без использования JS/flex сформировать такой вид:
5aaf96b630d70844396121.gif
Я имею ввиду простой начальный вид без переключения на другие вкладки, просто начальный вид, чтобы нижняя часть (поле контента) не была задана в стилях в position:absolute, так как в этом случае на нее будет наезжать блок, размещенный после нее.
  • Вопрос задан
  • 74 просмотра
Пригласить эксперта
Ответы на вопрос 2
Скорее всего, без изменения структуры HTML не обойтись. Рекомендую посмотреть первый пример в статье https://habrahabr.ru/post/320668/
Ответ написан
@frees2
<style type='text/css'>



section {  display: none;  padding:  0;  border-top: 1px solid #ddd; } input {   display: none;}
label {  display: inline-block;  margin: 0 0 -1px;  padding: 2px 2px;  border: 1px solid gray ;  border-radius: 4px 4px 0 0;  }
label:before {   font-weight: normal;  margin-right: 5px; } label:hover {  color: #888;  cursor: pointer; }
input:checked + label {  color: #555;  border: 1px solid #ddd;  border-top: 2px solid #D3D3D3;  border-bottom: 1px solid #fff; }

#tab1:checked ~ #content1,
#tab2:checked ~ #content2,
#tab3:checked ~ #content3,
#tab4:checked ~ #content4 
{  display: block;}



  </style>
  

  
</head>

<body>

  
 

   <input id="tab1" type="radio" name="tabs" checked> <label for="tab1">C</label>
   <input id="tab2" type="radio" name="tabs">  <label for="tab2">D</label>
   <input id="tab3" type="radio" name="tabs">  <label for="tab3">D</label>
   <input id="tab4" type="radio" name="tabs">  <label for="tab4">D</label>
 
  <section id="content1">
    <p>
      Bacon ipsum dolor sit amet beef venison beef ribs kielbasa. Sausage pig leberkas, t-bone sirloin shoulder bresaola. Frankfurter rump porchetta ham. Pork belly prosciutto brisket meatloaf short ribs.
    </p>
    <p>
      Brisket meatball turkey short loin boudin leberkas meatloaf chuck andouille pork loin pastrami spare ribs pancetta rump. Frankfurter corned beef beef tenderloin short loin meatloaf swine ground round venison.
    </p>
  </section>
    
  <section id="content2">
    <p>
      Bacon ipsum dolor sit amet landjaeger sausage brisket, jerky drumstick fatback boudin ball tip turducken. Pork belly meatball t-bone bresaola tail filet mignon kevin turkey ribeye shank flank doner cow kielbasa shankle. Pig swine chicken hamburger, tenderloin turkey rump ball tip sirloin frankfurter meatloaf boudin brisket ham hock. Hamburger venison brisket tri-tip andouille pork belly ball tip short ribs biltong meatball chuck. Pork chop ribeye tail short ribs, beef hamburger meatball kielbasa rump corned beef porchetta landjaeger flank. Doner rump frankfurter meatball meatloaf, cow kevin pork pork loin venison fatback spare ribs salami beef ribs.
    </p>
    <p>
      Jerky jowl pork chop tongue, kielbasa shank venison. Capicola shank pig ribeye leberkas filet mignon brisket beef kevin tenderloin porchetta. Capicola fatback venison shank kielbasa, drumstick ribeye landjaeger beef kevin tail meatball pastrami prosciutto pancetta. Tail kevin spare ribs ground round ham ham hock brisket shoulder. Corned beef tri-tip leberkas flank sausage ham hock filet mignon beef ribs pancetta turkey.
    </p>
  </section>
    
  <section id="content3">
    <p>
      Bacon ipsum dolor sit amet beef venison beef ribs kielbasa. Sausage pig leberkas, t-bone sirloin shoulder bresaola. Frankfurter rump porchetta ham. Pork belly prosciutto brisket meatloaf short ribs.
    </p>
    <p>
      Brisket meatball turkey short loin boudin leberkas meatloaf chuck andouille pork loin pastrami spare ribs pancetta rump. Frankfurter corned beef beef tenderloin short loin meatloaf swine ground round venison.
    </p>
  </section>
    
  <section id="content4">
    <p>
      Bacon ipsum dolor sit amet landjaeger sausage brisket, jerky drumstick fatback boudin ball tip turducken. Pork belly meatball t-bone bresaola tail filet mignon kevin turkey ribeye shank flank doner cow kielbasa shankle. Pig swine chicken hamburger, tenderloin turkey rump ball tip sirloin frankfurter meatloaf boudin brisket ham hock. Hamburger venison brisket tri-tip andouille pork belly ball tip short ribs biltong meatball chuck. Pork chop ribeye tail short ribs, beef hamburger meatball kielbasa rump corned beef porchetta landjaeger flank. Doner rump frankfurter meatball meatloaf, cow kevin pork pork loin venison fatback spare ribs salami beef ribs.
    </p>
    <p>
      Jerky jowl pork chop tongue, kielbasa shank venison. Capicola shank pig ribeye leberkas filet mignon brisket beef kevin tenderloin porchetta. Capicola fatback venison shank kielbasa, drumstick ribeye landjaeger beef kevin tail meatball pastrami prosciutto pancetta. Tail kevin spare ribs ground round ham ham hock brisket shoulder. Corned beef tri-tip leberkas flank sausage ham hock filet mignon beef ribs pancetta turkey.
    </p>
  </section>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы