customizing a file button using css - html

I tried customizing a file upload button using css.
<label class="custom-file-input">
<input type="file" name="file" id="videofile" /> <!--class="dropzone"-->
</label>
Full Code in jsfiddle. https://jsfiddle.net/2e7dLvoy/
How can i show the file name that is choosen just like a normal file upload button?

Use this
HTML:
<div class="form-group upload_btn">
<div class="fileUpload pull-left">
<span>Browse</span>
<input type="file" class="upload " id="uploadBtn">
</div>
<input disabled="disabled" class="input pull-left" placeholder="Upload your resume" id="uploadFile">
</div>
Css:
.form-group.upload_btn {
overflow: hidden;
margin-bottom: 20px;
}
.fileUpload {
background: #e1e1e1 none repeat scroll 0 0;
color: #626262;
display: inline-block;
font-size: 18px;
font-weight: 300;
overflow: hidden;
padding: 5.5px 10px;
position: relative;
}
.pull-left {
float: left;
}
.fileUpload input.upload {
cursor: pointer;
font-size: 20px;
left: 0;
margin: 0;
opacity: 0;
padding: 0;
position: absolute;
top: 0;
}
.upload_btn .input {
width: 79%;
}
.input {
border: 0px;
padding: 8px;
box-shadow: none;
background-color: #fff;
}
Js:
document.getElementById("uploadBtn").onchange = function () {
document.getElementById("uploadFile").value = this.value;
};
Here is the jsfiddle link

