I am having trouble centering the <p id="locations">Locations</p> .
I am attempting to replicate this webpage. enter image description here
Here is the HTML code that I have:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tea Cozy Project</title>
<!-- <link rel="stylesheet" href="styles.css"> -->
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<!--NAVIGATION-->
<nav class="navigation">
<ul>
<li>Mission</li>
<li>Featured Tea</li>
<li>Locations</li>
</ul>
</nav>
<!--Mission Statement BEGINS-->
<div class="mission">
<div class="statement">
<h2>Our Mission</h2>
<h4>Handpicked, Artisanally Curated, Free Range, Sustainable, Small Batch, Fair Trade, Organic Tea</h4>
</div>
</div>
<!--TEA OF THE MONTH BEGINS-->
<div>
<div class="teaintro">
<h2>Tea of the Month</h2>
<h4>What's Steeping at The Tea Cozy?</h4>
</div>
<br>
<div class="teaofthemonth1" id="teadivs">
<!--TEA IMAGES SET 1-->
<div class="image-container" id="teas">
<img src="images/3BerryBlitz.webp" alt="Berry Blitz" width="300px" height="200px">
<p>Fall Berry Blitz Tea</p>
</div>
<div class="image-container" id="teas" >
<img src="images/8SpicedRum.jpeg" alt="Berry Blitz" width="300px" height="200px">
<p>Spiced Rum Tea</p>
</div>
<div class="image-container" id="teas">
<img src="images/4Donut.jpeg" alt="Seasonal Donuts" width="300px" height="200px">
<p>Seasonal Donuts</p>
</div>
</div>
<div class="teaofthemonth2" id="teadivs">
<div class="image-container" id="teas">
<img src="images/7MyrtleAve.jpeg" alt="Myrtle Ave Tea" width="300px" height="200px">
<p>Myrtle Ave Tea</p>
</div>
<div class="image-container" id="teas">
<img src="images/2BedfordBizarre.jpeg" alt="Bedford Bizarre Tea" width="300px" height="200px">
<p>Bedford Bizarre Tea</p>
</div>
</div>
</div>
<!--LOCATIONS BEGIN-->
<div class="locationbox">
<p id="locations">Locations</p>
<div class="lcnbox">
<h3><b>Downtown</b> <br>
384 West 4th Street <br>
Suite 108 <br>
Portland, Maine <br>
</h3>
</div>
<div class="lcnbox">
<h3><b>East Bayside</b> <br>
3433 Phisherman's Avenue <br>
(Northwest Corner)<br>
Portland, Maine <br>
</h3>
</div>
<div class="lcnbox">
<h3><b>Oakdale</b><br>
515 Crescent Avenue<br>
Second Floor<br>
Portland, Maine <br>
</h3>
</div>
</div>
</div>
<!--CONTACT INFORMATION-->
<div class="teacozy">
<h2>The Tea Cozy</h2>
<h5>[email protected]
<br>
917-555-8904
</h5>
</div>
<!--FOOTER-->
<footer>
<p>copyright The Tea Cozy 2017</p>
</footer>
</body>
</html>
Here is the CSS code that I have:
/* NAVIGSTION SECTION */
li {
display: inline;
text-decoration: underline;
}
/* MISSION SECTION */
.mission {
display: flex;
background-image: url('/images/6Background.webp');
height: 700px;
width: 1200px;
border-bottom: 1px solid seashell;
}
.statement {
background-color: black;
height: 100px;
width: 1200px;
margin-top: 250px;
color: seashell;
font-family: Helvetica;
text-align: center;
}
/* TEA SECTION*/
.teaintro {
text-align: center;
}
.teaofthemonth1,
.teaofthemonth2 {
display: flex;
flex-direction: row; /* Arrange items in a row */
justify-content: center; /* Center items horizontally */
align-items: center; /* Center items vertically */
}
.image-container {
margin: 20px;
}
/* LOCATION SECTION*/
.locationbox {
display: flex;
background-image: url('images/5Locations.webp');
background-size: contain;
}
.locationbox #locations {
display: flex;
flex-direction: row; /* Arrange items in a row */
justify-content: center; /* Center items horizontally */
align-items: center; /* Center items vertically */
}
.lcnbox {
font-family: Helvetica;
text-align: center;
margin: 100px 40px;
color: seashell;
width: 300px;
height: 300px;
background-color: black;
line-height: 3.0;
}
/*TEA COZY CONTACT INFORMATION*/
.teacozy {
margin-left: 500px;
display: block;
justify-content: center;
align-items: center;
flex-wrap: nowrap; /* or wrap, wrap-reverse */
}
I've tried adjusting the display flex to inline and it doesn't work. I've tried adding margin-left to move that text but when I do that it moves all of the items in that specific div.
The positioning of the elements in your code is causing the problem,the easiest way to deal with it is by using a
gridlayout.1.In
htmladd a new<div>which will contain thelcnboxonly. here i added a new<div>withclass="locationbox-inside"which will contain thelcnboxso that its easy to place everything.2.Then in css i changed these:
here i have added many changes:
aspect-ratio property:this will keep the aspect-ratio..lcnboxflexfrom.locationbox #locationsand addedmargin: 15px 0px;only..locationbox-inside:added grid layout and positioned it also addedgrid-gap:40pxas required in the image your provided.gridlayout to.locationboxto position everything perfectly.(by removingflex) also addedplace-items:center(agridproperty) to place everything in the center..locationboxto take the entire height,you could try setting itsheight:100vh;or use any other methods.