Position with position absolute and translateY in displayFlex (DropDown item) - css

Hello I'm doing a popup menu signin and I'm trying to position my fontawesome icon in the same place as mine :: before
like this:
i want this:
but I got this:
code:
<div className="App">
<div className="a">A</div>
<div className="b">
<div className="icon">
<FontAwesomeIcon
className="adjust"
icon={faUser}
size="2x"
fixedWidth
color="red"
/>
</div>
<div className="popup" />
</div>
</div>
css:
.App {
width: 100%;
height: 100px;
background: red;
display: flex;
justify-content: space-between;
}
* {
margin: 0;
padding: 0;
}
.a {
display: flex;
align-items: center;
width: 100%;
height: 100%;
background: blue;
}
.b {
position: relative;
display: flex;
flex-direction: column;
width: 220px;
height: 100%;
background: green;
}
.icon {
width: 100%;
height: 100%;
display: flex;
background: yellow;
justify-content: flex-end;
align-items: center;
cursor: pointer;
}
.popup {
position: absolute;
transform: translateY(calc(50% + 15px));
width: 100%;
background: red;
height: 200px;
}
.popup::before {
content: "";
display: block;
position: absolute;
right: 20%;
top: -15px;
border-bottom: 15px solid #000;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
}
example:
https://codesandbox.io/s/morning-architecture-oi51j
I'm trying to use display: flex and position absolute for this, but to no avail

Related

How can i put the child div on the right top?

i have two divs, i want to put the child on top of the parent top, i was trying but the child div got stuck outside, what is the wrong?
.content {
align-items: center;
border-radius: 4px;
display: flex;
flex-direction: column;
height: 200px;
min-height: 140px;
min-width: 140px;
border: 1px solid;
}
.topcorner {
width: 42px;
height: 42px;
background: red;
position: absolute;
top: 0;
right: 0;
z-index: 1;
}
<div class="content">
<div class="topcorner">top</div>
</div>
Parent element needs to have position: relative.
Add position: relative to the parent class .content to make the child div inside the parent div.
.content {
align-items: center;
border-radius: 4px;
display: flex;
flex-direction: column;
height: 200px;
min-height: 140px;
min-width: 140px;
border: 1px solid;
position: relative; //Add this line
}
.topcorner {
width: 42px;
height: 42px;
background: red;
position: absolute;
top: 0;
right: 0;
z-index: 1;
}
<div class="content">
<div class="topcorner">top</div>
</div>

css when hover show multiple color around div using css or javascript

