hover on different elements (CSS only solution) - html

I'm having troubles on applying a hover effect on different HTML elements, such as changing the color of a DIV's border and it's parents DIV's background color.
My HTML code looks like this:
<div id="time-later">
<div class="time-arrow"></div>
<p>later</p>
</div>
The matching CSS code:
#time-later {
height: 35px;
width: calc(25% - (15px/4));
}
#time-later p {
display: block;
width: calc(100% - 14.5px);
margin-right: 14.5px;
}
#time-later .time-arrow {
float: right;
width: 0;
height: 0;
border-top: 17.5px solid transparent;
border-left: 14.5px solid green;
border-bottom: 17.5px solid transparent;
z-index: 1;
}
some styling
#time-later p {
text-align: center;
line-height: 35px;
background-color: green;
}
#time-later p:hover {
background-color: red;
}
#time-later p:active {
color: #FFF;
background-color: gray;
}
When I move the mouse over the #time-later element I want the background of the p-element and the border of the .arrow-element to be colored in the same color.
JSFiddle
Is there any CSS-only solution to achieve something like this? I know it would be easier to place an image instead, but I'm searching for a CSS-only solution. Thank you for your help!

Move :hover and :active to the parent element, then target the children as follows:
Example Here
#time-later:hover > p { background-color: red; }
#time-later:hover > .time-arrow { border-left-color: red; }
#time-later:active > p { background-color: gray; color: white; }
#time-later:active > .time-arrow { border-left-color: gray; }

JSBIN
Through modify their parent pseudo-style to handle what you want.
css
#time-later:hover p{
background-color: red;
}
#time-later:hover .time-arrow{
border-left: 14.5px solid red;
}
#time-later:active p {
color: #FFF;
background-color: gray;
}
#time-later:active .time-arrow{
border-left: 14.5px solid gray;
}

like this? http://jsfiddle.net/z0vm0nm4/1/
#time-later:hover p{
background-color: red;
}
#time-later:hover .time-arrow {
border-left: 14.5px solid red;
}

you can do hover on div
example:
div#time-later:hover .time-arrow{
border-top: 17.5px solid transparent;
border-left: 14.5px solid background:tan;
border-bottom: 17.5px solid transparent;
}
div#time-later:hover p{
background:tan;
}

try this one, worked for me:
/* some stylings */
#time-later p {
text-align: center;
line-height: 35px;
background-color: green;
}
#time-later:hover p {
background-color: red;
}
#time-later:active p {
color: #FFF;
background-color: gray;
}
#time-later:hover .time-arrow {
border-left: 14.5px solid red;
}
#time-later:active .time-arrow {
border-left: 14.5px solid gray;
}
http://jsfiddle.net/h50L9noy/

Related

Add a Stroke / Outline to a Custom Scrollbar

I have a custom scrollbar that I would like to add a stroke/outline to. I have not found any articles on how to do this and the 'stroke' nor the 'outline' using CSS seems to do the trick. Is this possible to do?
JSFiddle: https://jsfiddle.net/hd2u4gs3/
<div id="box"></div>
body {
background: black;
}
::-webkit-scrollbar {
width: 25px;
}
::-webkit-scrollbar-track {
background: black;
}
::-webkit-scrollbar-thumb {
background: #7e7e7e;
stroke: yellow;
stroke-width: 3px;
height: 80px;
}
::-webkit-scrollbar-thumb:hover {
background: #ffffff;
}
#box {
height: 10000px;
}
If i was not wrong you need outline around thumb of scroll bar please
check the solution below
body {
background: black;
}
::-webkit-scrollbar {
width: 23px;
background: red;
}
::-webkit-scrollbar-track {
background: red;
border: 4px solid #fff;
border-bottom: none;
border-top: none;
}
::-webkit-scrollbar-thumb {
background: #7e7e7e;
stroke: yellow;
stroke-width: 3px;
height: 80px;
border: 4px solid yellow;
border-bottom: none;
border-top: none;
}
::-webkit-scrollbar-thumb:hover {
background: #ffffff;
border: 3px solid green;
border-bottom: none;
border-top: none;
}
#box {
height: 10000px;
}
<div id="box"></div>
How about just adding a right border to the box?
body {
background: black;
margin: 0;
}
::-webkit-scrollbar {
width: 25px;
}
::-webkit-scrollbar-track {
background: black;
}
::-webkit-scrollbar-thumb {
background: #7e7e7e;
stroke: yellow;
stroke-width: 3px;
height: 80px;
}
::-webkit-scrollbar-thumb:hover {
background: #ffffff;
}
#box {
height: 10000px;
border-right: 1px solid grey;
}
<div id="box"></div>
Or just add a border-left to the track: https://jsfiddle.net/owuc4jdf/
::-webkit-scrollbar-track {
background: black;
border-left: 1px solid green;
}