try this:
fiddle with jquery: https://jsfiddle.net/2e7dLvoy/4/
HTML
<label class="custom-file-input">
<input type="file" name="file" id="videofile" /> <!--class="dropzone"-->
<p id="selectedFile"></p>
</label>
CSS
.custom-file-input {
display: inline-block;
position: relative;
color: #533e00;
}
.custom-file-input input {
visibility: hidden;
width: 100px
}
.custom-file-input:before {
content: 'Drag & Drop';
display: block;
background: -webkit-linear-gradient( -180deg, #ffdc73, #febf01);
background: -o-linear-gradient( -180deg, #ffdc73, #febf01);
background: -moz-linear-gradient( -180deg, #ffdc73, #febf01);
background: linear-gradient( -180deg, #ffdc73, #febf01);
border: 3px solid #dca602;
border-radius: 10px;
padding: 5px 0px;
outline: none;
white-space: nowrap;
cursor: pointer;
text-shadow: 1px 1px rgba(255,255,255,0.7);
font-weight: bold;
text-align: center;
font-size: 10pt;
position: absolute;
left: 0;
font-size: 12px;
}
.custom-file-input:hover:before {
border-color: #febf01;
}
.custom-file-input:active:before {
background: #febf01;
}
p {
float: left;
margin: -5% 14% 0% 32%;
}
jQuery
$('input[type=file]').change(function(e){
$in=$(this);
$('#selectedFile').html($in.val());
});

Related

Is the coding of the CSS incorrect? [duplicate]

This question already has an answer here:
How do I make :after box same size as parent and responsive? transform: scale(1) works, but why?
(1 answer)
Closed 2 years ago.
I have created a simple responsive login form. That allows the user to log-in and reset password. When filling out the username/password fields, both of these fields are mixed together and not on seperate lines. I have checked to see if the CSS layout was correct but I cannot seem to find a reason as to why the username and password fields do this.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: url(backgroundTwo.jpg) no-repeat center;
background-size: cover;
font-family: sans-serif;
}
.login {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
.form {
position: relative;
width: 100%;
max-width: 380px;
padding: 80px 40px 40px;
background: rgba(0, 0, 0, 0.7);
border-radius: 10px;
color: #fff;
box-shadow: 0 15px 25px rgba(0, 0, 0, 0.5);
}
.form::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 100%;
background: rgba(255, 255, 255, 0.08);
border-radius: 10px;
pointer-events: none;
}
.form img {
position: absolute;
top: -50px;
left: calc(50% - 50px);
width: 100px;
background: rgba(255, 255, 255, 0.8);
border-radius: 50%;
}
.form h2 {
text-align: center;
letter-spacing: 1px;
margin-bottom: 2rem;
color: #ff652f;
}
.form .input input {
width: 100%;
padding: 10px 0;
font-size: 1rem;
letter-spacing: 1px;
margin-bottom: 30px;
border: none;
border-bottom: 1px solid #fff;
outline: none;
background-color: transparent;
color: indianred;
}
.form .input label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 1rem;
pointer-events: none;
transition: .3s ease-out;
}
.form .input input:focus+label .form .input input:valid+label {
transform: translateY(-18px);
color: #ff652f;
font-size: .8rem;
}
.submit-button {
display: block;
margin-left: auto;
border: none;
outline: none;
background: #ff652f;
font-size: 1rem;
text-transform: uppercase;
letter-spacing: 1px;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.forgot-password {
color: inherit;
}
#forgot-password {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
top: 0;
left: 0;
right: 0;
height: 0;
z-index: #fff;
opacity: 0;
transition: 0.6s;
}
#forgot-password:target {
height: 100%;
opacity: 1;
}
.close {
position: absolute;
right: 1.5rem;
top: 0.5rem;
font-size: 2rem;
font-weight: 900;
text-decoration: none;
color: inherit;
}
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="LoginTwo.css">
<title>LoginFormTwo</title>
</head>
<body>
<div class="login">
<form action="" class="form">
<img src="avatarTwo.jpg" alt="">
<h2>Login</h2>
<div class="input">
<input type="text" name="loginUser" id="loginUser">
<label for="loginUser">User Name</label>
</div>
<div class="input">
<input type="password" name="loginPassword" id="loginPassword">
<label for="loginPassword">password</label>
</div>
<input type="submit" value="login" class="submit-button">
Forgot Password?
</form>
<div id="forgot-password">
<form action="" class="form">
×
<h2>Reset Password</h2>
<div class="input">
<input type="email" name="email" id="email" required>
<label for="email">Email</label>
</div>
<input type="submit" value="Submit" class="submit-button">
</form>
</div>
</div>
</body>
</html>
The problem I see here is that you didn't set a position: relative; to the <div> with class .input.
Since you set a position: absolute; to the label, its positioning is calculated from the closest parent with a position: relative; set. In your case, it's the <form> with class .form
Try adding these changes:
.form .input {
position: relative;
}
and adjust the top property of the label:
.form .input label {
top: -30px;
}
Here's a working Codepen
Hope this helps!
It's because your form is set to absolute so your labels are relative to the form.
By putting top: 0; your labels will be on top of the form. You can fix this by changing the .input position to relative like so:
.input {
position: relative;
}
And you can change the labels position by modifying the top value
.form .input label {
top: -25px /*or any value you want*/
}

fix position in a div css

I'm a new to css and i really can't fix all as i want...
How can i align vertical the h1 to the start of user form?
but most important problem for me is that i can't center good the check and the link, i want it one below the other and centered in the div.
I'm not sure if i have positioned good the div but i want it centred but not too low on the page.
thanks to everyone!
body {
text-align: left;
background-image: url("img/lemon.jpg");
color: #1b1b1b;
}
input[type=text],
input[type=password]{
width: 65%;
display: table;
margin: 0 auto;
padding: 12px 20px;
border: none;
border-bottom: 1px solid darkgray;
background-color: #e9e9e9;
box-sizing: border-box;
margin-bottom: 7px;
resize: vertical;
}
h1 {
font-size: x-large;
}
h2 {
font-size: x-large;
}
button {
background-color: #4CAF50;
color: white;
padding: 7px 20px;
width: 65%;
height: 20%;
display: table;
margin: 0 auto;
border: none;
cursor: pointer;
background: linear-gradient(to bottom, #3d94f6 5%, #1e62d0 100%);
background-color: #3d94f6;
border: 1px solid #337fed;
cursor: pointer;
color: #ffffff;
font-size: 17px;
text-decoration: none;
text-shadow: -1px 1px 1px #1570cd;
}
button:hover {
background: linear-gradient(to bottom, #1e62d0 5%, #3d94f6 100%);
background-color: #1e62d0;
}
button:active {
position: relative;
top: 1px;
}
.container {
width: 35%;
height: auto;
margin-right: auto;
margin-left: auto;
margin-top: 7%;
background-color: white;
box-shadow: 2px 2px 11px rgb(11, 11, 11);
-webkit-box-shadow: 2px 2px 11px rgb(11, 11, 11);
-moz-box-shadow: 2px 2px 11px rgb(11, 11, 11);
overflow: hidden;
}
#check {
display:block;
margin-top: 7px;
}
span.frgt {
margin-top: 7px;
display: block;
}
a {
text-decoration: none;
color: #1e62d0;
}
img {
width: 100%;
height: auto;
opacity: 0.4;
}
<!DOCTYPE html>
<head>
</head>
<body>
<div class="container">
<h1>Login</h1>
<input type="text" placeholder="Username" name="uname" required>
<input type="password" placeholder="password" name="psw" required>
<button type="submit">Login</button>
<hr>
<label id="check">
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
<span class="frgt">forgot password?</span>
</div>
</body>
</html>
If you set the h1 to the same width of the button and use "margin: 0 auto" to center it, this will make the h1 span the width of the button, and by default the text will be left aligned to the start of the button.
h1 {
font-size: x-large;
width: 65%;
margin: 0 auto;
}
I'm not too sure exactly what you want to do with the check section. If you use "text-align: center", this will center it, or use the same code as above to align it with the buttons.
you can use text-align: center; and vertical-align:top;
If your problem still exists, please explain more clearly what you want.
Use text-align: center; to center text within container.
To make it easier to align your elements, just wrap them into one div and adjust the div with CSS instead of dealing with each single element.
Here is an example of what you can do.
body {
text-align: left;
background-image: url("img/lemon.jpg");
color: #1b1b1b;
}
.form {
width: 75%;
margin: auto;
}
.form-bottom {
text-align: center;
}
input[type=text],
input[type=password] {
display: table;
margin: 0 auto;
width: 100%;
padding: 12px 20px;
border: none;
border-bottom: 1px solid darkgray;
background-color: #e9e9e9;
box-sizing: border-box;
margin-bottom: 7px;
resize: vertical;
}
h1 {
font-size: x-large;
}
h2 {
font-size: x-large;
}
button {
background-color: #4CAF50;
color: white;
padding: 7px 20px;
height: 20%;
width: 100%;
display: table;
margin: 0 auto;
border: none;
cursor: pointer;
background: linear-gradient(to bottom, #3d94f6 5%, #1e62d0 100%);
background-color: #3d94f6;
border: 1px solid #337fed;
cursor: pointer;
color: #ffffff;
font-size: 17px;
text-decoration: none;
text-shadow: -1px 1px 1px #1570cd;
}
button:hover {
background: linear-gradient(to bottom, #1e62d0 5%, #3d94f6 100%);
background-color: #1e62d0;
}
button:active {
position: relative;
top: 1px;
}
.container {
width: 35%;
height: auto;
margin-right: auto;
margin-left: auto;
margin-top: 7%;
background-color: white;
box-shadow: 2px 2px 11px rgb(11, 11, 11);
-webkit-box-shadow: 2px 2px 11px rgb(11, 11, 11);
-moz-box-shadow: 2px 2px 11px rgb(11, 11, 11);
overflow: hidden;
}
#check {
display: block;
margin-top: 7px;
}
span.frgt {
margin-top: 7px;
display: block;
}
a {
text-decoration: none;
color: #1e62d0;
}
img {
width: 100%;
height: auto;
opacity: 0.4;
}
<body>
<div class="container">
<div class="form">
<h1>Login</h1>
<input type="text" placeholder="Username" name="uname" required>
<input type="password" placeholder="password" name="psw" required>
<button type="submit">Login</button>
</div>
<hr>
<div class="form-bottom">
<label id="check">
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
<span class="frgt">forgot password?</span>
</div>
</div>
</body>

In Dual Slider HTML component, click inside first element is not recognized in Internet Explorer

I am trying to build a Dual Step Slider using HTML and CSS alone without any JQuery. It is working fine in Chrome and Mozilla, But in IE11, it is not registering the click inside first input element.
I designed the slider by using position:absolute and made two html input sliders on top of each other. In IE, i could click and drag on Second Input Elemenr only.
.slider {
-webkit-appearance: none;
width: 100%;
//height: 10px;
position: absolute;
//background: #f3f3f3;
outline: none;
border-radius: 8px;
}
.slider input {
pointer-events: none;
position: absolute;
overflow: hidden;
left: 25%;
top: 15px;
width: 50%;
outline: none;
height: 18px;
margin: 0;
padding: 0;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 8px;
background: #E6E6E6;
border: none;
border-radius: 3px;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
//border: none;
height: 20px;
width: 20px;
border-radius: 50%;
background: white;
border: 1px solid #3972D6;
margin-top: -4px;
cursor: pointer;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #e6e6e6;
border: 2px solid #cdcdcd;
pointer-events: all;
position: relative;
z-index: 1;
outline: 0;
}
.slider::-moz-range-thumb {
width: 20px;
height: 20px;
background: #ea4550;
pointer-events: all;
position: relative;
z-index: 10;
-moz-appearance: none;
}
.slider input::-moz-range-track {
position: relative;
z-index: -1;
border: 0;
}
.slider input:last-of-type::-moz-range-track {
-moz-appearance: none;
background: none transparent;
border: 0;
}
.slider input[type="range"]::-moz-focus-outer {
border: 0;
}
.flex-next {
display: flex;
justify-content: flex-start;
}
.dual-slider-container {
position: relative;
width: 100%;
}
.dual-slider-text-left {
position: relative;
bottom: 12px;
right: 8px;
.text-style {
color: #303030;
font-size: 20px;
font-weight: 600;
text-align: right;
}
.text2 {
text-align: right;
font-size: 14px;
}
}
.dual-slider-text-right {
position: relative;
bottom: 12px;
left: 8px;
.text-style {
color: #303030;
font-size: 20px;
font-weight: 600;
text-align: left;
}
.text2 {
text-align: left;
font-size: 14px;
}
}
.pointer {
cursor: pointer;
}
//Internet Explorer Support
input[type=range]::-ms-track {
width: 100%;
height: 8px;
/*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */
background: transparent;
/*leave room for the larger thumb to overflow with a transparent border */
border-color: transparent;
border-width: 6px 0;
/*remove default tick marks*/
color: transparent;
}
#lower::-ms-fill-lower {
background: #E6E6E6;
border-radius: 10px;
}
#lower::-ms-fill-upper {
background: #E6E6E6;
border-radius: 10px;
}
#higher::-ms-fill-lower {
background: transparent;
border-radius: 10px;
}
#higher::-ms-fill-upper {
background: transparent;
border-radius: 10px;
}
input[type=range]::-ms-thumb {
//border: none;
height: 18px;
width: 18px;
border-radius: 50%;
background: white;
border: 1px solid #3972D6;
//cursor: hand;
}
input[type=range]::-ms-tooltip {
display: none;
}
<div style="padding:8px" class="col-12 row m-0">
<div class="dual-slider-text-left col-2 p-0">
<div class="text-style">
{{minValue}}
</div>
<div class="text2">{{minValueText}}</div>
</div>
<div class="col-8 p-0">
<div class="dual-slider-container">
<input (click)="getSliderOneValue($event)" type="range" min="{{minValue}}" max="{{maxValue}}" step="1"
value="{{sliderOneValue}}"
class="slider" [disabled]="disabled" [ngClass]="{'pointer' : !disabled}"
id="lower">
</div>
<div class="dual-slider-container">
<input (click)="getSliderTwoValue($event)" type="range" min="{{minValue}}" max="{{maxValue}}" step="1"
value="{{sliderTwoValue}}"
class="slider" [disabled]="disabled" [ngClass]="{'pointer' : !disabled}"
id="higher">
</div>
</div>
<div class="dual-slider-text-right col-2 p-0">
<div class="text-style">{{maxValue}}</div>
<div class="text2">{{maxValueText}}</div>
</div>
</div>
It seems that you can only reach the second slider if they're lapped in IE. You could use two slides side by side as a workaround. I make a demo and you could refer to it.
body {
min-height: 100px;
}
div {
display: flex;
}
input {
flex: 1 0 0;
min-width: 0;
padding: 0;
}
input::-webkit-slider-thumb {
margin: 0;
padding: 0;
}
output {
display: block;
text-align: center;
margin-top: 3px;
color: gray;
}
<div>
<input id="a" type="range" min="0" max="10" value="0" />
<input id="b" type="range" min="11" max="20" value="20" />
</div>
<output></output>

