Problem with animation on detail element expansion (css only, no js) - html

I have this CSS / HTML code :
body {
font-family: "Segoe UI", "Helvetica Neue", "Helvetica", "Open Sans", "FreeSans", "Arial", "sans-serif";
margin: 2em 1em 5em 1em;
}
ul {
margin-top: 0px;
}
details {
margin-bottom: 1.3em;
}
details summary {
font-size: 1.1em;
font-weight: bold;
display: inline;
cursor: pointer;
}
details summary ~ * {
animation: expanddetails 0.3s ease-out;
transform-origin: left top;
}
#keyframes expanddetails {
0% {
opacity: 0;
line-height: 0%;
transform: scaleY(0%);
}
25% {
opacity: 0.5;
line-height: 25%;
transform: scaleY(25%);
}
100% {
opacity: 1;
line-height: 100%;
transform: scaleY(100%);
}
}
summary::marker, summary::-webkit-details-marker {
content: none;
}
summary::after {
content: "+";
display: inline-block;
transition: 0.3s;
transform: rotate(0);
}
details[open] summary::after {
content: "+";
transform: rotate(360deg);
}
h2 {
font-size: 1.1em;
margin-bottom: 0;
}
.nobullet {
list-style: none;
}
<div>
<p>Some text before inside div</p>
</div>
<details>
<summary>Summary 1 </summary>
<ul>
<li>List 1 - Item 1</li>
<li>List 1 - Item 2</li>
<li class="nobullet">See <strong>There</strong>, ...</li>
</ul>
</details>
<details>
<summary>Summary 2 </summary>
<ul>
<li>List 2 - Item 1</li>
<li>List 2 - Item 2</li>
<li>List 2 - Item 3</li>
<li class="nobullet">...</li>
</ul>
</details>
<details>
<summary>Summary 3 </summary>
<ul>
<li>List 3 - Item 1</li>
<li>List 3 - Item </li>
</ul>
</details>
<details>
<summary>Summary 4 </summary>
<ul id="myid">
<li>List 4 - Item 1</li>
<li>List 4 - Item 2</li>
<li class="nobullet">...</li>
</ul>
</details>
<h2>Some Element with no list</h2>
<div>
<p>Other text</p>
</div>
EDIT 2
The animation for the expansion of the detail elements works once only for each element, except on Firefox (always working). Furthermore, it is triggered on expand only, not when collapsing, while the "+" sign is rotating on expand and collpase and for each expand/collpase not only once.
Why ? and how can this works each time, and for collapsing too.
One more question : is there a way without javscript to expand summary 4 on anchor click (this don't work for Firefox).
Thanks

Related

Preventing headings from breaking on a new line SCSS/CSS

Here is my html:
<div>
<ul>
<li>Text 0</li>
<li>Text 1</li>
<li>Text Heading</li>
</ul>
</div>
here is my CSS:
ul{
position: relative;
top: -1.5rem;
left: -18rem;
list-style-type: none;
}
li{
display: inline;
margin-right: 0.5rem;
margin-left: 0.5rem;
}
a{
font-family: "Times New Roman", Serif;
color: white;
font-size: 18px;
text-decoration-line: none;
}
They are appearing like so:
Text0 Text1 Text
Heading
I want them to appear like so:
Text0 Text1 Text Heading
One solution I did was to do:
white-space: nowrap; for li.
But is that best practice ?
My second question is:
Is using position in CSS discouraged or no ?
You can use flexbox here to get the desired result. It's fine to use position in CSS but it's not necessary to use it in this case.
ul{
display: flex;
flex-wrap: nowrap;
list-style-type: none;
}
li{
margin-right: 0.5rem;
margin-left: 0.5rem;
}
a{
font-family: "Times New Roman", Serif;
color: black;
font-size: 18px;
text-decoration-line: none;
}
<div>
<ul>
<li>Text 0</li>
<li>Text 1</li>
<li>Text Heading</li>
</ul>
</div>

CSS: How to transform DIV when <li> Item of Navigation gets :hovered?

I want to decorate a horizontal navigation with a div-element that "slides" below the navigation, depending on which <li> item is currently hovered.
Example:
li:nth-child(1):hover { transform: translateX(100px) };
li:nth-child(2):hover { transform: translateX(200px) };
li:nth-child(3):hover { transform: translateX(300px) };
li:nth-child(4):hover { transform: translateX(400px) };
Challenge: Until now I couldn't figure out which CSS-selector I have to use according to move the div. I have tried all solutions mentioned in this approach, but none of them has worked yet.
Example:
* { list-style-type: none; }
ul { display: flex }
a {
display: block;
padding: 1em;
color: white;
background-color: orange;
}
.red_circle {
display: block;
top: 100px;
height: 50px;
width: 50px;
background-color: red;
}
li:nth-child(1):hover > .red_circle,
li:nth-child(1):hover + .red_circle,
li:nth-child(1):hover .red_circle,
li:nth-child(1):hover ~ .red_circle, {
transform: translatex(400px);
}
<container>
<ul>
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
<div class="red_circle"</div>
</container>
There is currently no way to select the parent of an element in CSS.
If there was a way to do it, it would be in the current CSS selectors specs:
Selectors Level 3 Spec
But to achieve this you can modify your html to put your red circle indide your ul tag
* {
list-style-type: none;
}
ul {
display: flex
}
a {
display: block;
padding: 1em;
color: white;
background-color: orange;
}
.red_circle {
position: absolute;
display: block;
top: 100px;
height: 50px;
width: 50px;
background-color: red;
transition: transform 300ms;
}
li:nth-child(1):hover~.red_circle {
transform: translatex(400px);
}
<container>
<ul>
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
<div class="red_circle"> </div>
</ul>
</container>
EDIT:
After reading the HTML 5 standard
Zero or more li and script-supporting elements.
So has i said in the comment you could use :beforepseudo element
* {
list-style-type: none;
}
.list-container {
padding-left: 40px;
}
ul {
display: flex;
padding: 0;
width: max-content;
}
a {
display: block;
padding: 1em;
color: white;
background-color: orange;
}
ul:before {
content: '';
position: absolute;
display: block;
top: 100px;
height: 50px;
width: 50px;
background-color: red;
transition: transform 1s;
}
ul:hover:before {
transform: translatex(400px);
}
<container>
<div class="list-container">
<ul>
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
</div>
</container>

HTML List Vertical Organization

JSFiddle: http://jsfiddle.net/oj1vrjzh/12/
I'm trying to create a dropdown navbar that will first show sections, then display subsections once hovered on, all controlled by jquery. In the JSFiddle currently shown, the submenu covers the super sections:
<ul class="dropdown">
<li id="menu1" class="nav_menu">
Menu1
</li>
<ul class="submenu">
<li>ASDF</li> <!-- These cover up 'Menu2' -->
<li>ASDF</li>
<li>ASDF</li>
</ul>
<li id="menu2" class="nav_menu">
Menu2
</li>
</ul>
How do I change is so that when the submenu class is displayed, that it will bump the "nav_menu" classes down to the bottom of the submenu class?
I would suggest to try this one i adjusted for you:
Just simple and awesome!
Check this out live at codepen here!
Implementation:
HTML
<nav class="nav">
<ul>
<li>
Home
<ul>
<li>Sub Menu 1
<ul>
<li>Level 3 Menu 1
<ul>
<li>Level 4 Item 1</li>
<li>Level 4 Item 2</li>
</ul>
</li>
<li>Level 3 Menu 2</li>
</ul>
</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
</ul>
</li>
</ul>
</nav>
CSS
$brand-primary: #fff;;
$text-color: grey;
nav {
font-family: Arial, sans-serif;
font-size: 18px;
line-height: 24px;
background: $brand-primary;
color: $text-color;
> ul {
list-style: none;
> li {
display: inline-block;
}
}
li {
position: relative;
&:hover {
background: mix(#000000, $brand-primary, 20%);
}
li:hover > a {
background: mix(#000000, $brand-primary, 30%);
}
}
a {
display: block;
padding: 10px 20px;
color: inherit;
text-decoration: none;
#include transition(all 0.3s);
}
// Submenu
.has-subnav {
> a {
padding-right: 30px;
position: relative;
&:after {
content: "ยท";
display: block;
font-family: sans;
font-size: 36px;
line-height: 0;
position: absolute;
right: 5px;
margin-right: 2px;
top: 22px;
}
}
}
ul ul {
width: 240px;
background: mix(#000000, $brand-primary, 20%);
position: absolute;
left: 0;
top: 100%;
ul {
left: 100%;
top: 0;
#include box-shadow(-1px 0 4px rgba(0,0,0,0.2));
}
}
// fade effect with css3
li {
& > ul {
visibility:hidden;
opacity:0;
#include transition(visibility 0s linear 0.1s, opacity 0.1s linear);
}
&.active {
> a {
}
& > ul{
visibility:visible;
opacity:1;
#include transition-delay(0s);
#include transition-duration(0.3s);
}
}
}
}
JAVASCRIPT
// navigation
$('.nav li:has(ul)')
.addClass('has-subnav')
.each(function(){
var $li = $(this)
, $a = $('> a', $li);
$a.on('mouseenter', function(){
$li.addClass('active');
});
$li.on('mouseleave', function(){
$li.removeClass('active');
});
});

List Items on same line in drop down menu

I have a drop down menu where I want some of the list items to be in one line.
See demo
You will notice that under Tab One, there are 9 rows. I want there to be three rows with three items in each row. How can this be done in CSS?
HTML:
<div id="wrapper">
<ul id="menu">
<li>Tab One
<ul style="width: 300%;">
<li>Column one</li>
<li>Column one</li>
<li>Column one</li>
<li>Column two</li>
<li>Column two</li>
<li>Column two</li>
<li>Column three</li>
<li>Column three</li>
<li>Column three</li>
</ul>
</li>
<li>Tab Two
<ul style="position: relative; left: -100%; width: 300%">
<li>Tab 2</li>
<li>Tab 2</li>
<li>Tab 2</li>
</ul>
</li>
<li>Tab Three
<ul style="position: relative; left: -200%; width: 300%">
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
</ul>
</li>
</ul>
</div>
CSS:
body {
font-family: arial;
margin: 0px;
padding-left: 40px;
padding-right: 40px;
}
#wrapper {
text-align: center;
height: auto;
margin: auto;
min-width: 500px;
}
#wrap {
display: inline;
}
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
#menu > li {
display: block;
position: relative;
float: left;
width: 33.3%;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 14px;
}
li:hover a {
background: #3b3b3b;
}
li:hover li a:hover {
background-color: black;
opacity: .7;
}
Working example: http://jsfiddle.net/w7a3N/5/
Remove > from #menu > li { and set inner <li> to <li style="width: 33%;">
Not sure if the style="width:33%;" is absolutely necessary since it works in Firefox 20 without it, but just to be safe.
UPDATE
You asked for a version that only does multiple columns under the first tab. Here you go:
http://jsfiddle.net/w7a3N/6/
Gave First tab an id like so <ul id="tab1" and then added this to CSS:
#tab1 li{
display: block;
position: relative;
float: left;
width: 33%;
}

