This question already has answers here:
Fixed position but relative to container
(31 answers)
Closed 4 years ago.
I need this button fixed at the bottom of the parent div and floating over its scrolling content.
I'm really surprised this doesn't work. I expected position: relative on the parent in combination with bottom: 0 on the fixed element to achieve this..
PS: the button must be inside the div.
div {
position: relative;
width: 200px;
height: 100px;
overflow-y: scroll;
background-color: lightblue;
}
button {
position: fixed;
bottom: 0;
}
body {
height: 200px;
}
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque, assumenda. Sint optio, praesentium omnis voluptas facilis nam asperiores quod itaque repellat eaque aut molestias reiciendis quibusdam harum rem, cumque nihil!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus, ab! Tempore sunt eligendi, voluptates quaerat autem reprehenderit perferendis id hic voluptate modi nisi in eaque quasi veniam delectus, voluptatibus quo.</p>
<button>Bütton</button>
</div>
div {
position: relative;
width: 200px;
height: 100px;
overflow-y: scroll;
background-color: lightblue;
}
button {
position: sticky;
bottom: 0;
}
body {
height: 200px;
}
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque, assumenda. Sint optio, praesentium omnis voluptas facilis nam asperiores quod itaque repellat eaque aut molestias reiciendis quibusdam harum rem, cumque nihil!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus, ab! Tempore sunt eligendi, voluptates quaerat autem reprehenderit perferendis id hic voluptate modi nisi in eaque quasi veniam delectus, voluptatibus quo.</p>
<button>Bütton</button>
</div>
You code is almost working.You need to do only one change.
Add position: sticky; for div element.
Try this and let me know the update ?
Related
I have a parent that has it's overflow-y property set to auto.
#parent {
position: relative;
overflow-x: hidden;
overflow-y: auto;
}
Then I have a child element that is larger than the window, it's overflowing with the parent, but the child element's styling isn't overflowing.
How do I make the child's styling overflow with itself?
You want something like that?
#parent {
position: relative;
overflow-x: hidden;
overflow-y: auto;
}
#child{
width: 100%;
overflow-x: scroll;
}
#child div {
width: 120%;
}
<div id="parent">
<div id="child">
<div>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolor, qui sapiente, architecto minima voluptatibus illo pariatur necessitatibus doloremque, officia odio nesciunt quod beatae molestias autem aliquam mollitia tenetur! Nisi, soluta!
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptas illum iure perspiciatis sint laudantium laborum vero ipsum, mollitia possimus consequuntur odio ullam veniam laboriosam culpa voluptatem neque, suscipit rem! Laboriosam.
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Consectetur placeat architecto dolores expedita quod ad? Praesentium quibusdam commodi cumque natus quos quam eius animi et reprehenderit tempora, ea, voluptas repellendus.
</div>
</div>
</div>
I'm trying to show the sidebar below the header initially, which works fine when the user lands on the website, but when a user scrolls the page, the sidebar not taking the full height, basically I want to achieve sidebar to be fixed at the left once user scrolls just like shown here.
Here is my code snippet
html,
body {
height: 100%;
}
.header {
border: 1px solid black;
height: 60px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.body {
height: 100%;
background-color: tomato;
display: flex;
padding-bottom: 2000px;
}
.sidebar {
width: 30%;
position: -webkit-sticky;
position: sticky;
height: 100%;
background: black;
color: white;
/* top: 0px; */
}
.content {
padding: 80px;
}
<div class="header">HEADER</div>
<div class="body">
<div class="sidebar">SIDEBAR</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio saepe tempora, voluptas quidem provident atque iste officiis repudiandae expedita, impedit error maxime laboriosam sit qui porro, quo eligendi inventore fugit.Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Quam non, omnis saepe error nesciunt magnam velit architecto! Pariatur possimus culpa dolor soluta laudantium at neque, consequuntur, mollitia sunt, necessitatibus vitae!Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Nesciunt laboriosam, facere laborum totam in qui ex illum necessitatibus, minus numquam enim! Distinctio facilis est reprehenderit sunt quasi consequuntur ullam autem.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorum ut doloremque
cupiditate facilis aliquid, voluptatibus at illo similique velit sequi dignissimos consectetur placeat, vero excepturi neque facere tempore id ratione.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem dignissimos veritatis libero praesentium
reprehenderit sequi. A, repellendus, hic. Laborum, et ea voluptas facere! Enim id soluta optio, quam totam officiis!</div>
</div>
I removed height:100% on body and html and also .height, because there is no goal of that as they are adapting their height based on content.
Then I fixed the sidebar height to 100vh.
Now it is fixed. It only leaves at the end because you added a padding-bottom: 2000px; in your .body container.
html,
body {
/*height: 100%;*/
}
.header {
border: 1px solid black;
height: 60px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.body {
/*height: 100%;*/
background-color: tomato;
display: flex;
padding-bottom: 2000px;
}
.sidebar {
width: 30%;
position: -webkit-sticky;
position: sticky;
height: 100vh;
background: black;
color: white;
top: 0;
}
.content {
padding: 80px;
}
<div class="header">HEADER</div>
<div class="body">
<div class="sidebar">SIDEBAR</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio saepe tempora, voluptas quidem provident atque iste officiis repudiandae expedita, impedit error maxime laboriosam sit qui porro, quo eligendi inventore fugit.Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Quam non, omnis saepe error nesciunt magnam velit architecto! Pariatur possimus culpa dolor soluta laudantium at neque, consequuntur, mollitia sunt, necessitatibus vitae!Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Nesciunt laboriosam, facere laborum totam in qui ex illum necessitatibus, minus numquam enim! Distinctio facilis est reprehenderit sunt quasi consequuntur ullam autem.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorum ut doloremque
cupiditate facilis aliquid, voluptatibus at illo similique velit sequi dignissimos consectetur placeat, vero excepturi neque facere tempore id ratione.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem dignissimos veritatis libero praesentium
reprehenderit sequi. A, repellendus, hic. Laborum, et ea voluptas facere! Enim id soluta optio, quam totam officiis!</div>
</div>
This question already has answers here:
Floating an image to the bottom right with text wrapping around
(11 answers)
Closed 4 years ago.
Well, im pretty new to grids and a little more experienced with tables. But im still not sure which is the best way to do it.
Here, this is what i want to do:
Text all together in 3/4 parts of the area, and 1/4 with an image on the bottom right side. Considering that this is done inside a jquery mobile app/page (I guess that has nothing to do with this but i just had to mention it)
How would you guys do it?
Using a Grid System makes no sense for your example. A grid system needs columns and rows. In your case you would have only 1 row and 1 column. Well, you could nest that grid but it would be complicated quickly.
But this is one way how you could do it without grid and without a table:
.wrapper {
max-width: 800px;
height: 700px;
}
.spacer {
height: calc(100% - 200px);
width: 0px;
float: right;
}
.item-1 {
width: 330px;
}
img {
height: 200px;
width: 150px;
float: right;
clear: right;
}
<div class="wrapper">
<div class="spacer"></div>
<div class="item-1">
<img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/flip.jpg" alt="image">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam, iure nulla veniam ab ratione, dicta eaque voluptas voluptatem porro nemo fuga quas aut at laborum. Error architecto illum, est quaerat.Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Numquam, iure nulla veniam ab ratione, dicta eaque voluptas voluptatem porro nemo fuga quas aut at laborum. Error architecto illum, est quaerat.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam, iure nulla veniam ab ratione,
dicta eaque voluptas voluptatem porro nemo fuga quas aut at laborum. Error architecto illum, est quaerat.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam, iure nulla veniam ab ratione, dicta eaque voluptas voluptatem porro nemo
fuga quas aut at laborum. Error architecto illum, est quaerat.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam, iure nulla veniam ab ratione, dicta eaque voluptas voluptatem porro nemo fuga quas aut at laborum. Error architecto
illum, est quaerat.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam, iure nulla veniam ab ratione, dicta eaque voluptas voluptatem porro nemo fuga quas aut at laborum. Error architecto illum, est quaerat.Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Numquam, iure nulla veniam ab ratione, dicta eaque voluptas voluptatem porro nemo fuga quas aut at laborum. Error architecto illum, est quaerat.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam, iure
nulla veniam ab ratione, dicta eaque voluptas voluptatem </p>
</div>
</div>
with or without grid system you can achieve the desired results. I'ts more a CSS related matter as you can see in this example.
.wrapper {
column-count: 2;
column-gap: 50px;
padding: 50px;
}
p {
line-height: 1.6;
font-family: Helvetica;
text-align: justify;
margin: 0;
font-size: 14px;
}
.star {
float: left;
width: 250px;
shape-outside: url(https://upload.wikimedia.org/wikipedia/commons/3/34/Red_star.svg);
shape-margin:20px;
margin-right: 20px;
margin-bottom: 20px;
}
.moon {
border-radius: 50%;
height: 200px;
width:200px;
background-color: #2badd9;
float: right;
shape-outside: inset(1% round 50%);
margin-left: 20px;
margin-bottom: 10px;
}
Codepen code
hope it helps!
I am overlaying some title text on an image, currently using relative/absolute position for one of the elements (doesn't matter which). What I am struggling with is getting the parent div to fully display the content of both, irrespective of which is taller.
Example markup:
.parent {
position: relative;
overflow: hidden;
width: 100px; /* This is only here to force the title text in this example to expand beyond the image height for illustrative purposes. */
}
.background {
width: 100%;
}
.title-text {
position: absolute;
top: 0;
font-size: 32px;
color: blue;
}
<div class="parent">
<img class="background" src="http://www.placebacon.net/200/200">
<div class="title-text">
My Title (which might be quite long)
</div>
<div>
(Assuming I can acheive what I am looking for, the overflow: hidden above would obviously become redundant, but presently without it, the taller element overlaps whatever is below the parent div.)
JSBin here: http://jsbin.com/yixiniwere/edit?html,css,output
How do I get both elements to be fully visible? I can change the mark-up or introduce additional container elements if necessary.
You can overlay elements without using positioning under CSS-Grid. You just assign them the same place in the grid.
.parent {
/* IE10/11 support */
display: -ms-grid;
-ms-grid-columns: 1fr;
-ms-grid-rows: 1fr;
margin: 1em auto;
display: grid;
width: 400px;
/* for demo purposes */
grid-template-columns: 1fr;
grid-template-rows: auto;
background: pink;
}
.parent * {
/* IE10/11 support */
-ms-grid-column: 1;
-ms-grid-row: 1;
grid-column: 1/2;
grid-row: 1;
color: red;
}
<div class="parent">
<img class="background" src="http://www.placebacon.net/400/200">
<div class="title-text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Rerum perspiciatis commodi, adipisci reiciendis quo suscipit! Ratione laborum magnam cumque tempora ab cupiditate delectus, perferendis enim porro impedit nihil architecto, ad consequatur exercitationem
fugiat error debitis molestias itaque, eligendi necessitatibus quae dolore beatae nemo doloremque. Quos voluptate tenetur explicabo beatae nesciunt! Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo est perspiciatis possimus iusto! Voluptatem
facilis blanditiis aspernatur facere animi placeat. Quisquam fuga laudantium cupiditate eos exercitationem neque eius, distinctio consectetur?Lorem ipsum dolor sit amet consectetur adipisicing elit. Officiis aperiam, ipsum tempora reiciendis, id ea
eveniet placeat necessitatibus deserunt mollitia dignissimos exercitationem aliquam porro quaerat, labore ducimus rerum animi praesentium?Lorem ipsum dolor sit, amet consectetur adipisicing elit. Placeat, laboriosam.
<div>
Another option could be to get rid of relative and absolute positioning and only set the 'margin-top' property of the text to the negative value of the background. Example (if the icon has fixed height of 100px you can just set margin top of title-text to -100px):
.parent {
width: 150px;
}
.background {
width: 100%;
}
.title-text {
margin-top:-100px;
width:100%;
font-size: 20px;
}
if the height of the background in not fixed you should be able to get it via javascript and set it there.
js bin example
The non css grid/flexboxy way
.parent {
position: relative;
width: 300px;
margin: 0 auto;
background: #a03;
}
img {
position: absolute;
top: 0;
left: 0;
max-width: 100%;
height: auto;
z-index: 1;
}
.title-text {
position: absolute;
z-index: 10;
}
<div class="parent">
<img class="background" src="https://images.unsplash.com/photo-1472837525377-e96df4f8f34e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=b29757bb040fca6a9b0d79cbd31f1119">
<div class="title-text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Rerum perspiciatis commodi, adipisci reiciendis quo suscipit! Ratione laborum magnam cumque tempora ab cupiditate delectus, perferendis enim porro impedit nihil architecto, ad consequatur exercitationem fugiat error debitis molestias itaque, eligendi necessitatibus quae dolore beatae nemo doloremque. Quos voluptate tenetur explicabo beatae nesciunt! Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo est perspiciatis possimus iusto! Voluptatem facilis blanditiis aspernatur facere animi placeat. Quisquam fuga laudantium cupiditate eos exercitationem neque eius, distinctio consectetur?Lorem ipsum dolor sit amet consectetur adipisicing elit. Officiis aperiam, ipsum tempora reiciendis, id ea eveniet placeat necessitatibus deserunt mollitia dignissimos exercitationem aliquam porro quaerat, labore ducimus rerum animi praesentium?Lorem ipsum dolor sit, amet consectetur adipisicing elit. Placeat, laboriosam.
<div>
</div>
I have this HTML:
<div id="main">
<div class="dummy">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis enim molestias illo id voluptas tempora minima sunt fugiat voluptatibus voluptatem dolores omnis iste. Fuga facilis adipisci similique explicabo sunt alias! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam omnis esse saepe eveniet modi harum quae laborum eaque vero nesciunt consequuntur placeat nisi velit commodi minima itaque voluptatem necessitatibus quasi.</div>
<div id="inner">I want this div to slide left on some action</div>
<div class="dummy">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reiciendis enim molestias illo id voluptas tempora minima sunt fugiat voluptatibus voluptatem dolores omnis iste. Fuga facilis adipisci similique explicabo sunt alias! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam omnis esse saepe eveniet modi harum quae laborum eaque vero nesciunt consequuntur placeat nisi velit commodi minima itaque voluptatem necessitatibus quasi.</div>
</div>
Please refer to this fiddle to view the full code with associated CSS.
I want the black inner div container to be visible even outside the main div container, but also want to give overflow:auto to the main div so that if content in the red div increases, a scroll bar should come. These things are not working together.
Please suggest how to achieve this.
Did you mean something like this?
I added the following:
HTML:
<div id="preventOverflow">
CSS:
#preventOverflow
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
}
It is not possible to merge two scroll bars of seperate blocks with a div in between them. I would recommend changing the layout.
do you mean this...
#inner {
background: none repeat scroll 0 0 #000000;
color: #FFFFFF;
left: 59px;
position: inherit;
top: 5px;
width: 80px;
}
http://jsfiddle.net/kisspa/xRasu/