Rating system using CSS (hover from left to right) - css

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

Related

Why is button element unaffected by CSS?

I have a problem with styling a button element. Here is the sample:
$clrWhite: #fff;
$clrPrimary: #3c9494;
.khanbank__button {
display: block;
height: 50px;
border: none;
color: $clrWhite;
cursor: pointer;
&--primary {
background: $clrPrimary;
&:hover {
background: darken($clrPrimary, 5%);
}
}
}
Here is the what i've tried:
Test
I see you are using BEM
The issue is on your HTML, as you need to have both classes applied to the element
<button class="khanbank__button khanbank__button--primary">Test</button>
From your Codepen, you wrote:
<button class="khanbank__button--primary">Test</button>
However, if I were to translate your SCSS into normal CSS, it would become:
:root {
--clrWhite: #fff;
--clrPrimary: #3c9494;
--clrPrimaryDarken: #358282;
}
.khanbank__button {
display: block;
height: 50px;
border: none;
color: var(--clrWhite);
cursor: pointer;
}
.khanbank__button--primary {
background: var(--clrPrimary);
}
.khanbank__button--primary:hover {
background: var(--clrPrimaryDarken);
}
<button class="khanbank__button--primary">Test</button>
Perhaps now you could see the problem.
In your HTML you have only applied .khanbank__button--primary to <button>. You need to also apply the base class .khanbank__button to it.
In short, your HTML should be:
<button class="khanbank__button khanbank__button--primary">Test</button>
See this pen for working example.

Make opaque div with text appear over image box over image upon hover

I have text that appears on top of an image when you hover over the image. Originally, I also had the entire image go opaque upon hovering.
Now I've decided I want to make only a section of the image go opaque upon hovering, the part with the text. I tried the tutorial here. Unfortunately, once I made those changes, nothing appears when I hover over the image -- not the text or any opaque filter.
Here is my html file:
<div class="container">
<div class="main">
<div class = "JFK">
<h6>JFK</h6>
<div class = "transbox">
<p> to
from</p>
</div>
</div>
/* continues on*/
Here is my css:
JFK {
position: relative;
left: 110px;
height: 300px;
width: 300px;
bottom: 40px;
background-image: url(https://media-cdn.tripadvisor.com/media/photo-s/03/9b/2d/f2/new-york-city.jpg);
line-height: 200px;
text-align: center;
font-variant: small-caps;
display: block;
}
.transbox{
margin: 30px;
background-color: $ffffff;
border: 1px solid black;
opacity: 0.6;
display: none;
}
.JFK h6{
font-size: 30px;
font-variant: small-caps;
font-weight: 600;
}
.transbox p{
position: relative;
top: -90px;
word-spacing: 100px;
font-size: 30px;
font-variant: small-caps;
font-weight: 600;
color: #c4d8e2;
display: none;
}
.JFK p a{
color: #c4d8e2;
top: -30px;
}
.JFK:hover transbox p {
display: block;
}
.JFK:hover{
display: block;
}
.JFK: hover transbox{
display: block;
opacity:0.6;
}
I thought I had added a wrapper class as suggested here by adding the transbox div. I also tried the background-color:rgba(255,0,0,0.5); trick mentioned here. No luck -- still nothing happens upon hover. Any suggestions?
Your problem lies with these 2 pieces of code in your css:
.JFK:hover transbox p {
display: block;
}
.JFK: hover transbox{
display: block;
opacity:0.6;
}
Firstly . is missing from the class transbox - is should be .transbox
Secondly there is a space between .JFK: and hover remove the space and it should all work.
.JFK:hover .transbox p {
display: block;
}
.JFK:hover .transbox{
display: block;
opacity:0.6;
}
Your code is not complete. In the "tutorial" you said you tried, <div class = "transbox"> is just a box with transparent background that is positioned above another box, with a background-image. You said you need "only a section of the image go opaque upon hovering".
Also, your CSS is not valid. "JFK" is a class, in the first row, so is ".JFK".
Then, is
.transbox {
margin: 30px;
background-color: #ffffff;
}
You wrote again with errors.
You can use:
.transbox{
margin: 30px;
background-color: rgba(255,255,255,0.6);
border: 1px solid black;
}

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

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>

Inherit CSS class from separate file?

I have a class for a button:
.client-header button {
/*Properties*/
}
and a class to detect when the menu is open:
.client-menu-open {
/*Properties*/
}
I would like to change the button background based on whether or not the menu is open. I want something like this:
.client-header button .client-menu-open {
/*Properties*/
}
But the classes are in two different files, so it doesn't work. Is there any way to do this across different files?
Here is the code for the header index.css:
#import url('../menu/index.css');
.client-header {
position: absolute;
top: 0;
left: 0;
right: 0;
height: var(--header-height);
overflow: hidden;
border-bottom: 1px solid #7E7E7E;
background: #cccccc;
}
.client-header button {
float: left;
height: 100%;
border: none;
border-right: 1px solid var(--border-color);
border-radius: 0;
box-shadow: none;
line-height: 39px;
background-color: #444444;
color: #FFF;
}
.client-header button:hover {
background-color: #555555;
}
.client-header button:active {
background-color: #4E4E4E;
}
.client-header-caption {
float: left;
}
.client-header-title,
.client-header-subtitle {
margin-left: 10px;
}
.client-header-title {
line-height: 25px;
}
.client-header-subtitle {
font-size: 0.5rem;
line-height: 15px;
}
#media (min-width: 640px) {
.client-header-title,
.client-header-subtitle {
display: inline-block;
line-height: var(--header-height);
}
.client-header-title {
font-size: 1.5rem;
}
.client-header-subtitle {
font-size: 1rem;
}
}
.client-header .client-menu-open button {
background: #CCCCCC;
}
And here is the code for the menu index.css:
.client-menu {
position: absolute;
top: var(--header-height);
bottom: 0;
left: -var(--menu-width);
width: var(--menu-width);
border-right: 1px solid var(--border-color);
padding-bottom: var(--menu-footer-height);
overflow: hidden;
transition: left 0.2s;
}
.client-menu-open {
left: 0;
box-shadow: 0 0 30px var(--shadow-color);
background: #444444;
}
.client-menu-pinned {
box-shadow: none;
}
.client-menu-header {
height: var(--menu-header-height);
text-align: right;
background-color: #444444;
}
.client-menu-footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: var(--menu-footer-height);
text-align: right;
}
And the HTML structure is:
<header class="client-header">
<button class="client-header-menu-toggle"/>
</header>
<div class="client-menu"/>
You can use #import like so (in your primary CSS stylesheet):
#import url('external.css');
/* external.css above will be loaded */
Refer to this documentation: http://www.cssnewbie.com/css-import-rule/
Link to the other file and style .client-menu-open
if this is your html
<div class="client-menu-open"> <!-- this class is here only if the menu gets opened, else, this div has no class -->
stuff
stuff
<div class="client-header-button">
<button></button>
</div>
</div>
the correct syntax is the following
button {
background:red;
}
.client-menu-open button {
background:blue
}
The #import rule allows you to include external style sheets in your document. It is a way of creating a style sheet within your document, and then importing additional rules into the document.
To use the #import rule, type:
<style type="text/css">
#import url("import1.css");
#import url "import2.css";
</style>
For more info refer here https://developer.mozilla.org/en-US/docs/Web/CSS/#import
your CSS selector is incorrect, that's why it doesn't work. It has nothing to do with where CSS styles are defined.
.client-header button .client-menu-open will only select the following elements:
elements with class="client-menu-open"
which are children of button elements
which themselves are children of elements with class="client-header"
.
what you want, I think, is
button elements
which are children of elements having "class=client-header" AND "class=client-menu-open".
the proper selector for those elements would be .client-header.client-menu-open button.

