css border radius mouse hover fog? - html

I want a css button with border-radius, but I want this border to be well contoured.
when I put mouse hover this button there is a kind of fog in borders:
.b_b{
cursor : pointer;
padding:6px;
font-size : 10pt;
font-weight : bold;
color : #2e9fff;
text-decoration : none;
border:1px solid #cce9ff;
background:#fff;
border-radius:9px;
z-index:999px;
}
.b_b:hover{
background-color:#2e9fff;
color:#fff;
}
<span class=b_b>button</span>
https://jsfiddle.net/42fmsj20/
what is wrong?

You can simply use the background-clip property to achieve this. For an in-depth description on how that property works you can check out the W3Schools example and explanation here.
CSS:
-webkit-background-clip: padding; /* Safari 4+, Chrome 6+ */
-moz-background-clip: padding; /* Firefox 3.6+ */
background-clip: padding-box; /* Firefox 4+, Safari 3+, Opera 10.5+, IE9+ */
JSFiddle
I also noticed the you had forgot to put double quotes "" around your class value, make sure you always include those as they are required for valid syntax.
<span class="b_b">button</span>

Example:
https://jsfiddle.net/2zbu8btx/
`<span>` tag is used to determine the line elements of the document
add display: inline-block; for span
In fact, an element in its effect similar to recessed elements (such as tag <img>). At the same time its interior is formatted as a block element, and the element itself - as built.
https://jsfiddle.net/mgcLbo92/
.b_b{
cursor : pointer;
display: inline-block;
padding:16px 50px;
font-size : 10pt;
font-weight : bold;
color : #2e9fff;
text-decoration : none;
border:1px solid #cce9ff;
background:#fff;
border-radius:9px;
z-index:999px;
}
.b_b:hover{
background:#2e9fff;
color:#fff;
}
<span class=b_b>button</span>

The problem is half aesthetical and half a matter of antialiasing.
When you put darker border around lighter element and then, on hover state, invert it to lighter border around darker element, you'll end in unpleasant effect like this, it will just look like the border is some kind of gradient on edges of the element. Your eye will not consider it as a border anymore since it does not delimit the area of element from the outer space.
Try adding darker border to hover state, you'll get rid of foggy effect and it will look nicer.
See updated version: https://jsfiddle.net/bd2h2h8b/
.b_b:hover{
background-color:#2e9fff;
color:#fff;
border-color: #1e6fCf;
}

Related

Change the color of the clear button (x) in input `type=search`

How do i change the color of X that appears on input[type=search]
By using webkit-search-cancel-button and webkit-appearance: none i have been able to change it to a colored square or circle but i have been unable to change the color of X.
The issue is default color of the X on safari is black and by textbox is black hence this is not visible. Chrome picks a safe color of grey but it too has the same issue.
You probably don't need the solution anymore, but I will just it leave here to see if it helps anyone.
You can't change the color of the clear button (x) directly (as far as I tried), but here's some trick I figured out to change the button appearance.
Basically, I just removed the default clear button and replaced it with a black clear button image (I used base64 encoded image here, you can use any).
[type="search"]::-webkit-search-cancel-button {
-webkit-appearance: none;
appearance: none;
height: 10px;
width: 10px;
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE2LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgd2lkdGg9IjEyMy4wNXB4IiBoZWlnaHQ9IjEyMy4wNXB4IiB2aWV3Qm94PSIwIDAgMTIzLjA1IDEyMy4wNSIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTIzLjA1IDEyMy4wNTsiDQoJIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPGc+DQoJPHBhdGggZD0iTTEyMS4zMjUsMTAuOTI1bC04LjUtOC4zOTljLTIuMy0yLjMtNi4xLTIuMy04LjUsMGwtNDIuNCw0Mi4zOTlMMTguNzI2LDEuNzI2Yy0yLjMwMS0yLjMwMS02LjEwMS0yLjMwMS04LjUsMGwtOC41LDguNQ0KCQljLTIuMzAxLDIuMy0yLjMwMSw2LjEsMCw4LjVsNDMuMSw0My4xbC00Mi4zLDQyLjVjLTIuMywyLjMtMi4zLDYuMSwwLDguNWw4LjUsOC41YzIuMywyLjMsNi4xLDIuMyw4LjUsMGw0Mi4zOTktNDIuNGw0Mi40LDQyLjQNCgkJYzIuMywyLjMsNi4xLDIuMyw4LjUsMGw4LjUtOC41YzIuMy0yLjMsMi4zLTYuMSwwLTguNWwtNDIuNS00Mi40bDQyLjQtNDIuMzk5QzEyMy42MjUsMTcuMTI1LDEyMy42MjUsMTMuMzI1LDEyMS4zMjUsMTAuOTI1eiIvPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPGc+DQo8L2c+DQo8Zz4NCjwvZz4NCjxnPg0KPC9nPg0KPC9zdmc+DQo=);
background-size: 10px 10px;
}
<input type="search">
I could't find a way to change only the color but you can overwrite the "x" button style with:
input[type="search"]::-webkit-search-cancel-button {
/* Remove default */
-webkit-appearance: none;
/*Your new styles */
height: 10px;
width: 10px;
background: red;
}
For now this is supported by Webkit browsers(Chrome, Safari).
https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-search-cancel-button
A workaround for changing the color is using filter. In my case, I simply wanted the x to be black or gray (instead of blue), so I used a black and white filter
You could use an invert filter to make the x light on a dark background.

