CSS stretch parent div to max height of overlaid children - html

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>

Related

How to resize container height based on browser width

How can I scale the black containers height from max-height of 550px to for example height of 400px by just changing browsers width. And together with the black container the box divs also should get smaller proportionally. I want it without the use of media queries.. I want it to change dynamically so you can see it resizing pixel by pixel. I don't want it to just jump from one height to another by reaching a media queries width.
.container-black {
height: 550px;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
border-bottom: solid 8px grey;
}
.box1 {
display: flex;
justify-content: center;
align-items: center;
height: 70%;
width: 30%;
background-color: red;
}
<body>
<div class="container-black">
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
</div>
</body>
Use dynamic values such as vw or viewport width. For example, to keep your black borders you can set box1 to width: 40vw;. This means box1 will use 40% of the viewport size when resizing, and the container-black will maintain 10% of viewport width on any device. Allowing it to be responsive.
The Dynamic Viewport is the viewport sized with dynamic consideration of any UA interfaces. It will automatically adjust itself in response to UA interface elements being shown or not
css-tricks.com
EDIT -- added 2 more container-blacks and nested them in parent container and defined their height based of % so that they resize responsively.
.container-black {
height: 33%;
width: 100vw;
background-color: black;
display: flex;
justify-content: center;
align-items: center;
border-bottom: solid 8px grey;
}
.box1 {
display: flex;
justify-content: center;
align-items: center;
height: 70%;
width: 40vw;
background-color: red;
}
.container {
height: 100vw;
}
<body>
<div class="container">
<div class="container-black">
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
</div>
<div class="container-black">
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
</div>
<div class="container-black">
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
<div class="box1">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda libero quidem minima tenetur delectus,
iusto hic perferendis repudiandae soluta maxime nemo facere rem vero officiis! Illo deserunt eum ullam
eligendi!</p>
</div>
</div>
</div>
</body>
You can use the vw unit (= percent of viewport width) in your height definition, if necessary, inside a media query
One way to do it is using vw unit on the height of the black box.
1vw equals 1% of the viewport's width.
Another way is the CSS aspect-ratio feature. You can learn more in the link below.
https://css-tricks.com/almanac/properties/a/aspect-ratio/

Flexbox - image disappear with column

I'm a little bit stuck to be honest. Here is an example of my original code, the problem is that when I change my flex direction from row to column my picture disappears and I don't understand why =>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: rgb(104, 92, 76);
}
.container {
display: flex;
flex-direction: row-reverse;
background-color: black;
max-width: 700px;
margin: 20vh auto;
}
.content {
width: 100%;
}
.text {
color: white;
}
.image {
background: url('https://www.silocreativo.com/en/wp-content/uploads/2017/04/flexbox-cssgrid-practical-example.png');
width: 100%;
}
<div class="container">
<div class="image"></div>
<div class="content">
<div class="text"> Lorem ipsum dolor sit amet consectetur adipisicing Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia corporis repudiandae Lorem Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam aut
autem molestias debitis unde atque quam at assumenda. Atque sint illo rerum magnam aperiam suscipit commodi repudiandae officia! ipsum dolor sit, amet consectetur adipisicing elit. Fugiat quidem quasi sint culpa et rem quas deserunt labore laboriosam
mollitia. Consequatur lorem minus earum sint eius reiciendis, deleniti id vero sapiente. officiis consequuntur voluptas optio dolore nobis blanditiis adipisci maxime itaque ducimus sit incidunt, eveniet doloremque cupiditate debitis deserunt ad!
elit. Optio nihil officia commodi nostrum iure dignissimos officiis, consectetur, quae minus libero qui hic quis voluptas et quas similique vero neque facere. Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores tenetur, veniam nobis
nulla molestiae recusandae quia a reiciendis corrupti exercitationem delectus iure ducimus ea odio animi cumque et optio eum! </div>
</div>
</div>
Since there is nothing that specifies the height on the <div class="image"></div>, it has a height of 0px. You could set the height to a certain value, like x vh or px,
but I would recommend using the img tag instead:
<img src="https://www.silocreativo.com/en/wp-content/uploads/2017/04/flexbox-cssgrid-practical-example.png"/> in place of <div class="image"></div>.
This way, the width and height are set to the dimensions of the actual image if nothing else is specified.
Your image tag has not an height specified, you need something like this to set the size of the div:
.image {
flex-basis: 200px; // or height: 200px;
}
Otherwise you can use the img tag instead of the background, so you can show the image at his correct dimensions. Remember to set height: auto to the img tag in this case.
A flex item needs either a height setting or content adding (which will determine the height). As the image div has no content or height its height is set to 0.
I don't recommend setting height on flex items as this is contrary to how flex works. You should set a height on the flex container and use flex-basis to set the height of your flex items.
This will allow your flex items to be responsive. If you want the image to have a fixed height you should set it's flex property to flex:0 0 <height>;
.container {
display: flex;
flex-direction: column;
background-color: black;
max-width: 700px;
margin: 20vh auto;
height: 400px;
}
.image {
display: flex;
background: url('https://www.silocreativo.com/en/wp-content/uploads/2017/04/flexbox-cssgrid-practical-example.png');
flex: 1;
}
.content {
flex: 1;
}
.text {
color: white;
}
<div class="container">
<div class="image"></div>
<div class="content">
<div class="text">Hey la bonbone est remplis de cocaine Lorem ipsum dolor sit amet consectetur adipisicing Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia corporis repudiandae Lorem Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam aut
autem molestias debitis unde atque quam at assumenda. Atque sint illo rerum magnam aperiam suscipit commodi repudiandae officia! ipsum dolor sit, amet consectetur adipisicing elit. Fugiat quidem quasi sint culpa et rem quas deserunt labore laboriosam
mollitia. Consequatur lorem minus earum sint eius reiciendis, deleniti id vero sapiente. officiis consequuntur voluptas optio dolore nobis blanditiis adipisci maxime itaque ducimus sit incidunt, eveniet doloremque cupiditate debitis deserunt ad!
elit. Optio nihil officia commodi nostrum iure dignissimos officiis, consectetur, quae minus libero qui hic quis voluptas et quas similique vero neque facere. Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores tenetur, veniam nobis
nulla molestiae recusandae quia a reiciendis corrupti exercitationem delectus iure ducimus ea odio animi cumque et optio eum! </div>
</div>
</div>

