So habe ich 4 verschiedene divs mit Tasten in ihnen und ich versuche einzurichten, wenn eine dieser Tasten geklickt wird, Es überlappt die anderen divs auf der Seite.Machen div überlappen horizontal die anderen 4 divs und dehnen über die Seite (Höhe 100%?)
Ich weiß, dass es etwas mit Z-Index und Positionierung der divs zu tun hat, aber ich denke, es muss zu den Jquery und nicht zum CSS hinzugefügt werden?
Ich habe einen früheren Code ausgecheckt, wo sich die divs vertikal überlappen. Hier ist der Code:
$('#divleft, #divmid, #divright').toggle(function() {
var cfg = {height:'200', width:'100%'};
$(this).css({'z-index':100});
var pct = $(this).css('left').split('p')[0]/$(document).width();
if(pct <= .33 && pct > 0){
cfg.left = '0';
$(this).data('oldLeft', "33%");
} else if(pct <= .66 && pct > .33) {
cfg.left = '0';
$(this).data('oldLeft', "66%");
}
$(this).animate(cfg)
}, function() {
var cfg= {height:'200', width:'33%', 'z-index':1};
if ($(this).data('oldLeft')) {
console.log($(this).data('oldLeft'));
cfg.left = $(this).data('oldLeft');
}
$(this).animate(cfg)
})
#divleft {
width:33.3%;
height:200px;
background:#ccc;
z-index: 1;
margin-top: 10px;
position: absolute;
left:0;
}
#divmid {
width:33.3%;
height: 200px;
background: #696;
margin-top: 10px;
z-index: 1;
position:absolute;
left:33%;
}
#divright {
width:33.3%;
height:200px;
background:#000;
margin-top: 10px;
z-index: 1;
position:absolute;
left:66%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="divleft"><p>Click Me!</p></div>
<div id="divmid"></div>
<div id="divright"></div>
Was dieser Code tut, ist, dass es die divs mit Breite 100% überlappt, vertikal. Ich habe mich nur gefragt, wie Sie vorgehen würden, wenn Sie die Divs horizontal überlappen würden.
bisher Mein Code ist dies:
html, body {
width: 80%;
margin: 0 auto;
}
head {
text-align:left;
}
head, img {
width: 350px;
height: 100px;
float: left;
margin-bottom: 1%;
}
.container {
width: 100%;
height: 100%;
margin: 0 auto;
}
button {
background-color: #cccccc;
color: #000000;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
padding-left: 15%;
outline: none;
font-size: 17px;
transition: 0.4s;
margin-top: 2%;
}
.icon {
width: 25px;
height: 25px;
padding-right: 15%;
float: right;
}
button.accordion.active, button.accordion:hover {
background-color: #ddd;
}
<div class="container">
<div id="first">
<button><h3>Random <img class ="icon" src="infoicon.png"></h3></button>
</div>
<div id="second">
<button><h3>Random <img class ="icon" src="infoicon.png"></h3></button>
</div> \t
<div id="third">
<button><h3>Random <img class ="icon" src="infoicon.png"></h3></button>
</div> \t
<div id="fourth">
<button><h3>Random <img class ="icon" src="infoicon.png"></h3></button>
</div> \t
<div id="last">
<button><h3>Random <img class ="icon" src="infoicon.png"></h3></button>
</div>
</div>
Dank!
Vielen Dank! Es hat jetzt funktioniert. –