I'm in the process of developing a blog and am trying to achieve a hover effect that slides up to reveal the full post preview on hover. The attached image is probably better at conveying the desired effect. Basically, only the title of the post is shown, then on hover the title slides up, also revealing the rest of the preview.
The only way I've been able to come close so far is by using two seperate div's, one with just the title and the other with the full preview (title included). Then fade the title div out while sliding the other up. It looked okay but it's just not as smooth as I'd like it to be. I would much prefer everything to slide up.
If any CSS wizards can help me, I'd appreciate it. Also, CSS-only would be great, JS as a last resort.
Thanks,
Oli.
Here's a quick / dirty solution:
HTML:
<div class="container">
<div class="post">
<div class="title">Bla bla bla</div>
<div class="body">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</div>
CSS:
.container {
background-color: #00f;
width: 300px;
height: 300px;
position: relative;
}
.post {
cursor: pointer;
background-color: #fff;
position: absolute;
bottom: 20px;
left: 20px;
right: 20px;
}
.body {
transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
height: 0;
opacity: 0;
overflow: hidden;
}
.post:hover .body {
height: 200px;
opacity: 1;
}
DEMO: https://jsfiddle.net/y7rb77sk/
Of course you can add transitions to animate it and make it cooler
Here is a solution: http://jsfiddle.net/leojavier/gbuLykdj/4/
Incase of overflow, this solution will give you a scroll: http://jsfiddle.net/leojavier/gbuLykdj/5/
<div class="container">
<img src="http://placecorgi.com/300/400" alt="">
<article>
<h1>My Title</h1>
<p>san leo vestibulum non. Donec porttitor semper malesuada. Morbi vel felis venenatis, tempus mi in, ornare purus. Morbi hendrerit orci ipsum, a fringilla ante tristique in. Fusce sollicitudin venenatis neque eget ornare. Integer semper, ante ut vestibulum finibus, ipsum ex aliquam quam, qui</p>
</article>
</div>
CSS
.container{
position:relative;
width:300px;
height:400px;
}
article{
position:absolute;
width:100%;
max-width:280px;
height:auto;
background:rgba(255,255,255,0.8);
bottom:0;
padding:10px;
font-family:arial;
opacity:0;
transition: opacity 1s;
}
.container:hover > article {
opacity:1;
}
Related
Is it possible to accomplish a diagonal line stroke, with a bit of an off-set in any side. I've seen a variation of this accomplished with css linear-gradient, but I need something slightly different. I don't know how to describe what I need exactly in words. I'll use pictures.
I've tried playing with gradients:
.diagonal{
background-color: #34ADFF;
background-image: linear-gradient(to right top, whitesmoke 50%, #34ADFF 50%);
height: 300px;
}
<div class="diagonal">
</div>
That's how far I've gone. I'm thinking of playing around with child divs, but I'm not sure yet.
Any ideas ?
I don't want to use images, I want to use just CSS.
You could try using a separate div for the linear-gradient
.diagonal-top {
background-image: linear-gradient(to left top, whitesmoke 50%, #34ADFF 50%);
height: 20px;
}
.diagonal-bottom {
background-image: linear-gradient(to right top, #34ADFF 50%, whitesmoke 50%);
height: 40px;
}
.header {
height: 30px;
background-color: #34ADFF;
}
.footer {
height: 50px;
background-color: #34ADFF;
}
.clearfix {
height: 30px;
background-color: whitesmoke;
}
<div class="header"></div>
<div class="diagonal-top"></div>
<div class="clearfix"></div>
<div class="diagonal-bottom"></div>
<div class="footer"></div>
Ok so here's the thing. This must stay responsive and able to evolve over time so I searched for a better solution and here's what I found. To simplify it a little bit, here's a snippet :
.se-container {
display: block;
width: 100%;
overflow: hidden;
padding-top: 100px;
}
.se-slope {
margin: 0 -50px;
transform-origin: left center;
}
.se-slope:nth-child(odd) {
background: url(http://lorempixel.com/400/200/);
background-size: cover;
transform: rotate(5deg);
margin-top: -200px;
box-shadow: 0px -1px 3px rgba(0, 0, 0, 0.4);
}
.se-slope:nth-child(even) {
background: linear-gradient(to right, purple 0%, red 100%);
transform: rotate(-5deg);
box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.4) inset;
}
.se-content {
margin: 0 auto;
}
.se-content p {
width: 75%;
max-width: 500px;
margin: 0 auto;
font-size: 18px;
line-height: 24px;
}
.se-slope:nth-child(odd) .se-content {
transform: rotate(-5deg);
padding: 130px 100px 250px 100px;
}
.se-slope:nth-child(even) .se-content {
transform: rotate(5deg);
padding: 150px 100px 250px 100px;
}
<section class="se-container">
<div class="se-slope">
<article class="se-content">
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
</article>
</div>
<div class="se-slope">
<article class="se-content">
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
</article>
</div>
<div class="se-slope">
<article class="se-content">
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
</article>
</div>
</section>
I am able to get the desired result using the following linear gradient:
linear-gradient( 6deg, transparent 73%, rgba(50, 87, 106, 0.72) 27%);
You can control the shape very easily.
the first parameter or linear-gradient( 6deg... controls the degree of the skew - You can use negative values as well
The percentages after each of the colors control the location of the dividing line.
If the numbers don't add up to 100% the divider will be blurry.
I added an image background and background-blend-mode:overlay; in the example below for demo purposes.
body {
text-align: center;
}
.test {
height: 400px;
width: 500px;
margin: 0 auto;
display: inline-block;
background: url(https://unsplash.it/500/400), linear-gradient( 6deg, transparent 73%, rgba(50, 87, 106, 0.72) 27%);
background-blend-mode:overlay;
}
<div class="test"></div>
An extremely unsophisticated demo using transform: rotate()
The rotateZ() CSS function defines a transformation that moves the element around the z-axis without deforming it. The amount of movement is defined by the specified angle; if positive, the movement will be clockwise, if negative, it will be counter-clockwise.
The working content of your slanted containers would require careful placement, and there are some potential positioning issues, but with effort, I think this could work.
body {
background: lightgray;
margin: 0;
height: 300vh;
}
header, footer {
position: fixed;
height: 20vh;
width: 120vw;
left: -10vw;
overflow: hidden;
}
header {
background: lightblue;
top: -6vh;
}
footer {
background: lightgreen;
bottom: -6vh;
}
footer,
header p {
transform: rotateZ( -3deg );
}
header,
footer p {
transform: rotateZ( 3deg );
}
<header>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</header>
<footer>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</footer>
I have serious troubles with my css layout.
This is my workingbase: http://jsfiddle.net/UeVm8/1/
<div id="container">
<div id="header">
<h1>
Site name
</h1>
</div>
<div id="content">
<h2>
Page heading
</h2>
<p>
Lorem ipsum dolor sit amet consect etuer adipi scing elit sed diam nonummy nibh euismod tinunt ut laoreet dolore magna aliquam erat volut. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
<p>
Lorem ipsum dolor sit amet consect etuer adipi scing elit sed diam nonummy nibh euismod tinunt ut laoreet dolore magna aliquam erat volut. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
</div>
<div id="footer">
Copyright © Site name, 20XX
</div>
html, body{
margin: 0;
height: 100%;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
padding-top:10px;
padding-bottom:10px;
}
#container
{
position:relative;
margin: 0 auto;
width: 600px;
background:#333;
min-height: 100%;
height:auto !important;
overflow: hidden !important;
}
#header
{
background:#ccc;
padding: 20px;
}
#header h1 { margin: 0; }
#content
{
padding: 20px;
padding-bottom:50px;
}
#footer
{
position:absolute;
background:#ccc;
bottom:0;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
width:100%;
}
The site should always be 100% height at minimum with small distances to top and bottom.
There shouldn't be scrollbars, except the content is too big. Then it should fit to the content and the distances to top and bottom should stay.
But when you resize the window, the padding at the bottom disappears!?!
I already tried different settings and found a solution for Firefox: http://jsfiddle.net/UeVm8/7/
But this solution does not work in Chrome and IE.
I am totally annoyed by this nasty inconsistence in the CSS implementations.
Does anybody know how to solve this issue for all (modern) browsers?
Thanks.
PS: It's an stylesheet only for desktops.
I finally found the answer! :)
As mentioned I already found a solution for Firefox, but it was not working on Chrome.
After some fiddling I also had a solution for Chrome, which wasn't working on Firefox.
I think the issue is that there seems to be a bug in Google Chrome.
But I could combine both solutions by just overwriting settings just for chrome with some special selector.
The CSS solution: http://jsfiddle.net/UeVm8/8/
html, body{
margin: 0;
height: 100%;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
padding-top:10px;
padding-bottom:10px;
}
#container
{
position:relative;
margin: 0px auto 20px;
width: 600px;
background:#333;
min-height: 100%;
height:auto !important;
overflow: hidden !important;
}
#media screen and (-webkit-min-device-pixel-ratio:0) {
#container{
margin: 0px auto 0px;
}
html, body{
overflow:auto;
}
}
#header
{
background:#ccc;
padding: 20px;
}
#header h1 { margin: 0; }
#content
{
padding: 20px;
padding-bottom:50px;
color:grey;
}
#footer
{
position:absolute;
background:#ccc;
bottom:0;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
width:100%;
}
I tested it on Firefox, Chrome, IE, Opera and Maxton and it worked.
Nevertheless CSS is a crazy chick.
I've been searching for an answer on this, and tried multiple methods of fixing it to no avail. I'm teaching myself CSS while re-building a site, and have a small problem.
I have a container within a parent container - the "sub-container" (for lack of a better term) has it's own header, a photo to the left, and copy to the right. The copy should be top-aligned to the photo, and equally spaced between the right edge of the photo and the right edge of the background image in the sub-container. What I'm getting is the photo in the proper place, with the copy butted up against the bottom right corner of the photo.
I'm fairly certain the issue is a mix between lack of knowledge and a mis-understanding of what is causing what... so any help with this is greatly appreciated.
Here's my CSS:
#wrapper {
background-image:url("images/About/Copy-Block.png");
background-repeat:no-repeat;
width: 745px;
height: 339px;
margin: 0 auto;
margin-top: 30px;
}
#wrapper head {
display:block;
padding-top: 15px;
padding-bottom: 2px;
}
#wrapper photo {
float: left;
}
.wrapcopy {
padding-left: 90px;
font-size: 13px;
color: #FFF;
}
and here is my html:
<div id="wrapper">
<div id="wrapper head" align="center">
<img src="images/About/About-Us-Subhead.png" width="748" height="116" />
</div>
<div class="wrapcopy">
<img src="images/About/image.png" width="257" height="194" class="wrapper photo"/>
<i>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</i>
</div>
</div>
You wrote "photo" instead of "img" in your CSS, edit it like this and it will work!
#wrapper img{
float: left;
}
However, you have 2 images in your example and this will float both of them. You can solve that by giving for example an ID/class to those images.
First off, you aren't referencing your classes properly: "#wrapper photo" should be "#wrapper .photo". Also, id's can't have spaces in them ("#wrapper head").
There are a few ways you can add spacing you desire. The most straight forward way would be to add padding directly to the image:
#wrapper .photo { float: left; padding-right: 10px }
I would also like to point out that the markup you are using is very poor. Headlines should go in h1-h6 tags (images are still allowed in these tags!), paragraphs of text should be in p tags. Section or article tags might be an appropriate replacement for your wrapper div. It's not enough to know CSS, you also need to know the appropriate HTML markup to go with it.
A more efficient way of doing this would be like this:
section.foo {
background-image:url("images/About/Copy-Block.png");
background-repeat:no-repeat;
width: 745px;
height: 339px;
margin: 0 auto;
margin-top: 30px;
}
section.foo h1 {
padding-top: 15px;
padding-bottom: 2px;
text-align: center;
}
section.foo p {
padding-left: 90px;
font-size: 13px;
color: #FFF;
font-style: italic;
}
section.foo p img {
float: left;
padding-right: 10px;
}
And the HTML:
<section class="foo">
<h1><img src="images/About/About-Us-Subhead.png" width="748" height="116" /></h1>
<p><img src="images/About/image.png" width="257" height="194" /> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</section>
First of all, Never use any spaces naming an ID.
So change id="wrapper head" to id=id="wrapper_head"
Next, elements can be selected by their tags.
An Image is coded by <img tag so you can select it directly in CSS by img { } .
In your case, you want to select image inside #wrapper division, so select it by :
#wrapper img
{
/* Code Here... */
}
The problem of your code are the spaces in the id tags.
Try something like
<div id="wrapper_head" ....
instead of
<div id="wrapper head" ....
That should solve your problem!
I have two divs under one parent div, the parent div has 100% width:
<div id="parent">
<div class="left"></div>
<div class="right"></div>
</div>
The conditions are:
I want two divs on the same line.
The right div may or may not be present. When it is present, I want it to always be fixed on the right. However, the left div must be elastic - it's width depends on its content.
I have tried both float:left, and dispaly:inline-block but neither solution seems to work.
Any suggestion would be appreciated.
I'd go with #sandeep's display: table-cell answer if you don't care about IE7.
Otherwise, here's an alternative, with one downside: the "right" div has to come first in the HTML.
See: http://jsfiddle.net/thirtydot/qLTMf/
and exactly the same, but with the "right div" removed: http://jsfiddle.net/thirtydot/qLTMf/1/
#parent {
overflow: hidden;
border: 1px solid red
}
.right {
float: right;
width: 100px;
height: 100px;
background: #888;
}
.left {
overflow: hidden;
height: 100px;
background: #ccc
}
<div id="parent">
<div class="right">right</div>
<div class="left">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam semper porta sem, at ultrices ante interdum at. Donec condimentum euismod consequat. Ut viverra lorem pretium nisi malesuada a vehicula urna aliquet. Proin at ante nec neque commodo bibendum. Cras bibendum egestas lacus, nec ullamcorper augue varius eget.</div>
</div>
#Yijie; Check the link maybe that's you want http://jsfiddle.net/sandeep/NCkL4/7/
EDIT:
http://jsfiddle.net/sandeep/NCkL4/8/
OR SEE THE FOLLOWING SNIPPET
#parent{
overflow:hidden;
background:yellow;
position:relative;
display:table;
}
.left{
display:table-cell;
}
.right{
background:red;
width:50px;
height:100%;
display:table-cell;
}
body{
margin:0;
padding:0;
}
<div id="parent">
<div class="left">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="right">fixed</div>
</div>
HTML:
<div id="parent">
<div class="right"></div>
<div class="left"></div>
</div>
(div.right needs to be before div.left in the HTML markup)
CSS:
.right {
float:right;
width:200px;
}
So left div style depends on the presence of right div. I can't think of a CSS selector allowing that kind of behavior yet.
Thus it seems to me that you'll need to programmatically add a class server side (or in JS) on parent div or left div to do that.
<div id="parent twocols">
<div class="left"></div>
<div class="right"></div>
</div>
or
<div id="parent">
<div class="left"></div>
</div>
So right style is always :
.right {
float: right;
width: 200px; /* or whatever value you need */
/* margin and padding at your discretion */
}
and left style is :
.parent.twocols .left {
margin-right: 200px; /* according to right div width + margin + padding*/
}
I've had success with using white-space: nowrap; on the outer container, display: inline-block; on the inner containers, and then (in my case since I wanted the second one to word-wrap) white-space: normal; on the inner ones.
I think this is you want:
<html>
<head>
<style type="text/css">
#parent
{width:100%;
height:100%;
border:1px solid red;
}
.left
{
float:left;
width:40%;
height:auto;
border:1px solid black;
}
.right
{
float:left;
width:59%;
height:auto;
border:1px solid black;
}
</style>
</head>
<body>
<div id="parent">
<div class="left">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="right">This is the right side content</div>
</div>
</body>
</html>
Here is the demo:http://jsfiddle.net/anish/aFBmN/
Code is here: http://lasers.org.ru/vs/example.html
How to remove an empty space under main block (#page)?
Another trick which worked fine for me is to use a negative margin-bottom in the relative element that you have moved. No need to go with absolute positioning.
Something like:
position: relative;
top: -200px;
left: 100px;
margin-bottom: -200px;
Similar (if not identical) to the solution I see now, from green.
Well, don't use relative positioning then. The element still takes up space where it originally was when using relative positioning, and you can't get rid of that. You can for example use absolute positioning instead, or make the elements float beside each other.
I played around with the layout a bit, and I suggest that you change these three rules to:
#layout { width: 636px; margin: 0 auto; }
#menu { position: absolute; width: 160px; margin-left: 160px; }
#page { width: 600px; padding: 8px 16px; border: 2px solid #404241; }
#page
{
overflow:hidden;
}
Try this rule:
#page {
border: 2px solid #404241;
bottom: 0;
padding: 8px 16px;
position: absolute;
top: 70px;
width: 600px;
}
I changed position to absolute, this allows you to use the bottom: 0 property.
#page {
padding-bottom: 0;
}
I was able to get rid of the whitespaces using the following framework:
And here is the markup
<div id="the-force-moved-element>I've been moved</div>
<div id="the-hack-part-1">
<div id="the-hack-part-2>The quick brown fox jumps over the lazy dog</div>
</div>
<p>Lorem ipsum dolor sit amet...</p>
My answer is late but it may help others with a similar issue that I had.
I had a <div> with position: relative; where all the child elements have the position: absolute; style. This caused around 20px of white space to appear on my page.
To get around this I added margin-top: -20px; to the next sibling element after the <div> with position: relative;.
If you have a sibling element before, you can use margin-bottom: -20px;
section {
height: 200px;
}
<h2>Extra Whitespace</h2>
<section>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<div style="position:relative;">
<div style="position:relative; top: -20px; left:100px;">ABSOLUTE</div>
</div>
<div>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</section>
<h2>No Whitespace margin-top</h2>
<section>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<div style="position:relative;">
<div style="position:relative; top: -20px; left:100px;">ABSOLUTE</div>
</div>
<div style="margin-top:-20px;">
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</section>
<h2>No Whitespace margin-bottom</h2>
<section>
<div style="margin-bottom:-20px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<div style="position:relative;">
<div style="position:relative; top: -20px; left:100px;">ABSOLUTE</div>
</div>
<div>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</section>
The best solution if you don't want to leave spaces below (relative)
Is to use margin-top and position: sticky
#page {
margin-top: -280px;
position: sticky;
}
A negative margin value usually does the trick.
container {
position: relative;
top: -100px;
marginBottom: -100px;
}
Wherever the space appears (top, bottom, left, right)
Just give a negative margin value on the element that was positioned relatively.
I had a similar problem. The easiest way is to replace top on margin-top for #page.
I had the same issue. Negative margin didn't work for me as it left a massive white area where it used to be. I solved this problem in my case by manually entering height.
.maincontent {
height: 675px;
}
This question seems to be well answered - however all the answers above had bad side effects in my layout. This is what really worked for me:
.moveUp {
position: relative;
}
.moveUp > * {
position: absolute;
width: 100%;
top: -75px;
}
/** This part is just design - ignore it ... ****/
.box1, .box2, .box3 {
height: 100px;
color: white;
}
.box1 {
background: red;
}
.box2 {
background: blue;
height: 50px;
}
.box3 {
background: green;
}
<div class="box1">Box 1</div>
<div class="moveUp"><div class="box2">Box 2 - 75px up</div></div>
<div class="box3">Box 3</div>
just add the marginBottom to the element equal to space that you moved relatively.
// you moved top:-120px
// then add marginBottom:-120px