I am wanting to create two identical nav bars on a site. What I want to do is "link" the :hover effects on each nav bar, so that when one link on NavBar1 is hovered, not only does the :hover effect display on NavBar1, but the same :hover effect should display simultaneously on the corresponsing link on NavBar2.
I've managed to get this to work one-way by using the adjacent sibling combinator in my CSS, but my problem is I can't seem to get it to work in reverse. In other words, when hovering over Link1 in NavBar1, the :hover effect displays on Link1 in NavBar1 and Link1 in NavBar2. However, when hovering over Link1 in NavBar2, the :hover effect displays on Link1 in NavBar2 only (because the adjacent sibling combinator affects only the element following it, not the preceding element).
Is it possible to achieve what I'm wanting to do here?
See what I mean here if I haven't explained clearly: http://jsfiddle.net/9AbvE/697/
This isn't exactly what I'm wanting. I need each nav bar to be in separate divs, but I haven't been able to get the effect to work yet by doing so. I've thrown this code together just to give readers an idea of what I'm trying to accomplish.
Notice the difference between selecting Link1 in the first list of links verses the second. I want the same effect when moving back and forth, and not just one-way (i.e. selecting the bottom "Link1" should turn both "Link1"'s black, just like selecting the top one does).
You could always fake it by "linking" the two using a common parent element: http://jsfiddle.net/jjordanca/TNeZU/
HTML:
<div id="navbar">
<div id="linkone">
<a class="one" href="#">Link1</a>
<a class="one" href="#">Link1</a>
</div>
<div id="linktwo">
<a class="two" href="#">Link2</a>
<a class="two" href="#">Link2</a>
</div>
<div id="linkthree">
<a class="three" href="#">Link3</a>
<a class="three" href="#">Link3</a>
</div>
</div>
CSS:
a {
text-decoration: none;
color: red;
margin-right: 20px;
padding: 0 10px;
}
#navbar {
border: 1px solid red;
width: 500px;
margin: 50px;
padding: 20px;
height: 100px;
position: relative;
}
#navbar div {
text-align: center;
width: 100px;
}
/* LINK 1 */
#linkone {
position: absolute;
}
.one + .one {
position: absolute;
top: 80px;
left: 0;
}
#linkone:hover {
color: #000;
background-color: #008800;
}
.one {
position: absolute;
left: 0;
color: inherit;
background-color: inherit;
}
/* LINK 2 */
#linktwo {
position: absolute;
left: 80px;
}
.two + .two {
position: absolute;
top: 80px;
left: 0;
}
#linktwo:hover {
color: #000;
background-color: #008800;
}
.two {
position: absolute;
left: 0;
color: inherit;
background-color: inherit;
}
/* LINK 3 */
#linkthree {
position: absolute;
left: 140px;
}
.three + .three {
position: absolute;
top: 80px;
left: 0;
}
#linkthree:hover {
color: #000;
background-color: #008800;
}
.three {
position: absolute;
left: 0;
color: inherit;
background-color: inherit;
}
Related
Here's a fairly simple jsfiddle. When I over over the blue square, the blue square's CSS hover state triggers (causing it to turn white). When I hover over the red square, the same thing happens with the red square.
What I want is when I hover over the overlap, that I trigger the hover states on both the red and blue square. Is this possible?
Specifically, can I indicate somehow that a hover state should trigger, but that it should also pass through to any element behind it?
Additionally, I'd like to do this in pure CSS. I'm sure it can be done with JS.
(The real code is more complicated, of course.)
Here's the full code:
HTML:
<div class="a">
<div class="b">
b
</div>
<div class="c">
c
</div>
</div>
CSS:
.a {
position: relative;
}
.b {
width: 40px;
height: 40px;
top: 5px;
left: 5px;
position: absolute;
background-color: blue;
}
.b:hover {
background-color: white;
}
.c {
width: 40px;
height: 40px;
top: 25px;
left: 25px;
position: absolute;
background-color:red;
}
.c:hover {
background-color: white;
}
If you don't mind editing your HTML slightly, there is a way to do this by adding another div in the HTML and using the CSS general sibling combinator (~), but it's still quite hacky and mostly side-steps the problem.
It's just creating a third div, changing its box so that it sits right in the overlap between .b and .c, and selecting .b and .c when it's hovered in the CSS to edit their styles.
jsfiddle
HTML
<div class="a">
<div class="overlap"></div>
<div class="b">
b
</div>
<div class="c">
c
</div>
</div>
CSS
.a {
position: relative;
}
.b {
width: 40px;
height: 40px;
top: 5px;
left: 5px;
position: absolute;
background-color: blue;
}
.b:hover {
background-color: white;
}
.c {
width: 40px;
height: 40px;
top: 25px;
left: 25px;
position: absolute;
background-color:red;
}
.c:hover {
background-color: white;
}
.overlap {
position: absolute;
top: 25px;
left: 25px;
/* w = leftOfC - leftOfB
h = topOfC - topOfB*/
width: calc(25px - 5px);
height: calc(25px - 5px);
background-color: none;
z-index: 2;
}
/* select .b and .c as siblings of the overlap div */
.overlap:hover ~ .b, .overlap:hover ~ .c {
background-color: white;
}
My question is actually more complex then the title, but I couldn't come up with a better one.
Initial Setup:
I use Bootstrap v4.0.0-alpha.2 and I ripped out this simple sidebar. I'm not sure why and if it's relevant but I also set flex: true in my _library-variable-overrides.scss (I use css-burrito) but since I only set it to try it out, I'm probably okay with turning it off. ;-)
What I want to do:
I would like to have a button in the sidebar that is bottom aligned. Ideally it's centered horizontally in the sidebar and has about 1em margin to the bottom.
What my code looks like:
_shell.scss & _sidenav.scss:
#shell-wrapper {
padding-left: 0;
transition: all 0.5s ease;
}
#shell-wrapper.toggled {
padding-left: 250px;
#shell-content-wrapper {
position: absolute;
margin-right: -250px;
}
}
#media(min-width:768px) {
#shell-wrapper {
padding-left: 250px;
}
#shell-wrapper.toggled {
padding-left: 0;
#shell-content-wrapper {
position: relative;
margin-right: 0;
}
}
#shell-content-wrapper {
padding: 20px;
position: relative;
}
}
#sidenav-wrapper {
z-index: 1000;
position: fixed;
left: 250px;
width: 0;
height: 100%;
margin-left: -250px;
overflow-y: auto;
background: #000;
transition: all 0.5s ease;
}
#shell-wrapper.toggled {
#sidenav-wrapper {
width: 250px;
}
}
#shell-content-wrapper {
width: 100%;
position: absolute;
padding: 15px;
}
/* Sidenav Styles */
.sidenav-nav {
position: absolute;
top: 0;
width: 250px;
margin: 0;
padding: 0;
list-style: none;
li {
text-indent: 20px;
line-height: 40px;
a {
display: block;
text-decoration: none;
color: #999999;
}
a:hover {
text-decoration: none;
color: #fff;
background: rgba(255, 255, 255, 0.2);
}
a:active, a:focus {
text-decoration: none;
}
}
>.sidenav-brand {
height: 65px;
font-size: 18px;
line-height: 60px;
a {
color: #999999;
}
a:hover {
color: #fff;
background: none;
}
}
}
#media(min-width:768px) {
#sidenav-wrapper {
width: 250px;
}
#shell-wrapper.toggled #sidenav-wrapper {
width: 0;
}
}
and index.html:
<div id="shell-wrapper" class="toggled">
<div id="sidenav-wrapper">
<ul class="sidenav-nav">
<li class="sidenav-brand">
Brand
</li>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li id="logout">
<button class="btn btn-danger-outline">Logout</button>
</li>
</ul>
</div>
<button class="navbar-toggler" type="button">
☰
</button>
<div id="shell-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<!--Main Content Here-->
</div>
</div>
</div>
</div>
</div>
The logout button is one in question. I just tried doing it as a <li> of the sidenav-nav but I'm not tied to this setup.
What I have tried so far:
a lot!
What came closest to what I want was adding this:
.sidenav-nav {
height: 100%;
}
#logout {
position: absolute;
bottom: 1em;
}
It's pretty close to my goal on a desktop browser, but hitting that show me this on a phone button in chrome, the logout button is just gone.
i haven't worked with css-buritto, but you could look into giving the button a class or id and passing the position:relative argument you can then set a bottom: 1em and that should position the button at the bottom. alternativly you can also look into the other position elements like fixed that could also do the trick
like you mentioned a the end
#logout {
position: relative;
bottom: 1em;
}
so, I have some html layout and I cannot change the html, ONLY the css. Now, I can achieve the colors I want and create that circle (see image), with border-radius. Here is the rub, each square is a span. There are no inner divs/outer divs.. just the span. Is there a way to achieve, with css, that circle and then the half background fill.
the code would be, on a base level:
<span class="day is-range is-selected" />22</span>
<span class="day is-range" />23</span>
Basically, when a user selects a date, I color it that bright reddish color, make it a circle, make the other dates backgrounds that more bourbon red color.. great... BUT the selected date with the cirle doesn't have that "bleed into" the other square look with half its span colored. Is there a way to achieve this with css and no mods to the html?
I've only been able to achieve the following:
What I want to achieve.
This is really what I am trying to achieve. The span, goes to a circle, I can do that - but somehow make half of the span have a different background color.
The CSS I am using is fairly trivial. Note, I have to use !important to override what is gen'ed.
.is-selected {
background-color: #selected-background !important;
color: #base;
border-radius: 20px;
}
.is-inRange {
background-color: #active-background !important;
color: #base;
}
A pseudo-element would seem the only option here as the HTML cannot be altered.
The specificity has be managed though:
.day {
float: left;
width: 40px;
height: 40px;
background: plum;
line-height: 40px;
text-align: center;
color: white;
}
.is-range {
background: plum;
}
.is-range.is-selected {
background-color: red;
border-radius: 50%;
position: relative;
}
.is-range.is-selected:after {
content: "";
position: absolute;
top: 0;
width: 50%;
height: 100%;
left: 50%;
background: plum;
z-index: -1;
}
<div>
<span class="day is-range is-selected">22</span>
<span class="day is-range">23</span>
<span class="day is-range">24</span>
<span class="day is-range">25</span>
</div>
.day {
float: left;
width: 3em;
height: 3em;
background: silver;
line-height: 3em;
text-align: center;
}
.is-selected {
background-color: red;
border-radius: 50%;
position: relative;
}
.is-selected:after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 50%;
background: silver;
z-index: -1;
}
<span class="day is-range is-selected">22</span>
<span class="day is-range">23</span>
If both days are in one row:
.day {
float: left;
width: 3em;
height: 3em;
background: silver;
line-height: 3em;
text-align: center;
}
.is-selected {
background-color: red;
border-radius: 50%;
position: relative;
}
.is-selected + .day {
margin-left: -1.5em;
padding-left: 1.5em;
}
<span class="day is-range is-selected">22</span>
<span class="day is-range">23</span>
I have a set of progress bars displaying different values in real time. My only problem is that I can't seem to figure out how to keep the number value in the center of the bar, as well as on top at all times. Right now it's being pushed 'ahead' of the blue bar, and disappears when it goes outside the right side of the bar.
Here's how it looks:
Markup:
<td class="gridTableCell">
<div style='position: relative' class='progress progress-info'>
<div class='bar' id='signalRdepthRangePercentage-#:ViewUnitContract.ConveyanceId #' style='width: #: DepthRangePercentage#%'>
</div>
<span class='gridSpan' id='signalRdepth-#:ViewUnitContract.ConveyanceId #'>#: ViewUnitContract.CurrentRun.LatestWellLogEntry.Depth#</span>
<span class='hidden' id='signalRMaxDepthRange-#:ViewUnitContract.ConveyanceId #'>#: MaxDepthRange#</span>
<span class='hidden' id='signalRMinDepthRange-#:ViewUnitContract.ConveyanceId #'>#: MinDepthRange#</span>
</div>
</td>
And my css 'gridSpan':
.gridSpan {
position: absolute;
top: 0px;
z-index: 2;
text-align: center;
color: #676767;
width: 100%
}
The first of the three spans is the one that displays the number value inside the bar.
Any suggestions how I can keep this centered at all times, and not pushed in front of the blue filler with a huge margin?
Do something like the following:
FIDDLE
The outer element has text-align:center
The gridSpan element has display:inline-block (not absolutely positioned)
The inner element (with the blue % progress) needs to be absolutely positioned, so as not to be effected by the text-align:center.
Markup:
<div class="outer">
<span class="inner"></span>
<span class="gridSpan">9048.343</span>
</div>
CSS
.outer
{
width: 70%;
margin:20px;
height: 30px;
border: 1px solid gray;
overflow: hidden;
border-radius: 15px;
position:relative;
text-align: center;
}
.inner
{
background: aqua;
display:inline-block;
position:absolute;
left:0;
width: 20%;
height: 30px;
}
.gridSpan {
display:inline-block;
margin-top: 5px;
color: #676767;
position: relative;
z-index:2;
}
Alternatively, if you knew the width of the value you could do this by adding display:block;left:0;right:0 and margin:0 auto to your class:
.gridSpan {
display:block;
position: absolute;
margin: 0 auto;
top: 0px;
left:0;
right:0;
z-index: 2;
color: #676767;
width: x px; /*(width of value)*/
}
Actually, I finally figured this out based on this fiddle:
http://jsbin.com/apufux/2/edit (Wonder why I've never seen this post before!?)
Seems that I was missing some style overrides to the .bar and .progress part:
.progress {
position: relative;
}
.bar {
z-index: 1;
position: absolute;
}
.progress span {
position: absolute;
top: 0px;
z-index: 2;
text-align: center;
color: #676767;
width: 100%
}
Anyways, thanks for your effort! :)
I have an element that looks something like this:
___
| X|
‾‾‾
So essentially a tiny box with a button to close it.
I have also applied CSS to the element, so that when hovered, it will turn to something like this:
___________________
| X|
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Simply put, it'll just become wider.
Now. what I want to do is that whenever the user hovers over the close button (X), the box will not change its size.
But when the user hovers on anywhere else on the box, it would behave as suggested.
Is this possible with pure CSS?
EDIT: Sorry that I added this late, but the answers should be based around this example: http://jsfiddle.net/fpY34
Using the markup you have, I have no clue how to do it without fixed widths, and absolute nastiness. But here's me giving my all! http://jsfiddle.net/fpY34/15/
<div id='outer'>
<div id='notOuter'>
<div id='content'>
<div id='img'>
</div>
<div id='label'>
Text example
</div>
<div id='closeButton'>
X
</div>
</div>
</div>
</div>
and the beauty:
#outer { height: 30px; }
#notOuter {}
#content { float: left; position: relative; }
#closeButton { background: #0f0; position: absolute; top: 0; left: 30px; width: 30px; height: 30px;}
#img { background: #f0f; width: 30px; height: 30px; position: absolute; left: 0; top: 0; }
#label { display: none; position: absolute; left: 0; top: 0; width: 60px; height: 30px; background: #f00; }
#img:hover { width: 60px; z-index: 10; }
#img:hover + #label,
#label:hover { display: block; z-index: 20; }
#img:hover ~ #closeButton,
#label:hover + #closeButton { left: 60px; }
would you check this please and tell me if that what you want ?
http://jsfiddle.net/UjPtv/10/
<style>
.divs
{
height: 20px;
width: 100px;
border: 1px solid;
padding: 5px 3px;
}
.divs:hover
{
width: 50px;
padding-left: 150px
}
</style>
<div class="divs"><span>X</span></div>
You could float them:
<div class="box">
<div>
Content
</div>
<span>X</span>
</div>
.box {display:inline-block;border:1px solid black}
.box div {width:100px;float:left}
.box div:hover {width:200px}
.box span {float:left}
Might not work in older browsers though.