Stack 3 divs while bottom div height is adjusted automatically - html

I've got 3 divs.
<div class="top"> TOP </div>
<div class="middle"> MIDDLE </div>
<div class="bottom"> BOTTOM </div>
.top{
position: fixed;
top:0;
width: 100%;
}
.bottom{
position: fixed;
bottom:0;
width: 100%;
}
middle div contains a dynamic data. So I have enabled the scrollbar there.
.middle{
overflow-y: auto;
width: 100%;
}
My question is, How can I stack the middle div and make thebottom adjusts its height automatically depending on the data in top and middle divs?
EDIT

the flex model is here to help you:
html, body {
height:100%;
margin:auto;
}
body {
display:flex;
flex-flow:column;
background:turquoise;
}
.middle {
flex:1;
overflow:auto;
background:tomato;
}
<div class="top"> TOP any height</div>
<div class="middle"> MIDDLE i scroll if too tall </div>
<div class="bottom"> BOTTOM any height</div>
demo http://jsfiddle.net/7yLFL/445/

Flex model with no restrictions on any section height:
html,
body {
height: 100%;
}
body {
font-family: sans-serif;
font-size: 22px;
line-height: 1.5em;
text-align: center;
color: #fff;
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.wrapper {
height: 100%;
display: flex;
flex-direction: column;
width: 50%;
border: 1px solid #fff;
float: left;
}
.top {
background: none #59B2FF;
}
.middle {
flex-grow: 100;
overflow-y: auto;
background: none #FFB800;
}
.bottom {
align-self: flex-end;
width: 100%;
background: none #A1FFB5;
color: #fff;
}
<div class="wrapper wrapper1">
<div class="top">top</div>
<div class="middle">middle</div>
<div class="bottom">bottom</div>
</div>
<div class="wrapper wrapper2">
<div class="top">top</div>
<div class="middle">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.?</div>
<div class="bottom">bottom</div>
</div>
Also on Fiddle playground.

I would create an .outer div that is basically a container for .top, .middle, .bottom. You would also create a css class called .inner that has position absolute:
#CSS
.outer {
#Can position however you want
}
.inner {
position: relative;
}
.top {
top: 0;
width: 100%;
}
.middle {
overflow-y: auto;
max-height: 100px; //Optional; if you want to specify the maximum height this div can take
width: 100%;
}
.bottom {
width: 100%;
bottom: 0
}
Then in your HTML:
<div class="outer">
<div class="inner top"> TOP </div>
<div class="inner middle"> MIDDLE </div>
<div class="inner bottom"> BOTTOM </div>
</div>
Here is a plunker DEMO

Just put:
.middle{
position: relative;
height: auto;
}
Since, you have put position fixed for top container, so it won't move out of screen and will be stuck at the top while the other two divs will be scrollable under the top div.

Related

How to make square image container with css grid

I want to make a modal with a image and other elements to the right, something like this:
I tried making the modal content as a grid with two columns, the problems is when I try to adjust the image to fill all the avaiable space in the modal content, it overflows like this:
My css code looks like this:
<div class="modal">
<div class="content">
<div class="frame">
<img src="https://picsum.photos/400" alt="Example">
</div>
<div class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis est mollitia possimus omnis nisi quo
aliquid ad accusantium dignissimos corrupti. Impedit, asperiores magnam corporis iste possimus tempore
quisquam provident dicta. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quibusdam
consequuntur, incidunt hic dolorum tempora inventore id sint ullam magnam veniam eveniet vitae, harum
dolorem tenetur libero voluptate voluptatibus. Inventore, excepturi!
</div>
</div>
</div>
.modal {
position: fixed;
height: 100%;
width: 100%;
background-color: rgba($color: #000000, $alpha: 0.6);
display: grid;
place-items: center;
}
.content {
background-color: $color-white;
width: 60%;
height: 600px;
border-radius: 5px;
display: grid;
grid-template-columns: auto 300px;
}
.frame > img {
width: 100%;
max-height: 100%;
object-fit: cover;
}
.text {
padding: 2rem 1rem;
}
The modal I tried to do has the problem of the image overflow. I setted the container div to grid with two columns, but the image column overflows the container as we can see in the picture. I want the image to take the space avaiable in the container but maintaining the 1 : 1 aspect ratio, also to be responsive, when the user change the screen size the image always has to maintain the 1:1 aspect ratio and not crop the image.I setted the height as static pixels because I want to add a element with a scrolling bar that otherwise will overflow or expand the container if its height was declared as percentages.
Just specify a max-height to the container(.frame) it will start working fine for 1:1 images because max-height:100% doesn't mean anything if you don't specify a height for its parent
and if you want to work for any ratio then remove the width property from the .frame > img because if you don't specify a width it will adjust itself according to it's height
I think the easiest way would be to use css aspect-ratio like this:
img {
width: 100%;
aspect-ratio: 1;
}
you can read more about it here
I think the problem might be the fact that your image's parent ( .frame ) does not have a set height.Try adding this:
.frame {
height:100%
}
I solved it removing the height of the modal content div. This allow the image to take all the space it needs. For the text to the right to not overgrow the image, what i did was make a div container and inside it a p tag with position absolute and with the widht and height of his parent, but with overflow: scroll. This allowed me to have mi image in 1:1 ratio taking all the space it needs in the card but without the text overflowing things. Here is how I did it.
.modal {
position: fixed;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
display: grid;
place-items: center;
}
.container {
width: 60%;
display: grid;
grid-template-columns: 1fr 30%;
background-color: #f4f4ed;
}
.frame {
width: 100%;
height: 100%;
}
.frame img {
width: 100%;
height: 100%;
object-fit: cover;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
padding: 2em 0.8em;
}
.content h5 {
font-size: 1.4rem;
font-weight: 600;
color: #00f0b5;
}
.text {
flex-grow: 1;
position: relative;
height: 100%;
width: 100%;
overflow-y: scroll;
}
.text p {
font-size: 0.8rem;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.actions {
width: 100%;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.5rem;
}
.actions button {
font-family: "Roboto Condensed", sans-serif;
font-weight: 600;
text-transform: uppercase;
border: none;
outline: none;
background-color: #00f0b5;
padding: 0.2em 0;
cursor: pointer;
font-size: 0.5rem;
}
body {
font-size: 62.5%;
box-sizing: border-box;
}
h5{
margin: 0;
line-height: 1;
}
<div class="modal">
<div class="container">
<div class="frame">
<img src="https://picsum.photos/800" alt="Some lorem picsum">
</div>
<div class="content">
<h5>Title</h5>
<div class="text">
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Laborum placeat sed voluptatem optio esse facere accusamus tempore, provident dolorem nemo rerum sit accusantium labore quae eveniet ea aliquam. Ipsa, aliquam? Lorem ipsum dolor sit amet consectetur,
adipisicing elit. Laborum placeat sed voluptatem optio esse facere accusamus tempore, provident dolorem nemo rerum sit accusantium labore quae eveniet ea aliquam. Ipsa, aliquam? Lorem ipsum dolor sit amet consectetur, adipisicing elit. Laborum
placeat sed voluptatem optio esse facere accusamus tempore, provident dolorem nemo rerum sit accusantium labore quae eveniet ea aliquam. Ipsa, aliquam?
</p>
</div>
<div class="actions">
<button>Accept</button>
<button>Cancel</button>
</div>
</div>
</div>
</div>

How to remove space between div elements? [duplicate]

This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
Closed 2 years ago.
I have two div elements and I want to remove the space between them, which is filled with the background color at the moment. This is what it looks like. I want to remove the space between the green section and where the background image ends for the first div element. Here is the HTML for the page:
<body style="background-color: #c5ffff">
<div class="main-search hero-image">
Log Out
<div class="welcome-text">
<div class="title">Welcome to Ripple.</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aliquam commodi doloremque esse itaque iusto, labore laborum maxime odio, quidem quos, repellat rerum? Ab, asperiores aspernatur assumenda atque distinctio dolor dolore eveniet facilis, id illo ipsa ipsam minus nemo nobis porro quam quia quibusdam quis ratione rerum soluta suscipit temporibus vel vitae voluptate. Accusamus dignissimos ea esse expedita itaque mollitia nobis, numquam odio, quaerat qui vel voluptatibus?</div>
<button class="search_button" >Search for a location</button>
<button class="search_button">Search for a song</button>
</div>
</div>
<div class="main-left">
<div class="title">Collections Near Me</div>
<div>
</div>
</body>
And the CSS:
.main-left {
vertical-align: top;
margin-top: 0;
margin-left: 0;
position: relative;
background-color: #85dcba;
text-align: left;
width: 100%;
float: top;
left: 50%;
transform: translate(-50%);
}
.main-search {
vertical-align: top;
background-color: #d2fdff;
text-align: left;
margin: 0;
padding-top: 2em;
position: relative;
top: 0;
width: 100%;
left: 50%;
transform: translate(-50%);
}
.hero-image {
background-image: url("main_background.jpg");
background-size: cover;
background-repeat: no-repeat;
}
.title {
color: black;
font-family: Roboto, sans-serif;
font-size: 3em;
margin-top: 0.5em;
margin-left: 10px;
margin-bottom: 0.5em;
}
.content {
color: black;
font-family: Roboto, sans-serif;
font-size: 1em;
margin: 1em;
}
.welcome-text {
top: 5%;
left: 5%;
max-width: 35%;
}
There is a gap because div is block element, if you want to remove the gap between div use display: inline-block to remove it.
body > div { display: inline-block; }
This will display an element as an inline-level block container. Please refer to CSS Display
You could try setting the margin values of the elements manually. I see you've set the padding- Which refers to the internal distance of contents to edge, but not the margin- which refers to the distance between seperate elements.
Also, nice looking design so far!
Display flex has a nifty way of removing undesirable whitespace from the html
So place flex on the wrapper of these elements, in this case the body tag
css
body {
display: flex;
flex-direction: column;
}
Set margin-top of the .title to zero and for space between the .main-search and .title, give padding-bottom to .main-search as well. Below is how it will look like:
body{
background-color: #c5ffff;
}
.main-left{
vertical-align: top;
margin-top: 0;
margin-left: 0;
position: relative;
background-color: #85dcba;
text-align: left;
width: 100%;
float: top;
left: 50%;
transform: translate(-50%);
}
.main-search{
vertical-align: top;
background-color: #d2fdff;
text-align: left;
margin: 0;
padding: 2em 0;
position: relative;
top: 0;
width: 100%;
left: 50%;
transform: translate(-50%);
}
.hero-image{
background-image: url("https://picsum.photos/500/500");
background-size: cover;
background-repeat: no-repeat;
}
.title{
color: black;
font-family: Roboto, sans-serif;
font-size: 3em;
margin-top: 0;
margin-left: 10px;
margin-bottom: 0.5em;
}
.content{
color: black;
font-family: Roboto, sans-serif;
font-size: 1em;
margin: 1em;
}
.welcome-text{
top: 5%;
left: 5%;
max-width: 35%;
}
<div class="main-search hero-image">
Log Out
<div class="welcome-text">
<div class="title">Welcome to Ripple.</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aliquam commodi doloremque esse itaque iusto, labore laborum maxime odio, quidem quos, repellat rerum? Ab, asperiores aspernatur assumenda atque distinctio dolor dolore eveniet facilis, id illo ipsa ipsam minus nemo nobis porro quam quia quibusdam quis ratione rerum soluta suscipit temporibus vel vitae voluptate. Accusamus dignissimos ea esse expedita itaque mollitia nobis, numquam odio, quaerat qui vel voluptatibus?</div>
<button class="search_button" >Search for a location</button>
<button class="search_button">Search for a song</button>
</div>
</div>
<div class="main-left">
<div class="title">Collections Near Me</div>
<div>
remove margin-top:0.5em; on your title class.
.title {
color: black;
font-family: Roboto, sans-serif;
font-size: 3em;
margin-top: 0.5em; <-- REMOVE
margin-left: 10px;
margin-bottom: 0.5em;

What is wrong with the layout of div's?

I'm fairly new to html and css and I have a trouble with understanding of the layout. Here is an example which I have created to show my problem.
What I would expect is for #bottom to be inside the #page but it is below it. Additionally the div #else which I would thought should be below the #page is in the same space as the #bottom.
Could you please help me understand what I'm doing wrong here?
header {
display: block;
margin: 0px auto;
height: 20vh;
width: 80vw;
border: 1px solid green;
}
#page {
margin: 0 auto;
width: 90vw;
border: 3px solid black;
}
#main {
display: block;
float: left;
height: 60vh;
width: 67.5vw;
border: 1px solid green;
}
#side {
display: inline-block;
margin-left: 2px;
height: 60vh;
width: 21.5vw;
border: 1px solid green;
}
#bottom {
float: left;
margin: 0 auto;
height: 4vh;
width: 90vw;
border: 1px solid green;
}
#else {
height: 10vh;
width: 90vw;
background-color: red;
margin: 0 auto;
}
<div id="page">
<header>
</header>
<div id="main">
</div>
<div id="side">
</div>
<div id="bottom">
</div>
</div>
<div id="else">
</div>
I don't get why did you put this float:left in your footer.If you remove it everything should work fine
#bottom {
margin: 0 auto;
height: 4vh;
width: 90vw;
border: 1px solid green;
}
Remove float left from #bottom
#bottom {
background-color:green;
margin: 0 auto;
height:50px;
width:100px;
border: 1px solid green;
}
here is the link: https://codepen.io/Dholu_Effect/pen/PoqByQa?editors=1100
Also I would sugges you to use Flex-box, it will make things much easier.
<body>
<div id="page">
<header>Header</header>
<div id="main">Main</div>
<div id="side">Side</div>
<div id="bottom">Bottom</div>
</div>
<div id="else">Else</div>
</body>
And the css
header {
display: block;
margin: 0px auto;
height: 20vh;
width: 80vw;
border: 1px solid green;
}
#page {
margin: 0 auto;
width: 90vw;
border: 3px solid black;
}
#main {
display: block;
float: left;
height: 60vh;
width: 67.5vw;
border: 1px solid green;
}
#side {
display: inline-block;
margin-left: 2px;
height: 60vh;
width: 21.5vw;
border: 1px solid green;
}
#bottom {
margin: 0 auto;
height: 4vh;
width: 90vw;
border: 1px solid green;
background-color:#ddd;
}
#else {
height: 10vh;
width: 90vw;
background-color: red;
margin: 0 auto;
}
https://codepen.io/erwinagpasa/pen/ZEGjqjY
I think you can see this
header {
display: block;
margin: 0px auto;
height: 20vh;
width: 90vw;
background-color: #011a2f
}
#page {
margin: 0 auto;
width: 90vw;
}
#main {
float: left;
height: 60vh;
width: 67.5vw;
background-color: #323232
}
#side {
overflow: hidden;
margin-left: 2px;
height: 60vh;
width: 22.5vw;
background-color: #ff1e56;
}
#bottom {
height: 5vh;
width: 90vw;
background-color: #000000;
}
#else {
height: 10vh;
width: 90vw;
background-color: #ffac41;
margin: 0 auto;
}
<div id="page">
<header></header>
<div id="main"></div>
<div id="side"></div>
<div id="bottom"></div>
</div>
<div id="else"></div>
This is the closest i can do for you to understand it in your beginner level
*{
box-sizing:border-box; /* this will let the border/padding be included in the elements size */
}
#page {
margin: 0 auto;
width: 90%;
border: 3px solid black;
}
header {
display: inline-block;
margin: 0 10%;
height: 20vh;
width: 80%;/* changed to percentage which is more logic to follow its parent not the viewport width */
border: 1px solid green;
}
#main {
display: inline-block;
height: 60vh;
width: 67.5%;
border: 1px solid green;
margin:0;
margin-left:5%;
}
#side {
display: inline-block;
margin-left: 2px;
height: 60vh;
width: calc(22.5% - 6px);/* 2 for the margin left, 4 for the borders*/
border: 1px solid green;
}
#bottom {
/*float: left;*/
margin: 0 auto;
height: 4vh;
width: 90%; /* percentage */
border: 1px solid green;
}
#else {
height: 10vh;
width: 90%;
background-color: red;
margin: 0 auto;
}
<div id="page">
<header>
</header>
<div id="main">
</div>
<div id="side">
</div>
<div id="bottom">
</div>
</div>
<div id="else">
</div>
I just made few adjustments in your code, I hope that is fine with you:
Note: View in full screen mode for more clarity.
#page {
margin: 0 auto;
width: 90vw;
border: 1px solid black;
}
header {
display: absolute;
margin: 0px auto;
height: 20vh;
width: 80vw;
border: 1px solid green;
}
#main {
float: left;
height: 60vh;
width: 67.5vw;
border: 1px solid green;
}
#side {
display: inline-block;
margin-left: 2px;
height: 60vh;
width: 21.5vw;
border: 1px solid green;
}
#bottom {
height: 4vh;
width: 90vw;
border: 1px solid green;
background-color:green;
}
#else {
height: 10vh;
width: 90vw;
background-color: pink;
margin: 0 auto;
}
<div id="page">
<header>header
</header>
<div id="main">main
</div>
<div id="side">side
</div>
<div id="bottom">bottom
</div>
</div>
<div id="else">else
</div>
My recommendation is that you use flexbox. Here is a quick responsive design I did with HTML5 selectors. Since you're new to HTML/CSS, I would suggest you start learning this way and avoid so many div classes, as that doesn't work that great with accessibility, which is a huge issue in today's development world.
And here is a codepen you can play with.
/* Roboto Font */
#import url('https://fonts.googleapis.com/css?family=Roboto:100,100i,300,300i,400,400i,500,500i,700,700i,900,900i&display=swap');
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
height: 100vh; /* Avoid the IE 10-11 `min-height` bug. */
font-family: 'Roboto', sans-serif;
}
.content {
flex: 1 0 auto; /* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */
background: darkgray;
}
header {
height: 20vh;
display: flex;
justify-content: center;
align-items: center;
background: #ccc;
}
header h1 {
font-size: 4rem;
font-weight: 300;
}
main {
display: flex;
}
article {
width: 70%;
justify-content: flex-start;
padding: 0.5rem;
}
aside {
width: 30%;
justify-content: flex-end;
padding: 0.5rem;
}
.footer {
flex-shrink: 0; /* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */
padding: 20px;
}
#media (max-width: 600px) {
main {
flex-direction: column;
}
main > article, aside {
width: 100%;
}
}
* {
box-sizing: border-box;
}
body {
margin: 0;
}
footer {
background: #333333;
color: white;
margin: 0;
text-align: center;
}
<div class="content">
<header>
<h1>Header</h1>
</header>
<main>
<article>
<h3>Current Article</h3>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odit vero quibusdam maxime magnam rerum nemo provident? Commodi, non! Ad facilis, doloribus voluptatum alias nostrum voluptatibus enim libero, distinctio nam sunt similique pariatur nesciunt accusantium eveniet perferendis ea doloremque molestiae culpa consequuntur quia aspernatur, itaque voluptate? Voluptatem magni delectus harum totam.</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fuga rerum repudiandae error eveniet est explicabo, nihil eum. Inventore laboriosam consectetur dolor consequatur. Unde in doloribus repellendus dolorum perferendis officia hic?</p>
<p>Dicta molestias doloremque, corrupti dolorum ipsum ea perferendis neque a, animi magnam ab sint impedit repudiandae aspernatur vel natus cum suscipit vero nisi nihil blanditiis iste laborum. Eum, sunt quo!</p>
<ul>
<li>Lorem ipsum dolor sit.</li>
<li>Nisi doloremque ut deserunt?</li>
<li>Impedit aliquam itaque placeat.</li>
<li>Sit incidunt iure assumenda.</li>
<li>Inventore fuga optio perferendis!</li>
</ul>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Natus illum aut quia alias delectus labore, maiores, excepturi quae nisi a non consequuntur! Officia fugiat enim nostrum molestias ipsa! Deleniti, repudiandae!</p>
<p>Illo, reprehenderit? Ipsum velit aut, ducimus minima in accusamus aperiam ex cumque recusandae tenetur architecto nemo repellat asperiores eum. Corrupti blanditiis, odio sequi ea ducimus ipsam temporibus culpa asperiores dicta.</p>
<p>Maxime alias, natus veritatis quis mollitia itaque voluptate iure neque dolore, expedita eaque, in ea sunt quibusdam ut ducimus fugit doloribus! Corporis molestiae nobis quae nesciunt inventore alias sed error.</p>
<p>Id est repellendus pariatur harum, hic sequi vero ab mollitia corporis nisi, consequuntur eaque doloremque, suscipit nobis velit dolore totam exercitationem facere voluptas iure? Temporibus eius minus vero aut cumque!</p>
</article>
<aside>
<h4>In other news:</h4>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Placeat, culpa.</p>
<p>Molestiae, officiis non esse perspiciatis provident a doloribus dignissimos sint!</p>
<p>Inventore nihil illum maxime ipsa repudiandae quia omnis quae consequuntur!</p>
</aside>
</main>
</div>
<footer class="footer">
Company Name | All rights reserved ©2020
</footer>

