I have an HTML input field like this. I would like to place an image inside the textbox on the right side. Can someone help me out with its CSS for that?
<input type="text" id="name"/>
In the picture is an image which is inside the text field email address, which is what I want. How do you do this?
HTML
<div class="fake-input">
<input type="text" />
<img src="http://www.zermatt-fun.ch/images/mastercard.jpg" width=25 />
</div>
CSS
.fake-input { position: relative; width:240px; }
.fake-input input { border:none; background-color:#fff; display:block; width: 100%; box-sizing: border-box }
.fake-input img { position: absolute; top: 2px; right: 5px }
Working demo
http://jsfiddle.net/HnJZa/
try this:
input {
background-image: url("icon.png");
background-position: right top;
background-repeat: no-repeat;
background-size: contain;
}
you can try something like this
.textBox{
background-image:url(iconimage.jpg);
background-position:right;
background-repeat:no-repeat;
padding-left:17px;
}
Then apply this style to your text box:
<input type="text" class="textBox" />
Use background-image and background-position property
DEMO
CSS:
input {
height: 70px;
width: 200px;
background-image:url("http://cloud.ohloh.net/attachments/25869/plone-icon-64_med.png");
background-repeat:no-repeat;
background-position: 133px 3px;
}
.text3 {
width: 300px;
height: 30px;
}
#text3 {
background-image: url(https://cdn3.iconfinder.com/data/icons/interface-8/128/InterfaceExpendet-09-128.png);
background-size: 30px;
background-repeat: no-repeat;
}
input {
text-align: center;
}
<p class="email">
Email
</p>
<input type="text" placeholder="Email_ID" class="text3" id="text3">
The answers above didn't replicate the format shown in the questioners image, or provide any explanation. This is a solution using background images.
Explanation of the background image syntax.
background: url('https://d1ululg65bfe3q.cloudfront.net/images/troy/email-icon.png') no-repeat 97.25% 10px white;
Location of image: url('https://d1ululg65bfe3q.cloudfront.net/images/troy/email-icon.png')
Show image once: no-repeat
Distance from left: 97.25%
Distance from top: 10px
Background color: white
.bg-email-icon {
background: url('https://d1ululg65bfe3q.cloudfront.net/images/troy/email-icon.png') no-repeat 97.25% 10px white;
padding-left: 5px;
padding-right: 50px;
width: 255px;
height: 30px;
border: 1px gray solid;
border-radius: 5px 5px 0px 0px;
}
.bg-lock-icon {
background: url('https://d1ululg65bfe3q.cloudfront.net/images/troy/lock-icon.png') no-repeat 96.75% 10px white;
padding-left: 5px;
padding-right: 50px;
width: 255px;
height: 30px;
border: 1px gray solid;
border-top-width: 0px;
border-radius: 0px 0px 5px 5px;
}
<input name="exampleEmail" class="bg-email-icon" placeholder="Email" type="email">
<input name="examplePassword" class="bg-lock-icon" placeholder="Password" type="password">
You can add class to your input
<input type="text" id="name" class="inputImage" />
and then background image to class in css
.inputImage
{
background:#FFFFFF url('img.jpg') no-repeat top right;
}
You need to add class like this:
CSS:
.bgInput {
background: url(path of your image.jpg) top right no-repeat;
}
HTML:
<input type="text" class="bgInput" id="name"/>
A small answer: you can do this by setting as a background image of input field.
try:
#name {
background: url('path/image.png') right no-repeat;
}
Related
I am finishing up this table and I added a search function to it. But in the search bar, I want to put a search icon png file for the background image just like the example on W3Schools. I put it in the myInput field, but either nothing appears in the search bar, or it is so massive you can see a tiny top corner piece of the search icon and I cant figure out how to fix it.
#myInput {
background-image: url('https://cdn1.iconfinder.com/data/icons/hawcons/32/698627-icon-111-search-512.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
<input type="text" id="myInput">
You need to use the background-size property. Because the image is larger than the input, you are seeing a white portion of the picture. By setting the property to contain the image is shrunk to the size of your input.
#myInput {
background-image: url('https://cdn1.iconfinder.com/data/icons/hawcons/32/698627-icon-111-search-512.png');
background-repeat: no-repeat;
background-position: left center;
background-size: 30px;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
<input placeholder="Search..." type="text" id="myInput">
Note: You should also set the background-position property to 0 or remove it all together; otherwise, the search icon will be skewed to the right and downwards.
If instead you want to make the icon smaller, change background-position to left center and set background-size to a px value of your choice.
HTML
<div class="fake-input">
<input type="text" />
<img src="http://www.zermatt-fun.ch/images/mastercard.jpg" width=25 />
</div>
CSS
.fake-input { position: relative; width:240px; }
.fake-input input { border:none; background-color:#fff; display:block; width: 100%; box-sizing: border-box }
.fake-input img { position: absolute; top: 2px; right: 5px }
Source is here
I put in input icon and i am trying to move it.
From:
to
HTML:
<input type="text" name="username" placeholder="Въведе потребителско име ...">
CSS
#contact input[name='username']{
background:url('../image/icon/user.png'), #ebebeb;
background-repeat: no-repeat, repeat;
background-position: right;
width: 355px;
padding: 10px;
padding-left: 10px;
padding-right:55px;
border: 0px;
margin-top: 6px;
transition: box-shadow 0.3s;
}
try
background-position: 0 5px 0 0;
instead of
background-position: right;
Try to add this to your CSS code
margin-right:10px;
I've the following tags
<input id="date" class="mandatory datepicker" type="date" name="Date"></input>
<input id="name" class="mandatory" type="text" name="Name"></input>
What I want to do is to have a common CSS background image for two fields on the left side which I am able to do using the mandatory class and have an unique CSS background image on the right side for the date field using datepicker class along with the common CSS.
What I want is
What I get is
So can I do that?
Below are the CSS codes which I tried but couldn't get what I wanted.
.mandatory {
background: #FFFFFF url(http://www.freecakefreecake.com/blog/wp-content/themes/Aggregate/epanel/shortcodes/images/list-dot.png) no-repeat 4px 4px;
background-position: left;
}
.mandatory.datepicker {
background: #FFFFFF url(http://upload.wikimedia.org/wikipedia/commons/9/99/Dot1.png) no-repeat 4px 4px;
background-position: right;
}
Is the datepicker image overlapping the mandatory image? If so how do I solve this issue?
Fiddle: http://jsfiddle.net/kumareloaded/aybghsfp/
UPDATE DUE TO COMMENT
input{position: relative}
.mandatory {
background: #FFFFFF url(http://www.freecakefreecake.com/blog/wp-content/themes/Aggregate/epanel/shortcodes/images/list-dot.png) no-repeat 4px 4px;
background-position: left;
}
.mandatory.datepicker {
background: #FFFFFF url(http://upload.wikimedia.org/wikipedia/commons/9/99/Dot1.png) no-repeat 4px 4px;
background-position: right;
text-indent: 4px
}
.mandatory.datepicker:before {
content:'';
position: absolute;
background: #FFFFFF url(http://www.freecakefreecake.com/blog/wp-content/themes/Aggregate/epanel/shortcodes/images/list-dot.png) no-repeat 4px 4px;
background-position: left;
width: 12px;
height: 14px;
top: 2px;
}
<input id="date" class="mandatory datepicker" type="date" name="Date" />
<input id="name" class="mandatory" type="text" name="Name" />
UPDATE: change your markup to this then (for typing reasons they have to be outside the box)
*{box-sizing: border-box; padding: 0; margin: 0}
form{
padding: 40px
}
[class=name]{
margin: 0 20px 0 80px
}
[class=date],[class=name],[class=submit]{
display: inline-block;
width: 160px;
height: 40px;
position: relative
}
input[id=name],input[id=date]{
width: 100%
}
[type=submit]{
width: 100%;
padding: 10px 0;
}
label[for=date],label[for=name]{
display: inline-block;
width: 16px;
height: 16px;
position: absolute;
left: -32px;
top: 2px;
border-radius: 50%
}
[class=date]:before{
content:'';
position: absolute;
right: -32px;
top: 2px;
background: yellow;
width: 16px;
height: 16px;
border-radius: 50%
}
input:valid + label[for=date],input:valid + label[for=name]{
background: green
}
input:invalid + label[for=date],input:invalid + label[for=name]{
background: red
}
<form>
<div class=date>
<input id=date class="mandatory datepicker" type=date name=Date required />
<label for=date></label>
</div>
<div class=name>
<input id=name class=mandatory type=text name=Name required />
<label for=name></label>
</div>
<div class=submit>
<input type=submit value=validate />
</div>
</form>
you can not style inputs easily that is why you should use label since they are going together
label{
position: relative;
display: inline-block;
width: 32px;
height: 32px;
cursor: pointer; margin-right: 10px
}
label[for=date]:after{
background: red
}
label[for=name]:after{
background: green
}
label:after{
content: '';
position: absolute;
top: 10px;
left: 0px;
width: 32px;
height: 32px;
border-radius: 50%;
border: 4px solid #333
}
<label for=date></label>
<input id=date class="mandatory datepicker" type=date name=Date />
<label for=name></label>
<input id=name class=mandatory type=text name=Name />
Use something like this
.mandatory {
background: #FFFFFF url(../images/mandatory.png) no-repeat 4px 4px;
background-position: left;
display:inline-block;
position:relative;
}
.mandatory.datepicker:after {
content:'';
display:block;
width:10px; /*Change accordinlgly*/
height:10px; /*Change accordinlgly*/
position:absolute;
top:5px; /*Change accordinlgly*/
right:5px; /*Change accordinlgly*/
background: url(../images/datepicker.png) no-repeat;
}
you can do this by using display:inline-block property for both the images.
.mandatory {
background: #FFFFFF url(../images/mandatory.png) no-repeat 4px 4px;
background-position: left;
display:inline-block;
}
.mandatory.datepicker {
background: #FFFFFF url(../images/datepicker.png) no-repeat 4px 4px;
background-position: right;
displya:inline-block;
}
Thanks all for your valuable inputs.
I was able to get the solution by using the following CSS.
.mandatory {
background: #FFFFFF url(http://www.freecakefreecake.com/blog/wp-content/themes/Aggregate/epanel/shortcodes/images/list-dot.png) no-repeat 4px 4px;
background-position: left;
}
.mandatory.datepicker {
background-image: url(http://www.freecakefreecake.com/blog/wp-content/themes/Aggregate/epanel/shortcodes/images/list-dot.png), url(http://upload.wikimedia.org/wikipedia/commons/9/99/Dot1.png);
background-repeat: repeat-y;
background-position: left, right;
}
Fiddle: http://jsfiddle.net/kumareloaded/jcpLp492/
.input {
background: url(assets/Symbol39-2-min.png) no-repeat right center,
url(assets/Symbol38-2-min.png) no-repeat left center;
}
I have the following form that I want to customize.
<form>
<input type="text" value="" />
<button></button>
</form>
I want the button to have a background image and no text.
The problem is that the button loses its vertical alignment when I don't write any text into it.
Can someone explain this behaviour?
input {
width: 200px;
height: 20px;
border: 1px solid #0066cc;
border-radius: 20px;
padding: 0;
}
button {
margin-left: -30px;
background-color: white;
background-image: url("http://s18.postimg.org/k6rruvokl/loupe_recherche.gif");
background-repeat: no-repeat;
background-position: center center;
border: none;
width: 19px;
height: 19px;
padding: 0;
}
<form>
<input type="text" value="" />
<button></button>
</form>
<form>
<input type="text" value="" />
<button>Some text</button>
</form>
Because they have a default vertical-align property of baseline, which alignes inline elements according to the bottom of the element's content (the text).
If there is no content, the vertical alignment cannot be based upon it, instead it is based on the bottom of the element.
You can fix this with a non-breaking space, or by changing the vertical alignment.
<form>
<input type="text" value="" />
<button> </button>
</form>
JSFiddle
-- Or --
button {
margin-left: -30px;
background-color: white;
background-image: url("http://s18.postimg.org/k6rruvokl/loupe_recherche.gif");
background-repeat: no-repeat;
background-position: center center;
border: none;
width: 19px;
height: 19px;
padding: 0;
vertical-align:middle;
}
JSFiddle
A good read:
All you need to know about vertical-align - Christopher Aue
If you add the vertical-align indicator to the button it should help it move to the position you want, it will need a little bit of extra margin just to push it up a bit though.
Try this out:
input {
width: 200px;
height: 20px;
border: 1px solid #0066cc;
border-radius: 20px;
padding: 0;
}
button {
margin-left: -31px;
background-color: white;
background-image: url("http://s18.postimg.org/k6rruvokl/loupe_recherche.gif");
background-repeat: no-repeat;
background-position: center center;
border: none;
width: 19px;
height: 19px;
padding: 0;
vertical-align: bottom;
margin-bottom: 1px;
}
<form>
<input type="text" value="" />
<button></button>
</form>
This seems to be a matter of vertical alignment because the elements are inline-(block?)
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
input {
width: 200px;
height: 20px;
border: 1px solid #0066cc;
border-radius: 20px;
vertical-align: top;
}
button {
background-color: white;
background-image: url("http://s18.postimg.org/k6rruvokl/loupe_recherche.gif");
background-repeat: no-repeat;
background-position: center center;
border: none;
width: 20px;
height: 20px;
border: 1px solid red;
vertical-align: top;
}
<form>
<input type="text" value="" />
<button></button>
</form>
I have a problem. While designing some codes, I stuck at a position. I want to pick a search icon from a CSS sprites and to keep it to a desired position like shown in below screenshot.
There are some limitation like I can only edit or add more CSS and I can't edit search Input tag and also can't add more element around Input tag like DIV,SPAN,P,B etc. For this purpose, I wrote a code that is live at www.jsfiddle.net/JFx9g.
Is this possible or not? Can you edit this?
try this (i have also updated the fiddle)
<div class='search_input_container'>
<input class="search_input" name="q" type="text" value=""/>
<div class='search_glass'></div>
</div>
css
.search_input_container{
width:450px;
height:30px;
border:1px solid #ccc;
display:table;
}
.search_input{
border:none;
padding:5px;
width:90%;
outline:none;
display:table-cell;
}
.search_glass{
border:none;
width:18px;
height:20px;
background: url(http://i.imgur.com/BX2OXxc.png);
background-repeat: no-repeat;
background-position: -20px 0px;
display:table-cell;
}
New Edited JSFIDDLE: http://jsfiddle.net/JFx9g/10/
http://jsfiddle.net/vikramjakkampudi/W2Cnc/
input{
height:30px;
}
.inputImage {
background-position: 100% center;
background-clip: border-box;
background-attachment: scroll;
background-origin: padding-box;
background-image: url("your image url");
background-repeat: no-repeat;
background-size: 8px auto;
cursor: pointer;
width: 93.5% !important;
padding-right: 5%;
}
add this css and assign inputImage class to your input field
Since I think that it is not possible to do it as I asked so I tried myself to do this with as short code as I can and then I got the following one That is also live on www.jsfiddle.net/JFx9g/18/
<style type="text/css">
.search_text {
position: relative;
}
.search_text:after {
content: "";
position: absolute;
top: -3px;
right: 7px;
width: 19px;
height: 19px;
background: url(http://i.imgur.com/BX2OXxc.png) -19px -2px no-repeat;
}
.search_text_input {
height: 24px;
width: 450px;
}
</style>
<span class="search_text">
<input class="search_text_input" name="q" type="text" value=""/>
</span>