Listview remove item border and checkmark

I'm sorry if answer on this question is to easy, but I was realy trying to find answer on the internet, but without any success.
I wish to remove all kind of borders and checkmark's from my listview. How can I do this?
I already tryed to set border and outline on none or transparent or something, but there is still some kind of gray border. I have no idea how can I remove this one or how to remove checkmark?
My current result is this(when item has .win-selected class):
Html code:
<div class="filterPanel left">
<h2 class="title">Status filter</h2>
<div id="labRole_name" class="filter-view win-selectionstylefilled" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'single', tapBehavior: 'directSelect', layout: { type: WinJS.UI.ListLayout } }"></div>
</div>
And css code:
.filter-view {
width: 250px;
margin-left: -7px;
color: gray;
}
.filter-view .item {
background-color: #F2F2F2;
outline: #F2F2F2 solid 10px;
}
.filter-view .item *{
display: inline-block;
}
.filter-view .win-selected .item:hover .count,
.filter-view .item:hover .count {
color: #4BB3DD !important;
}
.filter-view .win-selected .item:hover .filter,
.filter-view .item:hover .filter {
color: #8B8B8B !important;
}
.filter-view .win-selected .item .filter,
.filter-view .item .filter {
color: #333333 !important;
}
.filter-view .win-selected .item .count,
.filter-view .item .count {
color: #0096D1 !important;
}
.filter-view .item .filter {
margin-right: 10px;
width: 160px;
height: 20px;
white-space: nowrap;
overflow: hidden;
}
.filter-view .item .count{
min-width: 30px;
text-align: right;
font-weight: 400;
}
You need to remove this outline:
.filter-view .item {
background-color: #F2F2F2;
outline: #F2F2F2 solid 10px;
}
Should be
.filter-view .item {
background-color: #F2F2F2;
outline: 0;
}
And if is possible post a link of your page online.
To make items not selectable, selectionMode for the listview needs to be set. you may also want swipeBehavior and tapBehavior to be none.
<div id="listView" data-win-control="WinJS.UI.ListView"
data-win-options="{
selectionMode: 'none', swipeBehavior: 'none',
tapBehavior: 'none' }">
</div>
Regards the mouse hover highlight - styling listview topic might help.
To change the border appearance of ListView's item hover and active state, you'll have to override .win-itembox's value with ::before selector.
.win-listview .win-itembox:hover::before {
border-color: transparent; /* get rid of border, both of :hover and .win-pressed (same as :active) */
}
The default values can be found at ui-light.css or ui-dark.css, where the opacity and the color value of border is located.
/* the default value of WinJS ListView's item hover and active color from ui-light.css */
html.win-hoverable .win-listview .win-itembox:hover::before,
html.win-hoverable .win-itemcontainer .win-itembox:hover::before {
opacity: 0.4;
}
html.win-hoverable .win-listview .win-pressed .win-itembox:hover::before,
html.win-hoverable .win-listview .win-pressed.win-itembox:hover::before,
html.win-hoverable .win-itemcontainer.win-pressed .win-itembox:hover::before {
opacity: 0.6;
}
...
html.win-hoverable .win-listview .win-itembox:hover::before,
html.win-hoverable .win-itemcontainer .win-itembox:hover::before {
border-color: #000000;
}

Categories

Resources