This question already has answers here:
'transform3d' not working with position: fixed children
(10 answers)
Why does applying a CSS-Filter on the parent break the child positioning?
(4 answers)
Fixed position but relative to container
(31 answers)
Closed 2 years ago.
I am working on my react-app in which I am creating a horizontal scroll website (for which I have rotated my container). I want to create a static navbar inside my div and on the other hand, when I place my navbar inside any other component its working. How can I achieve this? Please kindly help me. Here is my code:
<>
<div
className="outer-wrapper"
id="outer-wrapper"
ref={outerWrapper}
onScroll={onScrollFunction}
>
{/* <Header /> */}
<div className="wrapper">
<div className="navmenu">
<h1>Logo</h1>
<button>Menu</button>
</div>
<HomePage />
<AnimationMain
tags="<h1><span>Animation</span> that Works like magic.</h1>"
data={pageDataArr[0]}
anim={animationPageAnim}
videoData={videoData}
servicesInfo={servicesInfoAnimation}
label={labelArr[0]}
/>
<AnimationMain
tags="<h1><span>Design</span> is intelligence made visible.</h1>"
data={pageDataArr[1]}
anim={animationPageAnim}
label={labelArr[1]}
/>
<AnimationMain
data={pageDataArr[2]}
anim={animationPageAnim}
label={labelArr[2]}
/>
<AnimationMain
tags="<h1>Making <span>Website</span> that capture Users.</h1>"
data={pageDataArr[3]}
anim={WebDevPageAnim}
label={labelArr[3]}
videoData={imageData}
servicesInfo={servicesInfoWebDev}
/>
<AnimationMain
data={pageDataArr[4]}
anim={animationPageAnim}
label={labelArr[4]}
/>
</div>
</div>
</>```
.outer-wrapper {
width: 100vh !important;
height: 100vw;
transform: rotate(-90deg) translateX(-100vh);
transform-origin: top left;
overflow-y: scroll;
overflow-x: hidden !important;
position: absolute;
top: 0;
left: 0;
border: 2px solid blue;
// margin-top: -4rem;
.wrapper {
display: flex;
flex-direction: row;
width: 600vw;
height: 100vh;
transform: rotate(90deg) translateY(-100vh);
transform-origin: top left;
border: 2px solid yellow;
.navmenu {
border: 1px solid red;
color: red;
position: fixed !important;
top: 0;
left: 0;
}
}
}
Kindly help me, I am stuck here all day.
Related
This question already has answers here:
Why does z-index not work?
(10 answers)
Why can't an element with a z-index value cover its child?
(5 answers)
Closed 1 year ago.
I need text be above the image, so I set z-indexto 10, and image to 5.
Text is in Navbar.
function ProductList2(props: OrganizationList2) {
return (
<div>
<div className={styles.container1}>
<Navbar />
<img
src="/Olovka_Studio_gyűrű_v2.png"
width="100"
height="140"
className={styles.img1}
/>
.container1 {
background-color: #12341b;
position: relative;
height: 38vw; /*543/1440*/
}
.img1 {
position: absolute;
right: 11vw; /*159/1440*/
top: 0px;
z-index: 5;
height: 38vw;
width: 24vw; /*372/1440*/
}
.container { /* <------------------ Inside Navbar*/
display: flex;
margin-left: 8vw; /*128/1440*/
margin-right: 8vw; /*430/1440*/
justify-content: space-between;
max-height: 88px;
z-index: 10;
}
An element with z-index doesn't work without a position element
Try:
.div-with-z-index {
position: relative /* Relative doesn't change the position of the element itself. */
}
Image:
I have a container div (yellow) which I’d like to keep at 50% width of the window. A child of that container is an image div (purple) that stretches to 100% of the parent container’s width. and there’s a sticky label (pink) on top of the image div (position: absolute so it can be offset relatively to the image). I'd like to keep that entire half of the screen fixed positioning so it stays sticky as I scroll.
There’s also a title under the image, and that title needs to be visible no matter if someone shrinks the window vertically. So in that scenario the image div should shrink vertically, if needed, in order for that title to be shown.
Basically I'm trying to have the image div always be 100% width of the parent container div. With the image div having a max % height so it can shrink vertically. Or have it keep a fixed aspect ratio (3:4 or whatever) when it shrinks vertically.
I'm trying to avoid using fixed pixels, or ems, in the entirety of my CSS. since the website needs to be stretchy/‘fluid’ vertically, because that title under the image has to show.
HTML looks roughly like:
<wrapper>
<left-column>
<normal text and scrollable stuff>
<right-column-yellow>
<image sticky label-pink>
<image div-purple>
<image title>
Sorry if this is damn confusing my brain is fried! Can anyone pls help me?
You can divide your left and right panel by using position fixed.
If I'm not wrong with your description, this is the answer.
<div class="wrapper">
<div class="left">
<p><!--Some very long text--></p>
</div>
<div class="right">
<div class="image">
<div class="label">Label</div>
<div class="title">Title</div>
</div>
</div>
Some CSS
.left,.right{
position: fixed;
width: 50%;
height: 100%;
display: inline-block;
}
.left{
left:0;
top: 0;
overflow: auto;
}
.right{
right: 0;
top:0;
background-color: yellow;
}
.right .image{
position: relative;
width: 100%;
height: 50%;
top: 50%;
left: 0;
background-color: #fff;
transform: translateY(-50%);
}
.right .image .label{
position: absolute;
left: 0;
right: 0;
top: -10px;
text-align: center;
width: 200px;
background-color: pink;
margin: auto;
}
.right .image .title{
position: absolute;
left: 0;
right: 0;
bottom: -40px;
text-align: center;
width: 200px;
background-color: #000;
margin: auto;
color: #fff;
font-size: 30px;
}
You can refer to my codeine as well.
https://codepen.io/masonwongcs/pen/WMJGZb
This question already has answers here:
Is there a "previous sibling" selector?
(30 answers)
Closed 5 years ago.
I want a div to disappear on hover over a different div, purely with CSS.
So I have two divs
<div class="" id="target">I will disappear</div>
<div class="hover_box">Hover me</div>
and my SCSS:
#target {
background-color: blue;
height: 100px;
width: 100px;
}
.hover_box {
background-color: red;
height: 100px;
width: 100px;
&:hover #target{
display: none !important;
/* background-color: green !important; */
}
}
However, it does not work. See here:
https://jsfiddle.net/ubLLga3q/3/
The problem is your HTML mark up. You are doing a hover and saying #target disappear. You can only use this method if you call a sibling/child. Right now #target is not a child from .hover_box.
<div class="box">
Hover me
<div class="hover_box">
</div>
</div>
.box {
background-color: blue;
height: 100px;
width: 100px;
}
.hover_box {
background-color: red;
height: 100px;
width: 100px;
}
.box:hover .hover_box {
display: none;
}
https://jsfiddle.net/ubLLga3q/6/
I was wondering if you can help me with this.
I have a div (in white) where I need to put two circular buttons (in green) on the borders. Everything should be done with CSS.
It should look like this:
Screenshot
Now, the thing is that I don't know the size of the white div, and I won't know it at the time of creation, because it will get added to the DOM afterwards. All I know is that the white div has a percentage width and height relative to its future parent. So, at the time of creation, since it's not yet added, any calls to width(), height() or its css values won't work.
I've seen all those snippets that tell you how to make a div with a fixed aspect ratio. I need this now, I need the button to be 1:1, but all I know about the dimensions, is that it has to be 100% of the height of the white div (and therefore, its width should be equal as its height). All the examples I've seen assume that you know the width and to make the height keep the ratio. In my case, what I know is the height (100%) and I want the width to adapt.
I have no idea how to achieve this.
This is my snippet:
body{
background-color: #DCDCDC;
}
.container {
width: 50%;
height: 7%;
background: white;
border-radius: 20px;
position: absolute;
}
.arrow {
background: green;
border-radius: 20px;
height: 100%;
position: absolute;
}
.arrow:after{
content: "";
display: block;
padding-right: 100%;
}
.arrow:last-child {
right: 0;
}
<div class="container">
<div class="arrow"></div>
<div class="arrow"></div>
</div>
https://jsfiddle.net/7bxecL9m/
If you know how can I do this without entering any fixed value (jQuery use is of course valid), I'd really appreciate it.
Thanks.
There are many variables here:
Since container's height is % and circle radius is px units, one is static and the other one will resize.
The only way to preserve 1:1 with just html/css, considering the container's height % will resize circle's height as well, would be to isolate circle's div width & height to something static like px units.
Now, since you said no fixed dimensions, the only thing I can think of is to comment .arrow's 100% height, to prevent resizing other than 1:1, and nesting a div inside .arrow to restrain 1:1 with static units (ideally impacting .arrow directly would be less code but if you don't want/can't set them on that element, maybe you consider this).
If you want the circle to remain circular as the content expands, you need to dynamically adjust the height to match the width. You could use Javascript to achieve this, but your border-radius is tied to container's in px static units, since container will always be bigger something like border-radius: 50% wouldn't work for both, 50% radius of circle would never match 50% of container's (that is, if you care about radius alignment).
body {
background-color: #DCDCDC;
}
body,
html {
height: 100%;
}
.container {
width: 50%;
height: 37%;
background: white;
border-radius: 20px;
position: relative;
}
.arrow {
background: green;
border-radius: 20px;
/*height: 100%;*/
position: absolute;
overflow: hidden;
}
.bLimit {
height: 40px;
width: 40px;
line-height: 40px;
}
.arrow:after {
content: "";
display: block;
padding-right: 100%;
}
.arrow:last-child {
right: 0;
}
<div class="container">
<div class="arrow">
<div class="bLimit">button overflow</div>
</div>
<div class="arrow">
<div class="bLimit">button</div>
</div>
</div>
Why not doing a fixed width in percent for your arrow :
.arrow {
background: green;
border-radius: 20px;
height: 100%;
position: absolute;
width: 10%;
}
body{
background-color: #DCDCDC;
}
.container {
width: 50%;
height: 7%;
background: white;
border-radius: 20px;
position: absolute;
}
.container:after,.container:before{
content: " ";
display: block;
padding: 4%;
z-index: 999;
top: 0;
position:absolute;
background: green;
border-radius: 50%;
}
.container:before {
left: 0;
}
.container:after{
right: 0;
}
<div class="container">
</div>
You can achieve using before and after CSS pseudo selectors. You check this Example.
There is a posibility to get this result using a image (that won't show) of the required ratio.
In this case, the ratio is 1:1 so we will use an image of 50px (but it can be any size)
.container {
width: 300px;
height: 20px;
border: solid 1px blue;
margin: 40px;
position: relative;
}
.container:nth-child(2) {
height: 40px;
}
.container:nth-child(3) {
height: 60px;
}
.arrow {
height: 100%;
background-color: red;
opacity: 0.5;
position: absolute;
border-radius: 50%;
transform: translateX(-50%);
}
.arrow:last-child {
right: 0px;
transform: translateX(50%);
}
img {
height: 100%;
opacity: 0;
}
<div class="container">
<div class="arrow">
<img src="https://placehold.it/50x50">
</div>
<div class="arrow">
<img src="https://placehold.it/50x50">
</div>
</div>
<div class="container">
<div class="arrow">
<img src="https://placehold.it/50x50">
</div>
<div class="arrow">
<img src="https://placehold.it/50x50">
</div>
</div>
<div class="container">
<div class="arrow">
<img src="https://placehold.it/50x50">
</div>
<div class="arrow">
<img src="https://placehold.it/50x50">
</div>
</div>
I am trying to overlay 2 DIV's in my main parent DIV:
I want to overlay the the second div over on top of the first one. I have a problem overlaying it as I cannot keep it in the middle of the screen.
I have tried this to overlay:
The overlay works fine here, but my container is no longer center when I do this. How can I overlay and keep it center ?
div {
border: 5px solid red;
}
#first {
position: absolute;
z-index: 1;
border-color: orange;
}
#second {
position: absolute;
z-index: 2;
border-color: green;
}
<div id="container" class="container text-center">
<div id="first">Hi</div>
<div id="second">Hello</div>
</div>
Here is what you need to do (see width of both divs and text-align properties):
You can give them background color to see z-index works perfectly :)
#first {
text-align: center;
height: 300px;
width: 100%;
position: absolute;
z-index: 1;
}
#second {
text-align: center;
height: 300px;
width: 100%;
position: absolute;
z-index: 2;
}
<div id="container" class="container text-center">
<div id="first">Hi</div>
<div id="second">Hello</div>
</div>
When you position absolute, the positioned element is taken out of the document flow and positioned relative to the next highest parent element that is not the default position, i.e. not position: static;
The following will cause the absolute positioned children to stay within the containing div:
#container {
position: relative;
}
Your container's text is no longer centered because you have removed its children from the document flow. In essence, it has no content and collapses, and therefore, has no width to which to align the text.
One thing you could do is set the container to position: relative and full-width (i.e. width: 100vw), then set its children to width: 100%.
Then the inner divs will take on the width of their parent.
See this working JSFiddle.
#container {
position: relative;
width: 100%;
height: 100px;
background-color: yellow;
display: flex;
justify-content: center;
align-items: center;
}
#first{
position: absolute;
}
#second{
position: absolute;
}
<div id="container" class="container">
<div id="first">Hi</div>
<div id="second">Hello</div>
</div>
Your main issue is that the divs will not have any relative width to the parent div.
Therefore the text is still technically "centered" in each corresponding div because they're inheriting text-align: center from the container div.
However, the divs' widths will automatically be as wide as they needs to be (i.e. to fit the text, in this case).
You can remedy this one of two ways:
Force the divs to be centered
Give both divs the following (extra) CSS:
left: 50%;
width: 100%;
margin-left: -50%;
This will literally center them in their parent div.
or
Force the divs to be the same size as their parent
Give both the divs the following (extra) CSS:
top: 0;
bottom: 0;
left: 0;
right: 0;
This sets the divs to span their entire parent's height and width.
In both situations, you might need to make the .container class use position: relative, in order for the child divs to have something to be absolute to.
If you're using Bootstrap, there is no need to worry about this, as .container class already has this applied.
Hope one of these solutions helps you :)
Try this style:
#first,
#second {
left: 50%;
transform: translate(-50%, 0);
}
div {
border: 5px solid red;
}
#first {
position: absolute;
z-index: 1;
border-color: orange;
}
#second {
position: absolute;
z-index: 2;
border-color: green;
}
#first,
#second {
left: 50%;
transform: translate(-50%, 0);
}
<div id="container" class="container text-center">
<div id="first">Hi</div>
<div id="second">Hello</div>
</div>