I'm trying to create a box around each letter to use for an odometer style stat counter. Do you know how to do this without wrapping each letter in a span? If you have any ideas I'd love to hear them.
If you are using a mono spaced font, you could probably use a background image with the boxes.
Another option would be to use javascript to add in all the extra markup you need. There are some jquery plugins that do this type of thing already:
http://daverupert.com/2010/09/lettering-js/
Using CSS3 gradients you can do this with pure css and no javascript. The main idea is to create a gradient where the box color you want is a solid color to a certain color stop, and then the gradient is transparent. You have to calculate the color stops in coordination with the font-size and letter-spacing of the text. Then apply the gradient to a pseudo class of the text's element and voila.
Here's an example I created for a span element that contained the amount of money raised for an organization. Each number needed a pink box around it. The reason the gradient is so complicated is because I made it only repeat after every 3 digits, since every 3 digits there was a comma that needed to be outside of the boxes and thus required an extra gap. If you are repeating after every character it can be much simpler, but figured I'd share this approach since you mentioned an odometer. You can also extend these gradients with more browser-prefixes to make it work in IE, opera, etc.
html:
<span id="amount-raised">10,123</span>
css:
span#amount-raised {
position: absolute;
z-index: 1;
font-size: 70px;
letter-spacing: 10px;
color: #fff;
}
span#amount-raised:before { /* pink boxes */
content: '';
position: absolute;
top: 0; left: 0;
z-index: -1;
height: 100%; width: 100%;
background-image: -webkit-repeating-linear-gradient(right, pink, pink 50px, transparent 50px, transparent 55px, pink 55px, pink 105px, transparent 105px, transparent 110px, pink 110px, pink 160px, transparent 160px, transparent 176px);
background-image: -moz-repeating-linear-gradient(right, pink, pink 50px, transparent 50px, transparent 55px, pink 55px, pink 105px, transparent 105px, transparent 110px, pink 110px, pink 160px, transparent 160px, transparent 176px);
}
I can't see a way to do this in HTML without wrapping each letter in an element that you can style.
You could create ten gifs, one for each number (you said stat counter) that look the way you want them. When you load the page, use javascript to split your string into an array, then loop through it and replace each character with the corresponding gif for that number.
Well, it's certainly possible to flip this around and use a font (via #font-face) that has boxed-in letters.
I liked DMTinter's answer but it was longer than necessary (plus it's 7 years old) - here's a quick and simple example css that I'm using on my page:
span { color: black;
font-family: "Lucida Console", Monaco, monospace;
border: 1px solid black;
background-image: repeating-linear-gradient(90deg, white, white 13.5px, black 14.5px);
}
The important thing is repeating-linear-gradient(). I just did trial and error to arrive at the values 13.5px and 14.5px as lining up with the background well.
Related
On the website of Palantir.com, the color of the logo (originally black) is always the inverse of the color of the background behind it, even as the background scrolls/changes.
I'm creating a website via Wordpress and would like to have the same effect. I've tried using "mix-blend-mode: exclusion;", and while similar, doesn't give the true effect of a proper color inverse.
How can I do this in CSS? Thanks!
mix-blend-mode: difference with the font color set at white might help.
The difference with white on white is 0 - ie black.
The difference with white on blue is rgb(255, 255, 0) ie yellow.
body {
background-image: linear-gradient(white 0 30px, blue 30px 100%);
width: 100vw;
height: 100vh;
}
.text {
mix-blend-mode: difference;
color: white;
font-size: 60px;
}
<body>
<div class="text">SOME TEXT</div>
</body>
There can be problems with grays though - you can end up with gray on gray so it depends a bit on what your underlying image is actually like as to whether this will be satisfactory enough. (One trick is to apply a slight shadow to the text).
I have a picture of a chess piece. I want to put this picture on some background representing chessboard. Now when I put this picture I have this white background. Is there any way (using HTML, CSS or JavaScript) to remove white background from the picture and leave only the piece? Now it looks like that: picture.
CSS file:
.dark-spot{
background-color: rgb(209, 139, 71);
}
.spot{
height: 110px;
width: 110px;
}
HTML file:
<div class="spot dark-spot">
<img class="img-fluid" src="images/pieces/black-rook-square.jpg">
</div>
Apparently you are using JPG images. JPG images will contain color everywhere, i.e. every pixel in it will contain a certain color. To make it fit with the background, you'd have to edit the JPG and convert all white pixels to your background color.
But since you have two background colors, you need to convert all white pixels to be transparent instead of white. This isn't possible with the JPG image type, you'll need to convert these images to either PNG or GIF and then "erase" the white pixels, making them transparent that way. The result will be that your background image color (the chessboard) will be displayed ("come through") at the transparent positions.
You can kind-of do this using CSS mix-blend-mode: multiply. This will "remove" any white color (making it transparent) and will also affect any bright pixels which also with the same transparency, so the closer the pixel color is to white, the more transparent it will be.
body{
height: 100vh;
background: linear-gradient(salmon, lightgreen) no-repeat;
}
.piece{
background: url(https://www.baytree-interiors.co.uk/_uploads/img/products/giant/aged-stone-outdoor-queen-chess-piece-ornament_19661.jpg) 0 0 / 100% 100% no-repeat;
height: 200px;
width: 180px;
}
input:checked ~ .piece{
mix-blend-mode: multiply;
}
<input type='checkbox' id='remove-bg'>
<label for='remove-bg'>Remove chess piece white background</label>
<div class='piece'></div>
I suggest you to get board pieces images which are in APNG format, which already allows an alpha channel. I guess you can find plenty such APNG chess pieces files online.
According to this answer it's possible if the background is white.
Here is a sample code:
.dark-spot{
background-color: rgb(209, 139, 71);
}
.spot{
height: 110px;
width: 110px;
}
.spot-image {
height: 110px;
width: 110px;
mix-blend-mode: multiply;
}
<div class="spot dark-spot">
<img class="img-fluid spot-image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAe1BMVEX///8AAAD8/PwFBQX5+fnLy8u+vr4ICAiqqqq6urrk5OTf39+QkJBqamrS0tL19fU2NjaYmJgmJiZiYmKlpaVZWVmKiopAQEDs7OxGRkbY2Nizs7MrKyuBgYHExMSfn58bGxsTExN5eXlQUFAoKChxcXFcXFx8fHwZGRkM760UAAAEoElEQVR4nO3aa2OaOhjA8VxQrFrRWi/V1tr2uLPv/wmXC2ASkO3FCt32/704beMDJw9JHghOCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPyBlFL1f/9S6jAeFeIvzvD4LI2XYuh+fBIlXmRpLFQWfaTM6B4n42nYrlQ6ncMW83N2Go/2IpwRWabqyM9JottrmV8u5UREPVBq4kZXPlbt8Y8otvw5WrojnsZBkMmruHt8PR6GWQbTagRzbVMMFRsptZamfVRHT+bb1SI+w+Lu7jQrfx9XZ5Pra4ASK9/2EJ+/J2ubQe1Yz65MFQ9184dvURf/53JkZp7ws27/IetxVqI+QptjfIk2h23q5m3b+H+uvQwyNL/N6pmoPuwAlvauZeNbzHyeC3+DEfuH8kD5bppO17Npuapi3u0RZdi09xTH4RCa/j/XHViZP+vPprZlIvPcZahzMxi+98/V8Vqe7JrW11NJN3WV/V/ouvGx9wy3MvF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AAA/4ofOSYkVPMxp9cAAAAASUVORK5CYII=">
</div>
You need to use a PNG with a transparent background. otherwise you'll have a white background if you use a JPG.
I have a textarea for user text input and I want each line to have different background color (from a predefined set of 10 colors, can be repeated if more lines). I understand that I can use CSS expressions like nth-of-type(10n+1) for the tables, static text etc. - but not sure how to implement it for the textarea content.
(attached snippet doesn't really do anything about that, it's just a template to work with)
.my1 {
background-image:
repeating-linear-gradient(white, white 30px, gray 31px, white 31px);
line-height: 31px;
padding: 8px 10px;
}
<textarea class="my1"></textarea>
Simply define the 10 colors inside your gradient.
Example with 4 colors:
.my1 {
--l:1.5em; /* height of line */
background-image:
repeating-linear-gradient(
red 0 calc(var(--l)*1),
green calc(var(--l)*1) calc(var(--l)*2),
blue calc(var(--l)*2) calc(var(--l)*3),
purple calc(var(--l)*3) calc(var(--l)*4));
line-height: var(--l);
color:#fff;
}
<textarea class="my1"></textarea>
If you want padding, you have to offset the gradient to avoid missalignment. Only an offset from the top is required
.my1 {
--l:1.5em; /* height of line */
background:
repeating-linear-gradient(
red 0 calc(var(--l)*1),
green calc(var(--l)*1) calc(var(--l)*2),
blue calc(var(--l)*2) calc(var(--l)*3),
purple calc(var(--l)*3) calc(var(--l)*4)) 0 8px no-repeat,
yellow;
line-height: var(--l);
padding:8px 10px;
color:#fff;
}
<textarea class="my1"></textarea>
This question already has answers here:
Is it possible to apply CSS to half of a character?
(20 answers)
Closed 4 years ago.
How to take something like a star unicode \u2605 which is a star in html/css and only fill it half way instead of full.
Here is code:
<div class="starHalfFill">
\u2605
</div>
My styles look like this thus far:
.starHalfFill {
color: orange;
}
Since this is colored by color and not background color we will have to do a little more work to get this filled halfway. Normally to fill a div half way you would do something like:
.starHalfFill {
background: linear-gradient(to right, orange 50%, grey 50%);
}
but since this is a text based color we will have to target that.
.star.star--non-filled {
background: linear-gradient(to right, orange 50%, grey 50%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Those properties will target the text inside the div and also make the fill color transparent allowing the effect to work.
I have a CSS3 button like this
<button class="button brownb">My Button</button>
CSS
.brownb:active {
background: -moz-linear-gradient(center top , #831516, #9B4141) repeat scroll 0 0 transparent;
color: #FFFFFF;
}
.button:active {
position: relative;
top: 1px;
}
.brownb {
background: -webkit-gradient(linear, left top, left bottom, from(#A55757), to(#831516));
background: -moz-linear-gradient(top, #A55757, #831516);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#A55757', endColorstr='#831516');
border: 1px solid #A55757;
color: #D7D7D7;
}
.button {
border-radius: 0.5em 0.5em 0.5em 0.5em;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
cursor: pointer;
display: inline-block;
font: bold 14px/100% Arial,Helvetica,sans-serif;
margin: 0 2px;
outline: medium none;
padding: 0.5em 2em 0.55em;
text-align: center;
text-decoration: none;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
vertical-align: baseline;
}
I would like something like light just catching the face of a sharp, shiny sword and then going off. Is it possible with CSS3? I have seen this effect many times using Flash and thats why the query.
English is not my native language and so this effect might have got a name ( which obviously I don't know and so I could not google it. ) Is it possible? I am not particular about having this effect on a gradient ( plain background will do )
Fiddle here: http://jsfiddle.net/naveen/V9Rtw/
Disclaimer: This is basically a give me the codez but I am not good with CSS and so this doubt. Any pointers / nudge with the right transitions will be of tremendous help.
Update
I want something like what Google implement in the search page for India.
Link here: http://www.google.co.in/search?q=hello+world
Google does this using this sprite: http://www.google.co.in/images/experiments/p1/p1sprite.png
And they place it inside a folder named experiments :)
Edit: I assume that you are talking about the search button. My network didn't allow me to see the other links that you posted :(. The way that I have found quite successful with the button is to create a background image like this. Say your image is 25px tall by 75px wide. Create an image 75px x 75 px. Put three buttons in there like this:
____________
| normal |
------------
____________
| over |
------------
____________
| |
------------
Then, use the background-position property to set which position you want in the image. Also make sure that the overflow:hidden. This way, you get more control over the effect, download time is negotiable (after all, for progressive download, the make image appears first), and you are more backwards compatible, and it is cached (presumeably). I also don't know how the gradient rendering affects browser performance, but I would imagine that it could possibly have some impact.
Also, please mark as an answer if this answers your question!
JMax
I haven't seen a way to do this. I assume that you want this effect to be visible when they click the button, correct? You could try changing the gradient so that it would either raise up or lower, but that would make the effect for entire way across. Here is a possible way for that:
background-image: -webkit-gradient(
linear,
right bottom,
right top,
color-stop(0.32, #A55757),
color-stop(0.57, #831517)
);
background-image: -moz-linear-gradient(
center bottom,
#A55757 32%,
#831517 57%
);
From: http://gradients.glrzad.com/
Also, have you thought about using an image? I think that would give you the flexibility that you are looking. I don't know of your targeted audience, but it might also provide better backward compatibility.
JMax
The answer to your question is: No it is not possible to do this with just CSS. It can however be done with a combination of JavaScript and CSS.
Using your Google +1 button as an example, they have a sprite and will be using JavaScript to switch the background position over a set period of time when the icon is hovered over.
An example of how to animate sprite images over time can be seen here:
How to show animated image from PNG image using javascript? [ like gmail ]
http://designlovr.com/beautiful-photoshop-like-buttons-with-css3/
This might help you for a shiny effect, transitions must be made still tho