This question already has an answer here:
Image displaying behind the section after using overflow hidden
(1 answer)
Closed 3 years ago.
I am using a css pseudo-classes. I tried before and after. There is no issue with before I am getting the horizontal scroll when using after class.
I don't want to use overflow: hidden;. If I use overflow then my image is displaying behind the first section.
Would you help me out with these issues?
This is the before class which is working.
.container {
width: 1140px;
margin: auto;
}
/*.test1{position: relative;}*/
.test1:before {
content: "";
background-image: url('https://w0.pngwave.com/png/546/532/computer-icons-sales-label-sale-icon-png-clip-art.png');
background-repeat: no-repeat;
background-size: contain;
width: 350px;
height: 308px;
display: block;
position: absolute;
top: -15%;
left: -10%;
}
<div class="container">
<section class="test1">
<p>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.
</p>
</section>
</div>
This is the after class which is not working. I am getting scrollbar
section {
height: 400px;
position: relative;
}
.test1 {
overflow: hidden;
}
.test1:after {
content: "";
background-image: url('https://www.netclipart.com/pp/m/16-165891_sale-price-tag-png-sale-icon-png.png');
background-repeat: no-repeat;
background-size: contain;
width: 350px;
height: 308px;
display: block;
position: absolute;
top: -15%;
right: -10%;
}
<section style="background-color: #f8f8f8;">
<p>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.</p>
</section>
<section class="test1">
<p>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.
</p>
</section>
I am getting the output
My expected output
Please add css
body {position: relative;}
.test1:after {
content: "";
background-image: url(https://www.netclipart.com/pp/m/16-165891_sale-price-tag-png-sale-icon-png.png);
background-repeat: no-repeat;
background-size: 100%;
width: 350px;
height: 400px;
display: block;
position: absolute;
top: 0;
right: 0;
}
.container {
width: 1140px;
margin: auto;
max-width: 100%;
}
/*.test1{position: relative;}*/
.test1 {position: relative; overflow: hidden; }
.test1:before {
content: "";
background-image: url('https://w0.pngwave.com/png/546/532/computer-icons-sales-label-sale-icon-png-clip-art.png');
background-repeat: no-repeat;
background-size: contain;
width: 350px;
height: 308px;
display: block;
position: absolute;
top: -15%;
left: 0;
}
.test1:after {
content: "";
background-image: url('https://www.netclipart.com/pp/m/16-165891_sale-price-tag-png-sale-icon-png.png');
background-repeat: no-repeat;
background-size: contain;
width: 350px;
height: 308px;
display: block;
position: absolute;
top: -15%;
right: -40%;
}
<div class="container">
<section class="test1">
<p>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.
</p>
</section>
</div>
Related
I am trying to create a cross-browser dialog box system. Basically, you click a link and the dialog pops down. Surprisingly, I got it to work on all major browsers, including IE 11. The only issue is if the content inside the dialog box exceeds the window, the box gets cut off in IE 11. Here's the code:
/* Core styles */
html,
body {
position: absolute;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
left: 0;
top: 0;
}
.page {
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
}
.content-wrapper {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
box-sizing: border-box;
overflow: auto;
}
.card {
position: relative;
box-sizing: border-box;
margin: 3rem;
padding: 3rem;
color: rgba(0, 0, 0, 0.8);
background-color: #ffffff;
border-radius: 0.4rem;
border: 1px solid rgba(0, 0, 0, 0.2);
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}
/* Dialog styles */
.dialog-outer {
position: absolute;
top: -100%;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
-webkit-transition: all .4s cubic-bezier(.25, .8, .25, 1);
transition: all .4s cubic-bezier(.25, .8, .25, 1);
z-index: 99;
outline: none;
}
.dialog-outer .dialog-inner {
height: 100%;
overflow: auto;
}
.dialog-outer .dialog-inner .dialog-content {
position: absolute;
box-sizing: border-box;
display: flex;
flex-direction: column;
top: -100%;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
}
.dialog-outer .dialog-inner .dialog-content .card {
margin: auto;
}
.dialog-outer:target {
top: 0;
}
.dialog-outer:target ~ .page .content-wrapper {
overflow: hidden;
}
.dialog-outer:target .dialog-content {
top: 0;
}
<!-- Dialog 1 -->
<div class="dialog-outer" id="dialog-1">
<div class="dialog-inner">
<div class="dialog-content">
<div class="card" style="width: 400px;">
<strong>Dialog 1</strong>
<br /><br />
<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>
Close
</div>
</div>
</div>
</div>
<!-- Dialog 2 -->
<div class="dialog-outer" id="dialog-2">
<div class="dialog-inner">
<div class="dialog-content">
<div class="card" style="width: 400px;">
<strong>Dialog 2 (long scrolling content)</strong>
<br /><br />
<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>
<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>
Close
</div>
</div>
</div>
</div>
<!-- Page -->
<div class="page">
<div class="content-wrapper">
<div style="padding: 20px;">
<!-- Toggles -->
Toggle dialog 1
<br /><br />
Toggle dialog 2
</div>
</div>
</div>
The huge chunks of code basically generates 2 dialog boxes. One where the content is tiny, so it does not exceed the page length, the other need requires scroll. Unfortunately, the second dialog box gets cut off in IE 11. It works on all the other browsers I tested on, including some old versions of Edge and Firefox. What exactly is the issue on IE 11?
The ideal answer would be one that requires no changes to the HTML markup, and the core styles.
You can download the above code as an HTML file here: https://anonfile.com/933cv8o0o0/dialog_html
Thanks for any help!
I think the issue is with flexbox. In the flex value of browser compatibility, it says:
IE incorrectly positions inline block content inside flex containers.
The issue can be fixed if you remove display: flex; in #dialog-2. You could change the following css styles like this:
.dialog-outer .dialog-inner .dialog-content {
position: absolute;
box-sizing: border-box;
/*display: flex;*/
flex-direction: column;
top: -100%;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
}
#dialog-1 .dialog-inner .dialog-content {
display: flex;
}
I have a div which is horizontally and vertically centred in the viewport. So I know the content will always be accessible, I allow the page to scroll when the content is taller than the viewport.
This appears to work fine, however, I am using a background-image on the div with an overlay on the :before pseudo-element to fade out the background. At first the background scroll, which I was able to resolve with background-attachment: fixed. Now the problem I have is that the overlay div scrolls up along with the page, so the area 'below the fold' doesn't now have a darkened background.
I know this is down to the position: absolute but when I change the position to fixed the desired effect is achieved but the overlay then covers the vertical scrollbar - is there a way around this?
I know I could use an image already darkened but this is markup that is used elsewhere and is being reused, so I'd like to find a CSS solution if possible.
Thanks in advance!
Code example attached + a CodePen version (https://codepen.io/moy/pen/xxbwvdL) depending on your preference. :)
html,
body {
margin: 0;
padding: 0;
}
h1,
p {
margin: 0 0 30px;
padding: 0;
}
.masthead {
background-color: rgb(0,0,0);
background-image: url("https://www.fillmurray.com/1920/1080");
background-position: left center;
background-repeat: no-repeat;
background-size: cover;
box-sizing: border-box;
color: white;
display: flex;
align-items: center;
justify-content: center;
min-height: 300px;
overflow: hidden;
overflow-y: auto;
padding: 60px 0 30px;
position: relative;
width: 100%;
}
.masthead:before {
background: rgba(0,0,0,.45);
content: "";
display: block;
height: 100%;
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: 4;
}
.wrap {
margin: auto;
padding: 0 30px;
z-index: 12;
max-width: 900px;
}
.masthead--fullbleed {
height: 100vh;
overflow-y: auto;
}
<section class="masthead masthead--fullbleed">
<div class="wrap wrap--narrow align-center">
<div class="hgroup">
<h1 class="hgroup__title">Title here</h1>
<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>
</div>
</section>
Urgh, why is it when you've been stuck on something then you post and instantly think of a solution (I think).
So basically, I changed height: 100vh to min-height: 100vh That seems to do the trick unless anyone can spot a problem with it. Attached snippet to reflect this.
You can tell I haven't coded for a year+ I guess :/
html,
body {
margin: 0;
padding: 0;
}
h1,
p {
margin: 0 0 30px;
padding: 0;
}
.masthead {
background-color: rgb(0,0,0);
background-image: url("https://www.fillmurray.com/1920/1080");
background-position: left center;
background-repeat: no-repeat;
background-size: cover;
box-sizing: border-box;
color: white;
display: flex;
align-items: center;
justify-content: center;
min-height: 300px;
overflow: hidden;
overflow-y: auto;
padding: 60px 0 30px;
position: relative;
width: 100%;
}
.masthead:before {
background: rgba(0,0,0,.45);
content: "";
display: block;
height: 100%;
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: 4;
}
.wrap {
margin: auto;
padding: 0 30px;
z-index: 12;
max-width: 900px;
}
.masthead--fullbleed {
min-height: 100vh;
overflow-y: auto;
}
<section class="masthead masthead--fullbleed">
<div class="wrap wrap--narrow align-center">
<div class="hgroup">
<h1 class="hgroup__title">Title here</h1>
<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>
</div>
</section>
try changing:
.masthead--fullbleed {
height: 100vh;
overflow-y: auto;
}
to
.masthead--fullbleed {
overflow-y: auto;
}
EDIT
Alternative is to attach the dark overlay to the body
.body:before {
background: rgba(0,0,0,.45);
content: "";
display: block;
height: 100%;
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: 4;
}
I'm trying to make the background-image fill the entire width of the parent div positioned in the top left corner relative to the image size (in this case 600x375) while keeping it at 100% width across the parent div as well. In addition to doing this, I have content overlaying on top of the background-image which is the intended effect. I tried background-size but that covers the whole div which I don't want. I want the background-color:red to remain the full background color of the parent div as it is now but have the background-image about half way depending on the image size. I also tried width and height attributes on the :after property but it seems to shifts the background-image around and not change the actual size of the image. What is the appropriate approach to making the background-image size fit and stretched across it but not covering the entire parent div.
Here's the jsfiddle: https://jsfiddle.net/TheAmazingKnight/6xgrftLj/4/
.container {
z-index: 10;
position: relative;
}
#parent {
padding-top: 70px;
padding-bottom: 35px;
content: '';
background-color: red;
background-repeat: no-repeat;
width: 100%;
height: 500px;
background-position-y: 50%;
background-position-x: 50%;
position: relative;
}
#parent:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-repeat: no-repeat;
background-position-y: 50%;
background-position-x: 50%;
background-image: url(https://via.placeholder.com/600x375);
height: 675px;
width: 900px;
}
<div id="parent">
<div class="container" style="
z-index: 10;
position: relative;
">
<h1>Heading 1</h1>
<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>
<span>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.</span>
<h3>Lorem ipsum dolor</h3>
<p>Download</p>
</div>
</div>
I've written a solution for you. In my solution i didn't use the image as background. I used the image as a child element of the div(#parent) and positioned it as absolute. I made some changes in both of your html and css file. Hope it will help you.
.container {
z-index: 10;
position: relative;
}
#parent {
position: relative;
content: '';
background-color: red;
background-repeat: no-repeat;
width: 100%;
height: 500px;
position: relative;
}
#parent img {
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 100%;
height: 250px;
object-fit: cover;
}
<div id="parent">
<div class="container"
>
<img src="https://via.placeholder.com/600x375" alt="">
<h1>Heading 1</h1>
<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>
<span>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.</span>
<h3>Lorem ipsum dolor</h3>
<p>Download</p>
</div>
</div>
I want to make the height of the paragraph 100%, but when I try it doesn't do it. Setting the size in pixels does work. What I have:
*,
html,
body {
margin: 0;
padding: 0;
height: 100%;
list-style: none;
}
.infoDiv {
height: 50%;
background: grey;
background-size: cover;
opacity: 0.6;
}
.textStart p {
height: 100%;
display: table-cell;
vertical-align: middle;
}
<div class="infoDiv">
<div class="imgStart col-xs-12 col-sm-7"></div>
<div class="textStart col-xs-12 col-sm-5">
<p>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.</p>
</div>
</div>
EDIT: The solution is giving it the ViewHeight (vh).
Here is the working code
*,
html,
body {
margin: 0;
padding: 0;
height: 100%;
list-style: none;
}
.infoDiv {
height: 50%;
background: grey;
background-size: cover;
opacity: 0.6;
}
.textStart p {
height: 100vh;
display: table-cell;
vertical-align: middle;
}
<div class="infoDiv">
<div class="imgStart col-xs-12 col-sm-7"></div>
<div class="textStart col-xs-12 col-sm-5">
<p>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.</p>
</div>
</div>
In CSS3 you could use
height: calc(100% - 60px);
I have a container div set to a fixed position at top of page and several relative position divs scrollable within the container. I can set margin left, right and bottom. But the top margin is ignored and runs up against the top of the container. What am I doing wrong here?
#container {
position: fixed;
width: 32rem;
height: 32rem;
background-color: #000000;
overflow: hidden;
}
#div1 {
position: relative;
width: 30em;
height: 40em;
margin: 5rem 1rem 5rem 1rem;
<div id="container">
<div id="div1"></div>
</div>
You need to add overflow:hidden and change height:22em in #div1
I think you want something like this and I hope it will helps you.
#container {
position: fixed;
width: 32rem;
height: 32rem;
background-color: #000;
overflow: hidden;
}
#div1 {
height: 22em;
margin: 5rem 1rem;
overflow: hidden;
position: relative;
width: 30em;
color:#fff;
}
<div id="container">
<div id="div1">
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.
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.
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>
Is this the desired output? http://jsfiddle.net/t9rkpspu/
#container {
position: fixed;
width: 32rem;
height: 32rem;
background-color: #000000;
overflow: hidden;
}
#div1 {
color: white;
position: relative;
width: 30em;
height: 40em;
margin: 5rem 1rem 5rem 1rem;
}