How to change a link's line-through / strikethrough color? - css

I have a link that has a strikethrough. I want to make the strikethrough lighter so the link text is easier to read, but can't figure out how to do it.
Here's what I want it to look like (using an inner span instead of a link because it comes out the way I want):
span.outer {
color: red;
text-decoration: line-through;
}
span.inner {
color: green;
}
<span class="outer">
<span class="inner">foo bar</span>
</span>
But this doesn't seem to work:
span.outer {
color: red;
text-decoration: line-through;
}
a.inner {
color: green;
}
<span class="outer">
foo bar
</span>
Any ideas?

Interesting that your first example works, I wouldn't have expected that… good to know, I guess!
You can achieve this appearance with a pseudo-element. Make sure the element is position:relative and then position the pseudo-element absolute, full-width, however tall you want the line to be, and top:[50% - half the height, rounded]. It'll look like this:
.fancy-strikethrough {
color: green;
position: relative; /* lets us position the `::after` relative to this element */
}
.fancy-strikethrough::after {
content: ''; /* pseudo-elements must always have a `content` */
position: absolute; /* lets us position it with respect to the `.fancy-strikethrough */
/* placement */
left: 0;
top: 50%;
/* make it a line */
height: 1px;
width: 100%;
background: red;
}
<a class="fancy-strikethrough">test</a>
You can even have the line extend a little on the sides by giving the element some horizontal padding.

There's a css3 property for this: text-decoration-color
So you can have text in one color and a text-decoration line-through (or underline etc.) - in a different color... without even needing an extra 'wrap' element
.inner {
color: green;
text-decoration: line-through;
-webkit-text-decoration-color: red;
text-decoration-color: red;
font-size: 24px;
}
green text with red strike-through in one element
Codepen demo
NB: Browser Support is limited... (caniuse)
...at the moment to Firefox and Safari (and Chrome - but you need to enable the "experimental Web Platform features" flag in chrome://flags)

Here you go you can also apply any 2 colors you want
a {
text-decoration: none;
}
.outer {
color:gray;
text-decoration:line-through;
}
.inner {
color: black;
text-decoration:underline;
}
<a href="#" >
<span class="outer">
<span class="inner">foo bar</span>
</span>
</a>

You can use border instead and set opacity to what you need:
#line-t {
color: green;
font-size: 20px;
position: relative;
display: inline-block;
}
#line-t span {
position: absolute;
width: 100%;
border-top: 2px solid red;
left: 0;
top: 50%;
opacity: 0.3;
}
<div id="line-t">
foo bar
<span></span>
</div>
here is the sample on codepen: http://codepen.io/startages/pen/wzapwV

