January 24, 20188 yr Hey everyone, I can't sort this out myself. Basically, I have implemented a CSS Accordion code on my website, which basically expands and shows content on hover and is based on ul and li elements. I'd like the content of one of the items to be visible without having to drag the mouse over it, however, so far I couldn't think of any way to do it and I wonder if anyone could help me out. That would be very much appreciated! HTML: <div class="accordion"> <ul class="a-ul"> <li class="a-li"> <div class="a-div"><a class="a-a" href="#"> <h2 class="a-h2">Heading 1</h2> <p class="a-p">Description here</p> </a> </div> </li> <li class="a-li"> <div class="a-div"><a class="a-a" href="#"> <h2 class="a-h2">Heading 2</h2> <p class="a-p">Description here</p> </a></div> </li> <li class="a-li"> <div class="a-div"><a class="a-a" href="#"> <h2 class="a-h2">Heading 3</h2> <p class="a-p">Description here</p> </a></div> </li> <li class="a-li"> <div class="a-div"><a class="a-a" href="#"> <h2 class="a-h2">Heading 4</h2> <p class="a-p">Description here</p> </a></div> </li> </ul> </div> CSS: /* This section is for the accordion styling */ body { margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; } .accordion { width: 100%; height: 100vh; overflow: hidden; } .accordion .a-ul { width: 100%; display: table; table-layout: fixed; margin: 0; padding: 0; } .accordion .a-ul .a-li { display: table-cell; vertical-align: bottom; position: relative; width: 16.666%; height: 100vh; background-repeat: no-repeat; background-position: center center; transition: all 500ms ease; } .accordion .a-ul .a-li .a-div { display: block; overflow: hidden; width: 100%; } .accordion .a-ul .a-li .a-div .a-a { display: block; height: 100vh; width: 100%; position: relative; z-index: 3; vertical-align: bottom; padding: 15px 20px; box-sizing: border-box; color: #fff; text-decoration: none; font-family: Open Sans, sans-serif; transition: all 200ms ease; } .accordion .a-ul .a-li .a-div .a-a * { opacity: 0; margin: 0; width: 100%; text-overflow: ellipsis; position: relative; z-index: 5; white-space: nowrap; overflow: hidden; -webkit-transform: translateX(-20px); transform: translateX(-20px); -webkit-transition: all 400ms ease; transition: all 400ms ease; } .accordion .a-ul .a-li .a-div .a-a .a-h2 { font-family: Montserrat, sans-serif; text-overflow: clip; font-size: 24px; text-transform: uppercase; margin-bottom: 2px; top: 250px; } .accordion .a-ul .a-li .a-div .a-a .a-p { top: 250px; font-size: 13.5px; } /* Background images for the Accordion Tabs */ .accordion .a-ul .a-li:nth-child(1) { background-image: url("..."); background-size: cover; } .accordion .a-ul .a-li:nth-child(2) { background-image: url("..."); background-size: cover; } .accordion .a-ul .a-li:nth-child(3) { background-image: url("..."); background-size: cover; } .accordion .a-ul .a-li:nth-child(4) { background-image: url("..."); background-size: cover; } /* Expands the accordion item on mouse hover using :hover pseudo element */ .accordion .a-ul:hover .a-li { width: 8%; } .accordion .a-ul:hover .a-li:hover { width: 60%; } .accordion .a-ul:hover .a-li:hover .a-a { background: rgba(0, 0, 0, 0.4); } .accordion .a-ul:hover .a-li:hover .a-a * { opacity: 1; -webkit-transition: All 1s ease-in-out; -webkit-transform: translateX(0); transform: translateX(0); }
January 29, 20188 yr Hello, let me see what i can do for you today, your most welcome. This may be a quicker/better? soloution for you. NEW FILE "Script.js" +++++++++++++ ( function( $ ) { $( document ).ready(function() { $('#cssmenu li.has-sub>a').on('click', function(){ $(this).removeAttr('href'); var element = $(this).parent('li'); if (element.hasClass('open')) { element.removeClass('open'); element.find('li').removeClass('open'); element.find('ul').slideUp(); } else { element.addClass('open'); element.children('ul').slideDown(); element.siblings('li').children('ul').slideUp(); element.siblings('li').removeClass('open'); element.siblings('li').find('li').removeClass('open'); element.siblings('li').find('ul').slideUp(); } }); $('#cssmenu>ul>li.has-sub>a').append('<span class="holder"></span>'); (function getColor() { var r, g, b; var textColor = $('#cssmenu').css('color'); textColor = textColor.slice(4); r = textColor.slice(0, textColor.indexOf(',')); textColor = textColor.slice(textColor.indexOf(' ') + 1); g = textColor.slice(0, textColor.indexOf(',')); textColor = textColor.slice(textColor.indexOf(' ') + 1); b = textColor.slice(0, textColor.indexOf(')')); var l = rgbToHsl(r, g, b); if (l > 0.7) { $('#cssmenu>ul>li>a').css('text-shadow', '0 1px 1px rgba(0, 0, 0, .35)'); $('#cssmenu>ul>li>a>span').css('border-color', 'rgba(0, 0, 0, .35)'); } else { $('#cssmenu>ul>li>a').css('text-shadow', '0 1px 0 rgba(255, 255, 255, .35)'); $('#cssmenu>ul>li>a>span').css('border-color', 'rgba(255, 255, 255, .35)'); } })(); function rgbToHsl(r, g, b) { r /= 255, g /= 255, b /= 255; var max = Math.max(r, g, b), min = Math.min(r, g, b); var h, s, l = (max + min) / 2; if(max == min){ h = s = 0; } else { var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); switch(max){ case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; } h /= 6; } return l; } }); } )( jQuery ); ========================================================== end - do not copy this section, the file ended at } )( jQuery ); ========================================================== NEW FILE index.html or rename or intergrate to an existing page. +++++++++ HTML CODE as follows.. <div id='cssmenu'> <ul> <li><a href='#'><span>Home</span></a></li> <li class='active has-sub'><a href='#'><span>Products</span></a> <ul> <li class='has-sub'><a href='#'><span>Product 1</span></a> <ul> <li><a href='#'><span>Sub Product</span></a></li> <li class='last'><a href='#'><span>Sub Product</span></a></li> </ul> </li> <li class='has-sub'><a href='#'><span>Product 2</span></a> <ul> <li><a href='#'><span>Sub Product</span></a></li> <li class='last'><a href='#'><span>Sub Product</span></a></li> </ul> </li> </ul> </li> <li><a href='#'><span>About</span></a></li> <li class='last'><a href='#'><span>Contact</span></a></li> </ul> </div> ========================================================== end - do not copy this section, the file ended at </div> ========================================================== now the CSS file.. #cssmenu, #cssmenu ul, #cssmenu ul li, #cssmenu ul li a { margin: 0; padding: 0; border: 0; list-style: none; line-height: 1; display: block; position: relative; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } #cssmenu { width: 200px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; } #cssmenu ul ul { display: none; } .align-right { float: right; } #cssmenu > ul > li > a { padding: 15px 20px; border-left: 1px solid #1682ba; border-right: 1px solid #1682ba; border-top: 1px solid #1682ba; cursor: pointer; z-index: 2; font-size: 14px; font-weight: bold; text-decoration: none; color: #ffffff; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35); background: #36aae7; background: -webkit-linear-gradient(#36aae7, #1fa0e4); background: -moz-linear-gradient(#36aae7, #1fa0e4); background: -o-linear-gradient(#36aae7, #1fa0e4); background: -ms-linear-gradient(#36aae7, #1fa0e4); background: linear-gradient(#36aae7, #1fa0e4); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15); } #cssmenu > ul > li > a:hover, #cssmenu > ul > li.active > a, #cssmenu > ul > li.open > a { color: #eeeeee; background: #1fa0e4; background: -webkit-linear-gradient(#1fa0e4, #1992d1); background: -moz-linear-gradient(#1fa0e4, #1992d1); background: -o-linear-gradient(#1fa0e4, #1992d1); background: -ms-linear-gradient(#1fa0e4, #1992d1); background: linear-gradient(#1fa0e4, #1992d1); } #cssmenu > ul > li.open > a { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 0, 0, 0.15); border-bottom: 1px solid #1682ba; } #cssmenu > ul > li:last-child > a, #cssmenu > ul > li.last > a { border-bottom: 1px solid #1682ba; } .holder { width: 0; height: 0; position: absolute; top: 0; right: 0; } .holder::after, .holder::before { display: block; position: absolute; content: ""; width: 6px; height: 6px; right: 20px; z-index: 10; -webkit-transform: rotate(-135deg); -moz-transform: rotate(-135deg); -ms-transform: rotate(-135deg); -o-transform: rotate(-135deg); transform: rotate(-135deg); } .holder::after { top: 17px; border-top: 2px solid #ffffff; border-left: 2px solid #ffffff; } #cssmenu > ul > li > a:hover > span::after, #cssmenu > ul > li.active > a > span::after, #cssmenu > ul > li.open > a > span::after { border-color: #eeeeee; } .holder::before { top: 18px; border-top: 2px solid; border-left: 2px solid; border-top-color: inherit; border-left-color: inherit; } #cssmenu ul ul li a { cursor: pointer; border-bottom: 1px solid #32373e; border-left: 1px solid #32373e; border-right: 1px solid #32373e; padding: 10px 20px; z-index: 1; text-decoration: none; font-size: 13px; color: #eeeeee; background: #49505a; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1); } #cssmenu ul ul li:hover > a, #cssmenu ul ul li.open > a, #cssmenu ul ul li.active > a { background: #424852; color: #ffffff; } #cssmenu ul ul li:first-child > a { box-shadow: none; } #cssmenu ul ul ul li:first-child > a { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1); } #cssmenu ul ul ul li a { padding-left: 30px; } #cssmenu > ul > li > ul > li:last-child > a, #cssmenu > ul > li > ul > li.last > a { border-bottom: 0; } #cssmenu > ul > li > ul > li.open:last-child > a, #cssmenu > ul > li > ul > li.last.open > a { border-bottom: 1px solid #32373e; } #cssmenu > ul > li > ul > li.open:last-child > ul > li:last-child > a { border-bottom: 0; } #cssmenu ul ul li.has-sub > a::after { display: block; position: absolute; content: ""; width: 5px; height: 5px; right: 20px; z-index: 10; top: 11.5px; border-top: 2px solid #eeeeee; border-left: 2px solid #eeeeee; -webkit-transform: rotate(-135deg); -moz-transform: rotate(-135deg); -ms-transform: rotate(-135deg); -o-transform: rotate(-135deg); transform: rotate(-135deg); } #cssmenu ul ul li.active > a::after, #cssmenu ul ul li.open > a::after, #cssmenu ul ul li > a:hover::after { border-color: #ffffff; } We both know where it ends, really hope this helps you or you create new things with it however it will stay open and a few little extras to help you advance.
January 29, 20188 yr here's what you want, well from what i can guess HTML CODE (file or intergrate) <div class="accordion"> <section class="accordion-item"> <h1>Section 1</h1> <div class="accordion-item-content"> <p>Content for section 1</p> </div> </section> <section class="accordion-item"> <h1>Section 2</h1> <div class="accordion-item-content"> <p>Content for section 2</p> </div> </section> <section class="accordion-item accordion-item--default"> <h1>Section 3</h1> <div class="accordion-item-content"> <p>Content for section 3</p> <p>This is my default state.</p> </div> </section> <section class="accordion-item"> <h1>Section 4</h1> <div class="accordion-item-content"> <p>Content for section 4</p> </div> </section> </div> CSS FILE .accordion:hover .accordion-item:hover .accordion-item-content, .accordion .accordion-item--default .accordion-item-content { height: 6em; } .accordion-item-content, .accordion:hover .accordion-item-content { height: 0; overflow: hidden; transition: height .25s; } /* Aesthetic */ body { background: #222; } .accordion { padding: 0; margin: 0 auto; width: 20%; font-family: "PT Sans" sans-serif } .accordion .accordion-item { background-image: linear-gradient(90deg, #eee, #f5f5f5, #eee); border-bottom: 1px solid #666; padding: 1em; color: #eee; } .accordion h1 { margin: 0; } .accordion .accordion-item:nth-child(1) { background-color: hsl(200, 80%, 60%); background-image: linear-gradient(-90deg, hsl(200, 80%, 60%), hsl(200, 80%, 45%) 2em, hsl(200, 80%, 60%)); } .accordion .accordion-item:nth-child(2) { background-color: hsl(280, 60%, 45%); background-image: linear-gradient(-90deg, hsl(280, 80%, 60%), hsl(280, 60%, 45%) 2em, hsl(280, 80%, 60%)); } .accordion .accordion-item:nth-child(3) { background-color: hsl(40, 80%, 40%); background-image: linear-gradient(-90deg, hsl(40, 80%, 60%), hsl(40, 80%, 45%) 2em, hsl(40, 80%, 60%)); } .accordion .accordion-item:nth-child(4) { background-color: hsl(80, 40%, 40%); background-image: linear-gradient(-90deg, hsl(80, 80%, 40%), hsl(80, 80%, 35%) 2em, hsl(80, 80%, 40%)); } Again hope this helps and all the best with your online venture!
Create an account or sign in to comment