Appearing and Disappearing extra space at bottom of page

I am building a simple page with a CSS-based collapsing menu on one side. The background for the page is a 3-stop linear gradient. At some point after putting in the collapsing menu, the page developed an extra band of blue at the bottom. It is below the <footer> section (there's nothing in the html below that, except the </body> and </html> tags). (This occurs in my Vivaldi browser (Chromium), and Edge, but not IceDragon (Firefox).)
If I hover over a "menuItem", it expands, and pushes the bottom of the gradient down toward the bottom edge of the browser. (The largest "menuItem" makes it almost disappear.) In Edge it then recovers the blue band when I stop hovering, while Vivaldi leaves it alone unless I move the cursor directly from the "menuItem"s to the "My opining:" bit.
Here's the html:
<body class="bkgdgradient">
<header>
<h1>Page title</h1>
<h3>tagline</h3>
</header>
<div class="layingout">
<div class="menuing">
<h4>My opining:</h4>
<div class="menuItem">
<h5>First Menu Category<h5>
<ul><p style="display: none;"></p>
<li>link item 1</li>
<li>link item 2</li>
<li>link item 3</li>
<li>link item 4</li>
</ul>
</div>
<div class="menuItem">
<h5>Second Menu Category<h5>
<ul>
<li>link item 1</li>
<li>link item 2</li>
<li>link item 3</li>
</ul>
</div>
<div class="menuItem">
<h5>Third Menu Category<h5>
<ul>
<li>link item 1</li>
</ul>
</div>
<div class="menuItem">
<h5>Fourth Menu Category<h5>
<ul>
<li>link item 1</li>
</ul>
</div>
<div class="menuItem">
<h5>Fifth Menu Category<h5>
<ul>
<li>link item 1</li>
<li>link item 2</li>
<li>link item 3</li>
</ul>
</div>
</div>
<div class="talking">
<p>A bunch of text.</p>
<p>A bunch more text.</p>
<p>Even more text</p>
<p>Finally finished</p>
</div>
</div>
<footer>
<p>About me</p>
<p>Contact me</p>
</footer>
</body>
And here's the CSS (internal to the page):
.bkgdgradient {
background-image: linear-gradient(#9cc3d2, #cfc4b8 30%, BurlyWood 95%);
}
header {
background-image: url("F14 & KC135R.jpg");
background-size: contain;
width: 1000px;
height: 556px;
}
h1 {
padding-left: 15px;
padding-top: 10px;
font-family: "Verdana", "Geneva", sans-serif;
font-size: 2.75em;
}
h3 {
text-align: right;
line-height: 800px;
padding-right: 30px;
font-family: "Arial", "Helvetica", sans-serif;
font-size: 1.75em;
}
h4 {
font-family: "Arial", "Helvetica", sans-serif;
font-size: 1.25em;
}
.layingout {
display: grid;
grid-template-columns: 250px 700px;
grid-gap: 30px;
padding: 10px;
}
.menuing {
grid-column-start: 1;
grid-row-start: 1;
box-shadow: 2px 2px 2px rgba(0,0,0,0.2);
color: SaddleBrown;
text-shadow: 1px 0px Sienna;
}
.menuItem {
padding: 0px;
margin: 0;
}
.menuItem h5 {
font-family: "Arial", "Helvetica", sans-serif;
font-size: 1em;
padding-left: 2px;
margin:0px;
}
.menuItem h5:hover {
font-size: 1.1em;
text-shadow: 2px 0px Sienna;
}
.menuItem ul {
background-color: Peru;
font-family: "Arial", "Helvetica", sans-serif;
font-size: 0.9em;
line-height: 15px;
display: block;
list-style-type: none;
padding-left: 10px;
overflow: hidden;
height: 0px;
margin: 0px;
}
.menuItem li {
border-bottom: 1px solid Chocolate;
line-height: 22px;
padding-left: 5px;
}
.menuItem li a {
text-decoration: none;
color: Bisque;
}
.menuItem:hover ul {
height: auto;
}
.talking {
grid-column-start: 2;
grid-row-start: 1;
padding-top: 10px;
}
What bit had an unintended consequence in that styling? Does it have to do with making the background gradient apply to the body?
Thank you.
Edit One more item: In IceDragon, the <div> for the menu items does not expand down along with the menu; it seems to already be at the correct size to hold the expanding menus. Edge and Vivaldi expand it as necessary to contain the extra information.
Edit Fixed the <ul> close tags.
.body{
min-height: 100%;
}
.layingout {
display: grid;
grid-template-columns: 250px 700px;
grid-gap: 30px;
padding: 10px;
margin-bottom: 110px;
}
It could remove extra space from bottom