I normally use relative positioning to center a div in its parent. I found that absolute positioning should also work. I am not certain what is making my div not centered. When a certain class is added to my div, it changes from relative to absolute positioning, but with the same type of margins:
#selectablesDiv{
order: 1;
position: relative;
margin: 10vh auto 30vh auto;
height: 45px;
width: 465.94px;
text-align: center;
user-select: none;
opacity: 1;
display: flex;
flex-direction: row;
&.aboutMeClicked{
position: absolute;
margin: 62vh auto 30vh auto;
}
}
The parent div has the following CSS applied to it:
#homePageDiv{
height: 100vh;
width: 100vw;
display: flex;
flex-direction: column;
position: relative;
overflow: hidden;
animation: backgroundChange 36s ease-in-out 0s infinite;
}
Why do the right and left margins become size 0. It seems that the margins are based off of relative/absolute positioning, or is there something I'm missing?
You have to use right : 0; and left: 0; to center an absolute positioned element in it's parent (combined with margin-left: auto; and margin-right: auto;).
#homePageDiv {
height: 100vh;
width: 100vw;
display: flex;
flex-direction: column;
position: relative;
overflow: hidden;
animation: backgroundChange 36s ease-in-out 0s infinite;
background-color: red;
}
#selectablesDiv {
order: 1;
position: relative;
margin: 10vh auto 30vh auto;
height: 45px;
width: 465.94px;
text-align: center;
user-select: none;
opacity: 1;
display: flex;
flex-direction: row;
background-color: yellow;
}
#selectablesDiv.aboutMeClicked {
position: absolute;
margin: 62vh auto 30vh auto;
right: 0;
left: 0;
}
<div id="homePageDiv">
<div id="selectablesDiv" class="aboutMeClicked"></div>
</div>
Related
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>
How is it possible to scale a div element correctly to fit into a specific area? I have a div element with that I want to scale on hover to fit into the circle in the middle (see code snippet). Now I can set the scaling values but this will not work correctly on smaller or bigger screens. The div with the coral color should have 100vw.
The following is my HTML, css an jquery:
$(".contact-button").hover(function(){
$(".holdeer").addClass('contact');
}, function(){
$(".holdeer").removeClass('contact');
});
.getintouch {
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
height: 20vh;
width: 100vw;
}
.contact-us {
position: relative;
z-index: 0;
display: flex;
height: 700px;
width: 100vw;
flex-direction: column;
justify-content: space-around;
align-items: stretch;
background-color: transparent;
}
.contact-button {
position: absolute;
z-index: 100;
display: flex;
width: 200px;
height: 200px;
margin-top: 0px;
flex-direction: row;
justify-content: center;
align-items: center;
align-self: center;
flex-grow: 0;
flex-shrink: 0;
flex-basis: auto;
border-top-style: solid;
border-top-width: 1px;
border-right-style: solid;
border-right-width: 1px;
border-bottom-style: solid;
border-bottom-width: 1px;
border-left-style: solid;
border-left-width: 1px;
border-top-left-radius: 50%;
border-top-right-radius: 50%;
border-bottom-left-radius: 50%;
border-bottom-right-radius: 50%;
background-color: transparent;
color: blue;
font-size: 32px;
font-weight: 700;
}
.holdeer {
position: absolute;
left: 0%;
top: 0%;
right: 0%;
bottom: 0%;
display: block;
width: auto;
height: auto;
justify-content: center;
align-items: center;
align-self: auto;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
background-color: coral;
}
.contact {
animation: shrink 1s ease forwards;
transition: all 1s;
}
#keyframes shrink {
from {
border-radius: 100%;
}
to{
border-radius: 100%;
transform: scale(0.15, 0.28);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="getintouch">
<div class="contact-us">
<div class = "contact-button"></div>
<div class="holdeer"></div>
</div>
</section>
You can do that with much easier & cleaner code, also with just css.
.contact-us {
overflow: hidden; /* to hide anything that goes outside */
display: flex;
height: 700px;
width: 100vw;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: transparent;
}
.contact-button {
position: relative; /* to make 'absolute' children relative to it */
display: flex;
width: 200px;
height: 200px;
flex-direction: row;
justify-content: center;
align-items: center;
border: 1px solid;
border-radius: 50%;
transition: all 1s;
}
.holdeer {
position: absolute;
z-index: -1;
display: block;
width: 100%; /* takes full width of parent */
height: 100%; /* takes full height of parent */
border-radius: 50%;
transform: scale(15); /* scale to very large value to cover .contact-us and overflow: hidden with cut off what goes outside */
transition: all 1s;
background-color: coral;
pointer-events: none; /* to disable hover on this child */
}
.contact-button:hover .holdeer {
transform: scale(1); /* normal scale to fit the parent circle */
}
<div class="contact-us">
<div class="contact-button"><div class="holdeer"></div></div>
</div>
I am trying to make a header in elementor using display: flex and Justify-content: space-between to place the elements where I want them to be. But I can't get it to work, justify-content does nothing when applied.
You can see the menu in this link, all colors are just to make it more visible while I get it to work.
https://wireframe.dk/
Each column has an ID and the section has the class .overlay. I want to make equal space between those columns.
Is there a problem with using display: flex in elementor or is it the justify-content that doesn't work? Or am I just missing something.
The CSS I use is included here:
.overlay{
background: grey;
width: 100vw;
height: 90px;
z-index: 10;
display: flex;
flex-direction: column;
justify-content: space-between;
}
#logo{
width: 180px;
height: 90px;
background: #464646;
flex-grow: 0;
}
#menu-actions{
width: 180px;
height: 90px;
background: red;
transition: .6s;
flex-grow: 0;
}
#menu-actions:hover{
background: blue;
width: 225px;
}
#menu-user{
width: 90px;
height: 90px;
background: yellow;
transition: .6s;
flex-grow: 0;
}
#menu-user:hover{
width: 135px;
background: green;
}
#menu-shop{
height: 90px;
width: 180px;
background: orange;
transition: .6s;
flex-grow: 0;
}
#menu-shop:hover{
width: 225px;
background: purple;
}
My DIV 1 is causing overlap with the CANVAS causing not draggable and not clickable the object inside of it.
How can I "hide" the area of DIV 1?
EDIT:
Here we are some code:
.DIV1 {
align-items: flex-end;
justify-content: flex-end;
flex-direction: row;
display: flex;
}
.PARENT of DIV1 {
position: absolute;
bottom: 0;
right: 0;
width: 100%;
}
.CANVAS {
width: 100%;
height: 100%;
}
.PARENT of everything {
width: 100%;
height: 100%;
justify-content: center;
display: flex;
}
You could always use pointer-events to get the desired results.
.DIV1 {
pointer-events: none;
}
.DIV1 .child-that-need-pointer-events {
pointer-events: all;
}
I want my sidebar to appear on top of everything .i have set z-index to 10000, but still, cards overlap it
the css of the sidebar and founder card is
.sidemenu{
position: fixed;
top: 0px;
width: 240px;
margin-left: -250px;
overflow: hidden;
height: 100vh;
background: black;
opacity: 1;
z-index: 100000000000000;
transition: all 0.3s ease-in-out;
}
.founders {
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: white;
}
Might be this will help
.sidemenu {
position: fixed;
top: 0px;
width: 100%;
margin-left: 100vw;
overflow: hidden;
height: 100vh;
background: black;
opacity: 1;
z-index: 100000000000000;
transition: all 0.3s ease-in-out;
}
.founders {
display: flex;
flex-wrap: wrap;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: white;
}
<div class="sidemenu">
<ul>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
<div class="founders">
<div class="item">
this is founder
</div>
</div>