Align pentagon shapes which have text in them

I'm trying to make a bar which holds the navigation stack.
For example: Here I am on the client page
And then when I click on a clients name I go to a new page and it adds onto the bar:
Here is what I have so far: http://jsbin.com/bahaqebiga/edit?html,css,js,output
All that needs to be done is change of shape and I'd think some how to manage the z-index as the next arrow should always be under the previous one. I have tried with svg but couldn't get it right because of the text and there was a weird padding I couldn't get rid of, and also with pure html/css but also failed.
Note: position absolute can NOT be used
Any ideas?
Thanks
You can have a pure css solution for that. No need for svg/js.
Use the :after pseudo-selector to create an arrow, and color it based on it's position:
.stack-arrow p:after {
content: "";
width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 25px solid blue;
top: 0;
margin-left: 14px;
position: absolute;
}
.stack-arrow:nth-child(2) {
background: red;
}
.stack-arrow:nth-child(2) p:after{
border-left-color: red;
}
.stack-arrow:nth-child(3) {
background: green;
}
.stack-arrow:nth-child(3) p:after{
border-left-color: green;
}
.stack-arrow:nth-child(4) {
background: blue;
}
.stack-arrow:nth-child(4) p:after{
border-left-color: blue;
}
Check this example:
http://jsbin.com/jusuwihize/1/edit?html,css,js,output
Here is a working example (after react):
.top-nav {
display: flex;
align-items: center;
position: absolute;
top: 0;
height: 50px;
width: 100%;
z-index: 1000;
background-color: #222;
}
.top-nav img {
cursor: pointer;
}
.stack-arrow {
cursor: pointer;
height: 50px;
color: white;
background-color: blue;
font-family: sans-serif;
padding: 0px 15px;
margin: 0.5px;
}
.stack-arrow {
padding-left: 25px;
}
.stack-arrow p:after {
content: "";
width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 25px solid blue;
top: 0;
margin-left: 14px;
position: absolute;
}
.stack-arrow:nth-child(2) {
background: red;
}
.stack-arrow:nth-child(2) p:after{
border-left-color: red;
}
.stack-arrow:nth-child(3) {
background: green;
}
.stack-arrow:nth-child(3) p:after{
border-left-color: green;
}
.stack-arrow:nth-child(4) {
background: blue;
}
.stack-arrow:nth-child(4) p:after{
border-left-color: blue;
}
<div class="top-nav" data-reactid=".0"><img height="50px" src="http://skihighstartups.com/wp-content/uploads/2015/07/logo-placeholder.jpg" data-reactid=".0.0"><div class="stack-arrow" data-reactid=".0.1"><p data-reactid=".0.1.0">Clients</p></div><div class="stack-arrow" data-reactid=".0.2"><p data-reactid=".0.2.0">Name</p></div><div class="stack-arrow" data-reactid=".0.3"><p data-reactid=".0.3.0">Extra</p></div></div>

Hover property not working on one element but is on another

