Salve a tutti, come da titolo, con il codice seguente, non riesco a posizionare centralmente all'interno di una section. Lo script è il seguente, ma solo una parte di codice non funziona, ovvero la prima:
Il codice HTML relativo è invece:codice:$(document).ready(function() { //Codice per posizionare l'accordion (Non funziona) var l = $('.accordion').height()/2; $('.accordion').css({ marginTop: $('#section2').height()/2 - l }); //Codice per il local scroll var $root = $('html, body'); $('nav a').click(function() { var section = ($(this).attr('href').substring(1)); var head_height = $('header').outerHeight(); // Adjusts the top of the window per slide switch(section) { case "section1": var adjustment = 0; break; case "section2": var adjustment = 0; break; case "section3": var adjustment = 0; break; case "section4": var adjustment = 0; break; } var spacing = adjustment + head_height; $root.animate({ scrollTop: $('#' + section).offset().top - spacing }, 750); }); //Codice per la dimensione delle section function fullpage(){ $('#section1').css({ width: $(window).width(), height: $(window).height()-$('header').height() }); $('#section2').css({ width: $(window).width(), height: $(window).height()-$('header').height() }); $('#section3').css({ width: $(window).width(), height: $(window).height()-$('header').height() }); $('#section4').css({ width: $(window).width(), height: $(window).height()-$('header').height() }); // Codice per posizionare un h3 $('h3').css({ left: $(window).width()/2-k }); // Fine del codice per posizionare un h3 } $(window).resize(function(){ fullpage(); }); fullpage(); });
Il CSS, fondamentale, è:codice HTML:<section id="section2"> <div class="container"> <div class="accordion"> <h4>CORSO MINERALOGICO</h4> <p>parola prova</p><h4>CORSO LETTERARIO</h4> <p>parola prova</p><h4>CORSO MUSICALE</h4> <p>parola prova</p><h4>CORSO GASTRONOMICO</h4> <p>parola prova</p><h4>CORSO ARTISTICO</h4> <p>parola prova</p><h4>CORSO INFORMATICO</h4> <p>parola prova</p> </div> </div> </section>
Grazie a tutti per le eventuali rispostecodice:.accordion { width: 84%; margin-left: 8%; border-bottom: solid 1px #c4c4c4; } .accordion h4 { background: #efefef url(arrow-square.gif) no-repeat right -51px; padding: 7px 15px; margin: 0; font: lighter 120%/100% Nunito; border: solid 1px #c4c4c4; border-bottom: none; cursor: pointer; } .accordion h4:hover { background-color: #e3e2e2; } .accordion h4.active { background-position: right 5px; } .accordion p { background: #f7f7f7; margin: 0; padding: 10px 15px 20px; border-left: solid 1px #c4c4c4; border-right: solid 1px #c4c4c4; font: lighter 100%/90% Nunito; } #section2 { background-color: #efefef; width: 100%; } .container { width: 1170px; height: 100%; margin: 0px auto; }![]()

Rispondi quotando