I use css to show colors around div when hover but I want to make it more than one color live demo I want it to be multiple colors instead of one
.container{
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.container a{
position: relative;
width: 200px;
height: 60px;
display: inline-block;
background: #fff;
margin: 20px;
}
.container a::before,
.container a::after
{
content: '';
position: absolute;
inset: 0;
background: rgb(26, 214, 58);
transition: 0.5s;
}
.container a:hover:before
{
inset: -3px;
}
<style>
#import url('https://fonts.googleapis.com/css2?family=Zilla+Slab:ital,wght#1,300&display=swap');
body {
background-color: #0e1538;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
a {
text-decoration: none;
}
.btn-wrapper {
width: 200px;
height: 60px;
}
.btn {
font-family: 'Zilla Slab', serif;
font-size: 2em;
color: #ffffff;
background-color: #0e1538;
width: 190px;
height: 50px;
}
.center-flex {
display: flex;
justify-content: center;
align-items: center;
}
.btn-wrapper:hover {
background-image: linear-gradient(90deg, #00C0FF 0%, #FFCF00 49%, #FC4F4F 100%);
}
</style>
<body>
<div class="btn-wrapper center-flex">
Hover Me</div>
</div>
</body>
Instead of having a background set as a single RGB color you can set it as a background-image with multi colors introduced through a gradient.
This snippet uses a linear-gradient (which gives a sort of image type) with just 3 colors but you can have more and you can adjust how much of each you get and whether the changes go from top to bottom or left to right - see MDN documentation for the various options.
The result here is:
#import url('https://fonts.googleapis.com/css2?family=Zilla+Slab:ital,wght#1,300&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Zilla Slab', serif;
}
body {
display: flex;
justify-content: center;
min-height: 100vh;
background: #0e1538;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.container a {
position: relative;
width: 200px;
height: 60px;
display: inline-block;
background: #fff;
margin: 20px;
}
.container a::before,
.container a::after {
content: '';
position: absolute;
inset: 0;
background: rgb(26, 214, 58);
background-image: linear-gradient(red, green, blue);
/* ADDED */
transition: 0.5s;
}
.container a:hover:before {
inset: -3px;
}
.container a span {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: inline-block;
background: #0e1538;
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
text-transform: uppercase;
letter-spacing: 2px;
color: #fff;
}
<div class="container">
<a href="#">
<span>Hover Me</span>
</a>
</div>

CSS :hover on button not working within already hovered div

I have a div appearing on top of an image when I hover the image itself. The div contains two divs (buttons) that also have a :hover that changes their color and sets the cursor to the pointer.
The issue is the hovering on the button doesn't trigger the hover.
Also, it seems that hovering on the image at the bottom where the btn_container will appear doesn't trigger to first :hover and doesn't make the btn_container appear.
//HTML
<div class="container">
<img src="src">
<div class="btn_container">
<div class=" btn">
<p>Select</p>
</div>
<div class="btn">
<p>Preview</p>
</div>
</div>
//SCSS
.container {
position: relative;
width: 100%;
img {
width: 100%;
height: auto;
}
.btn_container {
position: absolute;
width: 100%;
height: 40px;
background-color: var(--dark-purple-trans);
bottom: 0;
left: 0;
align-items: center;
display: none;
position: absolute;
}
img:hover + .btn_container,
.btn_container > * {
display: flex;
border: none;
text-align: center;
justify-content: space-around;
}
.btn {
padding: 6px 12px;
height: 14px;
background: var(--yellow-medium);
border-radius: 8px;
display: flex;
justify-content: space-evenly;
align-items: center;
color: var(--white);
font-family: roboto;
&:hover {
cursor: pointer;
background: var(--red);
color: var(--white);
}
}
}
Preview, button hovering not working:
If I force the hover on the img using the inspector, the button hovering seems to work:
The problem is in classes img:hover + .btn_container and .btn_container > *.
Here is the updated scss:
.container {
position: relative;
width: 100%;
img {
display: block;
width: 100%;
height: auto;
border: 0;
}
&:hover .btn_container {
display: flex;
}
.btn_container {
position: absolute;
bottom: 0;
left: 0;
display: none;
align-items: center;
justify-content: space-around;
width: 100%;
height: 40px;
text-align: center;
background-color: var(--dark-purple-trans);
border: none;
}
.btn {
display: flex;
align-items: center;
justify-content: space-evenly;
height: 14px;
padding: 6px 12px;
color: var(--white);
font-family: roboto;
background-color: var(--yellow-medium);
border-radius: 8px;
cursor: pointer;
&:hover {
color: var(--white);
background-color: var(--red);
}
}
}
You can view it in action here: Codepen
I tried using opacity instead of display to toggle visibility of the btn_container and added a hover to btn_container and it seemed to work: https://jsfiddle.net/pr8dxe2g/1/
.btn_container {
width: 500px;
height: 100px;
background-color: var(--dark-purple-trans);
bottom: 0;
left: 0;
align-items: center;
opacity: 0;
position: absolute;
}
img:hover + .btn_container,
.btn_container:hover,
.btn_container > * {
display: flex;
opacity: 1;
border: 1px solid blue;
text-align: center;
justify-content: space-around;
}
There may be some issue with your current code with the fact that the the img div has a higher stack-order if the display is set to none initially, however I am not certain so if anyone knows I would like to know why this is the case as well.

css overlapping circle and text box

I am trying to produce this effect with CSS. I have tried creating a box with a triangle and then using negative margin to overlap it onto the circle, but cannot get it right.
Many thanks for any help.
fiddle
https://jsfiddle.net/Hastig/n3w0tztv/
Getting the circle to stay vertically centered and have the text container min-height the height of circle is tricky and is not worked out in this example. A cheap fix is adding align-items: center to .container at a breakpoint with #media.
body {
display: flex;
justify-content: center;
align-items: center;
margin: 0;
background-color: white;
height: 100vh;
}
.container {
display: flex;
width: 100%;
padding: 10px;
overflow: hidden;
}
.left {
position: relative;
display: flex;
width: 150px;
height: 150px;
margin-top: -4px;
margin-bottom: -4px;
margin-right: -17px;
background-color: #ec847c;;
border-style: solid;
border-color: white;
border-width: 4px;
border-radius: 100%;
z-index: 10;
}
.right {
position: relative;
display: flex;
flex: 2;
font-size: 20px;
color: white;
background-color: #4ca132;
}
.square {
position: absolute;
left: 0;
width: 50px;
height: 50px;
background-color: white;
overflow: hidden;
}
.square-top { top: 0; }
.square-btm { bottom: 0; }
.square::before {
content: "";
position: absolute;
display: flex;
width: 100%;
height: 100%;
transform: rotate(45deg) scale(2);
background-color: #4ca132;
z-index: 1;
}
.square-top::before { top: 50%; left: 50%; }
.square-btm::before { bottom: 50%; left: 50%; }
.text {
position: relative;
z-index: 2;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
padding: 20px 20px 20px 40px;
}
<div class="container">
<div class="left">
</div>
<div class="right">
<div class="square square-top"></div>
<div class="square square-btm"></div>
<div class="text">
Roles play an extremely important part in family funtion.
</div>
</div>
</div>

Absolutely positioning with flexbox in Safari

Safari has full support for FlexBox according to caniuse.
I am simply trying to stack some differently sized div's on top of each other using flexbox. I am genuinely curious as to why this works in Chrome/Firefox but not in Safari:
<div class="container">
<div class="inner-one"></div>
<div class="inner-two"></div>
</div>
.container {
width: 15rem;
height: 15rem;
border-radius: 50%;
background-color: blue;
display: flex;
align-items: center;
justify-content: center;
}
.container div {
position: absolute;
}
.inner-one {
width: 13rem;
height: 13rem;
border-radius: 50%;
background-color: green;
}
.inner-two {
width: 11rem;
height: 11rem;
border-radius: 50%;
background-color: purple;
}
See JSFiddle here: https://jsfiddle.net/19n95exf/3/
Because position: absolute; break display: flex, use transform: translate instead
.container {
position: relative;
width: 15rem;
height: 15rem;
border-radius: 50%;
background-color: blue;
}
.container div {
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.inner-one {
width: 13rem;
height: 13rem;
background-color: green;
}
.inner-two {
width: 11rem;
height: 11rem;
background-color: purple;
}
<div class="container">
<div class="inner-one"></div>
<div class="inner-two"></div>
</div>
Or give the inner elements a left/top value
.container {
width: 15rem;
height: 15rem;
border-radius: 50%;
background-color: blue;
display: flex;
align-items: center;
justify-content: center;
}
.container div {
border-radius: 50%;
position: absolute;
}
.inner-one {
left: 1.5rem;
top: 1.5rem;
width: 13rem;
height: 13rem;
background-color: green;
}
.inner-two {
left: 2.5rem;
top: 2.5rem;
width: 11rem;
height: 11rem;
background-color: purple;
}
<div class="container">
<div class="inner-one"></div>
<div class="inner-two"></div>
</div>

Resources