W
W
weranda2018-03-19 13:53:59
css
weranda, 2018-03-19 13:53:59

How to make tabs (initial view only with styles)?

Hello
There is a code ( 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>

Is it possible to form this view from this HTML without changing the structure and without using JS / flex:
5aaf96b630d70844396121.gif
I mean a simple initial view without switching to other tabs, just an initial view so that the bottom part (content field) is not set in the styles in position:absolute , since in this case the block placed after it will run into it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai, 2018-03-19
@pragmatik

Most likely, you can't do without changing the HTML structure. I recommend looking at the first example in the article https://habrahabr.ru/post/320668/

F
frees2, 2018-03-19
@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>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question