I am extremely frustrated because I keep running into the same issue. So I apologize for having to ask this question again...
I want my website to have different sections and used divs for that. For some reason, when I reduce my browser's height, the sections will overlap. So for example, I set the middle section (div container 2) to a red background color and the first section (div container 1) to a different color, in this fist section I also have some placeholder text. When I then reduce the browser's height, the red background from section 2 will keep moving into my first section with the placeholder text. I removed all content from the second container but obviously this is an even bigger issue when I have elements in the second container because then not only the background but also the elements from this section will move into my first section and overlapping with the content from the first section.
When I asked this question yesterday, the issue was that I had position absolute but that's no longer the case. I tried all different positioning (flex, block, inline, inline block, absolute) but this overlapping when resizing the browser keeps happening :(
Can anyone please help me??
Here is my code:
.Container1 {
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74, 105, 113);
background: linear-gradient(90deg, rgba(74, 105, 113, 1) 0%, rgba(129, 161, 170, 1) 60%, rgba(181, 207, 214, 1) 100%);
text-align: center;
display: flex;
flex-direction: column;
}
.hp_slogan {
padding-top: 100px;
}
.showcase {
margin-top: auto;
}
/* Container2 Styling */
.container2 {
height: 100vh;
width: 100%;
background-color: red;
color: white;
display: block;
font-size: 16px;
}
<div class="Container1">
<div class="hp_slogan">
<div class="">
<?php
echo do_shortcode('[smartslider3 slider=19]');
?>
</div>
<p>Placeholder Text.</p>
</div>
<div class="showcase">
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. 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 class="container2">
</div>
From my own comment:
Try using min-height: 100vh instead of height: 100vh.
Related
I have a textarea that user can change its size.
I need to have an image background for it but I do not want the image disturbs the text so the image should be partially transparent without impacting the opacity of the text that user can type on top of it.
I followed this link which suggests using ::before but it does not work on my Firefox browser.
<textarea class="hero">
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.
</textarea>
CSS
.hero {
position: relative;
/* height: 100vh; */
/* width: 100%; */
display: flex;
align-items: center;
justify-content: center;
}
.hero::before {
content: "";
background-image: url('https://placekitten.com/1200/800');
background-size: cover;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
opacity: 0.75;
}
https://jsfiddle.net/z86yfLvh/1/
How should I fix this?
The easiest solution here would be wrapping your textarea element into a container, put background on it and tune the background of your textarea down, through background-color with alpha inside the rgba().
Like this:
.hero {
background-color: rgba(255, 255, 255, .7)
}
.hero-container {
background-image: url('https://placekitten.com/1200/800');
background-size: cover;
display: inline-block;
}
<div class="hero-container">
<textarea class="hero">
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.
</textarea>
</div>
I should mention also that ::before won't work with textarea because it would have to render it inside the textarea which can't contain any HTML elements directly. It's a hard limitation.
Alternative solution that also solves another issue that OP mentioned in the comment:
.hero {
background-color: rgba(255, 255, 255, .7);
width: 100%;
height: 100%;
resize: none;
}
.hero-container {
background-image: url('https://placekitten.com/1200/800');
background-size: cover;
resize: both;
overflow: auto;
width: 100%;
}
<div class="hero-container">
<textarea class="hero">
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.
</textarea>
</div>
I'm using resize: none on textarea to disable the ability to resize it and I'm adding it to the container instead, while width: 100%; height: 100% makes sure textarea stretches with the container too.
I asked a similar question already but haven't found an answer. I am now at a different section of my website but have the the issue here as well. The code is super basic, so I am hoping this will help to solve the issue.
Some context: My front page is sectioned in 3 container divs, each of them with 100vh, so they should take up the entire screen, even when someone resizes the browser. The second div in the code below (.showcase) should stick to the bottom of the Container div (that's why I added position: absolute and bottom: 0).
My issue is now that the two divs in the Container div 1, keep overlapping when I reduce the browser height for example. But I want them to 'push' each other away from each other, basically not giving space for the other div to overlap. So that when I, for example, would add a padding to the two divs, that the padding still shows on the page even if resizing the browser. And no matter what I added (display: block, Flexbox, even putting the divs into a table etc) all of this didn't help and the content of the two divs keeps overlapping.
Can anyone help me here? I literally don't know how to go from here...
Here is the code:
.Container1 {
overflow: hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74, 105, 113);
background: linear-gradient(90deg, rgba(74, 105, 113, 1) 0%, rgba(129, 161, 170, 1) 60%, rgba(181, 207, 214, 1) 100%);
text-align: center;
display: block;
}
.hp_slogan {
padding-top: 20%;
padding-bottom: 3%;
}
.showcase {
position: absolute;
bottom: 0;
display: block;
}
<div class="Container1">
<div class="hp_slogan">
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 class="showcase">
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>
I believe this will solve your problem If I understood correctly what you need.
.Container1 {
overflow:hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74,105,113);
background: linear-gradient(90deg, rgba(74,105,113,1) 0%, rgba(129,161,170,1) 60%, rgba(181,207,214,1) 100%);
text-align: center;
display: flex;
flex-direction:column;
}
.hp_slogan {
padding-top: 20%;
margin-bottom:20px;
padding-bottom: 3%;
}
.showcase {
bottom: 0;
}
You can simulate it in JSFiddle with this link
See if this works for you. Used flexbox to distance two divs
.Container1 {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
overflow: hidden;
height: 100vh;
width: 100%;
margin: 0;
background: rgb(74, 105, 113);
background: linear-gradient(90deg, rgba(74, 105, 113, 1) 0%, rgba(129, 161, 170, 1) 60%, rgba(181, 207, 214, 1) 100%);
text-align: center;
}
<div class="Container1">
<div class="hp_slogan">
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 class="showcase">
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>
I have a div which is bing map and i want to stretch it to fill all height. For width i just used container-fluid but height is more tricky because nav bar and footer have some constant height and when i set map height to lets say 90vh then if i change window height sooner or later map will be covered a little with footer or navbar height can change if width is smaller because all text won't fit in one line and once again map will be covered a little and scrollbar shows up.
Nav bar is at top of the page and footer is sticked to the bottom. I dont want to have scrollbar. I want to somehow anchor div with map to the nav bar and to footer so it will fully stretch between them.
Is there a way to keep for example 10px distance to div above and 10px to div bellow? So it will stretch or shrink to keep that?
How to achive this with bootstrap and/or css?
Something like this
/* Required Stuff */
body {
margin: 0;
height: 100%;
}
#wrapper {
display: grid;
grid-template-rows: 30px 1fr 30px;
}
#content {
height:auto /* or overflow-y: scroll; for fixed header and footer */
}
/* Optional Stuff */
#wrapper {
gap: 1px;
height: 100%;
border: 1px solid black;
background-color: black;
}
#wrapper > * {
padding: 5px;
background-color: white;
}
/* do not copy this into your own projects */
/* stack overflow needs fixed height */
/* just pretend "180px" is just the full page size */
#header {
background-color:green;
}
#footer {
background-color:blue;
}
<body>
<div id="wrapper">
<div id="header">Header Content</div>
<div id="content">
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. 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 id="footer">Footer Content</div>
</div>
</body>
I'm working on revamping an intranet page that was built years ago, and I'm trying to figure out the most effective CSS to properly lay out a page with the following requirements:
The page should occupy the full height and width of the viewport and should be responsive to resizing.
There should be a status bar that should always be visible at the bottom and should only be as tall as its contents.
If the user increases the font size, the status bar should properly adjust so the text isn't cut off.
If the content is taller than than the available screen height, scrollbars should appear in the content area to allow it to scroll (again, keeping the status bar visible).
Here's a mockup of the expected result:
As far as browser requirements go, this will ONLY be seen by a very specific group of users that will access it via Internet Explorer 11. No Chrome, no Firefox, no Edge - nothing except IE 11.
I've been experimenting with the "100vh" heights and flex, and I think I'm getting close but I'm just having some trouble getting everything the way I want. My current attempt looks like this:
body {
height: 96vh;
min-height: 96vh;
width: 95vw;
min-width: 95vw;
display: flex;
flex-direction: column;
}
#content
{
padding: 20px;
max-height: 95vh;
overflow:auto;
flex: 1 0 0;
}
#statusbar
{
background-color: #000;
color: #fff;
padding: 20px;
}
<div id="content">
<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>
<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>
<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>
</div>
<footer id="statusbar">Status bar</footer>
I appreciate whatever help can be provided! Thanks in advance!
Here is a solution using display:flex where the footer has variable height and the content adjusts accordingly. The content area is set to overflow:auto in order to scroll if necessary.
html,
body {
height: 100%;
margin: 0
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.box .row {
border: 1px dotted grey;
}
.box .row.footer {
flex: 0 1 auto;
}
.box .row.content {
flex: 1 1 auto;
overflow:auto;
}
<div class="box">
<div class="row content">
<p>
<b>content</b>
(fills remaining space)
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
some overflowing text
</p>
</div>
<div class="row footer">
<p><b>footer</b> (variable height)</p>
</div>
</div>
This question already has answers here:
Why don't flex items shrink past content size?
(5 answers)
Closed 5 years ago.
I'm trying to make a web page with a 'header' div of fixed height then a 'content' div below it. Within that content div are several different divs with actual page content in them. In the actual project, the height of all of these elements may vary between different screens and users as their content is mostly generated by PHP.
Sorry if that explanation is unclear, but the following demonstrates what I have got so far:
https://codepen.io/anon/pen/ZJPgWm
(the code is poorly formatted and some of the values look a bit wierd because I've just thrown this together quickly as an imitation of my actual project).
#main {
width: 90%;
min-width: 400px;
max-width: 1200px;
height: calc(100vh - 10px);
margin-left: auto;
margin-right: auto;
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
}
#head {
background-color: blue;
font-size: 3vh;
}
#content {
background-color: red;
flex-grow: 1;
display: flex;
}
#left {
width: calc(16% - 6px);
float: left;
background-color: green;
}
#inner {
font-size: 10vh;
flex-grow: 1;
width: calc(84% - 6px);
float: left;
margin-left: 8px;
margin-bottom: 10px;
flex-grow: 1;
overflow-x: hidden;
overflow-y: auto;
background-color: yellow;
}
<body>
<div id="main">
<div id="head">
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 id="content">
<div id="left">
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 id="inner">
<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>
</div
</div>
</div>
</body>
On chrome, a scroll bar is shown within the #inner div. This is what I want.
On firefox and MS Edge, the overflowing content of the #inner div is just cut off, so it is impossible to see that content (without a taller screen).
I should note that the reason for this seems to be that, in chrome, the #inner and #content divs have their height controlled such that their bounding boxes don't go outside the boundary of the #main div. However, in firefox, their bounding boxes extend to below the bottom of the page (shown by developer tools).
What I am looking for is a method which will make all browsers give the result which is currently given by chrome. Ideally, an explanation of which browser is 'correct' and why they are different would also be helpful.
Note that I want to avoid using JS if at all possible. Any help or advice is appreciated.
Flex item's has a min-height that defaults to auto, which means it doesn't shrink below its content's size, so when you nest them like this and put the overflow: auto on a flex item's child, you need to let it know it is allowed to shrink.
Add min-height: 0; to your content rule and they will behave similar.
#main {
width: 90%;
min-width: 935px;
max-width: 1600px;
height: calc(100vh - 90px);
margin-left: auto;
margin-right: auto;
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
}
#head {
background-color: blue;
font-size: 20px;
}
#content {
background-color: red;
flex-grow: 1;
display: flex;
min-height: 0;
}
#inner {
font-size: 60px;
flex-grow: 1;
overflow-y: auto;
}
<body>
<header>
</header>
<div id="main">
<div id="head">
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 id="content">
<div id="inner">
<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>
</div </div>
</div>
</body>