First off, here are some helpful suggestions regarding this code:
The HTML layout: Ensure that the "slideDivs" contains all the necessary components; I've added borders and colors for better visualization.
Using Jquery: It uses the state "onoffBtn" to determine if the block is open or closed. As mentioned in the code, a function would streamline this process with fewer lines of code, but unfortunately, Code Snippet doesn't support functions involving jquery xD.
Key sections of CSS:
#slideDivs{
right: 0;
top: 10px;/*Adjust as needed*/
position: absolute;
}
.comp{
display:inline-block;
}
.tabs{
width: 440px;
float: right;
height: 11em;
}
.tabs{/*Set all tabs div's visibility to "display: none"*/
display: none;
}
#btnTabs{
width:40px;
height:180px;
}
.btnTab{
transform: rotate(-90deg); /* Rotates button text, additional rules for different browsers (firefox, IE..)*/
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
float:left;
height: 40px;
width: 40px;
}
.btnTab:nth-child(2){
margin-top:2px;
}
I hope these pointers are useful! You can view the code on CodePen with some enhancements for reference (https://codepen.io/Alvargon/pen/QZaNmL). Good luck!
/*Ideally, using a function is more efficient, but Code Snippet doesn't allow it XD;*/
var onOffBtn1 = "off";
var onOffBtn2 = "off";
var exnum = 0;
var num = 0;
$("#btn1").click(function(){
num = 1;
switch(onOffBtn1){
case "off": {
$("#tab"+exnum).hide("fast");
$("#tab"+num).show("fast");
onOffBtn2="off"; onOffBtn1="on";
exnum = 1;
break;
}
case "on": {
$("#tab"+num).hide("fast");
$("#tab"+exnum).hide("fast");
onOffBtn2="off"; onOffBtn1="off"; break;
}
}
});
$("#btn2").click(function(){
num = 2;
switch(onOffBtn2){
case "off": {
$("#tab"+exnum).hide("fast");
$("#tab"+num).show("fast");
onOffBtn1="off";onOffBtn2="on";
exnum = 2;
break;
}
case "on": {
$("#tab"+num).hide("fast");
$("#tab"+exnum).hide("fast");
onOffBtn2="off";onOffBtn1="off"; break;
}
}
});
#mainDiv{
border: 1px solid red;
padding: 10px;
}
#slideDivs{
background-color:#add8e680;
border: 4px dotted blue;
/*width: 500px;*/
right: 0;
top: 10px;
position: absolute;
}
.comp{
display:inline-block;
}
.tabs{
border: 3px double orange;
width: 440px;
float: right;
height: 11em;
}
.tabs{
display: none;
}
#btnTabs{
width:40px;
height:180px;
border: 3px solid darkgreen;
}
.btnTab{
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
float:left;
height: 40px;
width: 40px;
}
.btnTab:nth-child(2){
margin-top:2px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="mainDiv">
Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu Tururu
<div id="slideDivs">
<div id="btnTabs" class="comp">
<button id="btn1" class="btnTab">BTN 1</button>
<button id="btn2" class="btnTab">BTN 2</button> </div>
<div id="tab1" class="tabs comp"><strong>TAB 1</strong><p>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p></div>
<div id="tab2" class="tabs comp"><strong>TAB 2</strong><p>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p></div>
</div>
</div>