When I hover over my Login and Register buttons, they do not turn yellow. When I hover over my click-to-email-admin button, it turns yellow. The code is the same for both links. As far as I can tell, nothing is stopping the two buttons from changing colors.
I'm aware that a:hover has to come AFTER a, a:visited. I've got it set up that way.
What is wrong with my CSS?
CSS
html {
min-height: 100%;
width: 2000px;
max-width: 100%;
}
body {
background: #292E37;
font-size: 13px;
width: 2000px;
max-width: 100%;
}
header {
z-index: 1;
top: 0;
max-width: 100%;
position: fixed;
background: cornflowerblue;
width: 100%;
height: 10%;
-moz-box-shadow: 0px 1px 5px 1px #000;
-webkit-box-shadow: 0px 1px 5px 1px #000;
box-shadow: 0px 1px 5px 1px #000;
border-bottom: 1px solid yellow;
font-family: fantasy;
/*This shadowbox is perfect to simulate floating on the bottom of a box */
}
these links do not work with hover
#loginButton {
bottom: 1%;
left: .5%;
position: absolute;
float: right;
text-decoration: none;
font-size: 12px;
max-width: 100%;
max-height: 100%;
}
#loginButton a {
color: green;
}
#loginButton a:visited {
color:black;
}
#loginButton a:hover {
color: yellow;
}
#registerButton {
bottom: 1%;
left: 3%;
position: absolute;
float: left;
text-decoration: none;
color: white;
font-size: 12px;
}
#registerButton a, a:visited {
color: white;
}
#registerButton a:hover {
color: yellow;
}
this link does work with hover
#centerIntro {
margin: inherit;
margin-top: 3%;
text-align: center;
-moz-box-shadow: 0px 1px 5px 1px #000;
-webkit-box-shadow: 0px 1px 5px 1px #000;
box-shadow: 0px 1px 5px 1px #000;
border: 1px solid yellow;
font-family: fantasy;
font-size: 20px;
color: white;
text-decoration: none;
text-shadow: 2px 0px 7px rgba(0, 0, 0, 1);
background-color: cornflowerblue;
border-radius: 1%;
width: 1000px;
max-width: 50%;
}
#centerIntro a, a:visited {
color: white;
}
#centerIntro a:hover {
color: yellow;
}
HTML
<header>
<img id="headerTitle" src="images/headerTSC.png" alt="The Stream Crate title">
<div>Login</div>
<div>Register</div>
</header>
Any ideas?
There's a few thing wrong here.
First, your selectors are wrong:
You have this markup:
<a id="loginButton" ...
And you're attempting to apply styles to it using this selector:
#loginButton a { ... }
That selector doesn't match that link. It would match an <a> tag nested inside any other element that had a id="loginButton", but it will not match an <a> tag whose id is loginButton.
You need to simply apply the styles to #loginButton and #loginButton:hover.
Also, you say...
I'm aware that a:hover has to come AFTER a, a:visited. I've got it set up that way.
That's wrong. That isn't how CSS selector precedence works. Order is important, but later selectors don't necessarily win just because they come later. In this case, a:hover is more specific, and it can come before or after a and it will still win.
Instead of
#loginButton a:hover {
color: yellow;
}
and
#registerButton a:hover {
color: yellow;
}
Try this, these buttons are already anchor elements so there is no need to add the "a" in the css
#loginButton:hover {
color: yellow;
}
and
#registerButton:hover {
color: yellow;
}
Here is an example of the buttons without the "a" references in the css
https://jsfiddle.net/41dha1p7/
Change your css
#loginButton a {
color: green;
}
to
#loginButton a:link {
color: green;
}
The same to #registrationButton.
The order also matters. It should be :link, :visited, :hover, and :active.

css border around two divs

