When I hover the mouse over the box and try to click on the button but flickering occurs.
Can some one help me please I dont know who to fix it.
JSFiddle: https://jsfiddle.net/PedroTavares/fv7qjw8b/3/
.box {
margin-top: -1.5rem;
position: relative;
width: 250px;
height: 250px;
background-color: #06F;
transition: all .3s cubic-bezier(.34,1.61,.7,1);
z-index: 1;
}
.box:hover {
transform: translateY(-80px);
}
.box-btn{
margin-top: -3rem;
width: 250px;
display: flex;
justify-content: center;
}
button{
margin: 5px;
}
<div style="margin-top: 110px;" ></div>
<div>
<div class="box"></div>
<div class="box-btn">
<button> Text </button>
<button> Text </button>
</div>
</div>
I believe that this is solution for you.
I just add `.wrap` class around `.box` and now you can click on buton when hovering.
.box {
margin-top: -1.5rem;
position: relative;
width: 250px;
height: 250px;
background-color: #06F;
transition: all .3s cubic-bezier(.34,1.61,.7,1);
z-index: 1;
}
.wrap {
display: inline-block;
}
.wrap:hover .box {
transform: translateY(-80px);
}
.box-btn{
margin-top: -3rem;
width: 250px;
display: flex;
justify-content: center;
}
button{
margin: 5px;
}
<div style="margin-top: 110px;" ></div>
<div class="wrap">
<div class="box"></div>
<div class="box-btn">
<button> Text </button>
<button> Text </button>
</div>
</div>
Related
When I am applying hover on the card container it is not working or it is not flipping but I when I remove the hover it flips to the back side, I have tried everything that I know but still no progress on that.
`
import React from 'react'
import './Summary.css'
function Summary() {
return (
<div className='summary'>
<img className="body__image" src={require("./Images/background3Color.jpg")}></img>
<div className='box__container'>
<div className='boxes'>
<div className='box__inner'>
<div className='box__front'>
<img className='boxes__pics' src={require('./Images/AboutMe.jpg')}></img>
</div>
<div className='box__back'>
<div className='headline'></div>
<div className='education'>
<h2>Bachelor Of Technology in Computer Science and Tech.</h2>
</div>
<div className='work-ex'>
<p>Worked as an Application Dvelopment Associate in Accenture for 1 year</p>
</div>
</div>
</div>
</div>
<div className='boxes'>
<div className='box__inner'>
<div className='box__front'>
<img className='boxes__pics' src={require('./Images/Contacts.jpg')}></img>
</div>
<div className='box__back'>
<div className='headline'></div>
<div className='education'>
<h2>Bachelor Of Technology in Computer Science and Tech.</h2>
</div>
<div className='work-ex'>
<p>Worked as an Application Dvelopment Associate in Accenture for 1 year</p>
</div>
</div>
</div>
</div>
</div>
</div>
)
}
export default Summary
`
I was expecting the flip will work but to no avail.
I have tried to add hover to both box__inner and boxes container but still it would not flip.
Here is what I tried:
`
.summary{
position: relative;
height: 100vh;
z-index: -1;
}
.body__image{
height: 100vh;
}
.box__container{
position: absolute;
/* background-color: aqua; */
top: 0px;
width: 100%;
height: 100%;
/* opacity: 0.4; */
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: center;
}
.boxes{
height: 320px;
width: 300px;
margin: 0px 10px 0px 10px;
position: relative;
background-color: rgba(107,186,167,0.7);
perspective: 1000px;
overflow: hidden;
}
.box__inner{
position: absolute;
width: 100%;
height: 100%;
text-align: center;
transition: all 0.8s ease;
transform-style: preserve-3d;
}
.boxes__pics{
height: 100%;
width: 100%;
opacity: 0.7;
}
.box__inner:hover{
cursor: pointer;
transform: rotateY(180deg);
}
.box__front, .box__back{
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.box__front{
}
.box__back{
transform: rotateY(180deg);
}
`
The z-index was causing the main problem after removing it from the parent div the hover effect worked fine.
I have two sticky boxes. On hovering over a particular area inside the sticky boxes a popup opens. I want these popups to appear always on top of the sticky boxes. But increasing the z index of one hides the other. Any solution ?
Note - Removing sticky from the boxes and keeping z index of both the box same solves the problem but I need the boxes to be sticky.
.box {
margin: 40px;
padding: 20px;
background: yellow;
border: 1px solid red;
position: sticky;
}
.innerBox {
width: 100px;
height: 50px;
background: lightgreen;
position: relative;
}
.popup1 {
position: absolute;
width: 50px;
height: 150px;
top: 25px;
left: 35px;
background: red;
display: none;
}
.popup2 {
position: absolute;
width: 50px;
height: 150px;
bottom: 25px;
left: 35px;
background: black;
display: none;
}
.box1:hover .popup1 {
display: block;
}
.box2:hover .popup2 {
display: block;
}
.boxUp {
z-index: 3;
}
.boxDown {
z-index: 3;
}
<div>
<div class="box boxUp">
<div class="innerBox box1">
<p>
Hover Here
</p>
<div class="popup1">
</div>
</div>
</div>
<div class="box boxDown">
<div class="innerBox box2">
<p>
Hover Here
</p>
<div class="popup2">
</div>
</div>
</div>
</div>
Set the z-index on hover the .box
.box {
margin: 40px;
padding: 20px;
background: yellow;
border: 1px solid red;
position: sticky;
}
.innerBox {
width: 100px;
height: 50px;
background: lightgreen;
position: relative;
}
.popup1 {
position: absolute;
width: 50px;
height: 150px;
top: 25px;
left: 35px;
background: red;
display: none;
}
.popup2 {
position: absolute;
width: 50px;
height: 150px;
bottom: 25px;
left: 35px;
background: black;
display: none;
}
.box1:hover .popup1 {
display: block;
}
.box2:hover .popup2 {
display: block;
}
.box:hover {
z-index: 2;
}
<div>
<div class="box boxUp">
<div class="innerBox box1">
<p>
Hover Here
</p>
<div class="popup1">
</div>
</div>
</div>
<div class="box boxDown">
<div class="innerBox box2">
<p>
Hover Here
</p>
<div class="popup2">
</div>
</div>
</div>
</div>
This is the epitome of DRY code, I need to find an effective way of writing this code. I am currently using The Odin Project and the guidelines were to Duplicate Youtube's video section. I completed the navigation bar, but I am unhappy with it since I am just using position: absolute all the time. I was about using Grid or flexbox but I do not really know if it will help.
* {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
background-color: #f8f8f8;
}
.navigation {
height: 70px;
width: 100%;
background-color: #fff;
box-shadow: 0px 1px 4px #ebebeb;
}
.menu {
position: absolute;
left: 30px;
top: 22px;
opacity: .4;
cursor: pointer;
}
.menu:hover {
opacity: 1;
}
.youtube-logo {
width: 90px;
position: absolute;
left: 70px;
top: 10px;
}
.search-bar {
position: absolute;
top: 21px;
left: 390px;
width: 600px;
height: 33px;
background: url(images/search.svg) no-repeat 95% 50%;
background-size: 16px;
border-radius: 2px;
border: 1px solid #b3b3b3;
padding-left: 20px;
box-sizing: border-box;
outline: none;
}
::placeholder {
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2em;
padding-left: 3px;
}
.video {
position: absolute;
left: 1150px;
top: 25px;
cursor: pointer;
opacity: .4;
}
.stack {
position: absolute;
left: 1210px;
cursor: pointer;
width: 18px;
opacity: .4;
top: 27px;
}
.message {
position: absolute;
left: 1265px;
top: 24px;
;
opacity: .4;
cursor: pointer;
}
.bell {
position: absolute;
left: 1320px;
top: 23px;
opacity: .4;
cursor: pointer;
}
.icon {
position: absolute;
top: 16px;
left: 1374px;
cursor: pointer;
width: 36px;
opacity: .4;
}
<nav class="navigation">
<img src="images/menu.svg" alt="menu for the top left, shaped like a hamburger" class="menu">
<img src="images/youtube.logo.png" alt="youtube logo" class="youtube-logo">
<input type="text" name="searchbar" placeholder="Search" class="search-bar">
<img src="images/video.svg" alt="video icon" class="video">
<img src="images/google-app-button.png" alt="square stacks" class="stack">
<img src="images/message-square (1).svg" alt="message forr youtube" class="message">
<img src="images/bell.svg" alt="bell for top right bar" class="bell">
<img src="images/icons8-male-user-512.png" alt="profile picture for the bar" class="icon">
</nav>
Flexbox is pretty straight forward. You only need to set display: flex; on the parent element and the children elements will be affected.
.parent-flex {
display: flex;
}
<h2>Without Flexbox</h2>
<div>
<div>Child 1</div>
<div>Child 2</div>
<div>Child 3</div>
</div>
<h2>With Flexbox</h2>
<div class="parent-flex">
<div class="child-1">Child 1</div>
<div class="child-2">Child 2</div>
<div class="child-3">Child 3</div>
</div>
Since you are trying to replicate the youtube navbar, I'd recommend using flexbox to setup the "regions" of the navbar and then applying justify-content: space-between; to space out the regions equally.
.flex {
display: flex;
}
.parent {
justify-content: space-between;
}
.child-1 {}
.child-2 {}
.child-3 {
justify-content: flex-end;
}
<div class="flex parent">
<div class="flex child-1">
<div class="menu">[Menu Icon]</div>
<div class="logo">[Logo]</div>
</div>
<div class="flex child-2">
<div class="search-box">[search box]</div>
<div class="search-button">[search button]</div>
</div>
<div class="flex child-3">
<div class="user-photo">[the user's photo]</div>
<div class="etc">[whatever other icons...]</div>
</div>
</div>
You can check out this great article on css-tricks to learn more about the ins and outs of flexbox.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I would like to place a text on an image when hovering it. So far, I have created a hover effect to zoom the picture in and reduce the opacity which looks smooth. My problem now is to place text on the image because I am not sure how to place it in the picture.
Here is what I have so far: enter link description here
Code:
#portfolio {
background-color: : white;
padding-bottom: 100px;
}
#portfolio h1 {
font-size: 30px;
font-weight: 400px;
letter-spacing: 5px;
text-align: center;
color: #000;
}
#portfolio h2 {
font-size: 15px;
letter-spacing: 2px;
text-align: center;
color: #000;
}
.project {
display: inline-block;
width: 33.33%;
margin-right: -4px;
}
.img-box {
padding: 20px;
}
.project img {
width: 100%;
display: block;
border-radius: 12px;
}
.img-box img:hover {
transform: scale(1.1);
transition: 0.5s;
opacity: 0.5;
}
<section id="portfolio">
<div class="container">
<h1>MY WORK</h1>
<h2>Below you will find my favorite projects & school assignments</h2>
<!--CPU-->
<div class="project">
<div class="img-box">
<img src="./img/cpu.png">
</div>
</div>
<!--JAVA-->
<div class="project">
<div class="img-box">
<img src="./img/JSON.png">
</div>
</div>
<!--PHOTOSHOP-->
<div class="project">
<div class="img-box">
<img src="./img/photoshop.png">
</div>
</div>
</div>
</section>
Add another DIV as a child element to .img-box with settings as follows which contains the text. The most important part is position: absolute, plus the top, left and transform settings for the text position.
.img-box .hovertext {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.img-box:hover .hovertext {
display: block;
}
Also make sure to add position: relative to .img-box to create an anchor element for the absolutely positioned text DIV:
#portfolio {
background-color: : white;
padding-bottom: 100px;
}
#portfolio h1 {
font-size: 30px;
font-weight: 400px;
letter-spacing: 5px;
text-align: center;
color: #000;
}
#portfolio h2 {
font-size: 15px;
letter-spacing: 2px;
text-align: center;
color: #000;
}
.project {
display: inline-block;
width: 33.33%;
margin-right: -4px;
}
.img-box {
padding: 20px;
position: relative;
}
.project img {
width: 100%;
display: block;
border-radius: 12px;
}
.img-box img:hover {
transform: scale(1.1);
transition: 0.5s;
opacity: 0.5;
}
.img-box .hovertext {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.img-box:hover .hovertext {
display: block;
}
<section id="portfolio">
<div class="container">
<h1>MY WORK</h1>
<h2>Below you will find my favorite projects & school assignments</h2>
<!--CPU-->
<div class="project">
<div class="img-box">
<img src="./img/cpu.png">
<div class="hovertext">Test Text 1</div>
</div>
</div>
<!--JAVA-->
<div class="project">
<div class="img-box">
<img src="./img/JSON.png">
<div class="hovertext">Test Text 2</div>
</div>
</div>
<!--PHOTOSHOP-->
<div class="project">
<div class="img-box">
<img src="./img/photoshop.png">
<div class="hovertext">Test Text 3</div>
</div>
</div>
</div>
</section>
You can use pseudo-element and you can either add the text you want as an attribute value or add it manually which would be hideous. and then style it as you would, but of course add position:absolute to take it off of the flow so it can be put on top of the image. And don't forget your position:relative on the parent.
I used the div, because <img> doesn't have a closing tag therefore no pseudo-elements
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#portfolio {
background-color: : white;
padding-bottom: 100px;
}
#portfolio h1 {
font-size: 30px;
font-weight: 400px;
letter-spacing: 5px;
text-align: center;
color: #000;
}
#portfolio h2 {
font-size: 15px;
letter-spacing: 2px;
text-align: center;
color: #000;
}
.project {
display: inline-block;
width: 33.33%;
margin-right: -4px;
}
.img-box {
padding: 20px;
position: relative;
}
.img-box:after {
/* the text will be coming from the custom attribute data-text*/
content: attr(data-text);
background: #000000ba;
width: 100%;
font-size: 1.5em;
padding: 10px 0;
left: 0;
bottom: 0;
text-align: center;
position: absolute;
opacity: 0;
transition: opacity .2s linear;
}
.img-box:hover:after {
opacity: 1;
}
.project img {
width: 100%;
display: block;
border-radius: 12px;
}
.img-box img:hover {
transform: scale(1.1);
transition: 0.5s;
opacity: 0.5;
}
<section id="portfolio">
<div class="container">
<h1>MY WORK</h1>
<h2>Below you will find my favorite projects & school assignments</h2>
<!--CPU-->
<div class="project">
<div data-text="Text" class="img-box">
<img src="http://via.placeholder.com/350x150">
</div>
</div>
<!--JAVA-->
<div class="project">
<div data-text="text on image" class="img-box">
<img src="http://via.placeholder.com/350x150">
</div>
</div>
<!--PHOTOSHOP-->
<div class="project">
<div data-text="i'm a text too" class="img-box">
<img src="http://via.placeholder.com/350x150">
</div>
</div>
</div>
</section>
I was playing with the opacity attribute and wrote the following code:
#outer {
width: 500px;
height: 500px;
background: pink;
margin: 50px;
position: relative;
}
.item {
width: 50px;
height: 50px;
margin-right: 10px;
background: black;
opacity: 0.5;
float: left;
}
.inner {
width: 500px;
height: 500px;
background: red;
display: none;
position: absolute;
left: 0;
top: 0;
}
.item:hover {
opacity: 1;
}
.item:hover .inner {
display: block;
}
<div id="outer">
<div class="item">
<div class="inner"></div>
</div>
<div class="item">
<div class="inner"></div>
</div>
<div class="item">
<div class="inner"></div>
</div>
<div class="item">
<div class="inner"></div>
</div>
</div>
I wanted the inner div to show up and cover its parent item div when its parent item div is hovered. Because all the other item divs are set to be transparent to show through the inner div and only the hovered item div's opacity is changed to 1, I expected only the hovered item to be covered. However, all the item divs before the hovered one are also hidden. What happened?
Your issue is with absolute positioning: it's relative to "containing block", which is not the parent, but the ascendent element with a non-static position (in your case, the #outer element).
Simply addd position: relative to .item, and it will become the containing box.
Note that this has nothing to do with opacity.
Working snippet:
#outer {
width: 500px;
height: 500px;
background: pink;
margin: 50px;
position: relative;
}
.item {
width: 50px;
height: 50px;
margin-right: 10px;
background: black;
opacity: 0.5;
float: left;
position: relative;
}
.inner {
width: 500px;
height: 500px;
background: red;
display: none;
position: absolute;
left: 0;
top: 0;
}
.item:hover {
opacity: 1;
}
.item:hover .inner {
display: block;
}
<div id="outer">
<div class="item">
<div class="inner"></div>
</div>
<div class="item">
<div class="inner"></div>
</div>
<div class="item">
<div class="inner"></div>
</div>
<div class="item">
<div class="inner"></div>
</div>
</div>
I've used some and inspired jquery tabs to make it easier
$(function(){
$('.item').hover(
function(e){
$('.item').removeClass('hover')
$(this).addClass('hover')
$('.content').removeClass('show')
var content = $(this).attr('data')
$(content).addClass('show')
},
function(e){
$('.item').removeClass('hover')
$('.content').removeClass('show')
}
)
})
#outer {
width: 500px;
height: 500px;
background: pink;
margin: 50px;
position: relative;
}
.btn{
position:absolute;
left:0;
top:0;
z-index:2
}
.btn .item {
width: 50px;
height: 50px;
margin-right: 10px;
background: black;
opacity: 0.5;
float: left;
position: relative;
-webkit-transition: all 0.2s; /* Safari */
transition: all 0.2s;
}
.content {
width: 500px;
height: 500px;
background: red;
position: absolute;
left:0;
top: 0;
z-index:1;
text-align:center;
opacity: 0;
-webkit-transition: all 0.2s; /* Safari */
transition: all 0.2s;
}
.item.hover {
opacity: 1;
}
.content.show{
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="outer">
<div class="btn">
<div class="item" data="#content1"></div>
<div class="item" data="#content2"></div>
<div class="item" data="#content3"></div>
<div class="item" data="#content4"></div>
</div>
<div class="content" id='content1'>content 1
</div>
<div class="content" id='content2'>content 2
</div>
<div class="content" id='content3'>content 3
</div>
<div class="content" id='content4'>content 4
</div>
</div>