CSS content Property not working as expected in firefox

What i am doing is that in search box when user enter a search term, i display a close button ('x' character to be specific, embedded as content after reset button) to clear the contents of search box.
It works fine in both Chrome and IE but not in firefox.
Any kind of help would be highly appreciated.
.search-box,.close-icon,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent;
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
}
.close-icon:after {
content: "X";
display: block;
width: 15px;
height: 15px;
position: absolute;
z-index:1;
right: 35px;
top: 0;
bottom: 0;
margin: auto;
padding: 2px;
border-radius: 50%;
text-align: center;
color: black;
font-weight: normal;
font-size: 12px;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
<div class="search-wrapper">
<form>
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset"></button>
</form>
</div>
This code should help you
.search-box,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box
{
width:300px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent,
display: inline-block;
vertical-align: middle;
outline: 0;
position: absolute;
top:19px;
left:305px;
z-index:1;
padding: 1px 2px;
border-radius: 50%;
text-align: center;
color: black;
font-weight: normal;
font-size: 12px;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
<div class="search-wrapper">
<form>
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset">X</button>
</form>
</div>
NOTE : set your .search-box width and according to it set left of your .close-icon
Try this code: Hope this solve your problem. Adjust "outer_box" class for width.
<style>
.search-box, .search-wrapper {
padding: 10px;
box-sizing: border-box;
}
.search-box {
position:relative;
width:100%;
}
.outer_boxs{
position:relative;
width:60%;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent,
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
position: absolute;
right:5px;
top: 10px;
background:#f2f2f2;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
</style>
<div class="search-wrapper">
<form>
<div class="outer_boxs" >
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset">X</button>
</div>
</form>
</div>

how I could hover in the label upload and submit button in order to change the background and text

I use this code due to design upload and submit button does not use jquery or Javascript. I need to change upload and submit button background color and text color when hover it.
This is the code : JS Fiddle
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.inputBtnSection {
display: inline-block;
vertical-align: top;
font-size: 0;
font-family: verdana;
}
.disableInputField {
display: inline-block;
vertical-align: top;
height: 27px;
margin: 0;
font-size: 14px;
padding: 0 3px;
}
.fileUpload {
position: relative;
overflow: hidden;
border: solid 1px gray;
display: inline-block;
vertical-align: top;
}
.fileUpload2 {
position: relative;
overflow: hidden;
border: solid 1px gray;
display: inline-block;
vertical-align: top;
}
.uploadBtn {
display: inline-block;
vertical-align: top;
background: rgba(0, 0, 0, 0.5);
font-size: 14px;
padding: 0 10px;
height: 25px;
line-height: 22px;
color: #fff;
}
.uploadBtn2 {
display: inline-block;
vertical-align: top;
background: rgba(0, 0, 0, 0.5);
font-size: 14px;
padding: 0 10px;
height: 25px;
line-height: 22px;
color: #fff;
}
.fileUpload input.upload {
top: 0;
position: absolute;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
}
.fileUpload2 input.submit {
top: 0;
position: absolute;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
}
<div class="formulir">
<form action="php/upload.php" method="post" enctype="multipart/form-data">
<div class="inputBtnSection">
<input id="uploadFile" class="disableInputField" placeholder="Choose File" disabled="disabled" />
<label class="fileUpload">
<input id="uploadBtn" type="file" class="upload" name="fileToUpload" />
<span class="uploadBtn">Browse File</span>
</label>
</div>
<label class="fileUpload2">
<input id="uploadtn2" type="submit" value="Upload Image" name="submit" class="submit">
<span class="uploadBtn2">upload</span>
</label>
</form>
</div>
Here is the Fiddle
Just added :hover class to the elements.
CSS:
.fileUpload:hover {
background-color: rgba(0, 0, 256, 0.5);
transition: all 0.25s;
}
.fileUpload2:hover {
background-color: green;
transition: all 0.25s;
}
You may try adding this to your css script:
.uploadBtn:hover{
display: inline-block;
vertical-align: top;
background: [the color on hover]
font-size: 14px;
padding: 0 10px;
height: 25px;
line-height: 22px;
color: #fff;
}
So I have only added :hover after the class name. Then do the same to the submit button.
Just add an :hover after your class. You only need to add the nessesary changes not everything.
.uploadBtn {
display:inline-block;
vertical-align:top;
background:rgba(0,0,0,0.5);
font-size:14px;
padding:0 10px;
height:25px;
line-height:22px;
color:#fff;}
.uploadBtn:hover {
background: [your new color];
color: [your new color];
}