Div with arrow up on top of div and box positioning - css

Hello I am trying to make a popup with dropdown login effect,
but I’m having trouble with how I could get my arrow up on the div
like this:
but i got this:
And I also have trouble positioning my invisible div correctly below my menu
I used position absolute, but is not responsive in mobiles devices etc.
I would like help with the best way to position my element in the right way
 and how I would position my arrow correctly
code:
export default function App() {
const [isHover, setisHover] = React.useState(false);
console.log(isHover);
return (
<>
<LoginColumn>
<WrapperLogin
onMouseOver={() => setisHover(true)}
onMouseOut={() => setisHover(false)}
>
<a>
<FontAwesomeIcon
className="adjust"
icon={faUserCircle}
size="2x"
fixedWidth
color="white"
/>
</a>
<div>
<a>
<h3>Olá !</h3>
<p>
Minha Conta
<span>
<FontAwesomeIcon
className="adjust"
icon={faAngleDown}
size="lg"
fixedWidth
color="white"
/>
</span>
</p>
</a>
</div>
</WrapperLogin>
<SignWrap hover={isHover}>a</SignWrap>
</LoginColumn>
</>
);
my css:
import styled from "#emotion/styled";
export const SignWrap = styled.div`
display: ${props => (props.hover ? "block" : "none")};
background: green;
position: absolute;
width: 100%;
height: 250px;
top: 100px;
:before {
content: "";
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
width: 0;
height: 0;
border-top: 15px solid #000;
transform: rotate();
border-left: 15px solid transparent;
border-right: 15px solid transparent;
}
`;
export const LoginColumn = styled.div`
position: relative;
width: 40%;
display: flex;
flex-direction: column;
background: red;
`;
export const WrapperLogin = styled.div`
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
:hover {
}
svg {
margin-right: 10px;
}
div {
display: flex;
flex-direction: column;
}
h3 {
color: white;
font-family: Roboto;
margin-bottom: 5px;
}
p {
color: white;
font-family: Roboto;
font-size: 0.8em;
}
`;
example:
https://codesandbox.io/s/ecstatic-matsumoto-mgy2q

The issue is basically 2 things. Your positioning, and which border you're using for the arrow effect. So if you change your position to top / right, and allow top to place the pseudo element outside of the box, and swap border-top for border-bottom to flip your arrow, voila. Oh and most of the rest of the properties you have in there are innocuous. Have a great weekend!
Change;
:before {
content: "";
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
width: 0;
height: 0;
border-top: 15px solid #000;
transform: rotate();
border-left: 15px solid transparent;
border-right: 15px solid transparent;
}
to;
:before {
content: "";
display: block;
position: absolute;
right: 1rem;
top: -15px;
border-bottom: 15px solid #000;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
}

Related

How to make a 3d shadow on bottom of the container so it looks like the container is standing like this on image?

I need to make a realistic 3d shadow that looks like the container is standing. Just like the image shows.
Instead of box-shadow, it can be implemented with a pseudo-element like ::before.
This is an over simplified example, but hopefully it will help as a reference.
Example:
*,
*::after,
*::before {
margin: 0;
padding: 0;
box-sizing: border-box;
}
section {
display: flex;
justify-content: center;
align-items: flex-start;
padding: 30px;
}
div {
position: relative;
isolation: isolate;
}
figure {
overflow: hidden;
border-radius: 20px;
z-idnex: 10;
height: 200px;
}
div::before {
content: "";
position: absolute;
left: 2px;
right: 2px;
bottom: 2px;
height: 9px;
borderradius: 25px;
filter: blur(6px);
background-color: #000;
z-index: -1;
}
<section>
<div>
<figure>
<img src="https://picsum.photos/200" />
</figure>
</div>
</section>
you can do that by using :pseudo-element, than add box shaddow to it, for example
style.css
.container {border: 5px solid black;
width: 160px;
height: 100px;
border-radius: 20px;
position: relative;
}
.container:after {
position: absolute;
bottom: -2px;
width: 100%;
box-shadow: 2px 3px 12px 1px rgba(0,0,0,0.75);
}
index.html
<div class="container"></div>

Overlapping triangle div inside a flex container

I'm trying to create a simple diagonally splitted header using flex container and triangle divs like this:
But for some reason it's not working.
Here is a simplified working example:
function myFunction() {
var e1 = document.getElementById("1");
var e2 = document.getElementById("2");
var els = document.getElementsByClassName("el");
for (let el of els)
el.classList.toggle("active");
e1.classList.toggle("active");
e2.classList.toggle("active");
}
button{
width: 40px;
height: 40px;
}
*{
transition: all 0.3s ease-in-out;
}
body{
background-color: #454545;
}
.el{
width: 50px;
height: 50px;
background-color: blue;
}
.el:nth-of-type(1){
background-color: red;
}
.el.active{
background-color: #454545;
}
.flex{
margin-top: 50px;
margin-left: 50px;
display: flex;
}
.triangle {
position: absolute;
width: 0;
height: 0;
margin-left: 30px;
border-style: solid;
border-width: 50px 30px 0 0;
border-color: red transparent transparent transparent;
}
.reversed-triangle {
position: absolute;
width: 0;
height: 0;
margin-left: 30px;
border-style: solid;
border-width: 0 0 50px 30px;
border-color: transparent transparent blue transparent;
}
.triangle.active{
border-color: #454545 transparent transparent transparent;
}
.reversed-triangle.active{
border-color: transparent transparent #454545 transparent;
}
<button onClick="myFunction()"> Click!
</button>
<div class="flex">
<div class="el active"> </div>
<div class="triangle active" id="1" > </div>
<div class="reversed-triangle" id="2"> </div>
<div class="el"> </div>
</div>
It works perfectly in jsfiddle but the same layout doesn't work in my project.
I'm using react and plain css, this is where it doesn't work:
I can't get both elements to work correctly. As you see, in the image above the right-hand h3 element (Things I've done) overlaps the dark triangle on the left.
If i add z-index: 1 to the overlapped triangle, the opposite triangle will be overlapped when i click the other element like so:
Here you can find the complete code (obv it doens't compile in jsfiddle).
If i forgot to mention something please let me know.
Thank you very much for your time!
Simple example using flex and :before to re-create your image.
body {
background-color: #565656;
}
.wrapper {
width: 400px;
margin: auto;
}
.full-width {
background-color: #565656;
border: solid #fff 1px;
}
.button {
min-height: 80px;
width: 100%;
margin: 0 auto;
display: flex;
}
.button-left {
background-color: #fff;
min-height: 80px;
width: 38%;
position: relative;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5em;
z-index: 1001;
}
.button-right {
width: 62%;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
margin-left: 1.7em;
font-size: 1.5em;
color: #fff;
}
.button-left:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 80px solid white;
border-bottom: 0px solid transparent;
border-left: 0px solid transparent;
border-right: 80px solid transparent;
position: absolute;
top: 0;
right: -80px;
}
<div class="wrapper">
<div class="full-width">
<div class="button">
<div class="button-left">
<p>Me</p>
</div>
<div class="button-right">
Things I've done
</div>
</div>
</div>
</div>

