Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Transition к <code>height: auto;</code> и <code>display: block;</code> с помощью CSS</h1>
<p class="note">*Прочитать подробнее <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transition-behavior" target="_blank">на MDN</a> и в <a href="https://developer.chrome.com/blog/entry-exit-animations?hl=ru" target="_blank">Chrome for Developers</a>.</p>
	
<button class="toggle">Показать / Скрыть блок</button>

<div class="container">
	<h2 class="container__headline">Видимость элемента в JavaScript и CSS.</h2>
	<p>Узнайте, как манипулировать видимостью элемента с помощью HTML, CSS, JavaScript.</p>
	<a href="https://html-plus.in.ua/svoystvo-display-none-i-block/" target="_blank">Полный текст статьи »</a>
</div> 
              
            
!

CSS

              
                *{
	box-sizing: border-box;
}
body {
	box-sizing: border-box;
	min-block-size: 100vb;
	padding: 2rem;
	font-family: sans-serif;
	font-size: 1.1rem;
	line-height: 1.5;
	color: hsl(261deg 100% 25%);
	background: linear-gradient(120deg, hsl(260 80% 50%), hsl(90.38deg 100% 50%))
}

a {
	color: #000;
}

h1 {
	max-inline-size: 55rem;
	margin-block: 2rem 3rem;
	margin-inline: auto;
	font-size: 1.8rem;
	line-height: 1.5;
	color: hsl(0 100% 95%);
	text-align: center;
}

code {
	padding-block: 0.5rem;
	padding-inline: 1rem;
	font-size: 0.8em;
	color: hsl(0 100% 15%);
	white-space: nowrap;
	background: yellow;
	border-radius: 5px;
}

.note {
	max-inline-size: 40rem;
	margin-inline: auto;
	margin-block: 2rem 3rem;
	color: #fff;
	text-align: center;
	text-wrap: balance;
}

.container :first-child {
	margin-block-start: 0;
	line-height: 1;
}

.container :last-child {
	margin-block-end: 0;
}

.container {
	position: relative;
	max-inline-size: 40rem;
	padding-block: 1.1rem;
	padding-inline: 2rem;
	margin-block: 1rem 0;
	margin-inline: auto;
	overflow: hidden;
	background: #fff;
	border: 1px solid hsl(260deg 100% 95%);
	border-radius: 0.5rem;
	box-shadow:  2px 2px 20px rgba(0,0,0,.4);
}

.toggle {
	position: relative;
	display: block;
	width: auto;
	padding-block: 0.8rem;
	padding-inline: 1.5rem;
	margin-block: 1.5rem;
	margin-inline: auto;
	color: hsl(261deg 100% 25%);
	text-decoration: none;
	cursor: pointer;
	background: hsl(261deg 100% 95%);
	border: 1px solid hsl(0 0% 10%);
	border-radius: 0.5rem;
	transition: all 0.4s ease-in-out;
}

.toggle:hover {
	color: hsl(261deg 100% 15%);
	background: hsl(261deg 100% 100%);
}

.toggle:active {
	inset-block-start: 0.1rem;
	inset-inline-start: 0.1rem;
}

/* Demo Code */
.container {
	block-size: 0;
	padding-block: 0;
	display: none;
	transition: all 0.5s ease-in-out;

	/* allow-discrete включает переходы для таких свойств, как отображение и видимость. Их значения применяются после завершения перехода. */
	transition-behavior: allow-discrete;
}

.container[open] {
	/* Fallback for browsers that don't support calc-size() */
 	block-size: auto;
	block-size: calc-size(auto);
	display: block;
	padding-block: 1.5rem;
	
	/* Transition starts from these styles */
 	@starting-style {
		block-size: 0;
		padding-block: 0;
	}
}

/* 
You can use @starting-style separately, not from within the selector 

@starting-style {
	.container[open] {
		block-size: 0;
		padding-block: 0;
	}
}
*/

              
            
!

JS

              
                //Forked by https://codepen.io/ZoranJambor/pen/GRaNZNV
// The video guide: https://youtu.be/1VsMKz4Zweg

// Only to toggle "open" attribute on .container after the button is pressed.
const toggle = document.querySelector('.toggle');
const content = document.querySelector('.container');

toggle.addEventListener('click', (e) => {
	content.toggleAttribute('open');
});

              
            
!
999px

Console