So, I have a div that appears at the top of my screen, and when you hover over it, at the bottom of the screen, text appears.
I want to add another effect to the div that makes more text appear in a completely different place on the screen, while the other text stays in the same place.
Is that possible? Preferably using CSS/HTML instead of Java or anything?
You can use ~ (tilde) operator to target all your siblings (all should have the same parent) show on hover. Please have a look at the example snippet below:
body { margin: 0; }
.holder {
text-align: center;
height: 100vh;
}
.hover {
position: absolute;
top: 10%;
left: 50%;
transform: translateX(-50%);
color: red;
font-size: 30px;
font-weight: bold;
border: 2px solid red;
padding: 10px 15px;
cursor: default;
transition: all .2s linear;
}
.hover:hover {
background: rgba(255, 0, 0, 0.1);
}
.hover:hover ~ .show-text {
opacity: 1;
transition: all .2s linear;
}
.show-text {
position: absolute;
opacity: 0;
font-size: 20px;
border-bottom: 1px solid #aaa;
transition: all .2s linear;
}
.one {
bottom: 20%;
left: 20%;
}
.two {
bottom: 20%;
right: 20%;
}
<div class="holder">
<div class="hover">Hover Me!</div>
<div class="show-text one">I'm Text 1</div>
<div class="show-text two">I'm Text 2</div>
</div>
Hope this helps!
Related
I am trying to create an effect when div class="container" is being hovered, a smooth upper transition occurs of another div from bottom. Only during hover, this should happen cause I want that .bottom div to be hidden. When that div is not hidden, I can see the effect as I want. But as I hide the bottom div, that hovering effect smooth transition effect cannot be seen. Check this code once.
HTML CODE
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
CSS code
.box{
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top:80px;
left:0;
/* display: none; */
}
.box:hover .bottom {
display: block;
transition: linear 0.2s;
top:55px;
}
Here is the codepen link
https://codepen.io/Biebk/pen/MWpREqb
First off, rather than display: none to hide the incoming element altogether, you can set its opacity to 0, and then when the parent is hovered, set it to 1, like so:
.bottom {
opacity: 0;
}
.box:hover .bottom {
opacity: 1;
}
I suppose that given you want an incoming "pull-up" effect on hover, you want to that element to also "pull-down" when the hover ends. You can reverse the same effect by using a :not(:hover) on the parent element:
.box:not(:hover) .bottom {
opacity: 0;
}
Also, be sure to set the transition on the non-hovered state. The following example provides the smooth transition you're looking for:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
transition: all .25s ease;
}
.box:not(:hover) .bottom {
top: 80px;
opacity: 0;
}
.box:hover .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
A secondary approach would be to place the bottom div as a sibling to the box, and use the adjacent sibling combinator to apply the hover effects:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
font-size: 20px;
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
top: 80px;
opacity: 0;
cursor: default;
transition: all .25s ease;
}
.box:hover + .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
</div>
<div class="bottom">
Everyone
</div>
Use opacity property rather than display to achieve the desired effect, then
use the following code
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
opacity: 0;
}
.box:hover .bottom{
opacity: 1;
transition: opacity 0.2s , top 1s;
top: 55px;
}
Use the following code.
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.hovered{
transition: all .2s;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
visibility: hidden;
}
.hovered:hover+.bottom {
transition: all .2s;
top: 55px;
visibility: visible;
}
<div class="box">
<div class="hovered">Hello</div>
<div class="bottom">
Everyone
</div>
</div>
This question already has answers here:
How to affect other elements when one element is hovered
(9 answers)
Closed 2 years ago.
When hovering over a side-info-panel (.popup-hover-section), I want the info-img to hide(.popup-hover-div p), and at the same time show the text in .show-span.
<section class="popup-hover-section">
<div class="popup-hover-div"><p></p><span class="show-span">Hidden text, but only until I am hovered over, and the whole section is shown! And my brother paragraph is hidden! :)</span></div>
</section>
.popup-hover-section {
height: 30%;
width: 65px;
position: absolute;
right: 0%;
top: 30%;
background-color: #111;
color: #eee;
border-radius: 40px 0 0 40px;
transition: width 1s;
transition-property: border-radius, width;
box-shadow: 7px 7px 3px 0px rgba(0,0,0,0.75);
z-index: 20;
}
.popup-hover-div p {
padding: 32px 32px 32px 32px;
display: flex;
align-self: center;
background: url(images/information.png) no-repeat;
background-size: 100%;
opacity: 0.5;
}
.show-span {
/*I want to show the text inside this one, and when I do, the p-img should not show anymore*/
}
.popup-hover-div p:hover {
opacity: 1;
}
.popup-hover-section:hover {
background-image: linear-gradient(147deg, #FFE53B 0%, #FF2525 74%);
transition-duration: 1.3s;
border-radius: 0 0 0 0;
transition-timing-function: cubic-bezier(0.18, 0.89, 0.32, 1.28);
width: 400px;
}
```
The trick is to catch the hover over the container (.popup-hover-section) and then continue the selector from there to style the elements within.
.popup-hover-div:hover .show-span{ //styles }
.popup-hover-div:hover p img{ //styles }
I trust you can tweak it from here, but if you need further assistance give a shout.
.popup-hover-section {
height: 30%;
width: 65%;
position: absolute;
right: 1%;
top: 30%;
background-color: #111;
color: #eee;
border-radius: 40px 0 0 40px;
transition: width 1s;
transition-property: border-radius, width;
box-shadow: 7px 7px 3px 0px rgba(0, 0, 0, 0.75);
z-index: 20;
}
.popup-hover-div p {
padding-left: 35px;
}
.show-span {
/*I want to show the text inside this one, and when I do, the p-img should not show anymore*/
color: transparent;
}
.popup-hover-div:hover .show-span{
color: lightblue;
}
.popup-hover-div:hover p img{
opacity: 0;
}
p, span{
position:absolute;
top:0;
left:0;
z-index: 1;
}
span{
top:30px;
left: 30px;
z-index: 2;
}
<section class="popup-hover-section">
<div class="popup-hover-div">
<p><img src="https://placekitten.com/380/100" /></p>
<span class="show-span">Hidden text, but only until I am hovered over, and the whole section is shown! And my brother paragraph is hidden! :)</span></div>
</section>
Hellooo
.show-span {
opacity: 0;
}
.popup-hover-section:hover .show-span {
/*I want to show the text inside this one, and when I do, the p-img should not show anymore*/
opacity: 1;
transition-delay: 1.3s;
}
I think this is the one you are looking for. Please let me know if this works.
Just hover on 'a headline' in the snippet below and you will see how elements are moving. Why?
There's no margin .. And they're only moving when I add border to the inline-block element. Try to add more border width in section.twelve a like:
section.twelve a {
border-bottom: 10px solid #FFFAFF;
}
But if you remove the border everything's fine.. Why is this behavior ? and is it only for border?
I just want to add any styles to the element without effecting the others.
section{
position: relative;
height: 300px;
padding: 15px 80px;
z-index: 1;
}
section h1{
font-size:3em;
font-weight: 100;
line-height: 1.3;
}
section a {
position: relative;
display: inline-block;
text-decoration: none;
transition: all 0.3s ease-in-out;
vertical-align: bottom;
}
section.twelve {
background: #121A5A;
color: #FFFAFF;
}
section.twelve a {
color:#D8315B;
font-weight: 700;
overflow: hidden;
padding: 0px 5px;
transition all 0.2s ease;
border-bottom: 5px solid #FFFAFF;
}
.twelve a:before{
content: "";
top:0; left: 0;
position: absolute;
width:100%; height: 100%;
background: #FFFAFF;
z-index: -1;
transition: all 0.2s ease;
transform: translateX(100%);
}
.twelve a:hover::before {
transform: translateX(-95%);
background: #D8315B;
}
.twelve a:hover{
color: #FFFAFF;
transform: translateX(5px);
border-bottom: 1px solid #FFFAFF;
}
<section class="twelve">
<h1>Write a headline that makes people do kind of a double take whenthey read it.</h1>
</section>
When you add, or change the width, of a border, that changes the size of the element. Hence, by adding the border on hover, the box grows to occupy more space, which naturally shifts the position of surrounding text / elements.
One method to resolve this issue is to always have the border present, so the size of the box is fixed. When the border shouldn't be visible, it's transparent.
Here's an example:
section {
position: relative;
height: 300px;
padding: 15px 80px;
z-index: 1;
}
section h1 {
font-size: 3em;
font-weight: 100;
line-height: 1.3;
}
section a {
position: relative;
display: inline-block;
text-decoration: none;
transition: all 0.3s ease-in-out;
vertical-align: bottom;
}
section.twelve {
background: #121A5A;
color: #FFFAFF;
}
section.twelve a {
color: #D8315B;
font-weight: 700;
overflow: hidden;
padding: 0px 5px;
transition all 0.2s ease;
border-bottom: 5px solid transparent; /* ADJUSTMENT */
}
.twelve a:before {
content: "";
top: 0;
left: 0;
position: absolute;
width: 100%;
height: 100%;
background: #FFFAFF;
z-index: -1;
transition: all 0.2s ease;
transform: translateX(100%);
}
.twelve a:hover::before {
transform: translateX(-95%);
background: #D8315B;
}
.twelve a:hover {
color: #FFFAFF;
transform: translateX(5px);
border-bottom: 5px solid white; /* ADJUSED */
}
<section class="twelve">
<h1>Write a headline that makes people do kind of a double take whenthey read it.</h1>
</section>
Yes, on hover you are changing element's border, so, element's total height also changes
I'm very new to CSS and HTML combination. I'm trying to make use of following code for dropdown menu. But when mouse is moved away from dropdown menu, it gets closed. I would like to close it onclick outside the dropdown menu. Can anyone suggest me a fix in CSS to achieve this? JSFiddle for me code is at following location Fiddle link. Your help will be much appreciated. HTML looks like this.
<div id="main">
<div class="wrapper">
<div class="content">
<content>
<div>
<ul>
<li>Lorem ipsum dolor</li>
<li>Consectetur adipisicing</li>
<li>Reprehenderit</li>
<li>Commodo consequat</li>
</ul>
</div>
</content>
</div>
<div class="parent">Drop Down Parent 1</div>
</div>
And CSS looks like this
#main {
margin: 30px 0 50px 0;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
}
#main .wrapper {
display: inline-block;
width: 180px;
margin: 0 10px 0 0;
height: 20px;
position: relative;
}
#main .parent {
height: 100%;
width: 100%;
display: block;
cursor: pointer;
line-height: 30px;
height: 30px;
border-radius: 5px;
background: #F9F9F9;
border: 1px solid #AAA;
border-bottom: 1px solid #777;
color: #282D31;
font-weight: bold;
z-index: 2;
position: relative;
-webkit-transition: border-radius .1s linear, background .1s linear, z-index 0s linear;
-webkit-transition-delay: .8s;
text-align: center;
}
#main .parent:hover, #main .content:hover ~ .parent {
background: #fff;
-webkit-transition-delay: 0s, 0s, 0s;
}
#main .content:hover ~ .parent {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
z-index: 2;
}
#main .content {
position: absolute;
top: 0;
display: active;
z-index: 2;
height: 0;
width: 180px;
padding-top: 30px;
-webkit-transition: height .5s ease;
-webkit-transition-delay: .4s;
border: 1px solid #777;
border-radius: 5px;
box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
#main .wrapper:active .content {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}
#main .content div {
background: #fff;
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
#main .content:hover {
height: 123px;
z-index: 3;
-webkit-transition-delay: 0s;
}
I'm looking at something like this and will set new content to content tag. What I'm really looking at is following
1) Click on dropdown menu. Show the dropdown.
2) When hovered on it keep displaying. When hover outside dropdown keep showing it.
3) When clicked somewhere outside dropdown then close the dropdown.
I know I'm using hover selector so my behavior is like that. But I want to covert it to above behavior and I don't know how to do it.
<div id="main">
<div class="wrapper">
<div class="content">
<content>
</content>
</div>
<div class="parent">Drop Down Parent 1</div>
Your HTML is wrong. If you see, you have wrapped <li> inside the <a> tag. That's a basic issue you have. And there are other issues.
Change your existing HTML:
<a><li>...</li></a>
To the right form:
<li><a>...</a></li>
And then the click works. An <a> cannot contain an <li> inside it. So the click doesn't happen.
I am trying to make a vertical splitter in background of a home-made slider (like here http://theymakeapps.com/users/add). How to do that ?
Here is what I've done so far:
<div id="wrapper">
<div id="dragger">
<div class="rect"></div>
<div class="arrow-down"></div>
</div>
<div id="slide-container"></div>
</div>
<br />
<span class="drag-caption active" id="hi-caption">Hi, bot</span> <span class="drag-caption" id="keep-caption">Keep sliding...</span> <span class="drag-caption" id="submit-caption">Submit</span>
And my css
* {
font-family: calibri
}
#dragger {
width: 10px;
padding: 5px 10px 5px 5px;
}
.rect {
background-color: #ccc;
height: 15px;
width: 10px;
}
.arrow-down {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #ccc;
}
#wrapper {
z-index: 55;
width: 200px;
padding: 0 10px;
}
#slide-container {
background: #dedede;
height:2px;
border-radius: 1px;
margin-top:-18px;
}
.drag-caption {
padding-right: 20px;
color: #d4d4d4;
-webkit-transition: color 500ms ease;
-moz-transition: color 500ms ease;
-ms-transition: color 500ms ease;
-o-transition: color 500ms ease;
transition: color 500ms ease;
}
.drag-caption.active {
color: black;
}
#submit-caption{
font-weight: bold;
}
And here is the jsfiddle. I'd like my separtors to be aligned over the caption and ON the background bar.
Like this:
---|---------|------------|
| | |
Hi bot Keep sliding Submit
I've added a div and two span elements and positioned the separators on the range using CSS Positioning.
Demo
Demo 2 (If you don't need the last one)
Demo 3 (As per your exact requirements)
Here, am using CSS Positioning to position each of the separator on the range bar, you can tweak up the lefts and rights according to your requirement.
<div id="slide-container"></div>
<div class="separators"><span></span><span></span></div> <!-- Add this after #slide-container -->
.separators {
position: relative;
}
.separators > span:before,
.separators > span:after{
content: "|";
position: absolute;
z-index: -1;
color: #DEDEDE;
}
.separators > span:nth-of-type(1):before {
left: 50px;
top: -12px;
}
.separators > span:nth-of-type(1):after {
left: 100px;
top: -12px;
}
.separators > span:nth-of-type(2):before {
left: 150px;
top: -12px;
}
.separators > span:nth-of-type(2):after {
left: 200px;
top: -12px;
}