mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-06 22:26:33 +02:00
feat: Dropdown
This commit is contained in:
9
contents/_includes/covers/dropdown.njk
Normal file
9
contents/_includes/covers/dropdown.njk
Normal file
@@ -0,0 +1,9 @@
|
||||
<div class="dropdown">
|
||||
<div class="dropdown__trigger">
|
||||
{% rectangle %}
|
||||
{% triangle "b" %}
|
||||
</div>
|
||||
<div class="dropdown__content">
|
||||
<div class="dropdown__body">{% lines "hor", 5 %}</div>
|
||||
</div>
|
||||
</div>
|
60
contents/dropdown.md
Normal file
60
contents/dropdown.md
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Dropdown
|
||||
description: Create a dropdown with CSS
|
||||
keywords: css dropdown, css menu
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="dropdown">
|
||||
<!-- The trigger element -->
|
||||
<div class="dropdown__trigger">
|
||||
...
|
||||
</div>
|
||||
|
||||
<!-- The content -->
|
||||
<div class="dropdown__content">
|
||||
...
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.dropdown {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.dropdown__trigger {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Hide the dropdown's content by default */
|
||||
.dropdown__content {
|
||||
display: none;
|
||||
|
||||
/* Position it right below the trigger element */
|
||||
left: 0;
|
||||
padding-top: 0.25rem;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
|
||||
/* It should be on the top of other elements */
|
||||
background-color: #fff;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
/* Show the content when hover on the container */
|
||||
.dropdown:hover .dropdown__content {
|
||||
display: block;
|
||||
}
|
||||
```
|
||||
|
||||
You can use a [triangle button](/triangle-buttons/) to indicate that there is content under it.
|
||||
|
||||
Move the mouse over the button to see the dropdown.
|
||||
|
||||
{% demo %}{% include "covers/dropdown.njk" %}{% enddemo %}
|
@@ -129,6 +129,7 @@ eleventyExcludeFromCollections: true
|
||||
{% pattern "Circular navigation" %}{% include "covers/circular-navigation.njk" %}{% endpattern %}
|
||||
{% pattern "Dot navigation" %}{% include "covers/dot-navigation.njk" %}{% endpattern %}
|
||||
{% pattern "Drawer" %}{% include "covers/drawer.njk" %}{% endpattern %}
|
||||
{% pattern "Dropdown" %}{% include "covers/dropdown.njk" %}{% endpattern %}
|
||||
{% pattern "Full screen menu" %}{% include "covers/full-screen-menu.njk" %}{% endpattern %}
|
||||
{% pattern "Menu" %}{% include "covers/menu.njk" %}{% endpattern %}
|
||||
{% pattern "Pagination" %}{% include "covers/pagination.njk" %}{% endpattern %}
|
||||
|
@@ -1,144 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import Head from 'next/head';
|
||||
import { Spacer } from '@1milligram/design';
|
||||
|
||||
import { RelatedPatterns } from '../../components/RelatedPatterns';
|
||||
import { Pattern } from '../../constants/Pattern';
|
||||
import { PatternLayout } from '../../layouts/PatternLayout';
|
||||
import Block from '../../placeholders/Block';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
import Rectangle from '../../placeholders/Rectangle';
|
||||
import Triangle from '../../placeholders/Triangle';
|
||||
|
||||
const Details: React.FC<{}> = () => {
|
||||
return (
|
||||
<PatternLayout pattern={Pattern.Dropdown}>
|
||||
<Head>
|
||||
<meta name="description" content="Create a dropdown with CSS" />
|
||||
<meta name="og:description" content="Create a dropdown with CSS" />
|
||||
<meta name="twitter:description" content="Create a dropdown with CSS" />
|
||||
<meta name="keywords" content="css dropdown, css menu" />
|
||||
</Head>
|
||||
<div style={{ lineHeight: 1.5, marginBottom: '16px' }}>
|
||||
Move the mouse over the button to see the dropdown.
|
||||
</div>
|
||||
<BrowserFrame
|
||||
html={`
|
||||
<div class="dropdown">
|
||||
<!-- The trigger element -->
|
||||
<button>...</button>
|
||||
|
||||
<!-- The content -->
|
||||
<div class="dropdown__content">
|
||||
...
|
||||
</div>
|
||||
</div>
|
||||
`}
|
||||
css={`
|
||||
.dropdown {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Hide the dropdown's content by default */
|
||||
.dropdown__content {
|
||||
display: none;
|
||||
|
||||
/* Position it right below the trigger element */
|
||||
left: 0;
|
||||
padding-top: 4px;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
|
||||
/* It should be on the top of other elements */
|
||||
background-color: #fff;
|
||||
z-index: 9999;
|
||||
|
||||
/* Size */
|
||||
height: 200px;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
/* Show the content when hover on the container */
|
||||
.dropdown:hover .dropdown__content {
|
||||
display: block;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="p-dropdown"
|
||||
style={{
|
||||
position: 'relative',
|
||||
}}
|
||||
>
|
||||
<button
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '4px',
|
||||
display: 'flex',
|
||||
height: '32px',
|
||||
width: '128px',
|
||||
}}
|
||||
>
|
||||
<span style={{ flex: 1, marginRight: '8px' }}>
|
||||
<Rectangle />
|
||||
</span>
|
||||
<Triangle size={8} corner="b" />
|
||||
</button>
|
||||
|
||||
<div
|
||||
className="p-dropdown-content"
|
||||
style={{
|
||||
backgroundColor: '#FFF',
|
||||
height: '200px',
|
||||
left: 0,
|
||||
paddingTop: '4px',
|
||||
position: 'absolute',
|
||||
top: '100%',
|
||||
width: '200px',
|
||||
zIndex: 9999,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '4px',
|
||||
display: 'flex',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '16px',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<Block numberOfBlocks={10} justify="center" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
marginTop: '16px',
|
||||
width: '256px',
|
||||
}}
|
||||
>
|
||||
<Block numberOfBlocks={20} justify="center" />
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
<Spacer size="extraLarge" />
|
||||
<RelatedPatterns patterns={[Pattern.MegaMenu, Pattern.Menu, Pattern.NestedDropdowns]} />
|
||||
</PatternLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
@@ -1,87 +0,0 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import Frame from '../../placeholders/Frame';
|
||||
import Line from '../../placeholders/Line';
|
||||
import Triangle from '../../placeholders/Triangle';
|
||||
|
||||
const Cover: React.FC<{}> = () => {
|
||||
return (
|
||||
<Frame>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '4px',
|
||||
display: 'flex',
|
||||
height: '24px',
|
||||
justifyContent: 'flex-end',
|
||||
marginBottom: '4px',
|
||||
paddingRight: '4px',
|
||||
width: '60%',
|
||||
}}
|
||||
>
|
||||
<Triangle corner="b" size={8} />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid #d1d5db',
|
||||
borderRadius: '4px',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
width: '80%',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
borderBottom: '1px solid #d1d5db',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
padding: '0 4px',
|
||||
}}
|
||||
>
|
||||
<Line />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
borderBottom: '1px solid #d1d5db',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
padding: '0 4px',
|
||||
}}
|
||||
>
|
||||
<div style={{ width: '80%' }}>
|
||||
<Line />
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
padding: '0 4px',
|
||||
}}
|
||||
>
|
||||
<div style={{ width: '60%' }}>
|
||||
<Line />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Frame>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cover;
|
@@ -38,6 +38,7 @@
|
||||
@import './patterns/drawer';
|
||||
@import './patterns/drop-area';
|
||||
@import './patterns/drop-cap';
|
||||
@import './patterns/dropdown';
|
||||
@import './patterns/fading-long-section';
|
||||
@import './patterns/feature-comparison';
|
||||
@import './patterns/feature-list';
|
||||
|
53
styles/patterns/_dropdown.scss
Normal file
53
styles/patterns/_dropdown.scss
Normal file
@@ -0,0 +1,53 @@
|
||||
.dropdown {
|
||||
position: relative;
|
||||
|
||||
/* Demo */
|
||||
width: 6rem;
|
||||
|
||||
align-items: flex-start;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.dropdown__trigger {
|
||||
cursor: pointer;
|
||||
|
||||
/* Demo */
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
height: 2rem;
|
||||
width: 6rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Hide the dropdown's content by default */
|
||||
.dropdown__content {
|
||||
display: none;
|
||||
|
||||
/* Position it right below the trigger element */
|
||||
left: 0;
|
||||
padding-top: 0.25rem;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
|
||||
/* It should be on the top of other elements */
|
||||
background-color: #fff;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.dropdown__body {
|
||||
/* Demo */
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
height: 6rem;
|
||||
width: 8rem;
|
||||
}
|
||||
|
||||
/* Show the content when hover on the container */
|
||||
.dropdown:hover .dropdown__content {
|
||||
display: block;
|
||||
}
|
Reference in New Issue
Block a user