پیشنمایش زنده
کد HTML
<div class="container">
<div class="drop-area">
<input
type="file"
class="file-input"
aria-label="Upload image file"
accept="image/svg+xml,image/png,image/jpeg,image/jpg,image/gif"
multiple=""
/>
<div class="file-section">
<div class="file-header">
<p class="file-title">Uploaded Files (4)</p>
<button class="add-button">
<svg
class="icon"
fill="none"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
>
<path d="M4 4v16h16V4H4zm8 1v14m7-7H5"></path>
</svg>
Add more
</button>
</div>
<div class="file-grid">
<div class="file-box">
<div class="preview-box">Image Preview</div>
<button class="remove-button" aria-label="Remove image">
<svg
class="icon"
fill="none"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
>
<path d="M18 6L6 18M6 6l12 12"></path>
</svg>
</button>
</div>
<div class="file-box">
<div class="preview-box">Image Preview</div>
<button class="remove-button" aria-label="Remove image">
<svg
class="icon"
fill="none"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
>
<path d="M18 6L6 18M6 6l12 12"></path>
</svg>
</button>
</div>
<div class="file-box">
<div class="preview-box">Image Preview</div>
<button class="remove-button" aria-label="Remove image">
<svg
class="icon"
fill="none"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
>
<path d="M18 6L6 18M6 6l12 12"></path>
</svg>
</button>
</div>
<div class="file-box">
<div class="preview-box">Image Preview</div>
<button class="remove-button" aria-label="Remove image">
<svg
class="icon"
fill="none"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
>
<path d="M18 6L6 18M6 6l12 12"></path>
</svg>
</button>
</div>
</div>
</div>
</div>
</div>
کد CSS
.container {
padding: 20px;
display: flex;
flex-direction: column;
gap: 16px;
}
.drop-area {
border: 2px dashed #444;
border-radius: 12px;
padding: 16px;
min-height: 200px;
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
overflow: hidden;
background-color: #1a1a1a;
}
.file-input {
display: none;
}
.file-section {
width: 100%;
display: flex;
flex-direction: column;
gap: 12px;
}
.file-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
}
.file-title {
font-size: 14px;
font-weight: 500;
color: #ccc;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.add-button {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 10px;
font-size: 14px;
color: #ccc;
border: 1px solid #555;
border-radius: 6px;
background-color: transparent;
cursor: pointer;
}
.add-button:hover {
background-color: #2a2a2a;
}
.icon {
width: 18px;
height: 18px;
opacity: 0.6;
}
.file-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
gap: 16px;
}
.file-box {
position: relative;
width: 100px;
height: 100px;
background-color: #2a2a2a;
border-radius: 8px;
}
.preview-box {
width: 100%;
height: 100%;
background-color: #444;
border-radius: inherit;
display: flex;
align-items: center;
justify-content: center;
font-size: 11px;
color: #aaa;
}
.remove-button {
position: absolute;
top: -8px;
right: -8px;
width: 24px;
height: 24px;
border-radius: 50%;
background-color: white;
color: black;
border: 2px solid white;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.remove-button .icon {
width: 14px;
height: 14px;
opacity: 1;
}