Input color and caret

I want my input element had different colors for text and for caret.
I'm already found a solution for webkit browsers:
input {
color: black;
-webkit-text-fill-color: red;
}
But still, I wonder how can I make it for other browsers.
Eventually, I want to have transparent text color and black caret, if it matters.

How to specify the css property text-fill-color in IE and Mozilla (as I did -webkit-text-fill-color for webkit)

In chrome the color is showing, but in IE, FF how do I use this property
CSS
#Grid td.note div.has-note i {
-webkit-text-fill-color: #b4efa8;
}
In Firefox and IE you do not have text-fill-color property.Use Color instead of text-fill-color.
AFAIK text-fill-color is a non-standard, webkit only property . There is no equivalent in other browsers (maybe somebody can correct me?).
But, as this property simply overrules the standard color property, you can just add the standard color property as a fallback...
#Grid td.note div.has-note i {
color: red; /* all browsers */
-webkit-text-fill-color: #b4efa8; /* webkit browsers only */
}
div {
color: red; /* all browsers */
-webkit-text-fill-color: blue; /* webkit browsers only */
}
<div>
What colour am I?
</div>
Use this CSS
Only webkit browsers have text-fill-color property othes have only color property
#Grid td.note div.has-note i {
-webkit-text-fill-color: #b4efa8;
color: #b4fa8;
}
It can be used to work with cursor color. See the snippet...
textarea { display: block; width:100%; height: 5em; } /* Unimportant */
#t1 { color: #ff0000; }
#t2 { color: #ff0000; -webkit-text-fill-color: #0000ff; }
<textarea id="t1">I'm all RED ! Both text and cursor.</textarea>
<textarea id="t2">My cursor is RED because of "color:", but my font face is BLUE because of "-webkit-text-fill-color:". I work only in Opera, Chrome, and should start working in new Firefox (v.48) by next month :) ...</textarea>
For example w3schools.com use this in their on-line example editor to make highlighting of the code possible. Since text in can't be formatted, they made it transparent using "-webkit-text-fill-color" but kept the cursor, then they clone the code into underlying div and color it.

Use text as a mask on background image