How to use Horizontal scroll container inside a grid item?

Unable to use Horizontal scroll container inside a grid item. Grid item width gets expanded when a scroll container is inserted. Even scroll container unable to scroll horizontally. When I define a fixed width for the scroll container then only it is working but I want a responsive result. Can anyone please help me with this?
Here is the code snippet.
.grid-container {
display: grid;
grid-template-columns: 1fr 3fr 1fr;
grid-gap: 10px;
}
.grid-container>div {
border: 2px dotted black;
padding: 10px;
}
.code_container {
padding: 10px;
margin: 10px 0;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
background-color: black;
color: white;
}
.code {
display: inline-block;
}
<div class="grid-container">
<div class="left">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quibusdam delectus ipsum quidem recusandae, optio
eos dolorem suscipit commodi.
</div>
<div class="main">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis dolorem veniam tempore eius aliquid!
<div class="code_container">
<div class="code">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere, amet aperiam libero cumque sit quod
voluptatem eligendi. Odio illo voluptas beatae omnis voluptatem, ex consectetur vitae error ad,
officia iste, debitis molestiae explicabo repellat saepe nemo cupiditate nisi. Asperiores dolorem
inventore ipsa, deleniti, consequuntur explicabo, repellendus laboriosam aut minus dolore itaque
magni incidunt odit porro ipsum. Sequi, esse! At suscipit modi laborum ex aliquam recusandae
necessitatibus distinctio, animi quo? Soluta labore enim fugiat, suscipit cumque facere impedit
iusto quaerat neque perspiciatis quas molestiae exercitationem tempora, ad cum obcaecati. Aperiam
eos, quae unde provident illum doloribus excepturi optio laudantium quidem nulla!
</div>
</div>
</div>
<div class="right">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quibusdam delectus ipsum quidem recusandae, optio
eos dolorem suscipit commodi.
</div>
</div>
Unless content is set to absolute, parent div will keep growing to fit its contents size. This will make your black box (code container) grow. To prevent it, set positioning of code_container's child(.code) to absolute.
.code {
display: inline-block;
position: absolute;
}
But now, code's content jumps out from code container. To prevent this, give .code a fixed width. In your case, give 100%.
.code {
display: inline-block;
position: absolute;
width: 100%;
}
But still nothing will change because it takes it's 100% width compared to the width of the body. To prevent this, set .code's parent (.code_container) position: relative;. Now because .code's parent is positioned relative, code will calculate it's 100% width relative to .code_container's width.
Now you should be able to do horizontal scrolling and it is responsive! But the horizontal scroll bar is covering the content. So give .code_container a min-height (about 30px in your case).
Tested in chrome and firefox. Works fine!
.grid-container {
display: grid;
grid-template-columns: 1fr 3fr 1fr;
grid-gap: 10px;
}
.grid-container>div {
border: 2px dotted black;
padding: 10px;
}
.code_container {
padding: 10px 20px;
margin: 10px 0;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
background-color: black;
color: red;
position: relative;
min-height: 30px;
}
.code {
display: inline-block;
position: absolute;
width: 100%;
}
<div class="grid-container">
<div class="left">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quibusdam delectus ipsum quidem recusandae, optio eos dolorem suscipit commodi.
</div>
<div class="main">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis dolorem veniam tempore eius aliquid!
<div class="code_container">
<div class="code">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere, amet aperiam libero cumque sit quod voluptatem eligendi. Odio illo voluptas beatae omnis voluptatem, ex consectetur vitae error ad, officia iste, debitis molestiae explicabo repellat saepe
nemo cupiditate nisi. Asperiores dolorem inventore ipsa, deleniti, consequuntur explicabo, repellendus laboriosam aut minus dolore itaque magni incidunt odit porro ipsum. Sequi, esse! At suscipit modi laborum ex aliquam recusandae necessitatibus
distinctio, animi quo? Soluta labore enim fugiat, suscipit cumque facere impedit iusto quaerat neque perspiciatis quas molestiae exercitationem tempora, ad cum obcaecati. Aperiam eos, quae unde provident illum doloribus excepturi optio laudantium
quidem nulla!
</div>
</div>
</div>
<div class="right">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quibusdam delectus ipsum quidem recusandae, optio eos dolorem suscipit commodi.
</div>
</div>
Finally I have resolved the issue. Just need to include these lines inside container:
min-width: 0;
overflow: auto;
.grid-container {
display: grid;
grid-template-columns: 1fr 3fr 1fr;
grid-gap: 10px;
}
.grid-container>div {
border: 2px dotted black;
padding: 10px;
/* Auto scroll horizontally */
min-width: 0;
overflow: auto;
}
.code_container {
padding: 10px;
margin: 10px 0;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
background-color: black;
color: white;
}
.code {
display: inline-block;
}
<div class="grid-container">
<div class="left">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quibusdam delectus ipsum quidem recusandae, optio
eos dolorem suscipit commodi.
</div>
<div class="main">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis dolorem veniam tempore eius aliquid!
<div class="code_container">
<div class="code">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere, amet aperiam libero cumque sit quod
voluptatem eligendi. Odio illo voluptas beatae omnis voluptatem, ex consectetur vitae error ad,
officia iste, debitis molestiae explicabo repellat saepe nemo cupiditate nisi. Asperiores dolorem
inventore ipsa, deleniti, consequuntur explicabo, repellendus laboriosam aut minus dolore itaque
magni incidunt odit porro ipsum. Sequi, esse! At suscipit modi laborum ex aliquam recusandae
necessitatibus distinctio, animi quo? Soluta labore enim fugiat, suscipit cumque facere impedit
iusto quaerat neque perspiciatis quas molestiae exercitationem tempora, ad cum obcaecati. Aperiam
eos, quae unde provident illum doloribus excepturi optio laudantium quidem nulla!
</div>
</div>
</div>
<div class="right">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quibusdam delectus ipsum quidem recusandae, optio
eos dolorem suscipit commodi.
</div>
</div>

