mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-11 16:44:57 +02:00
feat: Update contents
This commit is contained in:
157
contents/upload-button.mdx
Normal file
157
contents/upload-button.mdx
Normal file
@@ -0,0 +1,157 @@
|
||||
---
|
||||
category: Input
|
||||
created: '2019-11-29'
|
||||
description: Create an upload button with CSS flexbox
|
||||
keywords: css file input, css flexbox, css upload button
|
||||
thumbnail: /assets/css-layout/thumbnails/upload-button.png
|
||||
title: Upload button
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="upload-button">
|
||||
<!-- The real file input -->
|
||||
<input type="file" class="upload-button__input" />
|
||||
|
||||
<!-- The upload icon -->
|
||||
<div class="upload-button__icon">...</div>
|
||||
|
||||
<!-- The label -->
|
||||
...
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.upload-button {
|
||||
/* Used to position the input */
|
||||
position: relative;
|
||||
|
||||
/* Center the content */
|
||||
align-items: center;
|
||||
display: flex;
|
||||
|
||||
/* Border */
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
}
|
||||
|
||||
.upload-button__input {
|
||||
/* Take the full size */
|
||||
height: 100%;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
|
||||
/* Make it transparent */
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.upload-button__icon {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
```
|
||||
|
||||
<Playground>
|
||||
```css placeholders.css hidden
|
||||
.lines {
|
||||
padding: 0.25rem 0;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
.line {
|
||||
background: #d1d5db;
|
||||
height: 1px;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
.line.line--20 {
|
||||
width: 20%;
|
||||
}
|
||||
.line.line--40 {
|
||||
width: 40%;
|
||||
}
|
||||
.line.line--60 {
|
||||
width: 60%;
|
||||
}
|
||||
.line.line--80 {
|
||||
width: 80%;
|
||||
}
|
||||
.line.line--100 {
|
||||
width: 100%;
|
||||
}
|
||||
```
|
||||
|
||||
```css styles.css hidden
|
||||
body {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.upload-button {
|
||||
/* Used to position the input */
|
||||
position: relative;
|
||||
|
||||
/* Center the content */
|
||||
align-items: center;
|
||||
display: flex;
|
||||
|
||||
/* Border */
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 0.25rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
|
||||
/* Demo */
|
||||
width: 8rem;
|
||||
}
|
||||
|
||||
.upload-button__input {
|
||||
/* Take the full size */
|
||||
height: 100%;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
|
||||
/* Make it transparent */
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.upload-button__icon {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
.upload-button__svg {
|
||||
fill: none;
|
||||
height: 1.5rem;
|
||||
stroke: #d1d5db;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
stroke-width: 1;
|
||||
width: 1.5rem;
|
||||
}
|
||||
```
|
||||
|
||||
```html index.html hidden
|
||||
<div class="upload-button">
|
||||
<input type="file" class="upload-button__input" />
|
||||
<div class="upload-button__icon">
|
||||
<svg class="upload-button__svg" viewBox="0 0 24 24">
|
||||
<path d="M18.5,7.5c0.275,0,0.341-0.159,0.146-0.354l-6.292-6.292c-0.195-0.196-0.512-0.196-0.707-0.001 c0,0-0.001,0.001-0.001,0.001L5.354,7.147C5.154,7.342,5.225,7.501,5.5,7.501h3v10c0,0.552,0.448,1,1,1h5c0.552,0,1-0.448,1-1V7.5 H18.5z M23.5,18.5v4c0,0.552-0.448,1-1,1h-21c-0.552,0-1-0.448-1-1v-4"></path>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="lines">
|
||||
<div class="line line--20"></div>
|
||||
<div class="line line--80"></div>
|
||||
<div class="line line--40"></div>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
</Playground>
|
Reference in New Issue
Block a user