I am trying to get that text box at the bottom of the page to align with the second image down so that it is in the bottom right corner. I have made a big div containing the images and text.
body {
background-color:rgb(white);
margin: 0px;
padding: 0px;
}
p {
margin-left: 200px;
margin-right: 200px;
text-align: left;
font-size: 22px;
}
.centre {
display: block;
margin-left: auto;
margin-right: auto;
width: 70%;
border-radius: 5px;
margin-bottom: 20px;
}
h1 {
margin-top:10px;
text-align:center;
}
nav{
margin-top:0px;
width:100%;
background:rgb(97, 157, 255);
overflow:auto;
}
nav a{
display: block;
padding:20px 15px;
text-decoration: none;
font-family: arial;
color:white;
text-align:center;
}
nav a:hover{
background-color:rgb(203, 204, 212);
transition:0.4s;
}
ul{
padding:0;
margin:0 250px;
list-style:none;
margin-left: 200px;
position: fixed top;
}
li{
margin-bottom:-4px;
margin-top:-2.5px;
font-size: 24px;
float:left;
}
.logo1 img{
position:absolute;
margin-top:0px;
margin-right: 100px;
width:16%;
}
.collage{
display: block;
margin:auto;
width:70%;
border:1.5px solid rgba(112, 128, 144, 0.5);
}
.collage img{
width:40%;
height:300px;
display: inline-block;
}
.collage p{
border:1.5px solid rgba(112, 128, 144, 0.5);
display: inline-block;
vertical-align: bottom;
}
<!DOCTYPEhtml>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" href="layout_91893.css">
</head>
<body>
<div >
<a href = "index_91893.html"><img src="Maunga_Club_white.png"></a>
</div>
<nav>
<ul>
<li><a href = "page1_91893.html">Available Cabins</a></li>
<li><a href = "membership_91893.html">Club Membership</a></li>
<li><a href = "#">Bookings</a></li>
<li><a href = "#">About Us</a></li>
<li><a href = "#">FAQ</a></li>
</ul>
</nav>
<p style="text-align:center;"> Enjoy the winter season with your family and friends in our premium cabins and chalets based on the Maunga Summit.</p>
<h1>The Kakapo Chalet</h1>
<img src="cabin_exterior.jpg" alt="picture" >
<div >
<img src="bunk_room.jpg" alt="picture">
<img src="cabin_view.jpg"alt="picture">
<img src="hallway.jpg">
<p> The Kakapo Chalet is a great choice for a medium to large number of guests.</p>
</div>
</html>
not too sure if a lot of the code in my CSS is relevant either but I've just been experimenting with inline blocks and stuff like that. Can someone please show me how I can align the text with the image?
expected the text box to align with bottom left image.
CodePudding user response:
A Flexbox
layout might be a good choice as it would simplify the overall layout for you?
.collage {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
box-sizing: border-box;
margin: auto;
width: 70%;
}
.collage img {
padding: 20px;
width: 40%;
}
.collage,
.collage>img,
.collage>p {
border: 1.5px solid rgba(112, 128, 144, 0.5);
}
.collage>img,
.collage>p {
box-sizing: border-box;
margin: 0.1rem;
clear: none;
width: calc( 50% - 0.4rem);
height: 300px;
}
.collage>p {
display: inline-flex;
align-items: center;
align-content: center;
padding: 0.5rem;
}
<div >
<img src="bunk_room.jpg" alt="bunk">
<img src="cabin_view.jpg" alt="cabin">
<img src="hallway.jpg" alt='hallway'>
<p> The Kakapo Chalet is a great choice for a medium to large number of guests.</p>
</div>
CodePudding user response:
Use display: inline-block;
, with word-break
, vertical-align
to make <p>
display the same as image and set margin
, padding
to have same space.
.collage {
display: block;
margin: auto;
width: 70%;
border: 1.5px solid rgba(112, 128, 144, 0.5);
}
.collage img {
padding: 20px;
border: 1.5px solid rgba(112, 128, 144, 0.5);
width: 40%;
height: 300px;
display: inline-block;
}
.collage p {
display: inline-block;
border: 1.5px solid rgba(112, 128, 144, 0.5);
height: 300px;
width: 40%;
word-break: break-all;
vertical-align: top;
margin: 0;
padding: 20px;
}
<div >
<img src="https://picsum.photos/id/1011/300/200" alt="picture">
<img src="https://picsum.photos/id/1015/300/200" alt="picture">
<img src="https://picsum.photos/id/1016/300/200">
<p> The Kakapo Chalet is a great choice for a medium to large number of guests.</p>
</div>
The code above look bad in very small screen, click on Full page to view in larger size.
Flex box
You may use CSS Flex box.
.collage{
display: flex;
flex-wrap: wrap;
width:70%;
border:1.5px solid rgba(112, 128, 144, 0.5);
}
.collage p,
.collage img{
padding:20px;
border:1.5px solid rgba(112, 128, 144, 0.5);
width:50%;
}
.collage * {
box-sizing: border-box; /* I add this for use width: 50% WITH border so that it can be fit in outer div perfectly. */
}
<div >
<img src="https://picsum.photos/id/1011/300/200" alt="picture">
<img src="https://picsum.photos/id/1015/300/200" alt="picture">
<img src="https://picsum.photos/id/1016/300/200">
<p> The Kakapo Chalet is a great choice for a medium to large number of guests.</p>
</div>
Grid
Or you may use CSS grid.
.collage {
display: grid;
grid-template-columns: 1fr 1fr;
margin: auto;
width: 70%;
border: 1.5px solid rgba(112, 128, 144, 0.5);
}
.collage img {
box-sizing: border-box;
padding: 20px;
border: 1.5px solid rgba(112, 128, 144, 0.5);
display: inline-block;
max-width: 100%;
}
.collage p {
display: inline-block;
border: 1.5px solid rgba(112, 128, 144, 0.5);
word-break: break-all;
margin: 0;
padding: 20px;
}
<div >
<img src="https://picsum.photos/id/1011/300/200" alt="picture">
<img src="https://picsum.photos/id/1015/300/200" alt="picture">
<img src="https://picsum.photos/id/1016/300/200">
<p> The Kakapo Chalet is a great choice for a medium to large number of guests.</p>
</div>
CodePudding user response:
Just add this css
.collage p {
display: inline-block;
vertical-align: bottom;
}