I have a nice background on my page, and I want my text header to act as a mask to cut through its containing div and have the background as a texture.
Can I do this in CSS or do I have to open up Photoshop?
Limited browser support, but background-clip can get you this effect: http://tympanus.net/Tutorials/ExperimentsBackgroundClipText/ (Hit the Animate buttons for more fun)
Using SVG you can do it like this: http://people.opera.com/dstorey/images/newyorkmaskexample.svg (View source to see what is actually done, see reference article too)
Using a background image and then CSS, you could do this: http://www.netmagazine.com/tutorials/texturise-web-type-css
As CSS-Tricks shows in this article, 'image behind text' can be done as such:
h1 {
color: white; /* Fallback: assume this color ON TOP of image */
background: url(images/fire.jpg) no-repeat; /* Set the backround image */
-webkit-background-clip: text; /* clip the background to the text inside the tag*/
-webkit-text-fill-color: transparent; /* make the text transparent so
* the background shows through*/
}
But it isn't guaranteed to work on all browsers, so they suggest a few work arounds, like modernizr.
Here's what it looks like when it works:
There is a background-clip: text property in CSS3, although it doesn't work in every browser. See here for more details.
To extend #sgress454's answer. Nowadays, background-clip: text works in Firefox and Edge, but its browser compatibility is still not full. Safari does not and Chrome partially (It is supported with the prefixed version of the property only. According to the WebKit blog, text decorations or shadows are not included in the clipping.). background-clip: text is still what you are looking for:
background-clip: text;
The background is painted within (clipped to) the foreground text.
MDN
Demo:
body {background: black;}
div {
background: url(https://images.unsplash.com/photo-1543005472-1b1d37fa4eae?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=600&q=60), black;
background-clip: text;
color: transparent;
}
<div>This background clips to the text.</div>

Position of text in a submit button

The position of the text on the search submit button on my blog is very low in Firefox 4, but not Chrome 10 or IE9. I've tried almost everything, and nothing works except lowering the font size of the text, which isn't an optimal solution as the text will be too small.
Screenshots
Firefox 4 on Windows 7:
Google Chrome 10.0.648.204 on Windows 7:
The relevant HTML:
<form method="get" class="searchform" action="http://eligrey.com/blog">
<input type="search" placeholder="search" name="s" />
<input type="submit" value="🔍" title="Search" />
</form>
The relevant CSS rule (from http://eligrey.com/blog/wp-content/themes/eligrey.com/style.css):
.searchform input[type="submit"] {
font-family: "rfhb-lpmg";
color: #ccc;
font-size: 3em;
background-color: #959595;
text-align: center;
border: 1px solid #888;
height: 34px;
width: 42px;
line-height: 34px;
-webkit-border-bottom-right-radius: 4px;
-webkit-border-top-right-radius: 4px;
-moz-border-radius-bottomright: 4px;
-moz-border-radius-topright: 4px;
border-bottom-right-radius: 4px;
border-top-right-radius: 4px;
-webkit-background-clip: padding-box;
-moz-background-clip: padding-box;
background-clip: padding-box;
-webkit-transition-property: border, background-color, box-shadow;
-webkit-transition-duration: 0.2s;
-moz-transition-property: border, background-color, box-shadow;
-moz-transition-duration: 0.2s;
}
rfhb-lpmg is just a custom font I made which implements U+2767 rotated floral heart bullet and U+1F50E right-pointing magnifying glass with simplistic glyphs.
I've deduced that the main trouble is the line-height property.
Both browsers attempt to vertically center all text on buttons. In combination with the height property, however, if there is not enough room to render the full standard line-height (glyph padding grows quite large with large font sizes), both browsers will pin the glyph to the top of the button, trimming the bottom.
Normally, the line-height would help adjust this, and in Chrome, in your example, this was successful. However, in the case of button and input type="submit" elements, Firefox ignores line-height altogether, so it can't be used in this way to "fix" the positioning of the character. Using the extreme example below, we can see that the text has been pushed out of visbility in Chrome, while it still stays right in the (vertical) center in Firefox.
<!doctype html>
<html>
<body>
<style type="text/css">
input {
border:1px solid black;
line-height:1000px;
height:40px;
}
</style>
<input type="submit" value="Test"/>
</body>
</html>
Firefox:
Chrome:
When a button element is left to the native style (remove the border), line-height is ignored by both browsers (weirdly, Chrome also ignores the height but Firefox does not). As soon as the button is custom-styled, Chrome picks up the line-height but Firefox does not.
So what can you do?
If you still want to make use of CSS fonts...
First of all, make sure your font renders the glyphs in the same vertical-alignment that a standard font displays a basic full-height character, like H. (It appears you've done this for the most part, since your page looks significantly better than the screenshots in the question.)
Second, you'll notice that if you use a font like Arial, and display an H (at the same font size), it's also low. This is because the built in standard line-height of the font gives it quite a bit of room above the character. This indicates that you may have some success if you can edit the font to trim this, thereby giving the character enough room to not be trimmed at the bottom by the browser.
Probably less ideal to you, but still an option, you can use other elements, either in combination with or in place of the button/submit element, to get the character into place.
Alternative option
I'm not sure what your goal is in using CSS fonts, but often it is for some form of progressive enhancement/graceful degradation. In this case, although (as you said in the comments) the special character is a standardized Unicode "right-pointing magnifying glass", it still will not have any meaning to the user if it doesn't render.
Given that the benefit of graceful degradation is to allow simpler technologies to display your website without appearing broken, the use of this character seems suspect — without CSS fonts or a native font with this character, it will render as 🔍 a ?, or simply a blank box.
A better option for graceful degradation, given this problem, would be to simply use a background-image. Make the text of the button "Search", hide the text (through CSS), and apply the background image, and then you have actual graceful degradation, and a fancy character for better browsers.
A background image could also (obviously dependent on the files themselves) have other benefits, such as faster load and render times (for instance, if a developer wanted to use a single character from a full-character-set font).
FF4 sets it's own styles on input elements. You can check all of them if you paste this in your URL field:
resource://gre-resources/forms.css
Alternatively you can see this styles if you check Show user agent CSS from Style tab dropdown if you have Firebug instaled.
Check solution here: How to reset default button style in Firefox 4 +
I came to the same conclusion as Renesis, though I wasn't sure whether Firefox wasn't respecting line-height or vertical-align. Here is the outline to a different solution that allows you to continue to use your fancy glyph. Since you are using pixel-sizes for your button, try something along these lines (simplified html). This might be overkill, and a background-image would almost certainly be more appropriate, but anyway.
The simplified html:
<div class="searchform">
<input type="search" placeholder="search" name="s" />
<span><input type="submit" value="🔍" title="Search" /></span>
</div>
And the simplified css:
// hide the border and background for the submit button
.searchform input[type="submit"] {
border: none;
background: transparent;
}
// give the span the properties that the submit button has now
span {
position: relative;
width: 30px; // or whatever
height: 30px; // or whatever
}
// absolutely position the submit button
.searchform input[type="submit"] {
position: absolute;
margin-top: -15px; // half the span height
margin-left: -15px; // half the span width
top: 50%;
left: 50%;
bottom: 0;
right: 0;
}
I had been facing a similar problem when using CSS inside buttons. The text was offset by 1 pixel in firefox, and rest of the browsers it was just fine. I used "padding" property specific to Firefox, in the following way
The original code in which the input button's text was one pixel lower in Firefox
.mybutton {
height:32px; background-color:green;
font-size:14px; color:white; font-weight:bold;
border:0px; -moz-border-radius:16px; border-radius:16px;
}
and after adding the Firefox specific padding after the above css, it was perfect in Firefox
#-moz-document url-prefix() {
.mybutton { padding-bottom:1px; }
}
In your case, may be you need a bit more padding-bottom, and probably padding-top in negative too (-1px or -2px).
I came across this when I was looking for a solution to this problem, but since I never really found anything other than a hint at changing the padding bottom I wanted to share that I found adjusting the padding-bottom for just firefox worked great.
Every other browser allowed for enough line-height control to adjust the text positioning.
/* This gets picked up in firefox only to adjust the text into the middle */
#-moz-document url-prefix() {
input[type="button"],
input[type="submit"],
button.btn {
padding-bottom: 6px;
}
}
I had something like this happen earlier this week - I found out that you have to apply certain ccs elements to the 'parent' element instead of the 'child'. So basically try some of the css like vertical-align: in the .searchform div.
Meanwhile, I'm having trouble with my search icon at smartemini.com. It works in aaaaallllll browsers except ie9. :(
I ran into the same.
I was able to solve my issues, pushing padding from the bottom (!)
padding: 0 0 2px 0; /* total height: 36px */
height: 34px;
or, in a bigger picture, if you fancy consistent input['..'] and anchor button, use distinct overriding tweaking for the latter for full control.
/* general button styling for input and anchor buttons */
.buttonXS, .buttonS, .buttonM, .buttonL {
display: block;
font-size: 14px;
line-height: 14px; /* just a precaution, likely ignored in FF */
padding: 0 0 2px 0; /* total height: 36px */
height: 34px;
...
}
/* distinct vertical align for anchor buttons */
a.buttonXS, a.buttonS, a.buttonM, a.buttonL {
padding: 12px 0 0 0; /* total height: 36px */
height: 24px;
}
(the 'T-shirt-sizes' lead to different background-offsets and widths elsewhere)
What you're seeing here is how differently browsers render text inside button elements when space is tight. Chrome centers the test vertically, while Firefox top-aligns it.
On top of that, you're using a home-made font, that might have some latent issues when it comes to vertical-height/leading/etc.
I note that when I add any other character to the input's value - the magnifying glass drops down even further in Firefox. This suggests that tweaking the font somehow (like vertical-position, or cropping away top/bottom white-space) might help.
If that fails you should change your <input type="submit"/> into a <button type="search" title="Tooltip">Label</button> element, and see if styling the button is any easier than styling the input.
If the problem still remains, you'll need to switch tactics and wrap your button in a <div class="btnwrap" />.
.searchform .btnwrap {
display: inline-block;
overflow: hidden;
height: 32px;
border: 1px solid #888;
/* plus the border-radius styles */
}
.searchform button {
/* all the original button styles, except the border */
height: 50px;
margin: -9px 0; /* (32-50)/2 = -9 */
}
(BTW, You can alternatively inner-wrap button text in a <span/> and do similar negative-margin hack to that, although I suspect that getting the vertical-centering is easier with the button inside adiv.)
That said, you really should just use a good old fashioned background image replacement - it will both render and load faster. :-)
Good luck!
This problem only happens on Firefox 4/Win7 with DirectWrite enabled render mode (which is enabled by default). Firefor4 GDI render mode is working properly.
It might caused by the vertical-align attribute is baseline. But the baseline of U1F50D sin't on the lowest point. Maybe you should try to move the font points a little higher, set the lowest point's y point to 0.
lots of anwsers here... i think this is the simplest way to do this :
.searchform input[type="submit"]
{
height: 35px;
line-height: 35px;
font-size: 2em;
}
Hope this helps =D
I have found that a combination of padding and line-height does the trick. As stated Firefox ignores line-height.
Make sure you set a larger bottom padding than top padding. Fiddle around with it a bit and you will be able to vertically align the text in Firefox.
You will then see that this pushes the text too close to the top of the element in Webkit. Now use a large line-height to align it properly in Webkit and voila!
I have tested this on a Windows 7 machine running Firefox 7, Chrome 16, Safari 5.1 and IE9.