Here you go:
<style>body {color: #000;}</style>
<del> facebook </del>

Related

Wavy line in text field with CSS google like

How is it possible to get the wavy line in a textfield in all browsers, like google?
Google uses a repeated base64 encoded image as a span below the input. You can type stuff in your span and it will appear below it.
.error:hover {
background: url(data:image/gif;base64,R0lGODlhCgAEAMIEAP9BGP6pl//Wy/7//P///////////////yH5BAEKAAQALAAAAAAKAAQAAAMROCOhK0oA0MIUMmTAZhsWBCYAOw==) repeat-x scroll 0 100% transparent;
display: inline-block;
padding-bottom: 1px;
}
<span class="error">hello</span>
Disclaimer: You have to hover over the span for the effect to appear.
As mentioned here;
With Content:
.underline:after {
content: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
position: absolute;
width: 100%;
left:0;
overflow: hidden;
top:100%;
margin-top: -.25em;
letter-spacing:-.25em;
}
or with image:
.underline {
display: inline-block;
position:relative;
background: url(http://i.imgur.com/HlfA2is.gif) bottom repeat-x;
}
Try using text-decoration and text-decoration-skip-ink.
The text-decoration-skip-ink: none; can be drawn across the full length of the text content.
span {
text-decoration: red wavy underline;
text-decoration-skip-ink: none;
}
<span>asdsdfsf</span>

Rating system using CSS (hover from left to right)

Is there a simple way to reverse the colour order when hovering?
Using this trick here I have the order right > left:
&:hover,
&:hover ~ button {
color: red
}
The fiddle with the right > left: https://jsfiddle.net/celio/Lowc1ruh/
Example with the left > right: https://css-tricks.com/examples/StarRating/
It is impossible for me to use float, position: absolute; and anything that changes the right order of my current html.
Plain CSS example:
button {
margin: 0;
padding: 5px;
border: none;
background: transparent;
display: inline-block;
}
button:before {
content: "⋆";
font-size: 5rem;
line-height: 1;
}
button:hover,
button:hover ~ button {
color: red;
}
<div class="wrapper">
<button></button>
<button id="2"></button>
<button></button>
<button></button>
<button></button>
</div>
One way would be to make all the child button elements color: red; when hovering over .wrapper. Then use the sibling selector (~) to change any elements after the currently hovered element to color: black;.
You should remove any whitespace between the elements (in this case I put them into one line in the HTML) to ensure that the cursor is always hovering over a star.
Example with plain CSS:
.wrapper button {
margin: 0;
padding: 5px;
border: none;
background: transparent;
display: inline-block;
}
.wrapper button:before {
content: "⋆";
font-size: 5rem;
line-height: 1;
}
.wrapper button:hover ~ button {
color: black;
}
.wrapper:hover button {
color: red;
}
<div class="wrapper">
<button></button><button id="2"></button><button></button><button></button><button></button>
</div>
JS Fiddle using SASS

Pure CSS tabs switch

How can I make this tabs script: FIDDLE work like this: DEMO
I want to switch social tabs between each other but it doesn't work.
Where did I made a mistake?
a[name="tab1"] + .facebook_box {
display: block
}
:target + .twitter_box {
display: block
}
:target ~ a[name="tab1"] + .facebook_box {
display: none
}
** UPDATE: This is a duplicate of this question **
Here are the changes to make it work:
First a small bug: close the anchor tag like this: </a> not like this <a/>.
Then change the order of your articles:
<div class="tab-content">
<a name="tab2"></a>
<article class="twitter_box">t</article>
<a name="tab1"></a>
<article class="facebook_box">f</article>
</div>
Then delete the ".social_slider .tab-content" before the ".facebook_box" or add it also to the lines doing the magic otherwise you overwrite the magic with the more precice definition of your class.
And then you need to increase the size of your link inside the tab, otherwise you only click on the label, not the anchor.
.facebook_box {
border-radius: 8px;
background-color: #fff;
position: relative;
z-index: 99998;
display:none;
height:300px;
border:10px solid #3a93d6;
}
.twitter_box {
border-radius: 8px;
background-color: #19bfe5;
position: relative;
z-index: 99998;
display:none;
height:300px;
border: 10px solid #68c2ff;
}
.twitter_icon > a, .facebook_icon > a{
display: block;
height: 100%;
width: 100%;
}

Custom Checkboxes Failing on Firefox

I'm trying to make custom checkboxes with CSS3, which is working great on Chrome. On Firefox... not so much.
Edit: it seems to be working fine on Firefox 37.
The answer below is still relevant, but the style related issues from mid 2013 are resolved.
IE support isn't mentioned here but edits/answers regarding it are welcome.
demo
The HTML:
<input type="checkbox" id="first"/>
<label for="first">This is pretty awesome</label>
The CSS:
input[type=checkbox] {
appearance: none;
background: transparent;
position: relative;
}
input[type=checkbox]::after {
position: absolute;
top: 0;
left: 0;
content: '';
text-align: center;
background: #aaa;
display: block;
pointer-events: none;
opacity: 1;
color: black;
border: 3px solid black;
}
input[type=checkbox] + label {
line-height: 48px;
margin: 0 15px 0 15px;
}
input[type=checkbox]:hover::after {
content: '';
background: #32cd32;
opacity: .3;
}
input[type=checkbox]:checked::after {
content: '\2713';
background: #32cd32;
}
input[type=checkbox]:checked:hover::after {
opacity: 1;
}
input[type=checkbox],
input[type=checkbox]::after {
width: 48px;
height: 48px;
font-size: 46px;
line-height: 48px;
vertical-align: middle;
border-radius: 50%;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
Note: I removed vendor prefixes, and things like user-select for brevity. The full code is in the pen.
What do I need to change to have it look the same on Firefox as it does on Chrome?
Desired:
Not desired:
You can enable custom styles for checkbox specifically for mozilla browser by adding this property and it worked for me.
-moz-appearance:initial
I managed to fix it as much as seems possible (I'd still love a better solution, if one exists). I switched all of the selectors from
input[type=checkbox]::after
to
input[type=checkbox] + label::after
Downside:
requires a label
But:
HTML requires input elements to have a label
Conclusion:
only bad for invalid HTML
doesnt technically need a LABEL, but does need control over the mark up to ensure there is a target-able sibling immediately after the checkbox.
i.e.
input[type=checkbox] + span::after{
display:block;
width:50px;
height:50px;
background:yellow;
display:block;
}
input[type=checkbox]:checked + span::after{
display:block;
width:50px;
height:50px;
background:yellow;
display:block;
}
<input type="checkbox"></input>
<span class="targetMe"></span>
target the span using the sibling selector and :after elements as above.
Might as well put in a label tho at this point... :P
The problem is that :after and ::after technically create an element as the last child of the element the pseudoselector is applied to. Firefox doesn't like to create children inside of its checkboxes. This is actually part of a bigger topic which is replaced elements.
You will see the same issue with the :before and ::before pseudoelements not working on checkboxes because they would create elements as a first child element within the element being selected.

Adding a dotted line trail after menu description

How would I go about adding a dynamic ".........." to a restaurant menu in CSS? Like in printed ones they have the whole
"our food is made of blah blah blah.............$24.99."
How would you do that in CSS? Or is this even possible?
The best solution is this:
<ul>
<li><p class="food">Chinese Food</p><p class="price">$5.99</p></li>
</ul>
then CSS to match (untested, but tweakable to get the effect)
li {
width: 300px;
height: 20px;
border-bottom: 1px dotted black;
background-color: white;
}
.food, .price {
height: 22px; //key: just a bit taller than the LI
background-color: white;
}
.food {
float: left;
}
.price {
float: right;
}
So it basically fixes the rectangle of the LI and draws a border on the bottom, then the price and food name cover it up dynamically with their width. YMMV with browsers, but perhaps a negative margin-bottom will get the li border-bottom obscured for sure by the P elements.
It's possible but not well supported. You want the :after psuedo-selector and the content rule. See here: http://www.quirksmode.org/css/beforeafter.html Note that IE gets a big fat F for implementation.
You can do it in javascript. Or by creative use of the border-type 'dotted'. Or maybe a repeating background, as Brooks suggests, which would work by giving your price and descriptions spans that you apply a background color to to cover the repeating background.
Update What that might look like:
<ul class="menu">
<li><span class="name">Yummy stuff</span> <span class="price">$400</span></li>
</ul>
With CSS like:
.menu { list-style-type:none;margin: 0 0 0; padding: 0 10px 0; }
.menu li {
display:block;
overflow:hidden; //contain the float
background-image: url(dots.gif);
background-repeat:repeat-x;
}
.menu .name { background-color:#ffffff; }
.menu .price { float:right; clear:none; background-color:#ffffff; }
Alex's answer has one great drawback — multiline text in the .food hides bottom line.
Also there is a good old answer: http://www.search-this.com/2007/11/26/css-a-recipe-for-success/ (demo)
Here is live demo of a little modified old solution (try to resize): http://cssdesk.com/BqR96
And modified css:
.restaurant_menu__list {
min-width: 320px; /* For mobile devices */
max-width: 500px; /* Custom max width for readbility */
}
.restaurant_menu__row {
border-bottom: 2px dotted #B5ABAB; /* Our dotted line, we can use border-image instead */
position: relative;
float: left;
line-height: 1.2em;
margin: -.9em 0 0 0;
width: 100%;
text-align: left;
}
.restaurant_menu__meal span
, .restaurant_menu__price
{
background-color: #FFF; /* For .restaurant_menu__row background rewriting */
}
.restaurant_menu__meal {
padding-right: 3em; /* Custom number for space between text and right side of .restaurant_menu__row; must be greater than .restaurant_menu__price max-width to avoid overlapping */
}
.restaurant_menu__meal span {
margin:0;
position:relative;
top: 1.6em;
padding-right:5px; /* Custom number for space between text and dotted line */
}
.restaurant_menu__price {
padding:1px 0 1px 5px;
position:relative;
top:.4em;
left:1px;/* ie6 rounding error*/
float:right;
}
And modified html:
<ul class="restaurant_menu__list">
<li class="restaurant_menu__row">
<!-- Inside div we need inline element, to handle multiline meals -->
<div class="restaurant_menu__meal"><span>Crab Cakes with corn, roasted red pepper, and ginger vinaigrette</span></div>
<span class="restaurant_menu__price">€25</span>
</li>
<li class="restaurant_menu__row">
<div class="restaurant_menu__meal"><span>French Onion Soup</span></div>
<span class="restaurant_menu__price">€32</span>
</li>
</ul>
That's really graphics, not text, even if it's normally done as ASCII-art with dots. Thus, a repeating background image might do the trick appropriately?

Resources