i create a form where i upload image into database where i create icon input to select the image i want to convert that icon into that picture which i select after slecting the picture.
<label class="custom-file-upload">
<input asp-for="imge1" name="imge1" type="file" />
<i class="fa fa-camera"></i>
CSS
input[type="file"] {
display: none;
}
.custom-file-upload {
border: 1px solid #ccc;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
height: 80px;
width: 100px;
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
color: var(--primary-color);
}
Using readAsDataURL you can get file path and set to img tag.
jQuery(document).ready(function() {
var readURL = function(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('.input-img').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("input[type='file']").on('change', function() {
readURL(this);
});
});
.custom-input-file {
position: relative;
cursor:pointer;
}
.custom-input-file .input-file-wrapper {
height: 150px;
width: 150px;
border-radius: 10px;
position: relative;
}
.custom-input-file .input-file-wrapper .input-img {
height: 100%;
-o-object-fit: cover;
object-fit: cover;
border: 1px solid #ced4da;
border-radius: 10px;
width: 100%;;
}
.custom-input-file .input-file-wrapper input[type=file] {
position: absolute;
left: 0;
width: 100%;
height: 100%;
padding: 0;
opacity: 0;
top: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div class="input-wrapper">
<div class="custom-input-file ">
<div class="input-file-wrapper ">
<img src="https://storage.googleapis.com/proudcity/mebanenc/uploads/2021/03/placeholder-image.png " class="input-img">
<input type="file" class="form-control ">
</div>
</div>
</div>
little bit change and add some javascrpt and jquery in it.
firslty add this
<div class="form">
<div class="grid">
<div class="form-element">
<input type="file" id="file-1" asp-for="imge1" name="imge1">
<label for="file-1" id="file-1-preview">
<div>
<span>+</span>
</div>
</label>
</div>
</div>
</div>
then add this javascript and jquery
<script>
function previewBeforeUpload(id){
document.querySelector("#"+id).addEventListener("change",function(e){
if(e.target.files.length == 0){
return;
}
let file = e.target.files[0];
let url = URL.createObjectURL(file);
document.querySelector("#"+id+"-preview div").innerText = file.name;
document.querySelector("#"+id+"-preview img").src = url;
});
}
previewBeforeUpload("file-1");
previewBeforeUpload("file-2");
previewBeforeUpload("file-3");
previewBeforeUpload("file-4");
previewBeforeUpload("file-5");
previewBeforeUpload("file-6");
previewBeforeUpload("file-7");
previewBeforeUpload("file-8");
previewBeforeUpload("file-9");
previewBeforeUpload("file-10");
</script>
Also add this CSS
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
font-family: "Raleway",sans-serif;
background: #f8f8f8;
}
.form {
margin: 20px 0px 20px;
padding: 0px 10px;
}
.form h2 {
text-align: center;
color: #acacac;
font-size: 12px;
font-weight: 100;
}
.form .grid {
margin-top: 5px;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
gap: 20px;
}
.form .grid .form-element {
width: 80px;
height: 80px;
box-shadow: 0px 0px 20px 5px rgba(100,100,100,0.1);
}
.form .grid .form-element input {
display: none;
}
.form .grid .form-element img {
width: 80px;
height: 80px;
object-fit: cover;
}
.form .grid .form-element div {
position: relative;
height: 30px;
margin-top: -40px;
background: rgba(0,0,0,0.5);
text-align: center;
line-height: 40px;
font-size: 13px;
color: #f5f5f5;
font-weight: 600;
}
.form .grid .form-element div span {
font-size: 15px;
}
I have the following antd Tabs. How to get rid of the ... button on the right? (Note that it disappears when the screen width is decreased.)
The structure is like this:
<Tabs type="card">
<TabPane tab="A">
.....
</TabPane>
<TabPane tab="B">
.....
</TabPane>
</Tabs>
This is the style:
.ant-tabs-tab {
flex-grow: 1;
margin-right: 0px;
width: 100%;
height: 50px;
text-align: center;
font-weight: bold;
font-size: 15px;
justify-content: center;
color: #94a3ac;
}
.ant-tabs-nav-list {
width: 100%;
border-bottom: 6px solid #093150;
}
.ant-tabs-top > .ant-tabs-nav {
margin-bottom: 0;
}
.ant-tabs-card > .ant-tabs-nav .ant-tabs-tab {
border: none;
background-color: rgba(255, 255, 255, 0.68);
}
.ant-tabs-tab-active {
background-color: #093150 !important;
.ant-tabs-tab-btn {
color: white !important;
}
just add this code in your css :
ant-tabs-nav-more { display: none; }
You can inspect element like this
then add code in your css:
.ant-tabs-nav-operations {
display: none !important;
}
I created a custom 'searchbox'. The 'searchbox' actually built by a div and input text inside it.
Later on I will add a 'search' icon on the left and 'clear' button on the right.
The issue is, the input inside the div already sized based on it's container and when I'm focusing the input text, I couldn't find a way to expand the parent div (instead of the input itself). It's important the div will expand so the icons and buttons I will later add - will expand with the input.
Couldn't find a way doing it with CSS only (without JS).
Will appreciate your assistance!
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
.App {
width: 100%;
height: 200px;
background-color: tan;
}
.fieldcontainer {
display: flex;
padding-left: 8px;
background-color: #CCCCCC;
border-color: grey;
width: 300px;
min-height: 35px;
align-items: center;
justify-content: space-between;
border-radius: 8px;
cursor: default;
transition: 'background-color' 0.4s;
}
.fieldcontainer:hover {
background-color: #C3C3C3;
}
.searchfield {
background-color: inherit;
font-size: 1em;
border: 0;
flex-grow: 8;
transition: all 0.4s linear;
}
.searchfield:focus {
outline: none;
width: 100%;
}
</style>
</head>
<body>
<div class="App">
<div class="fieldcontainer">
<input class="searchfield" type="text" placeholder="search" />
</div>
</div>
</body>
</html>
Use focus-within (https://developer.mozilla.org/fr/docs/Web/CSS/:focus-within)
* {
box-sizing: border-box;
}
.App {
height: 200px;
background-color: tan;
}
.fieldcontainer {
display: flex;
padding-left: 8px;
background-color: #CCCCCC;
border-color: grey;
width: 300px;
min-height: 35px;
align-items: center;
justify-content: space-between;
border-radius: 8px;
cursor: default;
transition: 0.4s;
}
.fieldcontainer:hover {
background-color: #C3C3C3;
}
.searchfield {
background-color: inherit;
font-size: 1em;
border: 0;
flex-grow: 8;
transition: all 0.4s linear;
outline:none;
}
.fieldcontainer:focus-within {
width: 100%;
}
<div class="App">
<div class="fieldcontainer">
<input class="searchfield" type="text" placeholder="search" />
</div>
</div>
I'm working on an image grid feature in which images are being displayed. I'm facing issue regarding creating an expandable/collapsable div.
HTML
<div *ngIf="Display('images')">
<section class="image-grid" *ngFor="let item of items$|async">
<div class="image__cell is-collapsed">
<div class="image--basic">
<img (click)="expandImage()" class="basic__img" src="{{item.link}}">
</div>
<div class="image--expand" [ngClass]="{'image--expand': !_expand}">
<a class="expand__close"></a>
<img class="image--large" src="{{item.link}}">
</div>
</div>
</section>
</div>
.ts file
private _maxHeight: string;
private _marginBottom: string;
private _expand: boolean = false;
expandImage() {
this._expand = !this._expand;
this._maxHeight = '500px';
this._marginBottom = '10px';
}
CSS
.image-grid {
width: 100%;
padding-right: 30px;
padding-left: 30px;
}
.image__cell {
float: left;
position: relative;
}
.basic__img {
height: 200px;
max-width: 100%;
float: left;
overflow: hidden;
}
.image__cell.is-collapsed {
overflow: hidden;
padding: 0.6%;
}
.image__cell.is-collapsed .image--basic {
cursor: pointer;
}
.image--expand {
position: relative;
left: -5px;
padding: 0 5px;
box-sizing: content-box;
overflow: hidden;
background-color: #222;
max-height: 0;
transition: max-height .3s ease-in-out,margin-bottom .1s .2s;
}
.expand__close {
position: absolute;
top: 10px;
right: 20px;
color: #454545;
font-size: 50px;
line-height: 50px;
text-decoration: none;
}
.expand__close:before {
content: '×';
}
.expand__close:hover {
color: #fff;
}
.image--large {
max-width: 100%;
height: auto;
display: block;
padding: 40px;
margin: 0 auto;
box-sizing: border-box;
}
The code above creates an expandable div. But the problem is whenever, I click on any one image, the div gets expanded in each row. I'm trying to create similar to this: Recreating image-viewer. It would be great if someone can help me out in this. Thanks. :)
I am guessing here,
Pass clicked key to this functions (click)="expandImage(item.$key)"
and in your code
expandImage(key) {
this._expand = !this._expand;
this.clickedItem = key;
this._maxHeight = '500px';
this._marginBottom = '10px';
}
and in your template
<div class="image--expand" *ngIf="clickedItem == item.$key" [ngClass]="{'image--expand': !_expand}">
<a class="expand__close"></a>
<img class="image--large" src="{{item.link}}">
</div>
I have created a flexbox container that acts as a form control with two input fields, representing a range between two dates. If the user has entered something into any of the two fields a cross appears next to that field. The user can click on this cross to clear the field.
The cross is an :after pseudo-element, created and interacted with, with some nifty css and JavaScript, largely based on this answer on Stack Overflow. Here's my implementation (somewhat simplified, but not much):
$('.field.clearable').on('change input', 'input', function($e) {
$(this).parent().toggleClass('non-empty', !!this.value);
})
.on('mousemove', 'span.non-empty', function($e) {
var $this = $(this);
$this.toggleClass('onX', $this.width() < $e.clientX - $this.offset().left);
$this.hasClass('onX') ? $this.attr('title', 'Clear field') : $this.removeAttr('title');
})
.on('mouseleave', 'span.non-empty', function($e) {
var $this = $(this);
$this.removeClass('onX')
.removeAttr('title');
})
.on('click', 'span.non-empty.onX', function($e) {
$e.preventDefault();
var $this = $(this);
$this.removeClass('non-empty onX')
.removeAttr('title')
.children('input')
.val('')
.trigger('clear');
});
/* reset and cosmetic css */
* {
margin: 0;
padding: 0;
color: inherit;
font-family: inherit;
font-size: inherit;
}
::-webkit-input-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
:-moz-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
::-moz-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
:-ms-input-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
:focus::-webkit-input-placeholder {
opacity: .5;
}
:focus:-moz-placeholder {
opacity: .5;
}
:focus::-moz-placeholder {
opacity: .5;
}
:focus:-ms-input-placeholder {
opacity: .5;
}
html {
font-family: Arial;
font-size: 10px;
font-weight: normal;
text-align: left;
height: 100%;
}
body {
margin: 4em auto;
width: 400px;
color: #2c5ba0;
font-size: 1.5rem;
line-height: 1.5em;
background-color: #fff;
}
/* relevant css */
div.field {
display: inline-block;
margin: .4em 0;
}
div.field>label {
display: block;
margin: 0 0 .3em .2em;
font-size: 80%;
line-height: 1em;
}
div.field>span {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: space-between;
justify-content: space-between;
box-sizing: border-box;
height: 2em;
border: .1em solid #ddd;
background-color: #fff;
}
div.field>span>span {
-webkit-flex: 1;
flex: 1;
}
div.field>span>span>input {
width: 100%;
border: none;
}
div.field.range>span input {
text-align: center;
}
div.field.range>span label {
-webkit-flex: 0;
flex: 0;
margin: 0 .2em;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
div.field.clearable span.non-empty {
position: relative;
padding-right: 2em;
}
div.field.clearable span.non-empty:after {
position: absolute;
right: 0;
top: 0;
content: 'x';
display: inline-block;
width: 2em;
height: 2em;
color: #ddd;
vertical-align: middle !important;
text-align: center !important;
font-style: normal !important;
font-weight: normal !important;
text-transform: none !important;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: pointer;
}
div.field.clearable span.non-empty.onX:after {
color: #f37e31;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="field clearable range">
<label for="start">created</label>
<span>
<span>
<input type="text" id="start" placeholder="from">
</span>
<label for="end">–</label>
<span>
<input type="text" id="end" placeholder="until">
</span>
</span>
</div>
When both <input> fields contain values and thus have a cross next to them, their width-ratios cancel each other out nicely and nothing is wrong. However, when only one of the <input> fields contains a value and the cross appears next to only that <input> field, the cross / <input> field nudges the other content aside.
This is not supposed to happen. I suspect the <input> fields are the culprit. Even though the container div.field should keep its display: block flexibility, the ratios of the inner content should stay constant.
Here are the relevant bits I thought I could achieve this with:
/* the span that acts as the flexbox container */
div.field>span {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: space-between;
justify-content: space-between;
box-sizing: border-box;
height: 2em;
border: .1em solid #ddd;
}
/* let the spans, containing the <input> fields, take available space */
div.field>span>span {
-webkit-flex: 1;
flex: 1;
}
/*
let <input> fields take 100% content space of span
I thought this should take into account any padding on its parent
*/
div.field>span>span>input {
width: 100%;
border: none;
}
/* let center label (the dash) not be flexible */
div.field.range>span label {
-webkit-flex: 0;
flex: 0;
margin: 0 .2em;
}
/* if .non-empty class was set by JavaScript */
/*
make room for :after by setting padding-right accordingly
but this is the issue:
I thought this would also make the <input> shrink accordingly,
but it appears it doesn't shrink the amount I anticipated
*/
div.field.clearable span.non-empty {
position: relative;
padding-right: 2em;
}
/* show :after pseudo-element */
div.field.clearable span.non-empty:after {
position: absolute;
right: 0;
top: 0;
content: 'x';
display: inline-block;
width: 2em;
height: 2em;
/* etc. */
}
Do you know how I can let the complete control element maintain its flexibility, including its :after trickery, but have the <input>s shrink accordingly, when one of the crosses appear?
Or put more simply, I guess: is there a way to let two flex-items, with flex: 1, both take up an equal amount of space, at any given time?
The reason I'm using :after elements and not background-image like in the original answer I took the inspiration from, is because I'm using a custom icon font and not icon images.
However, when only one of the fields contains a value and the
cross appears next to only that field, the cross /
field nudges the other content aside.
This is not supposed to happen. I suspect the fields are the
culprit. Even though the container div.field should keep its display:
block flexibility, the ratios of the inner content should stay
constant.
This is because of the way your elements are structured for the close button trickery. Typically the padding on spans which then causes the flex items to gain or lose their size and affect the flex layout. But, if you remove the padding, then you would have a hard time calculating the offset for click-to-close.
Also, you have to keep on tinkering with the width and computing the position of mouse cursor on mousemove to keep the close button working.
One of the possible better solutions would be to use padding on inputs instead, and use only the position and opacity of the pseudo-element to work out the appearance and disappearance of the close button. This will keep the flex working without problems.
Then, rather than tracking the mousemove, you simply check the click on the span.
Example Fiddle (no jQuery): http://jsfiddle.net/abhitalks/4fnvukc2/
Example Snippet:
var closers = document.querySelectorAll('.closer'),
inputs = document.querySelectorAll('.closer input');
for (i=0; i < closers.length; i++) {
closers[i].addEventListener('click', clearer);
}
for (i=0; i < inputs.length; i++) {
inputs[i].addEventListener('input', closer);
}
function clearer(e) {
if (e.target.tagName == 'SPAN') {
e.target.firstElementChild.value = '';
e.target.classList.remove('dirty');
}
}
function closer(e) {
e.stopPropagation();
e.target.parentElement.classList.add('dirty');
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-size: 1em; font-family: sans-serif;}
div.field {
margin: 4em;
display: flex; justify-content: space-between;
}
span.closer {
display: inline-block; position: relative;
flex: 1 1 auto;
}
span.sep { flex: 0 1 auto; margin: 0 1em;}
span.closer::before {
content: '×'; font-weight: bold;
position: absolute;
right: -10px; top: 4px; opacity: 0;
transition: all 0.2s ease-out;
}
span.closer.dirty::before {
right: 6px; opacity: 1; cursor: pointer;
}
span.closer.dirty:hover::before { color: #00f; }
.closer input { padding: 3px 16px 3px 4px; width: 100%; }
::-webkit-input-placeholder { color: #ccc; }
:-moz-placeholder { color: #ccc; }
<div class="field range">
<span class="closer">
<input type="text" id="start" placeholder="from" />
</span>
<span class="sep">–</span>
<span class="closer">
<input type="text" id="end" placeholder="until" />
</span>
</div>
If you drop the padding-rightand resize the input it will work
You need to fix the click handler though
div.field.clearable span.non-empty {
position: relative;
}
div.field.clearable span.non-empty input {
width: calc(100% - 2em);
}
$('.field.clearable').on('change input', 'input', function($e) {
$(this).parent().toggleClass('non-empty', !!this.value);
})
.on('mousemove', 'span.non-empty', function($e) {
var $this = $(this);
$this.toggleClass('onX', $this.width() < $e.clientX - $this.offset().left);
$this.hasClass('onX') ? $this.attr('title', 'Clear field') : $this.removeAttr('title');
})
.on('mouseleave', 'span.non-empty', function($e) {
var $this = $(this);
$this.removeClass('onX')
.removeAttr('title');
})
.on('click', 'span.non-empty.onX', function($e) {
$e.preventDefault();
var $this = $(this);
$this.removeClass('non-empty onX')
.removeAttr('title')
.children('input')
.val('')
.trigger('clear');
});
/* reset and cosmetic css */
* {
margin: 0;
padding: 0;
color: inherit;
font-family: inherit;
font-size: inherit;
}
::-webkit-input-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
:-moz-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
::-moz-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
:-ms-input-placeholder {
color: #ccc;
font-size: 80%;
opacity: .8;
}
:focus::-webkit-input-placeholder {
opacity: .5;
}
:focus:-moz-placeholder {
opacity: .5;
}
:focus::-moz-placeholder {
opacity: .5;
}
:focus:-ms-input-placeholder {
opacity: .5;
}
html {
font-family: Arial;
font-size: 10px;
font-weight: normal;
text-align: left;
height: 100%;
}
body {
margin: 4em auto;
width: 400px;
color: #2c5ba0;
font-size: 1.5rem;
line-height: 1.5em;
background-color: #fff;
}
/* relevant css */
div.field {
display: inline-block;
margin: .4em 0;
}
div.field>label {
display: block;
margin: 0 0 .3em .2em;
font-size: 80%;
line-height: 1em;
}
div.field>span {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: space-between;
justify-content: space-between;
box-sizing: border-box;
height: 2em;
border: .1em solid #ddd;
background-color: #fff;
}
div.field>span>span {
-webkit-flex: 1;
flex: 1;
}
div.field>span>span>input {
width: 100%;
border: none;
}
div.field.range>span input {
text-align: center;
}
div.field.range>span label {
-webkit-flex: 0;
flex: 0;
margin: 0 .2em;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
div.field.clearable span.non-empty {
position: relative;
}
div.field.clearable span.non-empty input {
width: calc(100% - 2em);
}
div.field.clearable span.non-empty:after {
position: absolute;
right: 0;
top: 0;
content: 'x';
display: inline-block;
width: 2em;
height: 2em;
color: #ddd;
vertical-align: middle !important;
text-align: center !important;
font-style: normal !important;
font-weight: normal !important;
text-transform: none !important;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: pointer;
}
div.field.clearable span.non-empty.onX:after {
color: #f37e31;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="field clearable range">
<label for="start">created</label>
<span>
<span>
<input type="text" id="start" placeholder="from">
</span>
<label for="end">–</label>
<span>
<input type="text" id="end" placeholder="until">
</span>
</span>
</div>