Remove horizontal scroll from width

My goal with this code is to position an image and text above a background to create a sort of overlay, I have already positioned the image well across all sizes, but my problem is the width creates a long horizontal scrollbar. Looking for a way to keep my css while removing the scroll bar.
FULL SCREEN VIEW
MOBILE VIEW
As you can see the width (1000px) is highlighted in blue.
HTML
<div class="banner-partner-padding position-relative" style="background-image: url('img/bg-banners/banner-partner.jpg'); background-size: cover;">
<div class="header-p">
<div class="row">
<div class="col-6 div-partner text-center">
<div class="div-partner-content">
<img src="../img/uploads/<?php echo($rowMerchant['logosrc']); ?>" class="partner-image">
</div>
</div>
<div class="col-6 my-auto pl-4 d-none d-sm-block">
<?php echo '<h3 class="bold-font color-white t-shadow-black d-none d-sm-block">'.$rowMerchant['businessname'].'</h3>'; ?>
</div>
</div>
</div>
</div>
CSS
.banner-partner-padding {
padding-top: 250px;
}
.header-p {
width: 1000px !important;
position: absolute;
top: 140px;
left: 210px;
}
#media (max-width: 900px) {
.header-p {
width: 1000px !important;
position: absolute;
top: 140px;
left: 50px;
}
}
#media (max-width: 576px) {
.header-p {
width: 1000px !important;
position: absolute;
top: 140px;
left: 30px;
}
}
.div-partner {
max-width: 13%;
min-width: 13%;
background: white;
border-radius: 4px;
padding: 5px 5px;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
display: flex;
align-content: center!important;
align-items: center!important;
}
.div-partner-content {
display:block;
margin: auto auto;
height: 100%;
}
.partner-image {
width: 100%;
height: auto;
display:block;
margin: auto auto;
}
Solutions I tried but did not work:
adding overflow hidden: the image gets cut and the scroll bar stays
.header-p {
width: 1000px !important;
position: absolute;
top: 140px;
left: 210px;
overflow-x: hidden;
}
adding z-index: no change
.header-p {
width: 1000px !important;
position: absolute;
top: 140px;
left: 210px;
z-index: 1;
}
Use max-width: 100%
Example:
.header-p{
max-width: 100%;
}
Also you should remove position, width & top attributes from #media because you already declared same value above
I've tried to replicate your issue and modify a bit, you can have a look here:
Simply move all the content block outside, put them in separate block. Use negative margin top (margin-top: -40px;) to move this block up a bit, avoid using absolute position in this case.
Set a height to the background div behind.
As you see, I've removed all !important flag in your CSS. In header-p, add .container class to use default Bootstrap container properties. By default it maximizes the width by 1440px. You can override this number simply by:
This part I don't include in the CSS, just for your reference in case you want to change width value.
#media screen and (min-width: 1200px) {
.container.header-p {
max-width: 1000px;
}
}
.banner-partner-padding {
height: 300px;
}
.container-header {
margin-top: -40px;
background: salmon;
}
.div-partner {
flex: 0 0 auto;
width: 13%;
background: white;
border-radius: 4px;
padding: 5px 5px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
display: flex;
}
.div-partner-content {
display: block;
margin: auto auto;
height: 100%;
}
.partner-image {
width: 100%;
height: auto;
display: block;
margin: auto auto;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="banner-partner-padding" style="background-image: url('https://placeimg.com/1000/300/nature'); background-size: cover;">
</div>
<div class="container container-header header-p">
<div class="row">
<div class="col div-partner text-center">
<div class="div-partner-content">
<img src="https://placeimg.com/128/128/people" class="partner-image">
</div>
</div>
<div class="col my-auto pl-4 d-none d-sm-block">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Odio reiciendis reprehenderit veritatis eos saepe deleniti asperiores, impedit ad repellendus id eligendi adipisci animi blanditiis perspiciatis laboriosam esse delectus hic, labore commodi optio dolore ipsam. Labore, nesciunt! Corrupti asperiores sit temporibus cupiditate, sunt voluptatibus iure veniam repellat laudantium, aperiam soluta repudiandae.
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat animi nemo laborum facilis doloribus culpa sed numquam illum voluptates esse eaque quos quidem illo facere suscipit, hic, dignissimos totam unde soluta eius est voluptatem magni assumenda neque! Beatae quo perferendis cupiditate soluta, officia esse quam tempore ratione et doloremque aspernatur.</p>
</div>
</div>
</div>
Demo link: https://codepen.io/DieByMacro/pen/YzzBdZR
Let me know if this is your desired behavior for the content block.

Div with text and 3 divs inside it filling it

I would like to create a div which has auto height based on the length of the text inside it (the text should be in the parent element so that it has 100% width. But also there should be 3 divs in the background each taking 1/3rd of the parent width and being 100% of the parent height.
This is an example of what I expect.
Any ideas how to create this?
I usually don't post questions like this one. But I just got stuck on how to do that and I needed help
You can use Flexbox for this
.content {
display: flex;
position: relative;
}
h1 {
text-transform: uppercase;
font-size: 45px;
margin: 0;
font-family: sans-serif;
word-spacing: 15px;
}
.divs {
position: absolute;
z-index: -1;
width: 100%;
top: 0;
left: 0;
height: 100%;
display: flex;
}
.el {
flex: 1;
border: 3px solid lightgreen;
}
.el:nth-child(1) {background: #DBEBD4;}
.el:nth-child(2) {background: #CEE2F4;}
.el:nth-child(3) {background: #D9D2EA;}
<div class="content">
<h1>Lorem ipsum dolor sit.</h1>
<div class="divs">
<div class="el"></div>
<div class="el"></div>
<div class="el"></div>
</div>
</div>
Have a container div absolutely positioned under the text and then have three child divs inside that.
The reason for the container div is that it avoids having to position each child separately.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.parent {
position: relative;
}
.underlay {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: flex;
border: 1px solid grey;
}
.child {
flex:1;
border:1px solid red;
background: rgba(255,0,255,0.25);
z-index:-1;
}
<div class="parent">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta sunt natus architecto deserunt eligendi repellat corporis doloribus fugit ipsam fugiat, eius vitae, magni? Quasi consequatur voluptatem eius excepturi eum qui dolores placeat maxime corporis
laborum hic, magnam ipsa voluptatibus doloremque. Dignissimos dolorum corporis sunt amet unde repellat, dolor consectetur earum.</p>
<div class="underlay">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</div>