I have a image when hovered should show a small pencil icon to change upload new image. I am new to css, I have set the visibility of the icon to hidden by default. But when i change the visibility on hover to visible. It doesn;t show up.
<div class="col-lg-3">
<img id = "personal_profile_pic" src = "https://x1.xingassets.com/assets/frontend_minified/img/users/nobody_m.original.jpg">
<a href="#">
<span id="upload_pic_icon">
<label for="avatar" id="avatar_label">
<i class="fa fa-pencil" aria-hidden="true"></i>
</label>
</span>
</a>
<form id="change_pic_form">
<input type="file" name="avatar" id="avatar">
</form>
</img>
</div>
Here is my css
#upload_pic_icon{
margin-left: 62%;
margin-top: -25%;
display: block;
position: absolute;
visibility: hidden;
}
#personal_profile_pic:hover #upload_pic_icon{
visibility: visible;
}
I don't understand how to go about this.
You need to use + selector , it will select #upload_pic_icon that are placed immediately after #personal_profile_pic
#upload_pic_icon{
margin-left: 62%;
margin-top: -25%;
display: block;
position: absolute;
visibility: hidden;
}
#personal_profile_pic:hover + #upload_pic_icon {
visibility: visible;
}
<link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css">
<div class="col-lg-3">
<img width="200" id="personal_profile_pic" src="https://x1.xingassets.com/assets/frontend_minified/img/users/nobody_m.original.jpg">
<a href="#" id="upload_pic_icon">
<span>
<label for="avatar" id="avatar_label">
<i class="fa fa-pencil" aria-hidden="true"></i>
</label>
</span>
</a>
<form id="change_pic_form">
<input type="file" name="avatar" id="avatar">
</form>
</div>
Or you can wrap img and edit in div and the set hover on .wrap, and use display:none instead.
.wrap {
position: relative;
display: inline-block;
}
.wrap #upload_pic_icon {
display: none;
position: absolute;
top: 10px;
right: 10px;
}
.wrap:hover #upload_pic_icon {
display: block;
}
<link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css">
<div class="col-lg-3">
<div class=wrap>
<img width="200" id="personal_profile_pic" src="https://x1.xingassets.com/assets/frontend_minified/img/users/nobody_m.original.jpg">
<a href="#" id="upload_pic_icon">
<label class="fa fa-pencil" for="avatar" id="avatar_label">
</label>
</a>
</div>
<form id="change_pic_form">
<input type="file" name="avatar" id="avatar">
</form>
</div>
You shouldn't be wrapping html content inside an <img> tag, it's not syntatically correct.
Place all your content after the image tag, and trigger the css on hover using + selector. Use opacity instead of visibility as well for smoother transitions.
HTML:
<div class="col-lg-3">
<img id="personal_profile_pic" src="https://x1.xingassets.com/assets/frontend_minified/img/users/nobody_m.original.jpg"/>
<a href="#">
<span id="upload_pic_icon">
<label for="avatar" id="avatar_label">
<i class="fa fa-pencil" aria-hidden="true"></i>
</label>
</span>
</a>
<form id="change_pic_form">
<input type="file" name="avatar" id="avatar">
</form>
</div>
CSS:
#upload_pic_icon {
opacity: 0;
}
#personal_profile_pic:hover + #upload_pic_icon {
opacity: 1;
}
Try changing opacity from a very small value which the img could be considered invisible to fully visible (1.0). But your logic is likely wrong as there is no sense to hover something previously invisible.
#upload_pic_icon{
margin-left: 62%;
margin-top: -25%;
display: block;
position: absolute;
opacity: 0.000001;
}
#personal_profile_pic:hover #upload_pic_icon{
opacity: 1;
}
Very Simple Here is the Solution
https://jsfiddle.net/dineshkanivu/uddv4y9z/
HTML
<div class="MyImage">
<div class="penLayer">
<img src="https://cdn2.iconfinder.com/data/icons/snipicons/500/pencil-128.png"/>
</div>
</div>
CSS
.MyImage{
background: url("http://gretchenrubin.com/wp-content/uploads/2013/09/big_small_.jpg");
width: 350px;
height: 263px;
position:relative
}
.penLayer{
position:absolute;
width:100%;
height:100%;
background:rgba(0,0,0,0.8);
display:none;
}
.penLayer img{width:60px;
height:60px;
position:absolute;
left:50%;
top:50%;
margin-top:-30px;
margin-left:-30px}
Related
I know there is <input type="file"/> but I have an <img> inside of <div> and I would love to ask for user to upload an image after clicking on that <div>. This is the code I have:
<div class="container">
<img src="..." alt="Profile image" class="profileImg">
<div class="overlay">
<i class="fas fa-pencil-alt text"></i>
</div>
</div>
Is this possible only in HTML or do I need JS or something else?
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#image')
.attr('src', e.target.result)
.width(150)
.height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
.uploader {
opacity: 0;
position: absolute;
z-index: 1;
left: 0;
top: 0;
}
.container {
position: relative
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<img src="..." alt="Profile image" id='image' class="profileImg">
<input type='file' class='uploader' onchange="readURL(this);" />
<div class="overlay">
<i class="fas fa-pencil-alt text"></i>
</div>
</div>
You can take reference from above code. I click on image to add src to it and show it
If I am reading you right, you want to click an image to initiate the open file dialogue box, or prompt users on mobile to take a picture. You wanted it in just HTML, you can try this, however, it has a tiny bit of inline CSS.
Cheers,
Martin
<label for='image'>
<img src='image/source.png'>
<input type='file' id='image' style='display:none;' name='image'>
</label>
Custom styling of file inputs can be tricky, but there is a helpful article on codrops here.
Basically, you want to style and customize <input type="file"> in a semantic, accessible way using the <label> element.
HTML:
<input type="file" name="file" id="file" class="inputfile" />
<!-- The magic that makes it work -->
<label for="file">Choose a file</label>
CSS:
/* Hiding the default input */
.inputfile {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
/* Styling the new label */
.inputfile + label {
font-size: 1.25em;
font-weight: 700;
color: white;
background-color: black;
display: inline-block;
padding: 40px;
}
.inputfile:focus + label,
.inputfile + label:hover {
background-color: red;
}
/* Accessibility */
.inputfile + label {
cursor: pointer; /* "hand" cursor */
}
/* Keyboard Navigation */
.inputfile:focus + label {
outline: 1px dotted #000;
outline: -webkit-focus-ring-color auto 5px;
}
I have an image with a font awesome overlay of a plus. When I hover over the image (a tag) I want to display the plus, but I'm not sure if I have the correct css. The plus doesn't show when I hover over it!
Here is my code
a.registerTeacherAsHost:hover {
cursor: pointer !important;
opacity: 0.4;
}
a.registerTeacherAsHost:hover > .addTeacher {
display: normal;
}
<a class="registerTeacherAsHost" data-event-id=#Model.SpaceEvent.YogaSpaceEventId>
<div class="thumbnail">
<div>
<img class="img-responsive" src="~/Images/User_small_compressed_blue.png" style="position: relative; left: 0; top: 0;" alt="no teacher">
<i style="display:none; z-index: 200; position: absolute; top: 35%; right: 42%; color: grey;" class="addTeacher fa fa-plus fa-2x"></i>
</div>
</div>
</a>
Your CSS should look like this
a.registerTeacherAsHost:hover {
cursor: pointer !important;
opacity: 0.4;
}
a.registerTeacherAsHost .addTeacher { display: none; }
a.registerTeacherAsHost:hover .addTeacher {
display: block;
}
And the HTML
<a class="registerTeacherAsHost" data-event-id=#Model.SpaceEvent.YogaSpaceEventId>
<div class="thumbnail">
<div>
<img class="img-responsive" src="~/Images/User_small_compressed_blue.png" style="position: relative; left: 0; top: 0;" alt="no teacher">
<i style="z-index: 200; position: absolute; top: 35%; right: 42%; color: grey;" class="addTeacher fa fa-plus fa-2x">asd</i>
</div>
</div>
</a>
There were three problems with your code,
You were using the ">" selector which will only select the child element (.addTeacher) which is right after the parent element (.registerTeacherAsHost) which in you case doesn't work.
Other than that, the problem was with HTML where you declared the CSS for .addTeacher in the style tag, browsers take the CSS in this tag into consideration over any other stylesheets. One thing that could've worked was adding an !important to a.registerTeacherAsHost:hover .addTeacher { display: block !important; }. But it's better to write styles in a stylesheet and avoid using the !important as much as possible.
Next thing was, you were using display: normal which I've never heard of before and I think the browser hasn't too. display: block does the job.
Here's a fiddle: https://jsfiddle.net/5ncprd90/
Hope it helps!
There's been plenty wrong with your CSS which has been discussed already. I am focusing on a quick solution which goes here. Some adjustments have been made in the HTML structure and you are advised to avoid inline CSS. Hope this is what you are looking for.
a.registerTeacherAsHost{
display:inline-block;
}
a.registerTeacherAsHost:hover .thumbnail img {
cursor: pointer !important;
opacity: 0.4;
}
a.registerTeacherAsHost:hover i.addTeacher {
display: block;
cursor: pointer !important;
}
.thumbnail{
position:relative;
max-width:100%;
}
i.addTeacher{
display:none;
z-index: 200;
position: absolute;
top: 35%;
right: 42%;
color: grey;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a class="registerTeacherAsHost" data-event-id=#Model.SpaceEvent.YogaSpaceEventId>
<div class="thumbnail">
<img class="img-responsive" src="https://www.shareicon.net/data/128x128/2015/09/24/106425_man_512x512.png" alt="no teacher">
<i class="addTeacher fa fa-plus fa-2x"></i>
</div>
</a>
I am developing a website in Angular 2. I want to be able to upload images by clicking on a icon from font awesome, but i am having problems doing this. I can upload images when i use a label for this, but now when using font awesome icons i can't
What i have right now:
#pic {
border-radius: 200px;
width: 200px;
height: 200px;
background-size: 240px;
border-style: none;
border: 2px solid black;
outline: none;
cursor: pointer;
}
#pencilicon {
position: absolute;
margin-left: 85px;
margin-top: 85px;
font-size: 50px;
color: #fff;
visibility: hidden;
opacity: 0;
cursor: pointer;
transition: opacity .2s, visibility .2s;
}
#uploadinput{
position: absolute;
opacity: 0;
z-index: -1;
text-align: left;
}
<div id="picture">
<input type='file' (change)="readUrl($event)"id="uploadinput">
<i class="fa fa-pencil-square-o" for="uploadinput" id="pencilicon" aria-
hidden="true"> </i>
<img [src]="imageurl" id="pic" >
</div>
You have to include the font awesome library into your page and give the appropriate icon like so:
<i class="fa fa-upload"></i>.
See the code snippet below for an example and demo of your requirement.
input[type="file"].novisible {
display: none;
}
input[type="file"].novisible + label {
width:200px;
height:200px;
border-radius:50%;
border:2px solid #999;
display:inline-flex;
justify-content:center;
align-items:center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<input type="file" class="novisible" id="file_upload">
<label for="file_upload" class="btn btn-md btn-teak"><i class="fa fa-upload"></i> <span>Upload</span></label>
Have you tried putting your icon in a label ?
Personnaly I do like that (with Ember.js)
<input type='file' (change)="readUrl($event)"id="uploadinput">
<label for="uploadinput">
<i class="fa fa-pencil-square-o" for="uploadinput" id="pencilicon" aria-hidden="true"></i>
<span>{{uploadLabel}}</span>
<!-- This is then switched to file name -->
</label>
CSS :
input[type="file"] {
position: absolute;
left: -9999%;
& + label {
// your label style
}
}
Fits your method is attached to input wich have z-index -1, it's impossible to click it now.
Change z-index to 999 and click on the top border of the circle.
Your method should be run when you click on the circle, not input.
i used this below css
.fileContainer [type=file] {
cursor: inherit;
display: block;
font-size: 999px;
filter: alpha(opacity=0);
min-height: 100%;
min-width: 100%;
opacity: 0;
position: absolute;
right: 0;
text-align: right;
top: 0;
}
for my html
<div class=" btn btn-primary fileContainer">
<div class="input-group">
<i class="fa fa-paperclip fa-inverse"></i> Attachment
<input type="file" ngf-select ngf-multiple="true"
ng-model="noteListData.files" name="files">
</i>
</div>
</div>
using this css i am not able to see that text .
help me out.
i want to display button as well as text also.
thank you
It turns out should be the attribute "opacity" instead of "filter". Try to set the "opacity" to 1.
I'm trying to create a webpage which contains clickable image icons of some companies (eg. the logo of Mercedes Benz). When this icon is clicked, a text area appears on the same page (while the background is blurred out) and a user of this webpage can enter his comments about the company into the text area. I have searched long and hard about how to write a HTML code that produces this scenario, but have not been able to find anything. Can anyone help? I do not think that my code below is anywhere near what I need.
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<a href="mercedes"><img src="Mercedes logo.jpg"
alt="Daimler Benz" width="72" height="46" border="0" /></a>
<input type="text" name="mercedes"><br/>
</form>
You can achieve most of what you want without using Javascript. Instead of an anchor, use a label, so you can work with :focus:
label img {
transform: scale(0.5);
transition-duration: 0.2s;
}
label img:hover {
cursor: pointer;
transform: scale(1);
}
input[type='text'] {
opacity: 0;
font-size: 30px;
transition-duration: 0.2s;
}
input[type='text']:focus {
opacity: 1;
}
<label for="mercedes">
<img src="http://lorempixel.com/150/150/abstract/3">
</label>
<label for="porsche">
<img src="http://lorempixel.com/150/150/abstract/5">
</label>
<br />
<input type="text" id="mercedes" placeholder="Mercedes" />
<input type="text" id="porsche" placeholder="Porsche" />
You can do it using javascript, on the click event of the link focus on the text input:
function linktoText(){
var text=document.getElementById("mercedes");
text.focus();
}
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<a id="myLink" onclick="linktoText()" ><img src="Mercedes logo.jpg"
alt="Daimler Benz" width="72" height="46" border="0" /></a>
<input type="text" name="mercedes" id="mercedes"><br/>
</form>
EDIT:
And this is a Fiddle that shows a textarea by clicking the link.
you can do this in javascript
here is a fiddle
http://jsfiddle.net/PrakharThakur/0kdvunmx/
$('#img').click(function() {
$('#container').fadeIn(300);
});
$('#close').click(function() {
$('#container').fadeOut(300);
});
#container {
height: 100%;
width: 100%;
background-color: #aaa;
text-align: center;
display: none;
position: absolute;
top: 0px;
left: 0px;
z-index: 100;
opacity: 0.7;
}
#img {
cursor: pointer;
}
#close {
cursor: pointer;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="img">click me</div>
<div id="container">
<div id="box">What do you Think about merce?
<form>
<input type="text"></input>
<br>
<input type="submit"></input>
<div id="close">close</div>
</form>
</div>
</div>