1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-13 09:35:59 +02:00

feat: Initial avatar

This commit is contained in:
Phuoc Nguyen
2022-09-19 19:46:47 +07:00
parent 772d5b4f46
commit 8a68c8e144
7 changed files with 63 additions and 154 deletions

View File

@@ -0,0 +1,3 @@
<div class="initial-avatar">
PN
</div>

View File

@@ -157,6 +157,12 @@ eleventyExcludeFromCollections: true
<div class="pattern__title">Full background</div>
</a>
</div>
<div class="pattern__item">
<a class="pattern__link" href="/initial-avatar/">
<div class="pattern__cover">{% include "patterns/initial-avatar.njk" %}</div>
<div class="pattern__title">Initial avatar</div>
</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,38 @@
---
layout: layouts/post.njk
title: Initial avatar
description: Create an initial avatar with CSS
keywords: css avatar
---
## HTML
```html
<div class="initial-avatar">
...
</div>
```
## CSS
```css
.initial-avatar {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
/* Colors */
background-color: rgba(0, 0, 0, 0.3);
color: #fff;
/* Rounded border */
border-radius: 50%;
height: 3rem;
width: 3rem;
}
```
{% demo %}
{% include "patterns/initial-avatar.njk" %}
{% enddemo %}

View File

@@ -1,116 +0,0 @@
import * as React from 'react';
import Head from 'next/head';
import Link from 'next/link';
import { 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.InitialAvatar}>
<Head>
<meta name="description" content="Create an initial avatar with CSS" />
<meta name="og:description" content="Create an initial avatar with CSS" />
<meta name="twitter:description" content="Create an initial avatar with CSS" />
<meta name="keywords" content="css avatar" />
</Head>
<div style={{ lineHeight: 1.5, marginBottom: '16px' }}>
To center the content, you also can use other technique demonstrated in the{' '}
<Link href="/centering">
<a>Centering</a>
</Link>{' '}
pattern.
</div>
<BrowserFrame
html={`
<div class="avatar">
<div class="avatar__letters">
<!-- The letters -->
...
</div>
</div>
`}
css={`
.avatar {
/* Center the content */
display: inline-block;
vertical-align: middle;
/* Used to position the content */
position: relative;
/* Colors */
background-color: rgba(0, 0, 0, 0.3);
color: #fff;
/* Rounded border */
border-radius: 50%;
height: 48px;
width: 48px;
}
.avatar__letters {
/* Center the content */
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
`}
>
<div
style={{
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
height: '100%',
justifyContent: 'center',
padding: '8px',
}}
>
<div
style={{
backgroundColor: 'rgba(0, 0, 0, 0.3)',
borderRadius: '50%',
color: '#FFF',
display: 'inline-block',
fontSize: '24px',
height: '48px',
position: 'relative',
verticalAlign: 'middle',
width: '48px',
}}
>
<div
style={{
left: '50%',
position: 'absolute',
top: '50%',
transform: 'translate(-50%, -50%)',
}}
>
PN
</div>
</div>
</div>
</BrowserFrame>
<Spacer size="extraLarge" />
<RelatedPatterns
patterns={[
Pattern.Avatar,
Pattern.AvatarList,
Pattern.Badge,
Pattern.Centering,
Pattern.PresenceIndicator,
]}
/>
</PatternLayout>
);
};
export default Details;

View File

@@ -1,38 +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={{
alignItems: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.3)',
borderRadius: '9999px',
color: '#FFF',
display: 'flex',
flexDirection: 'column',
height: '48px',
justifyContent: 'center',
width: '48px',
}}
>
PN
</div>
</div>
</Frame>
);
};
export default Cover;

View File

@@ -35,6 +35,7 @@
@import './patterns/fixed-at-corner';
@import './patterns/fixed-at-side';
@import './patterns/full-background';
@import './patterns/initial-avatar';
// Placeholders
@import './placeholders/circle';

View File

@@ -0,0 +1,15 @@
.initial-avatar {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;
/* Colors */
background-color: rgba(0, 0, 0, 0.3);
color: #fff;
/* Rounded border */
border-radius: 50%;
height: 3rem;
width: 3rem;
}