提交 7cf0c316 编写于 作者: C codecalm

blog improvements

上级 5356f104
......@@ -2,7 +2,9 @@ import { notFound } from 'next/navigation';
import { allPosts } from 'contentlayer/generated';
import Mdx from '@/components/MDX';
import { Ad } from '@/components/Ad';
import Ad from '@/components/Ad';
import Link from '@/components/Link';
import Icon from '@/components/Icon';
interface PageProps {
params: {
......@@ -38,41 +40,36 @@ export default async function PostPage({ params }: PageProps) {
<>
<section className="section pt-0">
<div className="container">
<div>
{post && post.title && (
<div className="py-7 text-center">
{post.product && <div className="hero-subheader">{post.product}</div>}
<div className="text-muted mb-2">July 25, 2023</div>
<h1 className="hero-title">{post.title}</h1>
</div>
)}
</div>
<div className="row">
<div className="col-side">
<div className="col">
<div className="sticky-top">
<div className="py-7">back</div>
<Link href="/blog" className="link-muted">
<Icon name="chevron-left" />
Go back
</Link>
</div>
</div>
<div className="col-slim">
<div className="markdown">
{post.description && <p className="lead">{post.description}</p>}
<Mdx code={post.body.code} />
</div>
</div>
<div className="col">
<div className="row g-6">
<div className="col-12">
<div className="row g-6">
<div className="col">
{post && post.title && (
<div className="py-7 text-center">
{post.product && <div className="hero-subheader">{post.product}</div>}
<div className="text-muted mb-2">July 25, 2023</div>
<h1 className="hero-title">{post.title}</h1>
</div>
)}
</div>
<div className="col-side"></div>
</div>
</div>
<div className="col-12">
<div className="row g-6">
<div className="col">
<div className="markdown">
{post.description && <p className="lead">{post.description}</p>}
<Mdx code={post.body.code} />
</div>
</div>
<div className="col-side">
<div className="sticky-top">
<Ad />
</div>
</div>
<div className="sticky-top">
<div className="row justify-end">
<div className="col-side">
<Ad />
</div>
</div>
</div>
......
import Icon from '@/components/Icon';
import { iconsUrl } from '@/config/site';
import Link from 'components/Link';
import { allPosts } from 'contentlayer/generated';
import { format } from 'date-fns';
export const metadata = {
title: 'Blog',
......@@ -7,88 +10,69 @@ export const metadata = {
};
export default async function BlogPage() {
return (
<>
<div className="sm:gx-6 xl:gx-7">
{allPosts.map((post, i) => (
<div
className="guide"
key={post.slug}
itemScope={true}
itemType="https://schema.org/NewsArticle"
>
<div className="guide-date">
{/* <meta
itemProp="datePublished"
content={format(new Date(post.date), "yyyy-MM-dd")}
/>
<div>{format(new Date(post.date), "d")}</div>
<div>{format(new Date(post.date), "MMM")}</div> */}
</div>
<div className="box">
{post.image && (
<Link href={post.slug} className="d-block mb-4">
<div className="border-light rounded lh-1">
<img
src={post.image}
width={660}
height={361}
className="rounded"
alt={post.title}
itemProp="image"
/>
</div>
</Link>
)}
<div>
{post.title && (
<h2>
<meta itemProp="headline" content={post?.title} />
<meta itemProp="url" content={post.slug} />
<Link href={post.slug}>{post?.title}</Link>
</h2>
)}
<section className="section">
<div className="page-header">
<h2 className="page-title page-title-lg">Blog</h2>
<p className="page-description">
Stay in the loop with all things <Link href="/">Tabler</Link> and <a href={iconsUrl}>Tabler Icons</a>. Regular updates on new features, changelogs, and news, ensuring you never miss any of our software developments.
</p>
</div>
<div className="container">
<div className="row justify-center">
<div className="col-slim">
<div className="divider-y-8">
{allPosts.map((post, i) => (
<div className="" key={post.slug} itemScope={true} itemType="https://schema.org/NewsArticle">
{post.image && (
<Link href={post.slug} className="d-block mb-4">
<div className="outline-light rounded lh-1">
<img src={`/img/blog/${post.image}`} width={660} height={361} className="rounded" alt={post.title} itemProp="image" />
</div>
</Link>
)}
<div>
{post.title && (
<h2>
<meta itemProp="headline" content={post?.title} />
<meta itemProp="url" content={post.slug} />
<Link href={post.slug}>{post?.title}</Link>
</h2>
)}
<div className="markdown text-muted">
<p itemProp="description">{post.summary}</p>
</div>
</div>
<div className="markdown text-muted">
<p itemProp="description">{post.description}</p>
</div>
</div>
<div className="mt-4">
<div className="row items-center">
<div className="col">
<div
className="d-flex items-center"
itemProp="author"
itemScope={true}
itemType="https://schema.org/Person"
>
<div
className="avatar mr-3"
style={{
backgroundImage: 'url(/img/authors/codecalm.jpg)',
}}
/>
<span itemProp="name">Paweł Kuna</span>
<meta itemProp="url" content="https://tabler.io" />
<div className="mt-4">
<div className="row">
<div className="col">
<meta itemProp="datePublished" content={format(new Date(post.date), 'yyyy-MM-dd')} />
<div className="text-muted">{format(new Date(post.date), 'MMM d, Y')}</div>
</div>
<div className="col text-right">
<Link href={post.slug} aria-label={`Read more about "${post.title}"`}>
Read more <Icon name="arrow-right" />
</Link>
</div>
</div>
</div>
</div>
<div className="col-auto">
{/* <Link
href={post.slug}
className="btn"
aria-label={`Read more about "${post.title}"`}
>
Read more
</Link> */}
</div>
</div>
))}
</div>
</div>
</div>
))}
</div>
</div>
</section>
<section className="section section-light">
<div className="container">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis quibusdam quos est repellat rerum molestias, autem ullam, exercitationem magni non eos sunt, voluptates laboriosam dignissimos mollitia tempora ipsum illo
adipisci.
</div>
</section>
</>
);
}
'use client';
import clsx from 'clsx';
import { useRef, useEffect } from 'react';
export const Ad = () => {
export default function Ad({ className, horizontal }: { className?: string; horizontal?: boolean }) {
const ad = useRef<any>(null);
useEffect(() => {
if (ad.current) {
ad.current.innerHTML = '';
const script = document.createElement('script');
script.async = true;
script.src = '//cdn.carbonads.com/carbon.js?serve=CWYDCKQE&placement=tabler-iconsio';
......@@ -15,7 +18,5 @@ export const Ad = () => {
}
}, []);
return (
<div ref={ad} className="ads"></div>
);
return <div ref={ad} className={clsx('carbon', className, horizontal && 'carbon-horizontal')}></div>;
};
......@@ -4,10 +4,7 @@ const icons = {
plus: ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx(
'icon icon-tabler icon icon-tabler icon-tabler-plus',
className
)}
className={clsx('icon icon-tabler icon icon-tabler icon-tabler-plus', className)}
width="24"
height="24"
viewBox="0 0 24 24"
......@@ -212,10 +209,7 @@ const icons = {
'brand-bootstrap': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx(
'icon icon-tabler icon-tabler-brand-bootstrap',
className
)}
className={clsx('icon icon-tabler icon-tabler-brand-bootstrap', className)}
width={24}
height={24}
viewBox="0 0 24 24"
......@@ -339,10 +333,7 @@ const icons = {
'arrow-down-circle': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx(
'icon icon-tabler icon-tabler-arrow-down-circle',
className
)}
className={clsx('icon icon-tabler icon-tabler-arrow-down-circle', className)}
width="24"
height="24"
viewBox="0 0 24 24"
......@@ -358,6 +349,24 @@ const icons = {
<line x1="16" y1="12" x2="12" y2="16" />
</svg>
),
'arrow-right': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx('icon icon-tabler icon-tabler-arrow-right', className)}
width="24"
height="24"
viewBox="0 0 24 24"
strokWidth="2"
stroke="currentColor"
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M5 12l14 0" />
<path d="M13 18l6 -6" />
<path d="M13 6l6 6" />
</svg>
),
'thumb-up': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
......@@ -836,10 +845,7 @@ const icons = {
'layout-dashboard': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx(
'icon icon-tabler icon-tabler-layout-dashboard',
className
)}
className={clsx('icon icon-tabler icon-tabler-layout-dashboard', className)}
width="24"
height="24"
viewBox="0 0 24 24"
......@@ -879,10 +885,7 @@ const icons = {
'circle-x-filled': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx(
'icon icon-tabler icon-tabler-circle-x-filled',
className
)}
className={clsx('icon icon-tabler icon-tabler-circle-x-filled', className)}
width="24"
height="24"
viewBox="0 0 24 24"
......@@ -902,10 +905,7 @@ const icons = {
'circle-check-filled': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx(
'icon icon-tabler icon-tabler-circle-check-filled',
className
)}
className={clsx('icon icon-tabler icon-tabler-circle-check-filled', className)}
width="24"
height="24"
viewBox="0 0 24 24"
......@@ -925,10 +925,7 @@ const icons = {
'alert-circle-filled': ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
className={clsx(
'icon icon-tabler icon-tabler-alert-circle-filled',
className
)}
className={clsx('icon icon-tabler icon-tabler-alert-circle-filled', className)}
width="24"
height="24"
viewBox="0 0 24 24"
......
---
author: mdo
date: "2022-05-16T00:00:00Z"
title: Random Blog Post from Bootstrap
description: Bootstrap v5.3.1 is here with bug fixes, documentation improvements, and more follow-up enhancements for color modes. Keep reading for the highlights!
image: tabler-icons-2.30.0@2x.png
keywords:
- bootstrap
- guide
---
[Bootstrap v5.2.0-beta1](/2022/05/13/bootstrap-5-2-0-beta/) added a slew of CSS custom properties, or CSS variables, across the `:root` level and all our core components. Here's a quick look at how you can utilize them in your projects.
With CSS variables, you can now customize Bootstrap easier than ever, and without the need for a CSS preprocessor. All the power of Sass is still there behind the scenes, but CSS variables adds a ton of power for the future. Use and compose new values, updates styles globally without recompiling, set fallback values, setup new color modes, and more.
Let's dig in.
## CSS variables?
Their official name is custom properties, but they're often referred to as CSS variables thanks to their most immediate use case for setting specific values. Consider reading [the MDN CSS custom properties article](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties#first_steps_with_custom_properties) or [the CSS Tricks guide](https://css-tricks.com/a-complete-guide-to-custom-properties/) if you need a primer.
In a nutshell, CSS variables allow you to name frequently used values. For example, instead of writing `#6f42c1` everywhere, you can set `--purple: #6f42c1`. Then you can use that variable later on with the `var()` function.
```css
:root {
--purple: #6f42c1;
}
.custom-element {
color: var(--purple);
}
```
We use CSS variables in Bootstrap to set many property values globally, across our components, and in some of our utilities.
## Groups of variables
When we talk about CSS variables in Bootstrap, we're referring to three major groups:
- **Root variables —** Globally scoped variables available on the `:root` element (`<html>` usually) and accessible by any element throughout the DOM.
- **Component variables —** Variables scoped specifically to each component, usually on the component's base class, and their modifier classes and Sass mixins.
- **Utility variables —** Used as modifiers within other utility classes.
Regardless of where they are, all of our CSS variables are prefixed with `--bs-`, so you know where they're coming from and how they might be used across codebases that mix Bootstrap's CSS with additional custom styles. You'll also notice that we don't put all our component variables at the root level. This keeps CSS variables scoped to their intended use cases and prevents polluted variables in the global `:root` scope.
It's also worth mentioning two larger efforts that are still to come around CSS variables:
1. Adding CSS variables to all our forms
2. Adding more nuanced global theme variables and support for color modes like [dark mode](https://github.com/twbs/bootstrap/pull/35857).
These are likely coming in v5.3.0 (our next minor release after v5.2.0 stablizes), so in the mean time, check out the GitHub repo to see how things are shaping up.
## Root variables
![Root variables in web inspector](/assets/img/2022/05/docs-root-vars.png)
Bootstrap has a ton of [root variables](https://getbootstrap.com/docs/5.2/customize/css-variables/#root-variables) and we'll only be adding more in future updates for the aforementioned color mode support. As of this post, we have the following CSS variables on the `:root` element:
- **Colors —** All named colors, gray colors, and theme colors. This also includes all our `$theme-colors` in their `rgb` format.
- **Body font styles —** Everything from `font-size` to `color` and more, all applied to our `<body>` element.
- **Shared properties —** For property-value pairings that we consider theme specific, like link colors and border styles.
Root CSS variables are used extensively across other parts of Bootstrap to allow you to easily override our default styles at a global level. For example, if you wanted to adjust the default `border-radius` and link color for our components, you could override a couple variables instead of writing new selectors.
```scss
// custom.css
:root {
--bs-border-radius: .5rem;
--bs-link-color: #333;
}
```
You can even use other root variables to override those values:
```scss
// custom.css
:root {
--bs-border-radius: var(--bs-border-radius-lg);
--bs-link-color: var(--bs-gray-800);
}
```
Without CSS variables, you'd have to use a preprocessor like Sass or write new selectors for every instance of these properties across all components. The former is relatively easy, the latter not so much. CSS variables help solve that.
## Component variables
On our components, CSS variables get even more power for customizing. Nearly everything under the Components section in our docs sidebar now has CSS variables available to you:
- [Accordion](https://getbootstrap.com/docs/5.2/components/accordion/)
- [Alerts](https://getbootstrap.com/docs/5.2/components/alerts/)
- [Badge](https://getbootstrap.com/docs/5.2/components/badge/)
- [Breadcrumb](https://getbootstrap.com/docs/5.2/components/breadcrumb/)
- [Buttons](https://getbootstrap.com/docs/5.2/components/buttons/)
- [Button group](https://getbootstrap.com/docs/5.2/components/button-group/)
- [Card](https://getbootstrap.com/docs/5.2/components/card/)
- [Carousel](https://getbootstrap.com/docs/5.2/components/carousel/)
- [Collapse](https://getbootstrap.com/docs/5.2/components/collapse/)
- [Dropdowns](https://getbootstrap.com/docs/5.2/components/dropdowns/)
- [List group](https://getbootstrap.com/docs/5.2/components/list-group/)
- [Modal](https://getbootstrap.com/docs/5.2/components/modal/)
- [Navbar](https://getbootstrap.com/docs/5.2/components/navbar/)
- [Navs & tabs](https://getbootstrap.com/docs/5.2/components/navs-tabs/)
- [Offcanvas](https://getbootstrap.com/docs/5.2/components/offcanvas/)
- [Pagination](https://getbootstrap.com/docs/5.2/components/pagination/)
- [Placeholders](https://getbootstrap.com/docs/5.2/components/placeholders/)
- [Popovers](https://getbootstrap.com/docs/5.2/components/popovers/)
- [Progress](https://getbootstrap.com/docs/5.2/components/progress/)
- [Spinners](https://getbootstrap.com/docs/5.2/components/spinners/)
- [Toasts](https://getbootstrap.com/docs/5.2/components/toasts/)
- [Tooltips](https://getbootstrap.com/docs/5.2/components/tooltips/)
_Scrollspy and close button have no relevant CSS variables, so they're excluded here._
Throughout our documentation you'll find examples of customizing our default components by overriding their CSS variables. One great example comes from our own docs where we write our own button styles to [create a purple button](https://getbootstrap.com/docs/5.2/components/buttons/#variables).
```css
.btn-bd-primary {
--bs-btn-font-weight: 600;
--bs-btn-color: var(--bs-white);
--bs-btn-bg: var(--bd-violet);
--bs-btn-border-color: var(--bd-violet);
--bs-btn-border-radius: .5rem;
--bs-btn-hover-color: var(--bs-white);
--bs-btn-hover-bg: #{shade-color($bd-violet, 10%)};
--bs-btn-hover-border-color: #{shade-color($bd-violet, 10%)};
--bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
--bs-btn-active-color: var(--bs-btn-hover-color);
--bs-btn-active-bg: #{shade-color($bd-violet, 20%)};
--bs-btn-active-border-color: #{shade-color($bd-violet, 20%)};
}
```
Which looks like this:
![Custom Bootstrap docs button](/assets/img/2022/05/docs-custom-button.png)
Another great example is from [our tooltips](https://getbootstrap.com/docs/5.2/components/tooltips/#custom-tooltips). You can add custom classes to tooltips and popovers in Bootstrap with `data-bs-custom-class="custom-tooltip"`. Then, with one CSS variable, you can change the tooltip background and arrow color.
```css
.custom-tooltip {
--bs-tooltip-bg: var(--bs-primary);
}
```
Which looks like this:
![Custom tooltip](/assets/img/2022/05/docs-custom-tooltip.png)
There are dozens of CSS variables in play across our components. All of them are referenced in a new section on the relevant docs page. For example, [here are our modal CSS variables](https://getbootstrap.com/docs/5.2/components/modal/#variables). This is in addition to all the Sass variables, mixins, loops, and maps used for each component.
## Utility variables
Not every utility class uses CSS variables, but the ones that do gain a good amount of power and customization. [Background](https://getbootstrap.com/docs/5.2/utilities/background/), [border](https://getbootstrap.com/docs/5.2/utilities/borders/), and [color](https://getbootstrap.com/docs/5.2/utilities/colors/) utilities all have what we call "local CSS variables" to improve their usefulness. Each of them uses CSS variables to customize the alpha transparency value of `rgba()` colors.
Consider our [background color utilities](https://getbootstrap.com/docs/5.2/utilities/background/), `.bg-*`. By default each utility class has a local variable, `--bs-bg-opacity` with a default value of `1`. To change the background utility alpha value, you can override that value with your own styles, or some new `.bg-opacity-*` utilities.
```html
<div class="p-3 bg-success bg-opacity-25">
...
</div>
```
Here's how `.bg-success` looks with all our `.bg-opacity-*` classes applied:
![Background opacity examples](/assets/img/2022/05/bg-opacity.png)
And the same is available for [border color opacity](https://getbootstrap.com/docs/5.2/utilities/borders/#opacity) (`--bs-border-opacity` and `.border-opacity-*`) and [text color opacity](https://getbootstrap.com/docs/5.2/utilities/colors/#opacity) (`--bs-text-opacity` and `.text-opacity-*`). So many color options are now available with these utilities.
By default, we ship with five values for these various opacity utilities.
| Class names | Alpha value |
| --- | --- |
| `.text-opacity-10`<br /> `.bg-opacity-10`<br /> `.border-opacity-10` | `.1` |
| `.text-opacity-25`<br /> `.bg-opacity-25`<br /> `.border-opacity-25` | `.25` |
| `.text-opacity-50`<br /> `.bg-opacity-50`<br /> `.border-opacity-50` | `.5` |
| `.text-opacity-75`<br /> `.bg-opacity-75`<br /> `.border-opacity-75` | `.75` |
| `.text-opacity-100`<br /> `.bg-opacity-100`<br /> `.border-opacity-100` | `1` |
Expect more CSS variables to make their way into our utilities. There's a lot of power in real-time customization, even for what we consider immutable styles.
---
**Ready to get started with Bootstrap?** Checkout the [quick start guide](https://getbootstrap.com/docs/5.2/getting-started/introduction/#quick-start) so you can put these new CSS variables to work in your next project!
---
author: mdo
date: "2022-05-16T00:00:00Z"
title: Random Blog Post from Bootstrap
title: Marge, just about everything's a sin. Y'ever sat down and read this thing?
description: How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive? Books are useless! I only ever read one book, "To Kill A Mockingbird," and it gave me absolutely no insight on how to kill mockingbirds! Sure it taught me not to judge a man by the color of his skin…but what good does *that* do me?
image: tabler-icons-2.29.0@2x.png
keywords:
- bootstrap
- guide
---
[Bootstrap v5.2.0-beta1](/2022/05/13/bootstrap-5-2-0-beta/) added a slew of CSS custom properties, or CSS variables, across the `:root` level and all our core components. Here's a quick look at how you can utilize them in your projects.
Yes! I am a citizen! Now which way to the welfare office? I'm kidding, I'm kidding. __I work, I work.__ *Oh, loneliness and cheeseburgers are a dangerous mix.* Your guilty consciences may make you vote Democratic, but secretly you all yearn for a Republican president to lower taxes, brutalize criminals, and rule you like a king!
With CSS variables, you can now customize Bootstrap easier than ever, and without the need for a CSS preprocessor. All the power of Sass is still there behind the scenes, but CSS variables adds a ton of power for the future. Use and compose new values, updates styles globally without recompiling, set fallback values, setup new color modes, and more.
## …And the fluffy kitten played with that ball of string all through the night. On a lighter note, a Kwik-E-Mart clerk was brutally murdered last night.
Let's dig in.
Oh, loneliness and cheeseburgers are a dangerous mix. Please do not offer my god a peanut. We started out like Romeo and Juliet, but it ended up in tragedy. Remember the time he ate my goldfish? And you lied and said I never had goldfish. Then why did I have the bowl, Bart? *Why did I have the bowl?*
## CSS variables?
1. Jesus must be spinning in his grave!
2. Human contact: the final frontier.
3. Last night's "Itchy and Scratchy Show" was, without a doubt, the worst episode *ever.* Rest assured, I was on the Internet within minutes, registering my disgust throughout the world.
Their official name is custom properties, but they're often referred to as CSS variables thanks to their most immediate use case for setting specific values. Consider reading [the MDN CSS custom properties article](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties#first_steps_with_custom_properties) or [the CSS Tricks guide](https://css-tricks.com/a-complete-guide-to-custom-properties/) if you need a primer.
### Get ready, skanks! It's time for the truth train!
In a nutshell, CSS variables allow you to name frequently used values. For example, instead of writing `#6f42c1` everywhere, you can set `--purple: #6f42c1`. Then you can use that variable later on with the `var()` function.
We started out like Romeo and Juliet, but it ended up in tragedy. I don't like being outdoors, Smithers. For one thing, there's too many fat children. And here I am using my own lungs like a sucker. How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?
```css
:root {
--purple: #6f42c1;
}
.custom-element {
color: var(--purple);
}
```
* Oh, so they have Internet on computers now!
* You don't win friends with salad.
* Marge, you being a cop makes you the man! Which makes me the woman — and I have no interest in that, besides occasionally wearing the underwear, which as we discussed, is strictly a comfort thing.
We use CSS variables in Bootstrap to set many property values globally, across our components, and in some of our utilities.
…And the fluffy kitten played with that ball of string all through the night. On a lighter note, a Kwik-E-Mart clerk was brutally murdered last night. Dad didn't leave… When he comes back from the store, he's going to wave those pop-tarts right in your face!
## Groups of variables
Fat Tony is a cancer on this fair city! He is the cancer and I am the…uh…what cures cancer? Yes! I am a citizen! Now which way to the welfare office? I'm kidding, I'm kidding. I work, I work.
When we talk about CSS variables in Bootstrap, we're referring to three major groups:
Kids, we need to talk for a moment about Krusty Brand Chew Goo Gum Like Substance. We all knew it contained spider eggs, but the hantavirus? That came out of left field. So if you're experiencing numbness and/or comas, send five dollars to antidote, PO box… Old people don't need companionship. They need to be isolated and studied so it can be determined what nutrients they have that might be extracted for our personal use.
- **Root variables —** Globally scoped variables available on the `:root` element (`<html>` usually) and accessible by any element throughout the DOM.
I can't go to juvie. They use guys like me as currency. Attempted murder? Now honestly, what is that? Do they give a Nobel Prize for attempted chemistry? Ahoy hoy? Stan Lee never left. I'm afraid his mind is no longer in mint condition.
- **Component variables —** Variables scoped specifically to each component, usually on the component's base class, and their modifier classes and Sass mixins.
Books are useless! I only ever read one book, "To Kill A Mockingbird," and it gave me absolutely no insight on how to kill mockingbirds! Sure it taught me not to judge a man by the color of his skin…but what good does *that* do me? Old people don't need companionship. They need to be isolated and studied so it can be determined what nutrients they have that might be extracted for our personal use.
- **Utility variables —** Used as modifiers within other utility classes.
Son, a woman is like a beer. They smell good, they look good, you'd step over your own mother just to get one! But you can't stop at one. You wanna drink another woman! Donuts. Is there anything they can't do?
Regardless of where they are, all of our CSS variables are prefixed with `--bs-`, so you know where they're coming from and how they might be used across codebases that mix Bootstrap's CSS with additional custom styles. You'll also notice that we don't put all our component variables at the root level. This keeps CSS variables scoped to their intended use cases and prevents polluted variables in the global `:root` scope.
Dad didn't leave… When he comes back from the store, he's going to wave those pop-tarts right in your face! Mrs. Krabappel and Principal Skinner were in the closet making babies and I saw one of the babies and then the baby looked at me.
It's also worth mentioning two larger efforts that are still to come around CSS variables:
The Internet King? I wonder if he could provide faster nudity… A lifetime of working with nuclear power has left me with a healthy green glow…and left me as impotent as a Nevada boxing commissioner.
1. Adding CSS variables to all our forms
2. Adding more nuanced global theme variables and support for color modes like [dark mode](https://github.com/twbs/bootstrap/pull/35857).
Dear Mr. President, There are too many states nowadays. Please, eliminate three. P.S. I am not a crackpot. The Internet King? I wonder if he could provide faster nudity… But, Aquaman, you cannot marry a woman without gills. You're from two different worlds… Oh, I've wasted my life.
These are likely coming in v5.3.0 (our next minor release after v5.2.0 stablizes), so in the mean time, check out the GitHub repo to see how things are shaping up.
Books are useless! I only ever read one book, "To Kill A Mockingbird," and it gave me absolutely no insight on how to kill mockingbirds! Sure it taught me not to judge a man by the color of his skin…but what good does *that* do me? He didn't give you gay, did he? Did he?!
## Root variables
![Root variables in web inspector](/assets/img/2022/05/docs-root-vars.png)
Bootstrap has a ton of [root variables](https://getbootstrap.com/docs/5.2/customize/css-variables/#root-variables) and we'll only be adding more in future updates for the aforementioned color mode support. As of this post, we have the following CSS variables on the `:root` element:
- **Colors —** All named colors, gray colors, and theme colors. This also includes all our `$theme-colors` in their `rgb` format.
- **Body font styles —** Everything from `font-size` to `color` and more, all applied to our `<body>` element.
- **Shared properties —** For property-value pairings that we consider theme specific, like link colors and border styles.
Root CSS variables are used extensively across other parts of Bootstrap to allow you to easily override our default styles at a global level. For example, if you wanted to adjust the default `border-radius` and link color for our components, you could override a couple variables instead of writing new selectors.
```scss
// custom.css
:root {
--bs-border-radius: .5rem;
--bs-link-color: #333;
}
```
You can even use other root variables to override those values:
```scss
// custom.css
:root {
--bs-border-radius: var(--bs-border-radius-lg);
--bs-link-color: var(--bs-gray-800);
}
```
Without CSS variables, you'd have to use a preprocessor like Sass or write new selectors for every instance of these properties across all components. The former is relatively easy, the latter not so much. CSS variables help solve that.
## Component variables
On our components, CSS variables get even more power for customizing. Nearly everything under the Components section in our docs sidebar now has CSS variables available to you:
- [Accordion](https://getbootstrap.com/docs/5.2/components/accordion/)
- [Alerts](https://getbootstrap.com/docs/5.2/components/alerts/)
- [Badge](https://getbootstrap.com/docs/5.2/components/badge/)
- [Breadcrumb](https://getbootstrap.com/docs/5.2/components/breadcrumb/)
- [Buttons](https://getbootstrap.com/docs/5.2/components/buttons/)
- [Button group](https://getbootstrap.com/docs/5.2/components/button-group/)
- [Card](https://getbootstrap.com/docs/5.2/components/card/)
- [Carousel](https://getbootstrap.com/docs/5.2/components/carousel/)
- [Collapse](https://getbootstrap.com/docs/5.2/components/collapse/)
- [Dropdowns](https://getbootstrap.com/docs/5.2/components/dropdowns/)
- [List group](https://getbootstrap.com/docs/5.2/components/list-group/)
- [Modal](https://getbootstrap.com/docs/5.2/components/modal/)
- [Navbar](https://getbootstrap.com/docs/5.2/components/navbar/)
- [Navs & tabs](https://getbootstrap.com/docs/5.2/components/navs-tabs/)
- [Offcanvas](https://getbootstrap.com/docs/5.2/components/offcanvas/)
- [Pagination](https://getbootstrap.com/docs/5.2/components/pagination/)
- [Placeholders](https://getbootstrap.com/docs/5.2/components/placeholders/)
- [Popovers](https://getbootstrap.com/docs/5.2/components/popovers/)
- [Progress](https://getbootstrap.com/docs/5.2/components/progress/)
- [Spinners](https://getbootstrap.com/docs/5.2/components/spinners/)
- [Toasts](https://getbootstrap.com/docs/5.2/components/toasts/)
- [Tooltips](https://getbootstrap.com/docs/5.2/components/tooltips/)
_Scrollspy and close button have no relevant CSS variables, so they're excluded here._
Throughout our documentation you'll find examples of customizing our default components by overriding their CSS variables. One great example comes from our own docs where we write our own button styles to [create a purple button](https://getbootstrap.com/docs/5.2/components/buttons/#variables).
```css
.btn-bd-primary {
--bs-btn-font-weight: 600;
--bs-btn-color: var(--bs-white);
--bs-btn-bg: var(--bd-violet);
--bs-btn-border-color: var(--bd-violet);
--bs-btn-border-radius: .5rem;
--bs-btn-hover-color: var(--bs-white);
--bs-btn-hover-bg: #{shade-color($bd-violet, 10%)};
--bs-btn-hover-border-color: #{shade-color($bd-violet, 10%)};
--bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
--bs-btn-active-color: var(--bs-btn-hover-color);
--bs-btn-active-bg: #{shade-color($bd-violet, 20%)};
--bs-btn-active-border-color: #{shade-color($bd-violet, 20%)};
}
```
Which looks like this:
![Custom Bootstrap docs button](/assets/img/2022/05/docs-custom-button.png)
Another great example is from [our tooltips](https://getbootstrap.com/docs/5.2/components/tooltips/#custom-tooltips). You can add custom classes to tooltips and popovers in Bootstrap with `data-bs-custom-class="custom-tooltip"`. Then, with one CSS variable, you can change the tooltip background and arrow color.
```css
.custom-tooltip {
--bs-tooltip-bg: var(--bs-primary);
}
```
Which looks like this:
![Custom tooltip](/assets/img/2022/05/docs-custom-tooltip.png)
There are dozens of CSS variables in play across our components. All of them are referenced in a new section on the relevant docs page. For example, [here are our modal CSS variables](https://getbootstrap.com/docs/5.2/components/modal/#variables). This is in addition to all the Sass variables, mixins, loops, and maps used for each component.
## Utility variables
Not every utility class uses CSS variables, but the ones that do gain a good amount of power and customization. [Background](https://getbootstrap.com/docs/5.2/utilities/background/), [border](https://getbootstrap.com/docs/5.2/utilities/borders/), and [color](https://getbootstrap.com/docs/5.2/utilities/colors/) utilities all have what we call "local CSS variables" to improve their usefulness. Each of them uses CSS variables to customize the alpha transparency value of `rgba()` colors.
Consider our [background color utilities](https://getbootstrap.com/docs/5.2/utilities/background/), `.bg-*`. By default each utility class has a local variable, `--bs-bg-opacity` with a default value of `1`. To change the background utility alpha value, you can override that value with your own styles, or some new `.bg-opacity-*` utilities.
```html
<div class="p-3 bg-success bg-opacity-25">
...
</div>
```
Here's how `.bg-success` looks with all our `.bg-opacity-*` classes applied:
![Background opacity examples](/assets/img/2022/05/bg-opacity.png)
And the same is available for [border color opacity](https://getbootstrap.com/docs/5.2/utilities/borders/#opacity) (`--bs-border-opacity` and `.border-opacity-*`) and [text color opacity](https://getbootstrap.com/docs/5.2/utilities/colors/#opacity) (`--bs-text-opacity` and `.text-opacity-*`). So many color options are now available with these utilities.
By default, we ship with five values for these various opacity utilities.
| Class names | Alpha value |
| --- | --- |
| `.text-opacity-10`<br /> `.bg-opacity-10`<br /> `.border-opacity-10` | `.1` |
| `.text-opacity-25`<br /> `.bg-opacity-25`<br /> `.border-opacity-25` | `.25` |
| `.text-opacity-50`<br /> `.bg-opacity-50`<br /> `.border-opacity-50` | `.5` |
| `.text-opacity-75`<br /> `.bg-opacity-75`<br /> `.border-opacity-75` | `.75` |
| `.text-opacity-100`<br /> `.bg-opacity-100`<br /> `.border-opacity-100` | `1` |
Expect more CSS variables to make their way into our utilities. There's a lot of power in real-time customization, even for what we consider immutable styles.
---
**Ready to get started with Bootstrap?** Checkout the [quick start guide](https://getbootstrap.com/docs/5.2/getting-started/introduction/#quick-start) so you can put these new CSS variables to work in your next project!
Marge, you being a cop makes you the man! Which makes me the woman — and I have no interest in that, besides occasionally wearing the underwear, which as we discussed, is strictly a comfort thing. You know, the one with all the well meaning rules that don't work out in real life, uh, Christianity.
......@@ -3,7 +3,7 @@ import fs from 'fs-extra'
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
reactStrictMode: false,
images: {
domains: ["avatars.githubusercontent.com"],
},
......
.carbon {
position: relative;
background: #{$color-gray};
padding: 15px;
font-size: 0.8125rem;
line-height: 1.4;
border-radius: $border-radius;
}
.carbon-img {
display: block;
}
.carbon-text {
display: block;
margin-top: 0.75rem;
color: $color-text;
font-weight: 500;
}
.carbon-poweredby {
display: block;
margin-top: 0.75rem;
color: $color-muted;
}
.carbon-horizontal {
min-height: 130px;
padding-left: 160px;
.carbon-img {
position: absolute;
top: 15px;
left: 15px;
}
.carbon-text {
margin: 0;
}
}
......@@ -166,7 +166,7 @@ $grid-breakpoints: (
$container-max-width: px2rem(1280px);
$container-narrow-max-width: px2rem(990px);
$container-slim-max-width: px2rem(768px);
$container-slim-max-width: px2rem(660px);
$zindex-modal: 100;
$zindex-gototop: 90;
......@@ -468,6 +468,14 @@ $utilities: (
light: 1px solid $color-border-light
)
),
"outline": (
property: outline,
values: (
0: none,
null: 1px solid $color-border,
light: 1px solid $color-border-light
)
),
"border-top": (
property: border-top,
values: (
......
......@@ -35,7 +35,7 @@
position: absolute;
top: 2rem;
z-index: 1;
background: $color-gray;
background: $color-white;
color: $color-muted-light;
left: calc(4rem / -2 - 1rem);
text-transform: uppercase;
......
......@@ -260,6 +260,16 @@
width: 12rem;
}
.#{$prefix}col-slim {
flex: 0 0 auto;
width: calc(#{$container-slim-max-width} + var(--gutter-x))
}
.#{$prefix}col-narrow {
flex: 0 0 auto;
width: calc(#{$container-narrow-max-width} + var(--gutter-x));
}
@if $columns > 0 {
@for $i from 1 through $columns {
.#{$prefix}col-#{$i} {
......
......@@ -14,6 +14,7 @@
@import 'logo';
@import 'hero';
@import 'ads';
@import 'avatars';
@import 'badges';
@import 'breadcrumb';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册