Hi I have the following CSS class and dom element
<button [ngClass]="{ 'filter-icon-open': open, 'filter-icon-close': !open }">
</button>
css
.open-filter {
cursor: pointer;
float: right;
button {
width: 40px;
height: 40px;
background-repeat: no-repeat;
background-position: center;
background-size: initial;
}
button:hover {
background-image: url("./../../../../assets/images/ico_filter_over.png");
background-color: $dbsred;
border: none;
}
button:focus {
outline:none;
}
}
.filter-icon-open {
background-image: url("./../../../../assets/images/ico_filter_over.png");
background-color: red;
}
.filter-icon-close {
background-image: url("./../../../../assets/images/ico_filter.png");
border: solid #B3B3B3 1px;
}
It's working perfectly for chrome. But for IE the icon is big. How to solve this. newbie to CSS. can someone help. Thanks in advance.
Tried:
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='./../../../../assets/images/ico_filter.png', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='./../../../../assets/images/ico_filter.png', sizingMethod='scale')";
but i see this part been commented out in chrome and it didnt worked as well.
initial is not supported on IE. For IE the permitted values for background-size
as per documentation are :
background-size: [ <length> | <percentage> | auto ] {1,2} | cover | contain [ , [ <length> | <percentage> | auto ] {1,2} | cover | contain ]*
Additionally, initial just sets the property to the default value of the property and for background-size the default value is auto. So you can use that directly or use any of the above values.
If the problem is that the open and close images are different sizes, You can use CSS to resize the images in the browser:
.filter-icon-open {
background-image: url("./../../../../assets/images/ico_filter_over.png");
background-color: red;
height : 100px;
width : 100px;
}
.filter-icon-close {
background-image: url("./../../../../assets/images/ico_filter.png");
border: solid #B3B3B3 1px;
height : 100px;
width : 100px;
}
This will force both the open and close image to be the same size, however, I personally recommend against that approach, since it could cause skewing or pixelation of the image.
A better solution is to resize the images using an image editing tool of your choice, such as Photoshop.
Related
I have an HTML code :
<li class="bath-icon">bath</li>
Where class="bath-icon" is defined in CSS as :
.bath-icon a {
background: url('images/room_bath.png');
background-size: auto 40%;
background-repeat: no-repeat;
background-position: 50% 20px;
background-color: #7E7C14;
opacity: 0.8;
}
Now I want to replace background image room_bath.png with an image from a sprite image with values as:
.room_bath {
width: 107px;
height: 64px;
background: url('images/sprite.png') -0 -952px;
}
Can anyone help me how both CSS can be cascaded and background image from sprite is inserted in .bath-icon class?
You can create variable in css and refer the variable in your css declaration.
:root {
--room-bath-bg: url('images/sprite.png') -0 -952px;
}
.bath-icon a {
background: var(--room-bath-bg);
background-size: auto 40%;
background-repeat: no-repeat;
background-position: 50% 20px;
background-color: #7E7C14;
opacity: 0.8;
}
Like above you can create your variable and refer in any places. The variable declaration should start with -- to identify the system.
NOTE: This mehtod is supported by only modern browsers.
Refer this W3 Schools CSS3 Variables to learn more details about this.
my problem seems to be quite simple. I want to create the button which is png and has hover via .png also. I need this for email campaigns becouse Outlook doesn't understand some css attributes.
I tried make it simple
.button {
border: none;
background: url(/image1.png);
}
.button:hover {
border: none;
background: url(/image2.png);
}
And everything is just white. Any help will be great :)
according to documentation, you should do it like that,
background: url("/image1.png");
.button {
width: 50px;
height: 50px;
border: none;
background: url("https://i.stack.imgur.com/teLso.jpg?s=48&g=1");
}
.button:hover {
border: none;
background: url("https://graph.facebook.com/160520007817300/picture?type=large");
}
<button class="button"></button>
You have an error, use the simple, or double quotes "" - '', an example:
button{
background: url('https://s-media-cache-ak0.pinimg.com/736x/24/fe/e1/24fee13b4dc475c435984ab0aa1b8ecb.jpg');
background-size: 500px 100px;
background-position: center;
width: 500px;
height: 40px;
}
<button> Example button </button>
Same with any of the other html elements.
When I write in the email box the email, I have no problem and displays perfectly.
But when google chrome decides to autofill, the image on the left is removed.
http://s9.postimg.org/suz3z56f3/Sem_t_tulo.jpg
I've read some topics about hacking that yellow background, which works, but the image continues to disappear.
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
// html
<input type='email' class='email' placeholder='email'/>
// css
.email{
background-image: url('http://www.letsgocook.net/sites/default/img/email.png');
background-repeat: no-repeat;
padding-left: 35px;
}
http://jsfiddle.net/9AM6X/ > example, but no showing the error because I can't replicate the autofill of chrome in jsfiddle.
Puts the image back using keyframes:
#-webkit-keyframes autofill {
to {
background-image:url(images/your-input-bg-image.svg);
}
}
input:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
Kudos to #Steve for his answer to Removing input background colour for Chrome autocomplete?
I'm posting a solution here, essentially as a hack / workaround for the problem described.
Using extra elements we can place the icon on the input element.
Preview: http://output.jsbin.com/necigedago
Working Example:
CSS
.control {
position: relative;
}
.email {
padding-left: 35px;
padding-top: 10px;
padding-bottom: 10px;
font-size: 16px;
}
.email ~ .input-icon {
background-image: url('http://www.letsgocook.net/sites/default/img/email.png');
background-repeat: no-repeat;
background-size: 100%;
background-position: center center;
width: 22px;
height: 14px;
position: absolute;
left: 8px;
bottom: 0;
top: 0;
margin: auto;
}
HTML
<p class='control'>
<input type='email' class='email' placeholder='email'/>
<span class='input-icon'></span>
</p>
It is very inconvenient practice to use background images for textboxes. you can change your HTML markup
html
<div class='icon'></div>
<input type='email' class='email' placeholder='email'/>
css
.email {
border:1px solid black;
padding-left: 5px;
float:left;
border-left:none;
outline:none ;
margin-left:-3px
}
.icon {
background-image: url('http://www.letsgocook.net/sites/default/img/email.png');
background-repeat: no-repeat;
background-position:center center ;
float:left;
width:30px;
height:18px;
margin-top:2px;
border:1px solid black;
border-right:none
}
I have updated the code: jsFiddle
Only option is to remove the padding where the background image would have been in webkit but you can style as such:
/* CHROME ISSUE W/ YELLOW BG */
input:-webkit-autofill#username,
input:-webkit-autofill#usernameId_new,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
-webkit-text-fill-color: #646464 !important;
-webkit-box-shadow: 0 0 0px 1000px #fff inset;
-webkit-padding-start: 8px !important;
}
The image will still work for IE, FF, etc... but for chrome will overide.
Best-
Use animate to solve this matter is the most useful way!
kudos to #wkille for his answer: https://stackoverflow.com/a/51874418/11720087
You can set a animation like this:
#keyframes clearAutofill {
to { background: 'Your-code'; }
/* e.g background: url('./img/example.png') 0 0 no-repeat #fff; */
}
input:-webkit-autofill {
animation: clearAutofill forwards;
/* 'animation-fill-mode: forwards' can keep the style you set. */
}
I found a better solution to this.
For new Chrome versions, you can just put autocomplete="new-password" in your password field and that's it. I've checked it, works fine.
You just need to add autocomplete="off" to your input field and this will solved the issue. I tried it and it works.
I found another solution which should solve the problem using JavaScript. Add the onchange to your input element, and use following function. I'm using this along with the CSS rules input:focus:invalid and input:required:valid to show different background images based on if the input is valid or not valid.
Works in Chrome and Firefox, but not for Safari it seems :(
CSS:
input:required:valid {
background: url("IMAGE_PATH_HERE") no-repeat right;
background-size: 25px;
border: 3px solid green;
}
input:focus:invalid {
background: url("IMAGE_PATH_HERE") no-repeat right;
background-size: 25px;
border: 3px solid red;
}
HTML:
<input type="text" name="name" id="name" autocomplete="name" onchange="fixAuto(this)" required>
JavaScript:
/**
* Adds background image to input fields if they are removed by the browser.
*
* #param element An input HTML element.
*/
function fixAuto(element) {
setTimeout(() => {
// Store the current value of the input field
let value = element.value;
// Store the element itself
let input = document.getElementById(element.id);
// Change the input fields value
input.value = value;
}, 0);
}
I use the CSS Sprite Technique with a background image that looks something like this:
The CSS code for the icons:
div.icon {
background-color: transparent;
background-image: url("/images/icons.png");
background-position: 0 0;
background-repeat: no-repeat;
display: inline-block;
height: auto;
vertical-align: text-top;
width: auto;
}
div.icon:empty {
width:16px;
height:16px;
}
div.icon:not(:empty) {
padding-left:20px;
}
div.icon.attenuation {
background-position: 0 0;
}
My icons can be used like this:
<div class="icon warning"></div>
I want to put some text inside my icons like:
<div class="icon warning">There is a warning on this page</div>
But the problem is that the background image covers the entire text area:
The question is: how can I use only part of an image as a background image for part of my element?
Notes:
setting width to 16px for div.icon doesn't help.
Remember, where ever possible, you shouldn't change your markup just to achieve a design. It is possible using your markup.
div.icon:before {
content: "";
background-color: transparent;
background-image: url("/images/icons.png");
display: inline-block;
height: 16px;
vertical-align: text-top;
width: 16px;
}
div.icon:not(:empty):before {
margin-right: 4px;
}
div.icon.attenuation {
background-position: 0 0;
}
You have two ways:
1)Your markup must be like this:
<div class="icon warning"></div><div class="txt">There is a warning on this page</div>
.icon {width:10px(for ex.)}
2)You must change the image. Icons in the image must be below the another
Sorry, my previous answer was not well though out.
Edit:
If you have a 16px padding, you should set the width to 0, not 16px. And I've got troubles getting the :not(:empty) bit to work on all browsers; better get rid of it. So the CSS becomes:
.icon {
...
width:0; height:16px; padding-left:16px;
}
.icon:empty {
width:16px; padding-left:0;
}
jsFiddle
set width: 16px; height: 16px; overflow: hidden; text-indent: -9999em; and remove padding
I am currently working on an HTML5 form and using CSS3 for the styling. I have added CSS for input:required and input:valid and input:invalid to make an image get shown inside the text box.
Both the required and invalid CSS work fine but for some reason input:valid gets ignored and is just replaced with the same image as input:required.
Below is the CSS that I have used
input:required.fields, textarea:required.fields, select:required.fields
{
background:url("images/asterix.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
}
input:focus:required:invalid.fields, textarea:focus:invalid.fields, select:focus:invalid.fields
{
background:url("images/error.png") no-repeat;
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
Both CSS sections above work fine without any problems but its the CSS below that for some reason is not working.
input:valid.fields, textarea:required:valid.fields, select:value.fields
{
background:url("images/tick.png");
background-position: right;
width: 200px;
background-color: white;
opacity: 1.0;
}
In case it was to do with the image not being found I made the invalid image be the tick.png image and this worked fine but the valid section never seems to get called.
Thanks for any help you can provide.
I just used the following on my form:
input[required]:invalid {
background: #efdee0 url(../images/invalid.png) no-repeat center right;
}
input[required]:valid {
background: #f3f8ed url(../images/valid.png) no-repeat center right;
}
but then my fields are all required (http://www.paul-ellis.co.uk/contact.htm)