Expanding animation instant, while collapsing animation is as expected. Why? - css

I have a simple component in React that essentially expands and collapses when clicked. However, I noticed that the expanding animation is almost instant, while the collapsing animation fulfils the expectation of slowly collapsing the text till 18px.
Did I understand animations wrongly?
https://stackblitz.com/edit/react-plfamb?file=src/style.css
import React, { useState } from 'react';
import './style.css';
const text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
export default function App() {
const [collapsed, setCollapsed] = useState(true);
function handleOnClick() {
setCollapsed(!collapsed);
}
return (
<div
className={collapsed ? 'collapsed' : 'expanded'}
onClick={handleOnClick}
>
{text}
</div>
);
}
styles.css:
.collapsed {
max-height: 18px;
transition: max-height 0.3s ease;
overflow: hidden;
}
.expanded {
max-height: 500px;
transition: max-height 0.3s ease;
}

Missed out overflow: hidden in the expanded class. Many thanks to #KonradLinkowski

Related

Bootstrap - Wrap text around image not working

I am trying to wrap text around an image, just like this issue:
Wrap text around bootstrap image
I have tried all the solutions there and none of them worked.
Here is my layout I am working with:
div.col-md-6
img.imagePost(src=`/{{{blogPost['feature-image-2']}}}`)
| {{#if blogPost['feature-image-3'] == ""}}
video.postVideo(controls)
source(src=`/{{{blogPost['video']}}}`)
| {{else}}
img.imagePost(src=`/{{{blogPost['feature-image-3']}}}`)
| {{/if}}
| {{#if blogPost['feature-image-4'] != ""}}
img.imagePost(src=`/{{{blogPost['feature-image-4']}}}`)
| {{/if}}
div(style=`float: none;`)
| {{{blogPost['post']}}}
Try adding pull-left along with imagePost in your jade/pug file if you are using bootstrap 3.3. You can also remove the last wrapper div with float none. Final code will looks like this.
div.col-md-6
img.imagePost.pull-left(src=`/{{{blogPost['feature-image-2']}}}`)
| {{#if blogPost['feature-image-3'] == ""}}
video.postVideo(controls)
source(src=`/{{{blogPost['video']}}}`)
| {{else}}
img.imagePost.pull-left(src=`/{{{blogPost['feature-image-3']}}}`)
| {{/if}}
| {{#if blogPost['feature-image-4'] != ""}}
img.imagePost.pull-left(src=`/{{{blogPost['feature-image-4']}}}`)
| {{/if}}
| {{{blogPost['post']}}}
I think it would be useful if you create separate CSS class
See this example :
Css:
.wrapper {
column-count: 2;
column-gap: 50px;
padding: 50px;
}
p {
line-height: 1.6;
font-family: Helvetica;
text-align: justify;
margin: 0;
font-size: 14px;
}
.star {
float: left;
width: 250px;
shape-outside: url(https://upload.wikimedia.org/wikipedia/commons/3/34/Red_star.svg);
shape-margin:20px;
margin-right: 20px;
margin-bottom: 20px;
}
.moon {
border-radius: 50%;
height: 200px;
width:200px;
background-color: #2badd9;
float: right;
shape-outside: inset(1% round 50%);
margin-left: 20px;
margin-bottom: 10px;
}
HTML
<div class="wrapper">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/34/Red_star.svg" alt="" class="star">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use. </p>
<div class="moon"></div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use. </p>
</div>
Result will be like this :
It is hard to guess the cause of your problem because you haven't shared the entire HTML so hope this example helps!

How to insert banner along with the text in shiny app

How do I insert a banner along with my text I have in my APP? I saw an app that did this, I will insert the image below. The link to access this APP is:https://shiny.rstudio.com/gallery/lego-mosaic.html
Notice it has the text and a blue banner. I would like to do something similar to this. Can you help me?
Thank you very much!
Executable code below:
library(shiny)
ui <- shiny::navbarPage(
title="Test", collapsible = TRUE,
tabPanel("",
br(),
hr(),
h2(HTML("Project <b>Description</b>"),
style="text-align:center; color: blue;"),
hr(),
div(
style = "width: 75%; margin: auto;",
h2(HTML("Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software
like Aldus PageMaker including versions of Lorem Ipsum"),
style="text-align:center"),
h2(HTML("Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software
like Aldus PageMaker including versions of Lorem Ipsum"),
style="text-align:center"))
)
)
server <- function(input, output,session) {
}
shinyApp(ui = ui, server = server)
It's not entirely clear what you want. What about that:
library(shiny)
ui <- fluidPage(
div(
style =
"height: 80px; background-color: blue; width: 100%; position: absolute; right:0;",
div(
style = "height: 100%; background-color: cyan; position: relative; width: fit-content;",
tags$p(
"Here some text vertically centered",
style =
"position: relative; top: 50%; -ms-transform: translateY(-50%); transform: translateY(-50%); padding-right: 10px; padding-left: 10px;"
)
)
)
)
server <- function(input, output, session){}
shinyApp(ui, server)

CSS Grid for a table with dynamic number of columns while only some of them have set widths

In the below snippet. I am trying to make a grid layout that will replace a table. This is easy enough in this article.
https://medium.com/evodeck/responsive-data-tables-with-css-grid-3c58ecf04723
however. the desired layout has a few curve balls
Users will be adding and removing columns at runtime. we are looking for css which will not require us to know the number of columns in advanced.
The name columns should always be 50% of the total rows' width
this is actually pretty easy in flexbox but i really want to switch to css grid
run the code snippet below. to simulate a solution
.container {
display: grid;
grid-auto-flow: column;
grid-gap: 10px;
margin-bottom: 10px;
grid-template-columns: repeat(auto-fit, minmax(4em, 1fr));
}
.item {
height: 3em;
background: black;
color: #fff;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="containers">
<div class="container">
<div class="item"></div>
<div class="item name">This col should always take 50% but has a varying text length</div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>
<hr>
<button class="row">Add Row</button>
<button class="add">Add Column</button>
<button class="rm">Remove Column</button>
<hr>
<hr>
<p><strong>With every new row</strong></p>
<ul>
<li>All columns should line up vertically like a table</li>
<li>the name column should always take the 50% width of total row</li>
<li>adding a column should still follow the rules above</li>
<li>How can i elips or wrap <strong>overflow text</strong> in this kind of layout</li>
</ul>
<script>
const addButton = document.querySelector('button.add');
const rmButton = document.querySelector('button.rm');
const rowButton = document.querySelector('button.row');
const container = document.querySelector(".container");
const lorem = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`;
// listen
addButton.addEventListener("click", addColumn);
rmButton.addEventListener("click", rmColumn);
rowButton.addEventListener("click", rowColumn);
function addColumn(event) {
$(".container").each(function () {
const newCol = document.createElement("div");
newCol.className += "item";
$(this).append(newCol)
});
}
function rmColumn(event) {
$(".container").each(function () {
this.removeChild(this.lastElementChild);
});
}
function rowColumn(event) {
const randLength = Math.floor(Math.random() * 100) + 1
const newRowClass = "new-row" + randLength;
const newRow = container.cloneNode(true);
newRow.className += ` ${newRowClass}`;
container.parentNode.appendChild(newRow);
const newRowName = document.querySelector(`.${newRowClass} .name`);
newRowName.innerHTML = lorem.slice(0, randLength);
}
</script>
set template columns only for the first 2 columns, and set the remaining columns as auto columns:
.container {
display: grid;
grid-auto-flow: column;
grid-gap: 10px;
margin-bottom: 10px;
grid-template-columns: minmax(4em, 1fr) 50% repeat(auto-fit, minmax(4em, 1fr));
}
.item {
height: 3em;
background: black;
color: #fff;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="containers">
<div class="container">
<div class="item"></div>
<div class="item name">This col should always take 50% but has a varying text length</div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>
<hr>
<button class="row">Add Row</button>
<button class="add">Add Column</button>
<button class="rm">Remove Column</button>
<hr>
<hr>
<p><strong>With every new row</strong></p>
<ul>
<li>All columns should line up vertically like a table</li>
<li>the name column should always take the 50% width of total row</li>
<li>adding a column should still follow the rules above</li>
<li>How can i elips or wrap <strong>overflow text</strong> in this kind of layout</li>
</ul>
<script>
const addButton = document.querySelector('button.add');
const rmButton = document.querySelector('button.rm');
const rowButton = document.querySelector('button.row');
const container = document.querySelector(".container");
const lorem = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`;
// listen
addButton.addEventListener("click", addColumn);
rmButton.addEventListener("click", rmColumn);
rowButton.addEventListener("click", rowColumn);
function addColumn(event) {
$(".container").each(function () {
const newCol = document.createElement("div");
newCol.className += "item";
$(this).append(newCol)
});
}
function rmColumn(event) {
$(".container").each(function () {
this.removeChild(this.lastElementChild);
});
}
function rowColumn(event) {
const randLength = Math.floor(Math.random() * 100) + 1
const newRowClass = "new-row" + randLength;
const newRow = container.cloneNode(true);
newRow.className += ` ${newRowClass}`;
container.parentNode.appendChild(newRow);
const newRowName = document.querySelector(`.${newRowClass} .name`);
newRowName.innerHTML = lorem.slice(0, randLength);
}
</script>

Page jumps when menu gets sticky on scrolling down

I am working on one HTML theme. I have an issue with the sticky menu. When scrolling down on the page, Page content jumps up as the header is removed from the natural flow of the page.
I tried by giving margin-top to the main content of the site and it worked. But as I am working on a template, this solution is not useful for me. Any jQuery code would work fine. Thanks for the help in advance!
$(document).ready(function(){
var sticky = $('.header-sticky');
var scroll = $(window).scrollTop();
if (scroll >= 100) sticky.addClass('header-sticky-on');
else sticky.removeClass('header-sticky-on');
});
header {
position: relative;
z-index: 99;
background-color: #ccc;
}
/* Sticky header */
header.header-sticky-on {
position: fixed;
z-index: 1000;
top: 0;
left: 0;
right: 0;
background-color: #fff;
-webkit-animation: fadeInDown .5s;
animation: fadeInDown .5s;
width: 100%;
box-shadow: 0px 0px 40px rgba(83, 88, 93, 0.1);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header class="header-sticky">
<!-- =======================
Main header Start-->
<nav class="main-header">
<div class="container">
"Content goes here Content goes here Content goes here"
</div>
</nav>
<!-- =======================
Main header End-->
</header>
<section class="main-content">
<p>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
Where can I get some?
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</p>
</section>
What you could do is add padding-top to the <body> element. So when your sticky header becomes sticky it won't leave a gap between your content and the main wrapper.
This will stop it from jumping around but keeps the flexibility to make your theme.
$(document).scroll(function() {
var sticky = $('.header-sticky');
var scroll = $(window).scrollTop();
/* Added body padding when actived */
if (scroll >= 100) {
sticky.addClass('header-sticky-on');
$('body').addClass('js-sticky-on');
} else {
sticky.removeClass('header-sticky-on');
$('body').removeClass('js-sticky-on');
}
});
/* added: height of element */
body.js-sticky-on {
padding-top: 18px;
}
header {
position: relative;
width: 100%;
z-index: 99;
background-color: #ccc;
}
header.header-sticky-on {
position: fixed;
z-index: 1000;
top: 0;
left: 0;
right: 0;
background-color: #fff;
-webkit-animation: fadeInDown .5s;
animation: fadeInDown .5s;
box-shadow: 0px 0px 40px rgba(83, 88, 93, 0.1);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<header class="header-sticky">
<!-- =======================
Main header Start-->
<nav class="main-header">
<div class="container">
"Content goes here Content goes here Content goes here"
</div>
</nav>
<!-- =======================
Main header End-->
</header>
<section class="main-content">
<p>
What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The
point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem
Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where
does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College
in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and
1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..",
comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact
original form, accompanied by English versions from the 1914 translation by H. Rackham. Where can I get some? There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour,
or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend
to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The
generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</p>
</section>
</body>

Cannot scroll vertically

I have this page:
http://projects.kleelof.com/rr_chat_roulette/
It is a very simple page, but, for some reason, when the page is too tall, the vertical scroll bars do not come on.
Could someone take a quick look and tell me what I am doing wrong?
I will post the CSS and related HTML below:
CSS:
body
{
width: 100%;
background-color: #000000;
color: #ffffff;
}
#main_area
{
width: 1000px;
padding-top: 20px;
margin-left: auto;
margin-right: auto;
}
.bottom_text
{
font-family: 'Source Sans Pro', serif;
}
HTML:
<div id="main_area">
<center>
<img src="images/header.png"/>
<br/><br/>
<div id="altContent" style="width:900px; background-color:#000000;">
<h1>rickrose_chat_roulette</h1>
<p>Get Adobe Flash player</p>
</div>
<br/><br/>
<span class="bottom_text" style="font-size: 24px;">Chatroulette &
Omegle Alternative for Hot Good Looking People</span>
<br/><br/>
<span class="bottom_text" style="font-size: 14px;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>
</center>
</div>
take care,
lee
In answer to your question, on line 31 in your main CSS file you have html,body{overflow:hidden) If you change this to auto then that will solve your problem.

Resources