Have floating button at the bottom of parent div [duplicate]

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 ?

CSS: margin-right and parent element

Is margin-right not calculated or taken into account in the following example? what happens when someone increases margin-right on .box? it has no effect. why?
.outer {
width: 500px;
margin: 0 auto;
background: #9CF;
}
.box {
width: 300px;
background-color: #ffd900;
margin: 50px;
}
p {
background: #EEA458;
}
<div class="outer">
<div class="box">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fuga ipsam quibusdam pariatur animi doloremque libero sed odio asperiores aliquam, accusamus vel voluptas iusto labore ipsa aspernatur voluptates, blanditiis. Eaque rem sapiente officiis dolores
incidunt assumenda natus reprehenderit quisquam, perspiciatis ab nostrum eligendi deserunt, pariatur, obcaecati fuga quos sunt nemo ullam!</p>
</div>
</div>
You have a margin: 50px declaration, which applies margins on all sides, as well as a width: 300px declaration. The values are over-constrained — since you can't expect a 300-pixel wide box to only have 50-pixel horizontal margins in a containing block whose width is greater than 300 + 50 + 50 pixels — which does indeed result in the specified value of margin-right being ignored (in the typical LTR writing mode).
Here, the margin is getting collapsed. It does have a margin, but you cannot see. To make it visible, we need ti add the overflow: hidden to recalculate and show up the margin.
.outer {
width: 500px;
margin: 0 auto;
background: #9CF;
overflow: hidden;
}
.box {
width: 300px;
background-color: #ffd900;
margin: 50px;
}
p {
background: #EEA458;
}
<div class="outer">
<div class="box">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fuga ipsam quibusdam pariatur animi doloremque libero sed odio asperiores aliquam, accusamus vel voluptas iusto labore ipsa aspernatur voluptates, blanditiis. Eaque rem sapiente officiis dolores
incidunt assumenda natus reprehenderit quisquam, perspiciatis ab nostrum eligendi deserunt, pariatur, obcaecati fuga quos sunt nemo ullam!</p>
</div>
</div>
After applying overflow: hidden to the parent, you could see the top and bottom margins too.
And since your margin-right: 50px; is lesser than 150px of the space on the right, you cannot see the right margins.
This is the current box model of the .box:
If you want the background of .box to be visible, use padding instead of margin:
.outer {
width: 500px;
margin: 0 auto;
background: #9CF;
}
.box {
width: 300px;
background-color: #ffd900;
padding: 50px;
}
p {
background: #EEA458;
}
<div class="outer">
<div class="box">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fuga ipsam quibusdam pariatur animi doloremque libero sed odio asperiores aliquam, accusamus vel voluptas iusto labore ipsa aspernatur voluptates, blanditiis. Eaque rem sapiente officiis dolores
incidunt assumenda natus reprehenderit quisquam, perspiciatis ab nostrum eligendi deserunt, pariatur, obcaecati fuga quos sunt nemo ullam!</p>
</div>
</div>