Hello guys need your help by merging two <div>s' borders. Here is what I want to get and what I've gotten until now:
enter image description here
and this is what i want to do enter image description here
Could someone please tell me how to do so? Here is my code if it helps something:
css :
#plink {
position: relative;
width: 200px;
float: left;
}
#open {
border-top: 1px solid black;
border-bottom: 1px solid black;
border-left: 1px solid black;
width: 200px;
text-align: center;
line-height: 50px;
}
#closed {
border: 1px solid black;
width: 200px;
text-align: center;
line-height: 50px;
}
#closed:hover a {
display: block;
}
#open:hover a {
display: block;
}
#pbase {
border: 1px solid black;
position:relative;
width: 600px;
height: 300px;
float: left;
}
and html :
<div id="plink">
<div id="open">My details</div>
<div id="closed">My ads</div>
<div id="closed">Favorites</div>
</div>
<div id="pbase"></div>
#plink {
position: relative;
width: 200px;
float: left;
border-top: 1px solid black;
border-left: 1px solid black;
}
#open {
border-bottom: 1px solid black;
border-right: 1px solid white;
text-align: center;
line-height: 50px;
}
#closed {
border-bottom: 1px solid black;
width: 200px;
text-align: center;
line-height: 50px;
}
#pbase {
border: 1px solid black;
position: relative;
width: 600px;
height: 300px;
float: left;
margin-left: -1px;
z-index: -1;
}
https://jsfiddle.net/8rrov5hb/
This was achieved by setting #pbase with margin-left: -1px and z-index: -1 to put it behind #plink
The div #open has border-right: 1px solid white to make it appear transparent - just change this to whatever background color you need
Set border-right color white and use z-index to keep open menu on over the right part. Try like following. Hope this will help you.
#open {
border-color: black #fff black black;
border-style: solid;
border-width: 1px;
line-height: 50px;
position: relative;
text-align: center;
width: 199px;
z-index: 1;
}
Update:
$('.menu a').click(function (e) {
e.preventDefault();
$(this).closest('div').siblings().removeClass('open');
$(this).closest('div').addClass('open');
});
#plink {
position: relative;
width: 200px;
float: left;
}
.open {
background-color: #a7a7ff !important;
border-right: 1px solid #a7a7ff !important;
line-height: 50px;
position: relative;
text-align: center;
z-index: 1;
}
.menu {
border: 1px solid black;
width: 200px;
text-align: center;
line-height: 50px;
background-color: #5e5eb6;
}
.menu:hover a {
display: block;
}
.open:hover a {
display: block;
}
#pbase {
border: 1px solid black;
position: relative;
width: 600px;
height: 300px;
float: left;
background-color: #a7a7ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="plink">
<div class="menu open">My details</div>
<div class="menu">My ads</div>
<div class="menu">Favorites</div>
</div>
<div id="pbase"></div>
A couple of issues. You were using multiple id's with the same name, these should have been changed to classes. and 'open' / 'active' should be a state set with a class.
There was duplication in the css for the different states.
The main takeaway is that you needed to change the width of the active `.tab-nav'.
css was missing box-sizing
* {
box-sizing: border-box;
}
.tab-navigation {
position: relative;
width: 200px;
float: left;
}
.tab-nav {
border-top: 1px solid black;
border-left: 1px solid black;
background-color: white;
width: 200px;
text-align: center;
line-height: 50px;
}
.tab-nav:last-of-type {
border-bottom: 1px solid black;
}
.tab-nav:hover, .tab-nav.open {
width: 202px;
}
.tab-nav a {
display: block;
}
#pbase {
border: 1px solid black;
position:relative;
width: 600px;
height: 300px;
float: left;
z-index: -1;
}
<div class="tab-navigation">
<div class="tab-nav open">My Details</div>
<div class="tab-nav">My ads</div>
<div class="tab-nav">Favorites</div>
</div>
<div id="pbase"></div>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#plink').click(function(){
$('#open, #pbase').css('border','2px solid #000');
})
})
</script>

Buttons now under transparency?

I've been having trouble all day with these buttons. First, both buttons were on top of each other looking like this, http://i.imgur.com/wVmntpQ.jpg and now after posting here asking what to do, it looks like this now, http://imgur.com/OmXDQct
I was told to change in my css from this :
CSS:
button {
float:left;
margin-top:250px;
color:white;
display: block;
margin: 30px;
padding: 7px 35px;
font: 300 150% langdon;
background: transparent;
border: 3px solid white;
cursor: pointer;
}
button:hover {
background: black;
border: 1px solid black;
}
button:active {
background: #2e2e2e;
border: 1px solid black;
color: white;
}
I guess you just need to add position:relative to the div which contains the buttons, so make it like this:
HTML
<div style="position: relative;">
GO ROAM</br>
START HERE.
<button>SIGN UP</button>
<button>LOG IN</button>
</div>
Hope this will help you ...
Ok, here is the working code on jsfiddle. I have removed the absolute path from the buttons and added display: inline-block; so now they're one next to the other. I have also added the top: 250px declaration in the wrapper.
button {
color:white;
display: inline-block;
margin: 30px;
padding: 7px 35px;
font: 300 150% langdon;
background: transparent;
border: 3px solid white;
cursor: pointer;
}
button:hover {
background: black;
border: 1px solid black;
}
button:active {
background: #2e2e2e;
border: 1px solid black;
color: white;
}