Is there a way to edit the inside color of a color input selector?

I want to change the inside color of a css so that it looks like this:
How i want it to look
How it looks so far:
Color i want to change
I've tried many things so that it looks like that, here is my html:
<div className="forms__highlightcolor">
<p>Highlight Color</p>
<input type="color" id="colorpicker" value="#0000ff"></input>
</div>
And the CSS i've made so far:
.forms__highlightcolor > input{
background: #F1F1F1;
width: 250px;
height: 35px;
border: 1px solid #F1F1F1;
border-radius: 20px;
}
.forms__highlightcolor > input[type="color"]::-webkit-color-swatch {
border: none;
width: 0px;
border-radius: 4px;
}
I want to change the inside color, but don't know how to do it.
Here is my code I hope this may help.
First You need to separate the input section and color has code section and wrap it inside a div.
#colorpicker {
border: 0;
padding: 0;
background: unset;
width: 30px;
height: 35px;
left: -5px;
position: absolute;
}
#colorpicker:hover {
cursor: pointer;
}
.color-input-wrapper {
display: flex;
align-items: center;
position: relative;
border-radius: 57px;
overflow: hidden;
width: 200px;
height: 25px;
position: relative;
background: #fdf8f5;
}
.color-input-wrapper:hover {
cursor: pointer;
}
.hash-code-section {
margin-left: 30px;
display: flex;
align-items: center;
flex:1;
margin-right: 10px;
text-transform: uppercase;
}
.arrow {
border: solid black;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
margin-left: auto;
}
.down {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<div className="forms__highlightcolor">
<p>Highlight Color</p>
<div class="color-input-wrapper"><input type="color" id="colorpicker" value="#FF5733"></input>
<div class="hash-code-section">#FF5733 <i class="arrow down"></i></div>
</div>
</div>

How can two classes share the same style for reactjs #emotion/styled

For my regular html code, I have this:
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
For the regular CSS, I have this:
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 100%;
left: 50%;
margin-left: -60px; /* Use half of the width (120/2 = 60), to center the tooltip */
}
In my react app using #emotion/styled, I have the code
const TooltipContainer = styled('div')`
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
`
for the .tooltip class but how can I implement the .tooltip .tooltiptext part?
Based from the tutorial https://www.w3schools.com/css/css_tooltip.asp
You can use Inheritance of Styled component like below.
// The Button from the last section without the interpolations
const Button = styled.button`
color: palevioletred;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 3px;
`;
// A new component based on Button, but with some override styles
const TomatoButton = styled(Button)`
color: tomato;
border-color: tomato;
`;
try
'.tooltip, .tooltiptext'
or
'.tooltip .tooltiptext '

Can't style the button using ::after & ::before in CSS

I've used the ::before and ::after elements in my CSS class to put a bottom border in my button, but that doesn't seem to work in my case.
I've positioned the ::before element tag as absolute so that the border would be inside the button, but for some reasons the border extends all the way throughout the page instead of just the button.
.mydiv {
background-color: #242128;
border-radius: 0;
height: 1000px;
width: 100%;
}
body {
margin: 0px;
}
.mybtn2 {
border: none;
font-size: 2em;
border-radius: 5px;
cursor: pointer;
color: white;
font-family: Serif;
margin-top: 50px;
margin-left: 5%;
background-color: #242128;
padding: 5px 10px;
}
.mybtn2::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-bottom: 2px solid white;
}
<body>
<div class="mydiv">
<button class="mybtn2">Hover Me</button>
</div>
</body>
You need position: relative; on .mybtn2.

Resources