mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-06 06:07:33 +02:00
feat: Corner ribbon pattern
This commit is contained in:
6
contents/_includes/patterns/corner-ribbon.njk
Normal file
6
contents/_includes/patterns/corner-ribbon.njk
Normal file
@@ -0,0 +1,6 @@
|
||||
<div class="corner-ribbon">
|
||||
<div class="corner-ribbon__inner">
|
||||
<div class="corner-ribbon__ribbon">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
65
contents/corner-ribbon.md
Normal file
65
contents/corner-ribbon.md
Normal file
@@ -0,0 +1,65 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Corner ribbon
|
||||
description: Create a corner ribbon with CSS flexbox
|
||||
keywords: css flexbox, css ribbon
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="corner-ribbon">
|
||||
<!-- The container -->
|
||||
<div class="corner-ribbon__inner">
|
||||
<!-- The ribbon -->
|
||||
<div class="corner-ribbon__ribbon">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.corner-ribbon {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.corner-ribbon__inner {
|
||||
/* Displayed at the top left corner */
|
||||
left: 0px;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
|
||||
/* Size */
|
||||
height: 4rem;
|
||||
width: 4rem;
|
||||
|
||||
/* Hide the part of its children which is displayed outside */
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.corner-ribbon__ribbon {
|
||||
/* Position */
|
||||
left: 1rem;
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
|
||||
/* Size */
|
||||
height: 1.5rem;
|
||||
width: 5.656rem;
|
||||
|
||||
/* Displayed diagonally */
|
||||
transform: translate(-38px, -8px) rotate(-45deg);
|
||||
|
||||
/* Background color */
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
|
||||
/* Centerize the text content */
|
||||
text-align: center;
|
||||
}
|
||||
```
|
||||
|
||||
{% demo %}
|
||||
{% include "patterns/corner-ribbon.njk" %}
|
||||
{% enddemo %}
|
@@ -79,6 +79,12 @@ eleventyExcludeFromCollections: true
|
||||
<div class="pattern__title">Cookie banner</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pattern__item">
|
||||
<a class="pattern__link" href="/corner-ribbon/">
|
||||
<div class="pattern__cover">{% include "patterns/corner-ribbon.njk" %}</div>
|
||||
<div class="pattern__title">Corner ribbon</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@@ -1,204 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import Head from 'next/head';
|
||||
import Link from 'next/link';
|
||||
import { Heading, Spacer } from '@1milligram/design';
|
||||
|
||||
import { RelatedPatterns } from '../../components/RelatedPatterns';
|
||||
import { Pattern } from '../../constants/Pattern';
|
||||
import { PatternLayout } from '../../layouts/PatternLayout';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
|
||||
const Details: React.FC<{}> = () => {
|
||||
return (
|
||||
<PatternLayout pattern={Pattern.CornerRibbon}>
|
||||
<Head>
|
||||
<meta name="description" content="Create a corner ribbon with CSS flexbox" />
|
||||
<meta name="og:description" content="Create a corner ribbon with CSS flexbox" />
|
||||
<meta name="twitter:description" content="Create a corner ribbon with CSS flexbox" />
|
||||
<meta name="keywords" content="css flexbox, css ribbon" />
|
||||
</Head>
|
||||
<BrowserFrame
|
||||
html={`
|
||||
<div class="container">
|
||||
<!-- The container -->
|
||||
<div class="container__wrapper">
|
||||
<!-- The ribbon -->
|
||||
<div class="container__ribbon">
|
||||
...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`}
|
||||
css={`
|
||||
.container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.container__wrapper {
|
||||
/* Displayed at the top left corner */
|
||||
left: 0px;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
|
||||
/* Size */
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
|
||||
/* Hide the part of its children which is displayed outside */
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.container__ribbon {
|
||||
/* Position */
|
||||
left: -64px;
|
||||
position: absolute;
|
||||
top: 32px;
|
||||
|
||||
/* Size */
|
||||
height: 24px;
|
||||
width: 206px;
|
||||
|
||||
/* Displayed diagonally */
|
||||
transform: rotate(-45deg);
|
||||
|
||||
/* Background color */
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
|
||||
/* Centerize the text content */
|
||||
text-align: center;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
||||
borderRadius: '4px',
|
||||
height: '256px',
|
||||
position: 'relative',
|
||||
width: '256px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
height: '100px',
|
||||
left: 0,
|
||||
overflow: 'hidden',
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
width: '100px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
||||
height: '24px',
|
||||
left: '-64px',
|
||||
position: 'absolute',
|
||||
textAlign: 'center',
|
||||
top: '32px',
|
||||
transform: 'rotate(-45deg)',
|
||||
width: '206px',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
|
||||
<Spacer size="extraLarge" />
|
||||
|
||||
<section>
|
||||
<Heading level={2}>Use cases</Heading>
|
||||
|
||||
<div style={{ padding: '2rem' }}>
|
||||
<div style={{ lineHeight: 1.5, marginBottom: '16px' }}>
|
||||
You can add a ribbon to a{' '}
|
||||
<Link href="/pricing-table">
|
||||
<a>pricing table</a>
|
||||
</Link>{' '}
|
||||
to indicate the most popular option.
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
width: '60%',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
||||
borderRadius: '4px',
|
||||
flex: 1,
|
||||
height: '200px',
|
||||
margin: '0 8px',
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
||||
borderRadius: '4px',
|
||||
flex: 1,
|
||||
height: '300px',
|
||||
margin: '0 8px',
|
||||
position: 'relative',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
height: '100px',
|
||||
left: 0,
|
||||
overflow: 'hidden',
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
width: '100px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: '#00449E',
|
||||
color: '#FFF',
|
||||
fontWeight: 'bold',
|
||||
left: '-64px',
|
||||
padding: '2px 0',
|
||||
position: 'absolute',
|
||||
textAlign: 'center',
|
||||
top: '32px',
|
||||
transform: 'rotate(-45deg)',
|
||||
width: '210px',
|
||||
}}
|
||||
>
|
||||
Popular
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
||||
borderRadius: '4px',
|
||||
flex: 1,
|
||||
height: '250px',
|
||||
margin: '0 8px',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Spacer size="extraLarge" />
|
||||
<RelatedPatterns patterns={[Pattern.FixedAtCorner, Pattern.Ribbon]} />
|
||||
</PatternLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
@@ -1,56 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import Frame from '../../placeholders/Frame';
|
||||
|
||||
const Cover: React.FC<{}> = () => {
|
||||
return (
|
||||
<Frame>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid rgba(0, 0, 0, 0.3)',
|
||||
borderRadius: '4px',
|
||||
height: '100%',
|
||||
position: 'relative',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
height: '48px',
|
||||
left: 0,
|
||||
overflow: 'hidden',
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
width: '48px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
||||
height: '16px',
|
||||
left: '-16px',
|
||||
position: 'absolute',
|
||||
textAlign: 'center',
|
||||
top: '8px',
|
||||
transform: 'rotate(-45deg)',
|
||||
width: '70px',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Frame>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cover;
|
@@ -22,6 +22,7 @@
|
||||
@import './patterns/color-swatch';
|
||||
@import './patterns/concave-corners';
|
||||
@import './patterns/cookie-banner';
|
||||
@import './patterns/corner-ribbon';
|
||||
|
||||
// Placeholders
|
||||
@import './placeholders/circle';
|
||||
|
41
styles/patterns/_corner-ribbon.scss
Normal file
41
styles/patterns/_corner-ribbon.scss
Normal file
@@ -0,0 +1,41 @@
|
||||
.corner-ribbon {
|
||||
position: relative;
|
||||
border: 1px solid rgba(0,0,0,.3);
|
||||
border-radius: 0.25rem;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.corner-ribbon__inner {
|
||||
/* Displayed at the top left corner */
|
||||
left: 0px;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
|
||||
/* Size */
|
||||
height: 4rem;
|
||||
width: 4rem;
|
||||
|
||||
/* Hide the part of its children which is displayed outside */
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.corner-ribbon__ribbon {
|
||||
/* Position */
|
||||
left: 1rem;
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
|
||||
/* Size */
|
||||
height: 1.5rem;
|
||||
width: 5.656rem;
|
||||
|
||||
/* Displayed diagonally */
|
||||
transform: translate(-38px, -8px) rotate(-45deg);
|
||||
|
||||
/* Background color */
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
|
||||
/* Centerize the text content */
|
||||
text-align: center;
|
||||
}
|
Reference in New Issue
Block a user