I'm wondering if there is a way to fix an element inside a visible area of the div as I've described in the image below.
Here is an example of my problem (jsfiddle):
HTML:
<div id="header" ></div>
<div id="menu">
<a id="menu-collapse">collapse</a>
<div id="some-block"></div>
</div>
<div id="content"></div>
CSS:
#menu {
position: fixed;
top: 70px;
bottom: 0px;
left: 0;
width: 200px;
background-color: rgb(100, 134, 27);
overflow-x: auto;
}
#header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 70px;
background-color: rgb(27, 48, 0);
min-width: 540px;
}
#menu-collapse{
}
#content {
position: fixed;
top: 70px;
right: 0px;
bottom: 0px;
left: 200px;
background-color: rgb(27, 118, 0);
}
#some-block{
position:absolute;
display:inline;
background-color: yellow;
width: 200px;
height: 2500px;
}
I need to have #menu-collapse in the middle of the visible area of #menu, while scrolling #menu.
Use position: fixed; in your CSS class definition. This will position the div relative to the browser window instead of the document itself, allowing it to maintain its position as you scroll.
There is now way to fix the element inside a div area if you use position:fixed; property then it will automatically fix it relatively to the browser.
Its a default feature.
On #menu-collapse, you need to add position: fixed; to get it to stay in the same position. And, you need top: 50%; in order to have it in the middle of #menu, and z-index: 1; in order for it to display on top of #some-block.
JSFiddle
HTML:
<div id="header" ></div>
<div id="menu">
<a id="menu-collapse">collapse</a>
<div id="some-block">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vitae tortor fermentum, pellentesque lorem vitae, ullamcorper urna. Sed in imperdiet nisl, porta porta sem. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum euismod sapien a imperdiet placerat. Ut a maximus felis. Mauris porta purus id mi feugiat ultrices. Etiam mattis leo id hendrerit sagittis. Vivamus dapibus blandit ligula varius semper.</p>
<p>Ut nisl neque, efficitur non risus vitae, luctus cursus dui. Pellentesque aliquam varius cursus. Fusce lobortis, sapien at dictum porta, erat eros rhoncus metus, sit amet finibus libero quam nec nisl. Phasellus tempus ante vitae rutrum ultricies. Fusce sit amet hendrerit quam, egestas gravida risus. Donec eget tristique enim, ac lacinia nunc. Nam pulvinar, nunc et scelerisque ornare, est augue mollis sem, vel vulputate arcu mi et eros. Proin varius arcu vitae nisi porttitor, sit amet finibus eros congue. In dapibus tincidunt tortor. Sed at sem id tortor molestie finibus eget ut sem. In semper feugiat elementum. Morbi enim mauris, venenatis non felis ac, interdum euismod sapien. Praesent semper ante vel mauris auctor, ut commodo ipsum malesuada. Morbi hendrerit tortor sapien. Nulla in hendrerit dui, eu accumsan est</p>
</div>
</div>
<div id="content">
</div>
CSS:
#menu {
position: fixed;
top: 70px;
bottom: 0px;
left: 0;
width: 200px;
background-color: rgb(100, 134, 27);
overflow-x: auto;
}
#header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 70px;
background-color: rgb(27, 48, 0);
min-width: 540px;
}
#menu-collapse{
position: fixed;
top: 50%;
z-index: 1;
background: red;
}
#content {
position: fixed;
top: 70px;
right: 0px;
bottom: 0px;
left: 200px;
background-color: rgb(27, 118, 0);
}
#some-block{
position:absolute;
display:inline;
background-color: yellow;
width: 200px;
height: 2500px;
}
Related
When hovering a div, I want to display a full-page div with a background image and text on top. The hovered div should then stay on top of everything. This works so far, with the only exception that I can’t figure out how to make the overflow text scrollable.
Any ideas how to make this work?
JSFiddle
html:
<div class="container">
<div class="title">Show content</div>
<div class="content">
<div class="background"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg/800px-Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg"></div>
<div class="infocontainer">
<div class="info">
Lorem Ipsum...
</div>
</div>
</div>
</div>
css:
.container {
position: fixed;
left: 50%;
top: 10%;
}
.content {
display: none;
}
.title:hover + .content {
display: block;
width: 100%;
height: 100%;
}
.title:hover {
position: relative;
z-index: 3;
}
.background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.infocontainer {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
z-index: 2;
overflow: scroll;
}
.info {
height: 100%;
padding-right: 70%;
}
UPDATE: When I put .info on top with z-index, it becomes scrollable but I get a flickering effect because .title:hover gets over overridden. See: jsfiddle.net/dm41eo5z
You can't hover to make something appear over the whole page, because as soon as it is over the whole page you are no longer hovering the original thing (that's why your example above flickers) and it will disappear. If you use a JavaScript Event listener (such as onMouseOver) you could make it appear by adding a class with a "display: absolute" or "block" or whatever you want it to do. Then it would stay open until you use some other event listener (such as "Click" on an X) to close the element.
The .content div disappears as soon as you stop hovering the .title. To prevent that, continue showing .content while you hover it:
.title:hover + .content, .content:hover {
display: block;
width: 100%;
height: 100%;
}
Note: to hide .content, the user will have to move the cursor out of the screen.
Demo:
.container {
position: fixed;
left: 50%;
top: 10%;
}
.content {
display: none;
}
.title:hover + .content, .content:hover {
display: block;
width: 100%;
height: 100%;
}
.title:hover {
position: relative;
z-index: 3;
}
.background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.infocontainer {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
z-index: 2;
overflow: scroll;
}
.info {
height: 100%;
padding-right: 70%;
}
<div class="container">
<div class="title">Show content</div>
<div class="content">
<div class="background"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg/800px-Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg"></div>
<div class="infocontainer">
<div class="info">
Pellentesque venenatis tempor ultrices. Nunc maximus erat vel tellus vestibulum, id auctor justo tristique. Ut volutpat eu tellus ut vulputate. Cras id finibus massa. Quisque neque lacus, pretium sed luctus in, semper ut quam. Donec elementum volutpat elementum. Morbi nibh nunc, scelerisque congue turpis nec, lacinia venenatis tortor.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi quis magna urna. Etiam tincidunt velit lacus, ac blandit ex pretium nec. Nulla semper erat ut tortor luctus, sit amet suscipit felis ullamcorper. Etiam laoreet, mauris ut volutpat pellentesque, velit neque euismod sem, in condimentum mauris orci nec nibh. Vivamus ac sem et turpis pellentesque volutpat ac ac ligula. Phasellus feugiat dapibus maximus. Donec eros felis, suscipit eu neque quis, sagittis faucibus ipsum. Nam auctor molestie quam nec tristique. Aliquam dolor velit, condimentum in vehicula ut, pretium sed leo. Proin sit amet quam nunc.
Integer eu orci quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sed felis vitae justo faucibus blandit at a dolor. Curabitur id nisi nec elit aliquam convallis nec eu est. Aenean viverra id diam ac accumsan. Praesent tempor, magna eget molestie sodales, neque libero pretium magna, id euismod justo erat at est. Phasellus ultrices metus et massa varius, at rutrum augue pretium. Mauris ultrices felis et magna luctus sodales. Curabitur sodales pellentesque ante auctor molestie. Donec sed massa scelerisque elit auctor lacinia ac vel risus. In eleifend vulputate sapien a tristique. Nam eleifend rutrum metus.
</div>
</div>
</div>
</div>
Thank you for your replies so far but they don't exactly achieve what I'm looking for. Is there maybe a way to keep .title on top but specifically target .info for scrolling?
I need to create a website (two columns) where one column contains some text (vertical centered) and the other column contains a picture (sticky to bottom).
Both of them need to be responsive (so position: fixed is not an option for the image).
I tried to achieve this by using Bootstrap and the w3 responsive framework. But both of them seem unable to put a responsive image inside a column that is always stuck to the bottom.
Any tips on how I can achieve this layout while being responsive (Picture needs to resize etc)?
Here's a solution without using flex. It's completely responsive and can be scaled both horizontally and vertically.
body {
margin: 0;
padding: 0;
}
#container {
width: 100%;
height: 100vh;
overflow: hidden;
}
#column1 {
position: relative;
width: calc(50% - 4px);
height: calc(100% - 4px);
display: inline-block;
border: 2px solid black;
}
#column1 span {
display: block;
position: relative;
top: 50%;
transform: translateY(-50%);
padding: 10px;
}
#column2 {
position: relative;
top: -50%;
left: 50%;
width: calc(50% - 2px);
height: calc(50% - 4px);
display: inline-block;
border: 2px solid black;
border-left: none;
}
<div id="container">
<div id="column1">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus interdum bibendum laoreet. Suspendisse eu mauris urna. Vestibulum vel blandit erat. Suspendisse egestas semper urna in convallis. Aliquam lobortis, leo nec pharetra semper, elit risus aliquet metus, non malesuada massa turpis tincidunt lectus. Fusce pellentesque metus ac lectus ultricies, et fermentum tellus fringilla.</span>
</div>
<footer id="column2"></footer>
</div>
Here's a quick example of how you can achieve it with flex.
/* Std */
body {
margin: 0;
width: 100%;
height: 100%;
}
/* Flex Classes */
.flex {
display: flex;
}
.flex--row {
flex-direction: row;
}
/* Column Classes */
.column {
position: relative;
min-height: 100vh;
}
.left-column {
flex: 0.7;
background: red;
}
.right-column {
flex: 0.3;
background: blue;
}
/* Picture */
#column-picture {
width: 100%;
height: inherit;
position: absolute;
bottom: 0;
}
<div class="flex flex--row">
<div class="column left-column">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur lacinia auctor tincidunt. Sed a turpis et eros iaculis convallis quis in nisl. Donec fringilla auctor eros ut ultrices. Donec laoreet dui urna, ut pharetra neque molestie et. Ut sagittis diam a lacus euismod dignissim. Sed vulputate dui erat, at hendrerit ante commodo et. Sed gravida ex et est bibendum pretium. Aliquam a convallis dui. Maecenas magna velit, ultrices eu massa sit amet, dictum accumsan tellus. Maecenas eget placerat magna. Nullam mollis lacus tempor lorem tempor tincidunt. Aliquam erat volutpat.
</div>
<div class="column right-column">
<img id="column-picture" alt="Lion" src="https://cbs.umn.edu/sites/cbs.umn.edu/files/public/african_lion_king-wide.jpg"/>
</div>
</div>
Tell me what you think of this. #Mech
https://codepen.io/rickydam/pen/zdrmWX
HTML
<div class="left">
<div class="innerleft">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus interdum bibendum laoreet. Suspendisse eu mauris urna. Vestibulum vel blandit erat. Suspendisse egestas semper urna in convallis. Aliquam lobortis, leo nec pharetra semper, elit risus aliquet metus, non malesuada massa turpis tincidunt lectus. Fusce pellentesque metus ac lectus ultricies, et fermentum tellus fringilla. Phasellus vel quam a sem elementum volutpat vel eget neque. Nam efficitur maximus risus, ac eleifend augue tempor rutrum. Fusce vehicula non lorem vitae blandit. Donec in scelerisque sem, quis congue velit.
</p>
</div>
</div><!--
--><div class="right">
<img src="http://www.uniwallpaper.com/static/images/Sunset-Village-Wallpaper_8I7ogbf.jpg">
</div>
CSS
.left {
width: 50%;
height: 100vh;
background-color: lightgray;
display: inline-block;
vertical-align: middle;
margin: auto;
}
.innerleft {
background-color: lightblue;
height: 100vh;
display: flex;
align-items: center;
}
.left p {
margin: 20px;
padding: 10px;
background-color: gray;
}
.right {
width: 50%;
height: 100vh;
background-color: slategray;
display: inline-block;
vertical-align: top;
position: relative;
}
.right img {
position: absolute;
bottom: 0;
max-width: 100%;
}
want to give border on two div but full height is not looking good. i want to keep it 50%. how can i do that?
<div class="border-right">
<h4>>Web Design</h4>
<p>Morbi ac molestie justo. Donec sagittis scelerisque enim a tempus. Integer eget purus est. Phasellus consectetur sodales enim, eu dapibus metus mollis a. Phasellus luctus nulla in eros vestibulum mattis. Mauris pellentesque sem quis tortor vestibulum lacinia. Suspendisse hendrerit enim id pulvinar euismod. Etiam et neque vitae justo dignissim laoreet sit amet eget metus. Ut tristique porttitor lorem vitae auctor. </p>
</div>
<div class="border-left">
<h4>>Web Design</h4>
<p>Morbi ac molestie justo. Donec sagittis scelerisque enim a tempus. Integer eget purus est. Phasellus consectetur sodales enim, eu dapibus metus mollis a. Phasellus luctus nulla in eros vestibulum mattis. Mauris pellentesque sem quis tortor vestibulum lacinia. Suspendisse hendrerit enim id pulvinar euismod. Etiam et neque vitae justo dignissim laoreet sit amet eget metus. Ut tristique porttitor lorem vitae auctor. </p>
</div>
Border can't be set to 50% of element total height. But you can use ::after & ::before to draw some lines on sides
body{
background-color: #f3f3f3;
}
div{
height: 300px;
margin: 10px auto;
width: 300px;
background: #fff;
position: relative;
}
div::before{
content: "";
height: 50%;
display: block;
border-left: 1px solid #333;
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
}
div::after{
content: "";
height: 50%;
display: block;
border-left: 1px solid #333;
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
}
.all-border{
border: 1px solid #000;
}
.all-border::before,
.all-border::after{
display: none;
}
<div>50% Height Border</div>
<div class="all-border">100% Height Border</div>
Add some css. Change <div class="border-right"> to <div class="border-right" style="max-height:50%;">.Comment if this is not what you are looking for.
I want to create HTML layout like this
https://dribbble.com/shots/2136656-Minions-Promo/attachments/393961
I tried to use some css codes to make elements non rectangular, but no luck so far :).
I saw this post:
How can i Create This Non-Rectangular Layouts?
But couldn't find answers there :)
Anyone have an idea how to build this thing?
Thanks
You can use :pseudo element to add a background and use skew property
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.red {
padding: 15px;
position: relative;
color: white;
margin-bottom: 50px;
}
.red:after {
content: '';
position: absolute;
bottom: 0;
top: 0;
right: 0;
left: 0;
background: tomato;
z-index: -1;
transform: skew(0deg, 2deg);
}
.blue {
position: relative;
padding: 15px;
}
.blue:after {
content: '';
position: absolute;
bottom: 0;
top: 0;
right: 0;
left: 0;
background: cornflowerblue;
z-index: -1;
transform: skew(0deg, -2deg);
}
<div class="red">
<h1>Sed augue ipsum egestas</h1>
<p>Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Vivamus aliquet elit ac nisl. Donec id justo. Praesent turpis.</p>
<p>Integer tincidunt. Fusce convallis metus id felis luctus adipiscing. Sed augue ipsum, egestas nec, vestibulum et, malesuada adipiscing, dui. Vestibulum volutpat pretium libero.</p>
<p>Pellentesque posuere. Nam pretium turpis et arcu. Etiam imperdiet imperdiet orci. Quisque id mi.</p>
</div>
<div class="blue">
<h1>Sed augue ipsum egestas</h1>
<p>Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Vivamus aliquet elit ac nisl. Donec id justo. Praesent turpis.</p>
<p>Integer tincidunt. Fusce convallis metus id felis luctus adipiscing. Sed augue ipsum, egestas nec, vestibulum et, malesuada adipiscing, dui. Vestibulum volutpat pretium libero.</p>
<p>Pellentesque posuere. Nam pretium turpis et arcu. Etiam imperdiet imperdiet orci. Quisque id mi.</p>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.yellow {
margin: 80px 0;
padding: 15px;
background: yellow;
position: relative;
}
.yellow:before,
.yellow:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
left: 0;
background: yellow;
z-index: -1;
}
.yellow:before {
top: -40px;
transform: skew(0, 3deg);
}
.yellow:after {
bottom: -40px;
transform: skew(0, -3deg);
}
<div class="yellow">Fusce fermentum odio nec arcu. Nullam accumsan lorem in dui. Nullam accumsan lorem in dui. Cras varius. Morbi mollis tellus ac sapien. Cras dapibus. Fusce pharetra convallis urna. Fusce a quam. Maecenas ullamcorper, dui et placerat feugiat, eros pede
varius nisi, condimentum viverra felis nunc et lorem. Phasellus consectetuer vestibulum elit. Aliquam lobortis. Cras ultricies mi eu turpis hendrerit fringilla.</div>
I'd like to achieve something similar to the picture below (2 icons, mail and phone outside my Article DIV (in white on the image), aligned to the top of the DIV and under each other (with 1 or 2 pixels space). I tried to set a class with a negative margin for the images but without success. What would be the best way to achieve this?
Many thanks
.article {
clear: right;
float: right;
text-align:justify;
width: 450px;
min-height:420px;
height: 60%;
padding: 50px 32px 49px 62px;
margin-right:75px;
position: relative;
z-index: 15;
margin-top: 90px;
background: #fff;
/* max-width: 25%; */
overflow-y: scroll!important;
}
I would use position: relative on the article and position: absolute positioning on the icon set (I used a ul for simplicity):
JSFiddle: http://jsfiddle.net/szLsH/
HTML code:
<article>
<div id="icons">
<ul>
<li></li>
<li></li>
</ul>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ac libero velit. Proin euismod erat non diam malesuada ac semper purus dapibus. Donec id suscipit metus. Ut eu auctor mauris. Proin sed felis dui. Maecenas congue dapibus dolor, sodales feugiat nisi feugiat ac. Nulla nec massa in mi pharetra sollicitudin. Aliquam eu dui quis odio porttitor viverra ut cursus dui. Nullam quis tristique magna. Aliquam erat volutpat. Suspendisse potenti. Pellentesque rhoncus commodo odio vitae tincidunt. Praesent rutrum, nibh vitae porta luctus, felis quam dignissim risus, non tempus lectus magna non odio. Donec commodo laoreet dolor ut volutpat. Ut lobortis lobortis augue, in placerat arcu dapibus et. Maecenas vitae lectus quis enim suscipit euismod.
</p>
</article>
CSS:
article {
width: 200px;
margin: 0 auto;
position: relative;
padding: 10px;
border: 1px solid #AAA;
}
#icons {
position: absolute;
right: 100%;
top: 0;
}
#icons ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#icons li {
width: 50px;
height: 50px;
background: blue;
margin: 0 5px 5px;
}