Reputation: 85
and I want to put some text at bottom of div2 just like in the pic.
I have the following code:
<style>
.grey_box {
background-color: grey;
width: 680px;
height: 500px;
}
.yellow_box {
background-color: yellow;
width: 450px;
height: 300px;
}
</style>
</head>
<body>
<div class="grey_box">
<div class="yellow_box">
<h1>when I say div</h1>
</div>
</div>
Upvotes: 1
Views: 71
Reputation: 5337
I am not sure as per your little drawing that you made if the h1 is needed to be inside of the inner div like your code suggests, but your drawing does not. If its not needed inside that inner div You can simply move the header text outside of the child div like this example. But otherwise if you want the text at the bottom of the inner div, and not outside of it then you can follow the answer provided by @thenomadicmann
.grey_box {
background-color: grey;
width: 680px;
height: 500px;
}
.yellow_box {
background-color: yellow;
width: 450px;
height: 300px;
}
<div class="grey_box">
<div class="yellow_box">
</div>
<h1>when I say div</h1>
</div>
Upvotes: 0
Reputation: 522
Add display: flex;
and align-items: flex-end;
to .yellow-box
. See the snippet below:
<style>
.grey_box {
background-color: grey;
width: 680px;
height: 500px;
}
.yellow_box {
display: flex;
align-items: flex-end;
background-color: yellow;
width: 450px;
height: 300px;
}
</style>
</head>
<body>
<div class="grey_box">
<div class="yellow_box">
<h1>when I say div</h1>
</div>
</div>
Upvotes: 2