CSS Positioning card outside of header container - html

I am attempting to position a card over a gradient background. Currently, I tried pushing the card down using margins but the card is being cut off once it gets to the end of the container. I would like to have the card sit on top of the end of the gradient background. I attempted to work around this issue using z-index on the card but it did not have an effect. I also tried using position: absolute but the card is still getting cut off at the end. How can I have the card position over the background to show the full
Here is my code snippet:
.content-container-header {
overflow: hidden;
height: 800px;
-webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
mask: radial-gradient(100% 95% at top, #000 100%, #0000);
background: linear-gradient(#f5fafd, #E8F3F9);
}
.flex-display {
display: flex;
}
.justify-center {
justify-content: center;
}
.margin-bottom-96 {
margin-bottomottom: 96px;
}
.header-content-posts {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
}
.container-1200 {
margin: 0 auto;
max-width: 1200px;
}
.margin-top-128 {
margin-top: 128px;
}
.margin-top-300 {
margin-top: 300px;
}
.align-center {
align-items: center;
}
.flex-display-col {
flex-direction: column;
}
.featured-post-ct {
width: 978px;
height: 308px;
background: #FFFFFF;
-webkit-box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
border-radius: 8px;
}
.div-50 {
width: 50%;
}
.margin-r-32 {
margin-right: 32px;
}
.margin-bottom-8 {
margin-bottomottom: 8px;
}
<div class='content-container-header flex-display justify-center margin-bottom-96'>
<div class="container-1200 header-content-posts">
<div class="flex-display flex-display-col justify-center align-center margin-top-128">
<h1 class="text-dark-blue heading-48 margin-top-disabled margin-bottom-20">
Placement Header
</h1>
</div>
<div>
<div class="flex-display align-center featured-post-ct margin-top-300">
<div class="div-50 margin-r-32 ">
<img alt="" height="308px" width="472px" src="https://media.istockphoto.com/photos/modern-skyscrapers-in-business-district-picture-id1137991385?k=20&m=1137991385&s=612x612&w=0&h=dcSq5oF99RjNW0kQo-LtkUg-Wf15ofZRg87pBOVWLkk=" />
</div>
<div class="div-50">
<div> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eget mi in rhoncus. Praesent dignissim libero a purus facilisis, eu blandit tortor mollis. Maecenas vitae justo ac tortor rhoncus congue.</div>
</div>
</div>
</div>
</div>
</div>

You cannot see any child element inside a masked parent.
You should move your background elsewhere, and fortunately you can achieve that with CSS only using :before pseudo-element.
/* Not needed anymore */
/* .content-container-header {
height: 800px;
-webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
mask: radial-gradient(100% 95% at top, #000 100%, #0000);
background: linear-gradient(#f5fafd, #E8F3F9);
clip-path: ellipse(100% 95% at top);
background: radial-gradient(100% 95% at top, #000 100%, #0000);
} */
/* A pseudo element with your cropped background */
.content-container-header:before {
content: "";
display: block;
height: 800px;
width: 100%;
position: absolute;
z-index: -1;
-webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
mask: radial-gradient(100% 95% at top, #000 100%, #0000);
background: linear-gradient(#f5fafd, #E8F3F9);
}
.flex-display {
display: flex;
}
.justify-center {
justify-content: center;
}
.margin-bottom-96 {
margin-bottom: 96px;
}
.header-content-posts {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
}
.container-1200 {
margin: 0 auto;
max-width: 1200px;
}
.margin-top-128 {
margin-top: 128px;
}
.margin-top-300 {
margin-top: 300px;
}
.align-center {
align-items: center;
}
.flex-display-col {
flex-direction: column;
}
.featured-post-ct {
width: 978px;
height: 308px;
background: #FFFFFF;
-webkit-box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
border-radius: 8px;
}
.div-50 {
width: 50%;
}
.margin-r-32 {
margin-right: 32px;
}
.margin-bottom-8 {
margin-bottom: 8px;
}
<div class='content-container-header flex-display justify-center margin-bottom-96'>
<div class="container-1200 header-content-posts">
<div class="flex-display flex-display-col justify-center align-center margin-top-128">
<h1 class="text-dark-blue heading-48 margin-top-disabled margin-bottom-20">
Placement Header
</h1>
</div>
<div>
<div class="flex-display align-center featured-post-ct margin-top-300">
<div class="div-50 margin-r-32 ">
<img alt="" height="308px" width="472px" src="https://media.istockphoto.com/photos/modern-skyscrapers-in-business-district-picture-id1137991385?k=20&m=1137991385&s=612x612&w=0&h=dcSq5oF99RjNW0kQo-LtkUg-Wf15ofZRg87pBOVWLkk=" />
</div>
<div class="div-50">
<div> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eget mi in rhoncus. Praesent dignissim libero a purus facilisis, eu blandit tortor mollis. Maecenas vitae justo ac tortor rhoncus congue.</div>
</div>
</div>
</div>
</div>
</div>

To get around the mask on the main element you'll probably need to put that stuff outside it.
.content-container-header {
overflow: hidden;
height: 800px;
-webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
mask: radial-gradient(100% 95% at top, #000 100%, #0000);
background: linear-gradient(#f5fafd, #E8F3F9);
}
.flex-display {
display: flex;
}
.justify-center {
justify-content: center;
}
.margin-bottom-96 {
margin-bottom: 96px;
}
.header-content-posts {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
}
.container-1200 {
margin: 0 auto;
max-width: 1200px;
}
.margin-top-128 {
margin-top: 128px;
}
.margin-top-300 {
/* margin-top: 300px; */
}
.align-center {
align-items: center;
}
.flex-display-col {
flex-direction: column;
}
.featured-post-ct {
width: 978px;
height: 308px;
background: #FFFFFF;
box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
border-radius: 8px;
}
.div-50 {
width: 50%;
}
.margin-r-32 {
margin-right: 32px;
}
.margin-bottom-8 {
margin-bottom: 8px;
}
.margin-top-neg-a-bunch {
margin-top: -240px;
}
.position-relative {
position: relative;
}
<div class='content-container-header flex-display justify-center margin-bottom-96'>
<div class="container-1200 header-content-posts">
<div class="flex-display flex-display-col justify-center align-center margin-top-128">
<h1 class="text-dark-blue heading-48 margin-top-disabled margin-bottom-20">
Placement Header
</h1>
</div>
</div>
</div>
<div class="margin-top-neg-a-bunch position-relative">
<div class="flex-display align-center featured-post-ct margin-top-300">
<div class="div-50 margin-r-32 position-relative">
<img alt="" height="308px" width="472px" src="https://via.placeholder.com/400" />
</div>
<div class="div-50">
<div> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eget mi in rhoncus. Praesent dignissim libero a purus facilisis, eu blandit tortor mollis. Maecenas vitae justo ac tortor rhoncus congue.</div>
</div>
</div>
</div>

The reason that the card is cut off is because you have overflow set to hidden on .content-container-header.
If you change this to:
.content-container-header {
overflow: visible;
height: 800px;
-webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
mask: radial-gradient(100% 95% at top, #000 100%, #0000);
background: linear-gradient(#f5fafd, #E8F3F9);
}
the issue should be resolved.

Related

Flipping the styled container

This is the pen I am working on and I want to create something more interesting for my portfolio, but I've stuck on the part when I want to have the same elements on the right side of the screen doing the same expanding but to the other direction (mirrored/flipped/reverted/opposite).
The full code can be viewed in the pen. https://codepen.io/benjaminj/pen/oNqWPRb
As You can see I have used scale but this also flipped and the text inside which is not the end goal of this project. Also when hovering the elements on the right weird tremble occurs which also I don't get from where is coming.
I have designed a container with expanding side where the text of the container is revealed. Also a grid seemed to me the best for positioning the elements. Below is the HTML code:
Because of the pretty weird and complex (for me) design I have used: before and: after for the text.
The elements on the left side are working as a charm, but when I tried to "mirror" those elements on the right side and expand to the center of the screen the troubles started.
But for the element on the right side I used only the scaleX (-1)
.main3 {
display: block;
grid-column-start: 3;
grid-column-end: 4;
grid-row-start: 1;
grid-row-end: 2;
transform: scaleX(-1);
}
Here is the code
.gridContainer {
display: grid;
grid-template-columns: 100px auto auto 100px;
grid-template-rows: repeat(4, auto);
row-gap: 100px;
}
.main {
display: block;
grid-column-start: 2;
grid-column-end: 3;
}
.main2 {
display: block;
grid-column-start: 2;
grid-column-end: 3;
grid-row-start: 2;
grid-row-end: 3;
}
.main3 {
display: block;
grid-column-start: 3;
grid-column-end: 4;
grid-row-start: 1;
grid-row-end: 2;
transform: scaleX(-1);
}
.main3 span {
}
.main3 .background::before {
width: 35%;
}
.test {
z-index: 100;
width: 400px;
height: 100px;
background-color: #67ade0;
position: absolute;
border-bottom-style: solid;
border-color: #93cff1;
border-width: 100px;
clip-path: polygon(10% 0%, 5% 50%, 10% 100%, 5% 100%, 0% 50%, 5% 0%);
}
.background {
display: inline-block;
margin-left: 20px;
width: 0px;
height: 200px;
background-color: #e1effa;
clip-path: polygon(95% 0, 100% 50%, 95% 100%, 5% 100%, 0 50%, 5% 0);
transition: width 6.5s, transform 5s;
z-index: 10;
opacity: 0.8;
}
.diamondStatic {
margin-left: 20px;
display: inline-block;
position: absolute;
height: 200px;
width: 400px;
background-color: #c4e0f5;
clip-path: polygon(5% 0, 10% 50%, 5% 100%, 0% 50%);
}
.diamondAnimate {
margin-left: -20px;
display: inline-block;
z-index: 100px;
height: 200px;
width: 400px;
background-color: #c4e0f5;
clip-path: polygon(5% 0, 10% 50%, 5% 100%, 0% 50%);
transition: margin-left 6.5s, transform 5s;
}
.test:hover ~ .background {
width: 400px;
}
.test:hover ~ .diamondAnimate {
margin-left: -45px;
}
.background::after {
margin-top: 10px;
margin-left: 140px;
position: absolute;
content: 'Managed Services';
}
.background::before {
width: 15%;
margin-top: 50px;
margin-left: 50px;
position: absolute;
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eget erat maximus, mattis ex sed, aliquet arcu. Maecenas eleifend ornare nulla, id placerat turpis pretium quis. Class aptent taciti sociosqu.';
}
.innerBtn {
display: inline;
position: absolute;
margin-top: 150px;
margin-left: 160px;
}
<div class="gridContainer">
<div class="main">
<div class="test"></div>
<div class="diamondStatic"></div>
<span class="background">
<button class="innerBtn">CLICK ME</button>
</span>
<div class="diamondAnimate"></div>
</div>
<div class="main2">
<div class="test"></div>
<div class="diamondStatic"></div>
<span class="background">
<button class="innerBtn">CLICK ME</button>
</span>
<div class="diamondAnimate"></div>
</div>
<div class="main3">
<div class="test"></div>
<div class="diamondStatic"></div>
<span class="background">
<button class="innerBtn">CLICK ME</button>
</span>
<div class="diamondAnimate"></div>
</div>
</div>
As You can see from the visual box of the codepen, the element on the right side is trembling and the text is inverted. This issue seems to be outside of my little knowledge and that's the reason for taking the guts and posting here.
PS: I have also tried to rebuild the whole container on another way ( https://codepen.io/benjaminj/pen/zYWwyeQ) but here I stumbled with the background that I want to be visible only in the expanding area.
For the test being flipped: You just need to transform:scaleX(-1) also the inner div .background
For the hover being shaking, is because the horizontal scroll showing then hiding, so use overflow: hidden in .main
I also improved your code a bit, deleting duplicated properties and other minor stuff
body {
margin: 0;
overflow: hidden
}
.gridContainer {
display: grid;
grid-template-columns: 100px auto auto 100px;
grid-template-rows: repeat(4, auto);
row-gap: 100px;
}
.main {
grid-column: 2 / 3;
overflow: hidden
}
.main2 {
grid-row: 2 / 3;
}
.main3 {
grid-column: 3 / 4;
transform: scaleX(-1);
}
.main3 .background {
transform: scaleX(-1);
}
.test {
z-index: 100;
width: 400px;
height: 100px;
background-color: #67ade0;
position: absolute;
border-bottom-style: solid;
border-color: #93cff1;
border-width: 100px;
clip-path: polygon(10% 0%, 5% 50%, 10% 100%, 5% 100%, 0% 50%, 5% 0%);
}
.background {
display: inline-flex;
margin-left: 20px;
width: 0;
height: 200px;
background-color: #e1effa;
clip-path: polygon(95% 0, 100% 50%, 95% 100%, 5% 100%, 0 50%, 5% 0);
transition: width 6.5s, transform 5s;
opacity: 0.8;
}
.diamondStatic,
.diamondAnimate {
display: inline-block;
position: absolute;
height: 200px;
width: 400px;
background-color: #c4e0f5;
clip-path: polygon(5% 0, 10% 50%, 5% 100%, 0% 50%);
}
.diamondStatic {
margin-left: 20px;
}
.diamondAnimate {
margin-left: -20px;
transition: margin-left 6.5s, transform 5s;
}
.test:hover~.background {
width: 400px;
}
.test:hover~.diamondAnimate {
margin-left: -45px;
}
.background::before {
max-width: 75%;
margin-top: 50px;
margin-left: 50px;
content: attr(data-text)
}
.background::after {
margin-top: 10px;
margin-left: 140px;
position: absolute;
content: attr(data-title);
}
.innerBtn {
display: inline;
position: absolute;
margin-top: 150px;
margin-left: 160px;
}
<div class="gridContainer">
<div class="main">
<div class="test"></div>
<div class="diamondStatic"></div>
<span class="background" data-title="Managed Services" data-text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eget erat maximus, mattis ex sed, aliquet arcu. Maecenas eleifend ornare nulla, id placerat turpis pretium quis. Class aptent taciti sociosqu.">
<button class="innerBtn">CLICK ME</button>
</span>
<div class="diamondAnimate"></div>
</div>
<div class="main main2">
<div class="test"></div>
<div class="diamondStatic"></div>
<span class="background" data-title="Managed Services" data-text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eget erat maximus, mattis ex sed, aliquet arcu. Maecenas eleifend ornare nulla, id placerat turpis pretium quis. Class aptent taciti sociosqu.">
<button class="innerBtn">CLICK ME</button>
</span>
<div class="diamondAnimate"></div>
</div>
<div class="main main3">
<div class="test"></div>
<div class="diamondStatic"></div>
<span class="background" data-title="Managed Services" data-text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eget erat maximus, mattis ex sed, aliquet arcu. Maecenas eleifend ornare nulla, id placerat turpis pretium quis. Class aptent taciti sociosqu.">
<button class="innerBtn">CLICK ME</button>
</span>
<div class="diamondAnimate"></div>
</div>
</div>

Tons of whitespace on page for no reason

I'm writing a website for a restaurant (Not commercially) and need to know why there's so much whitespace to the right side of the page? Take a look
.top-container{
background-color: white;
background-image: url("images/charmlogoTrans.png");
padding: 170px;
text-align: center;
background-position: center;
background-repeat: no-repeat;
background-size:contain;
position: relative;
max-width: 100%;
}
.menuBar{
background-color: rgb(168, 123, 81);
padding: 30px 40px;
text-align: left;
z-index: 3;
}
.content{
padding:16px;
background-color:rgba(230,199,177,255);
margin-left: 2%;
margin-right: 50%;
margin-top: 2%;
border-radius:4px;
position: relative;
z-index: 1;
}
.imgContent{
position: absolute;
z-index: 2;
left: 50%;
width: 100%;
height:auto;
}
.exampleImg{
width: 32%;
height:auto;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky + .content {
padding-top: 102px;
}
<body>
<div class="top-container"></div>
<div class="menuBar" id="menuBar"> The sticky bar</div>
<div class="mainContent">
<div class="imgContent">
<img class="exampleImg" src="Images/example.png" width="300" height="200">
</div>
<div class="content">
<h3>Vestibulum nulla turpis, hendrerit nec sodales vitae, congue at felis. Cras auctor ac quam sed
fermentum. Quisque libero est, aliquam ac lorem a, semper molestie mi. Cras suscipit eu erat eget
hendrerit.
</h3>
</div>
<img src="Images/example.png" width="300" height="200">
<img src="Images/example.png" width="300" height="200">
</div>
</body>
Please excuse me for such messy code, I'm still learning how to do some things. The measurements I'm still working on a bit, but any help is appreciated! If there's anything I've missed, or need to include, please let me know.
That's because imgContent is taking position: absolute, left: 50% so the element will overflow the page because you also set the width of imgContent to 100% there's 3 ways to fix this
set witdth to less than 100% something like 45% is enough
set Left to 0;
use flex box instead that's will be better in fact
Welcome to SO,
Try this!
It seems that the 50% left was adding the whitespace!
body {
margin: 0;
overflow-x: hidden;
width: 100vw
}
.top-container {
background-color: white;
background-image: url("images/charmlogoTrans.png");
padding: 170px;
text-align: center;
background-position: center;
background-repeat: no-repeat;
background-size: contain;
position: relative;
max-width: 100vw;
}
.menuBar {
background-color: rgb(168, 123, 81);
padding: 30px 40px;
text-align: left;
z-index: 3;
}
.content {
padding: 16px;
background-color: rgba(230, 199, 177, 255);
margin-left: 2%;
margin-right: 50%;
margin-top: 2%;
border-radius: 4px;
position: relative;
z-index: 1;
}
.imgContent {
position: relative;
z-index: 2;
width: 100vw;
height: auto;
}
.exampleImg {
width: 32vw;
height: auto;
}
.sticky {
position: fixed;
top: 0;
width: 100vw;
}
.sticky+.content {
padding-top: 102px;
}
<body>
<div class="top-container"></div>
<div class="menuBar" id="menuBar"> The sticky bar</div>
<div class="mainContent">
<<div class="imgContent">
<img class="exampleImg" src="Images/example.png" width="300" height="200">
</div>
<div class="content">
<h3>Vestibulum nulla turpis, hendrerit nec sodales vitae, congue at felis. Cras auctor ac quam sed fermentum. Quisque libero est, aliquam ac lorem a, semper molestie mi. Cras suscipit eu erat eget hendrerit.
</h3>
</div>
<img src="Images/example.png" width="300" height="200">
<img src="Images/example.png" width="300" height="200">
</div>
</body>

Make <div> with childs always fit in parent <div>

I'm trying to make a div with some children inside always fit to the parent div which covers the whole page. It already works that the child div's width fits into the parent's. But the height should also fit inside the parent div. I want to avoid using overflow: auto because then the user will have to scroll in some cases. The child div (with it's children inside) should always fit in the parent's height and width.
How can I make this in CSS?
<div class="parent">
<div class="child">
<button>Toggle</button>
<img />
<p>Some text here...</p>
</div>
</div>
The <div class="parent"> covers the whole page. The <div class="child"> should scale into the <div class="parent"> width and height.
You can try this. You would need a media query for mobile but does what I think you are asking...
<html>
<head>
<style>
body {
font-weight: 400;
background-color: black;
color: white;
font-family: sans-serif;
margin: 0;
}
.grid {
min-height: 100%;
grid-column: 1 / -1;
grid-gap: 0;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(33%, 1fr));
}
.grid>span {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
}
.image {
background-image: url('https://live.staticflickr.com/7206/6859864719_5d68aedbd7.jpg');
background: cover;
background-position: center center;
background-repeat: no-repeat;
}
.toggle {
background: #4096C0;
border-radius: 2px;
padding: 12px 24px;
color: white;
width: auto;
text-align: center;
cursor: pointer;
}
.toggle:hover {
background: #00537C;
}
.text {
background: #40B6C0;
padding: 72px;
color: white;
}
</style>
</head>
<body>
<div class="container">
<div class="grid">
<span class="toggle">TOGGLE</span>
<span class="image"></span>
<span class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu fermentum dolor. Cras aliquet tempus elit ut eleifend. In commodo malesuada nisi non vulputate.</span>
</div>
</div>
</body>
</html>

How do I create a border over div with content?

I have to create a div over which there is a 3px border, and this boundary is positioned over the content in the div, how can I do this without knowing the size of the block?
An example is in the image below:
My code: https://codepen.io/pen/yLObXvv
HTML:
<div class="container">
<div class="row justify-content-center">
<div class="col-12 col-md-4">
<div class="case-study">
<div class="case-study-image">
<img src="https://images.unsplash.com/photo-1551434678-e076c223a692?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" class="img-fluid" alt="Intro image"/>
</div>
<div class="case-study-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
</div>
</div>
</div>
CSS:
body {
background-color: #04142d;
}
.case-study {
color: #fff;
display: flex;
margin-top: 2rem;
flex-direction: row;
background-color: #0E53DD;
border-radius: 1rem;
overflow: hidden;
}
.case-study-image {
flex: 0 0 50%;
width: 50%;
}
.case-study-image img {
height: 100%;
max-height: 20rem;
object-fit: cover;
oject-position: 0 0;
}
.case-study-content {
flex: 0 0 50%;
padding: 1rem;
}
Please Use CSS ::after Selector with position: absolute
The coordinates of an absolute positioned element are relative to its parent. It is positioned automatically to the starting point (top-left corner) of its parent element.
body {
background-color: #04142d;
}
.case-study {
color: #fff;
display: flex;
margin-top: 2rem;
flex-direction: row;
background-color: #0E53DD;
border-radius: 1rem;
position:relative;
max-width:500px;
}
img {
max-width:100%;
}
.case-study-image {
flex: 0 0 50%;
width: 50%;
}
.case-study-image img {
height: 100%;
max-height: 20rem;
object-fit: cover;
oject-position: 0 0;
}
.case-study-content {
flex: 0 0 50%;
padding: 1rem;
}
.case-study:after {
content: '';
border: 3px solid yellow;
position: absolute;
width: calc(100% - 6px);
height: calc(100% - 6px);
border-radius: 5px;
right: -10px;
top: -10px;
}
<div class="case-study">
<div class="case-study-image"> <img src="https://images.unsplash.com/photo-1551434678-e076c223a692?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" class="img-fluid" alt="Intro image"/> </div>
<div class="case-study-content">
<p>Lorem ipsum dolor sit amet</p>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<title>style</title>
<style>
div {
width: 200px;
height: 200px
background-color:white;
}
.move {
transform: (30px, 180px)
background: transparent;
border: 3px solid red;
}
</style>
</head>
<body>
<div class="move"></div>
<div></div>
</body>
</html>
you can use this and try to style it the way you want

Stick a Div element during Horizontal scroll

I am struggling with a layout problem and I hope to find some help to solve it.
I am designing a page with row/lane based content.
Each row has multiple div elements with some content.
So it has to be possible to scroll through the rows vertically as well as horizontally.
Now the problem is, that the first div element inside every row is kind of like the row header, which provides some description about the content of that row.
I want this div element to always stay visible during horizontal scrolling.
Position: fixed is not a option since it would prevent the "row-header" to scroll with its content during a vertical scroll.
What it should look like during a horizontal scroll
Here's the fiddle with my code: https://jsfiddle.net/rco56cbp/
html,
body {
font-family: 'Arial', sans-serif;
margin: 0;
}
* {
box-sizing: border-box;
}
header {
background: #F7F7F7;
box-shadow: 0px 2px 6px 0px rgba(0,0,0,0.50);
/**/
width: 100%;
height: 90px;
/**/
display: flex;
align-items: center;
justify-content: center;
position: fixed;
z-index: 55;
top: 0;
}
/* Left Sidebar */
.side-bar-bg {
width: 130px;
height: 100vh;
z-index: -1;
position: fixed;
background: #F7F7F7;
border: 1px solid #E0E0E0;
box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.50);
}
/* Wrapper around main content */
.content-container {
margin-top: 110px;
height:100%;
position:absolute;
width:100%;
}
/* Content elements*/
.lane,
.lane-head,
.phase,
.lane-content {
display: flex;
}
.lane {
margin-bottom: 1.25em;
//flex-direction: row;
align-items: center;
}
.lane-head {
min-width: 130px;
background-color: #ffffff;
box-shadow:0px 0px 0px 1px #BFC0C2 inset;
/* Flex & Layout */
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
align-self: stretch;
/**/
margin-right: 1em;
}
.lane-label {
font-weight: 500;
font-size: 13px;
color: rgba(82,94,106,0.65);
line-height: 22px;
margin-left: 1em;
margin-right: 1em;
text-align: center;
}
.lane-content {
z-index: -3;
}
/* Grid System */
.col-1 { min-width: 200px; max-width: 200px; }
.col-2 { min-width: 420px; max-width: 420px; }
.col-3 { min-width: 640px; max-width: 640px; }
.col-1, .col-2, .col-3 { margin-right: 20px; }
.textbox {
padding: 0.7em 1em 1.5em 1em;
color: #FFFFFF;
min-width: 200px;
max-width: 200px;
background-color: #78BE20;
}
.phase {
background: #005691;
align-self: stretch;
align-items: center;
padding: 0.6em 1em;
}
/* Typo */
.phase {
font-weight: 500;
font-size: 16px;
color: #FFFFFF;
}
.textbox h3 {
font-weight: bold;
font-size: 16px;
margin: 0 0 0.3em 0;
}
.textbox p {
font-weight: normal;
font-size: 13px;
margin: 0 0;
}
<header>
<h1>Header</h1>
</header>
<div class="side-bar-bg"></div>
<!------ CONTENT ------>
<div class="content-container">
<div class="lane">
<div class="lane-head"><span class="lane-label">Small Boxes</span></div>
<div class="lane-content">
<div class="phase col-2">Lorem Ipsum</div>
<div class="phase col-3">Bacon Ipsum</div>
<div class="phase col-2">Egg Ipsum</div>
</div>
</div>
<div class="lane">
<div class="lane-head"><span class="lane-label">Bigger Boxes</span></div>
<div class="lane-content">
<div class="textbox col-1">
<h3>Aenean commodo</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
</div>
<div class="textbox col-1">
<h3>Consequat</h3>
<p>Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.</p>
</div>
<div class="textbox col-1">
<h3>Consequat</h3>
<p>Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.</p>
</div>
<div class="textbox col-1">
<h3>Consequat</h3>
<p>Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.</p>
</div>
<div class="textbox col-1">
<h3>Consequat</h3>
<p>Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.</p>
</div>
<div class="textbox col-1">
<h3>Consequat</h3>
<p>Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.</p>
</div>
<div class="textbox col-1">
<h3>Consequat</h3>
<p>Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.</p>
</div>
</div>
</div>
</div>
The fixed left sidebar shall serve as a background to the "lane-headers".
The reason I want the lane-headers and the lane-content to be inside one div container is that later the whole canvas becomes dynamic and interactive. The content will be generated dynamically and the user will be able to interact with the canvas with drag-drop and so on.
I would appreciate your help very much, thanks in advance!
Hi you need to use javascript as well, once you scroll down or up add a class say posi_stat which will be position:static.and when you do horizontal scrolling just remove the class. In default case it will be position :fixed .
Something like this , you need to remove the class , and add on scrolldown too
$(function() {
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 500) {
//your code , what should be done//
}
});
});
Similarly to it for .scrollBottom(); .scrollRight(); .scrollLeft();
Okay I kind of found a solution to it thanks to this: Fixed position in only one direction in future releases of CSS?
Although the javascript solution did not work for me (I still can't figure out why), the CSS solution works pretty good.
By adding the following lines to the .lane-head class the problem was solved:
left: 0;
position: -webkit-sticky;
position: -moz-sticky;
position: -o-sticky;
position: -ms-sticky;
position: sticky;
Using the new "position: sticky" property you can perfectly stick any element basically anywhere you want.
Unfortunately Chrome still does not support this yet, but Safari and Firefox do.