HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!-- Bootstrap loaded via CDN -->
<body>
<div class="textbox">
<h1 class="header">Из бутстрапа в CSS grid</h1>
<p>Q: Зачем это вообще?</p>
<p>A: Причин много (см. <a href="https://medium.com/@tallys/bootstrap-to-css-grid-87b3f5f830e4">статью на Medium</a> и ее <a href="http://css-live.ru/articles/ot-butstrapa-k-css-gridam.html">перевод</a>). В основном я хотела всех «плюшек» CSS Grid, но не могла позволить себе удалить старый код или сломать его в старых браузерах. Шаг назад, два шага вперед. Меняйте размер окна браузера и находите себе самые разные возможности. Спасибо CSS за гибкость!
</div>
<div class="container css-grid-container css-grid--card">
<div class="row">
<div class="col-md-4 col-lg-3">
<div class="card">
<h1>Some content!</h1>
<div class="image-container">
<img src="https://pbs.twimg.com/media/Cq-inMBWEAAZyZ_.jpg" alt="My cats (Lumen and Waffle) cuddled up in a blanket"/></div>
<p> This line is longer, but it doesn't break anything!</p>
</div>
</div>
<div class="col-md-4 col-lg-3">
<div class="card">
<h1>Some content!</h1>
<div class="image-container">
<img src="https://pbs.twimg.com/media/Cq-inMBWEAAZyZ_.jpg" alt="My cats cuddled up in a blanket"/></div>
<p>Some *more* content!</p>
</div>
</div>
<div class="col-md-4 col-lg-3">
<div class="card">
<h1>Some content!</h1>
<div class="image-container">
<img src="https://pbs.twimg.com/media/Cq-inMBWEAAZyZ_.jpg" alt="My cats cuddled up in a blanket"/></div>
<p>Some *more* content!</p>
</div>
</div>
<div class="col-md-4 col-lg-3">
<div class="card">
<h1>Some content!</h1>
<div class="image-container">
<img src="https://pbs.twimg.com/media/Cq-inMBWEAAZyZ_.jpg" alt="My cats cuddled up in a blanket"/></div>
<p>Some *more* content!</p>
</div>
</div>
<div class="col-md-4 col-lg-3">
<div class="card">
<h1>Some content!</h1>
<div class="image-container">
<img src="https://pbs.twimg.com/media/Cq-inMBWEAAZyZ_.jpg" alt="My cats cuddled up in a blanket"/></div>
<p>Some *more* content!</p>
</div>
</div>
</div>
</div>
</body>
/* Инструкция: меняйте размер окна браузера с поддержкой гридов и смотрите, какие крутые штуки CSS может вам сделать!
+ Выравнивание высот карточек для каждого ряда
+ Настраиваемые интервалы между колонками и рядами!
+ Произвольные брейкпойнты, и хватит уже довольствоваться бутстраповскими!
+ И т.д.!
Затем, чтобы увидеть, как выглядит оригинальный Bootstrap найдите две строчки @supports(display:grid) в коде ниже, и поменяйте на что-нибудь другое - лично мне нравится писать @supports(display:gridlock), суперское фейковое свойство и каламбур сразу, которое фактически говорит браузеру выполнять код внутри ТОЛЬКО если браузер поддерживает display:gridlock, а его ни один браузер не поддерживает. Тыдыщ! Теперь вы смотрите это в старом браузере!
*один иомент, за которым надо следить - если у вас старая версия автопрефиксера, убедитесь, что он не добавляет префиксы к display: grid для Edge!
*/
//Настраиваем рабочую область
body {
background: #222;
font-family: 'Bad Script', sans-serif;
margin-top: 20px;
a {
color: lightblue;
text-decoration: underline;
}
.header {
font-family: 'Bad Script', sans-serif;
text-align: center;
font-size: 3em;
}
p {
font-size: 2.4rem;
}
.textbox {
border-top: 4px solid hsl(153, 48, 53);
border-bottom: 4px solid hsl(153, 48, 53);
padding: 10px;
color: #efefef;
margin: auto;
max-width: 1160px;
background: hsla(333, 47, 27, .86);
margin-bottom: 30px;
}
}
// Наш маленький компонент карточки
.card {
background: #efefef;
padding: 1px 10px;
border-radius: 19px / 6px;
box-shadow: 1px 2px 3px 1px #111;
margin-bottom: 20px;
@media(min-width: 992px) {
height: 400px;
}
.image-container {
overflow: hidden;
margin-bottom: 7px;
}
img {
max-width: 100%;
border-radius: 3px;
}
h1 {
font-size: 3.5rem;
text-align: center;
margin: .5rem 0;
}
}
// Фактически убираем бутстраповские стили, несовместимые с CSS-гридами, на уровне контейнера
.css-grid-container {
@supports(display: grid) {
padding: 0;
&:before {
display: none;
}
div[class^="col-"] {
width: 100% !important;
padding: 0;
}
.row {
display: grid;
margin: 0;
&:before {
display: none;
}
}
}
}
// Теперь можно менять наши карточки как нам угодно на уровне контейнера
.css-grid--card {
@supports(display: grid) {
.row {
grid-column-gap: 5px;
grid-row-gap: 7px;
padding: 5px;
grid-template-columns: 1fr;
.card {
//только если хотите растянуть карточкм на 100% высоты грид-контейнера - иначе сбросьте на auto;
height: 100%;
margin-bottom: 0;
}
//произвольные брейкпойнты, нет проблем!
@media (min-width: 697px) and (max-width: 1099px) {
grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
align-items: stretch;
.card {
height: auto;
}
}
//произвольные брейкпойнты, нет проблем!
@media (min-width: 1100px) {
grid-template-columns: repeat(3, 1fr);
grid-column-gap: 12px;
grid-row-gap: 8px;
}
@media (min-width: 1400px) {
//Они даже не должны быть одинаковыми! Пробуйте разные комбинации!
grid-template-columns: 1.1fr 2fr 1.3fr 1.1fr;
grid-column-gap: 3px;
grid-row-gap: 8px;
}
}
}
}
Also see: Tab Triggers