• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Accordion via Mausklick öffnen + schließen

htmlDevil

Neues Mitglied
Hallo Gemeinde,

bei folgendem Code werden die Einzelnen Elemente momentan via Mousover geöffnet und geschlossen.

Was muss geändert werden, damit die einzelnen Elemende via Mausklick öffnen und schließen ?

Edit: Ich hab den Code aus dem Netz und bin fachlichen Fragen gegenüber nicht gut gerüstet... Es funktioniert, aber ich hätt´s gern per Mausklick...

Vielen Dank für eure Hilfe !!! :D


#accordion .item {
width: 630px;
height: 30px; /* This is the height of the gray portion of each section */
overflow: hidden;
transition: height ease-in-out 500ms; /* This is the bit that makes the slider...slide */
-o-transition: height ease-in-out 500ms;
-moz-transition: height ease-in-out 500ms;
-webkit-transition: height ease-in-out 500ms;
border: 1px solid #ccc; /* This sets the color and width of the border */
border-radius: 5px; /* This sets the roundness of the border corners */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
margin-bottom: 2px;
}
#accordion a {
display: block;
height: 20px;
line-height: 20px;
background: #eeeeee; /* This is for all the old browsers */
background: -moz-linear-gradient(top, #eeeeee 0%, #cccccc 100%); /* This gradient is for firefox */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#cccccc)); /* This one is for webkit browsers */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#cccccc',GradientType=0 ); /* and of course we musn't forget ie */
padding: 5px;
color: #333333; /* This and the next few lines sets the font up for the header on each box */
text-decoration: none;
font-family: Verdana, Arial, Tahoma, sans-serif;
}
#accordion p {
height: 150px; /* This and the next few lines sets the font up for the content of each box */
padding: 5px;
font-family: Verdana, Arial, Tahoma, sans-serif;
font-size: 0.9em;
}
#accordion div:hover {
height: 350px; /* This is the total height when the scroll unfolds see the 150px in the element above */
}
#accordion div:hover a {
border-bottom: 1px solid #cccccc;
}
 
Willkommen im Forum.

Das geht nicht per CSS. Die Pseudoklasse :hover reagiert nur auf mouseover, also „Berührung“ mit dem Mauszeiger. Da müsstest du auf JavaScript ausweichen.

Ich würde der Einfachheit halber versuchen, ein JavaScript-Accordion zu finden, das das von Haus aus unterstützt.
 
Theoretisch könnte man statt hover auch focus nehmen, was einem Klick entspricht. Da Du den HTML-Code nicht zeigst kann ich aber nicht beurteilen, ob das bei dem o.g. Code funktioniert.
 
Zurück
Oben