Flex items won't wrap and shrink properly - html

I want the flex item on the right to wrap under the image on smaller devices. I would also like both flex items to have the same height with each other when they shrink (along with the browser window).
.new-collection-wrapper {
background-color: #f1f1f1;
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.new-collection-card {
width: 80%;
margin: 5em 0;
display: flex;
align-items: center;
}
.new-collection-card-img img {
height: 400px;
width: auto;
}
.new-collection-content {
height: 400px;
color: #f1f1f1;
background-color: #111111;
padding: 0 3em;
}
.new-collection-content h3 {
font-size: 2.5em;
font-weight: 300;
text-transform: uppercase;
line-height: 1.3;
margin-bottom: .2em;
}
.new-collection-content p {
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: .8em;
letter-spacing: 1px;
}
/* layout for medium screens */
#media screen and (min-width: 810px) {
.new-collection-content {
display: flex;
flex-direction: column;
justify-content: center;
}
}
<main class="new-collection-wrapper">
<section class="new-collection-card">
<div class="new-collection-card-img">
<img src="http://www.petmania.ie/images/default-source/cat/petmania-kitten-1.jpg?sfvrsn=4" alt="new collection" alt="new collection">
</div>
<div class="new-collection-content">
<h3>AW19 collection</h3>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Corporis, a sequi molestias nam odit sunt. Unde dolore fugit suscipit amet.</p>
<span>JOIN</span>
</div>
</section>
<!-- End of New Collection -->
</main>

Change the flex-direction for smaller screens (note that the media query has been changed to #media screen and (max-width: 810px)) on new-collection-card to column - see demo below:
.new-collection-wrapper {
background-color: #f1f1f1;
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.new-collection-card {
width: 80%;
margin: 5em 0;
display: flex;
align-items: center;
}
.new-collection-card-img img {
height: 400px;
width: auto;
}
.new-collection-content {
height: 400px;
color: #f1f1f1;
background-color: #111111;
padding: 0 3em;
}
.new-collection-content h3 {
font-size: 2.5em;
font-weight: 300;
text-transform: uppercase;
line-height: 1.3;
margin-bottom: .2em;
}
.new-collection-content p {
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: .8em;
letter-spacing: 1px;
}
#media screen and (max-width: 810px) {
.new-collection-card { /* change the flex direction */
flex-direction: column;
}
}
<main class="new-collection-wrapper">
<section class="new-collection-card">
<div class="new-collection-card-img">
<img src="http://www.petmania.ie/images/default-source/cat/petmania-kitten-1.jpg?sfvrsn=4" alt="new collection" alt="new collection">
</div>
<div class="new-collection-content">
<h3>AW19 collection</h3>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Corporis, a sequi molestias nam odit sunt. Unde dolore fugit suscipit amet.</p>
<span>JOIN</span>
</div>
</section>
<!-- End of New Collection -->
</main>

Related

My header is going up when scrolling i have already add the position sticky

/* #import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Noto+Serif&family=Roboto:wght#500&display=swap"); */
#import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Kanit&family=Montserrat:ital,wght#1,200&family=Noto+Serif&family=Oswald:wght#300;400&family=Roboto+Mono:ital,wght#0,500;1,400&family=Roboto:ital,wght#1,900&display=swap");
* {
padding: 0;
margin: 0;
font-family: calibri;
box-sizing: border-box;
}
html {
font-size: 62.5%;
height: 100%;
scroll-behavior: smooth !important;
}
body {
line-height: 1.4;
font-weight: 300;
position: relative;
font-size: 1.6rem;
height: fit-content;
}
.container {
max-width: 120rem;
margin: 0 auto;
padding: 0 2rem;
}
header {
background-color: #3498db;
position: sticky;
top: 0;
z-index: 100;
box-shadow: 0.5rem 0.5rem 0.5rem rgba(0, 0, 0, 0.5);
/* width: 100%; */
/* min-height: 100%; */
}
ul {
list-style: none;
}
a {
text-decoration: none;
color: black;
font-weight: 40rem;
font-size: 2ren;
}
nav {
display: flex;
justify-content: space-between;
place-items: center;
/* height: 15vh; */
}
nav ul {
display: flex;
flex-direction: row;
gap: 2.2rem;
}
nav ul li {
border-bottom: 0.2rem solid transparent;
transition: 0.2s ease-in;
}
nav ul li:hover {
border-bottom: 0.2rem solid #1b0058;
transition: 0.2s ease-in;
}
.logo {
font-size: 3rem;
font-family: "Noto Serif", serif;
}
.hero-section {
grid-template-columns: repeat(3, 1fr);
background-image: url(../images/Red\ background.jpg);
background-position: center;
background-size: cover;
min-height: 100vh;
width: 100%;
color: white;
}
.hero-section-data {
padding-left: 7rem;
padding-top: 7.5rem;
padding-right: 5rem;
}
.hero-section .container {
display: flex;
justify-content: space-between;
place-items: center;
flex-direction: row;
padding: 3rem 1rem;
flex-direction: row;
}
.hero-section-data h1 {
font-size: 5rem;
font-weight: 500;
line-height: 1.2;
}
.hero-section-data p {
margin: 2rem 0;
padding-bottom: 2rem;
font-size: 1.8rem;
}
.hero-section button {
padding: 1rem 1rem;
background: orange;
border-radius: 1rem;
}
.hero-section button:hover {
color: white;
transition: 0.3s ease-in;
/* transform: scale(1.2) translateY(10px); */
}
.hero-section .image img {
width: 200rem;
max-width: 100%;
position: relative;
left: 5rem;
}
.features-section {
padding-top: 3rem;
background-color: #9df9ef;
width: 100%;
}
.features-section .container {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.features-section h2 {
padding-bottom: 2rem;
}
.features-section h3 {
font-family: "Oswald", sans-serif;
padding-bottom: 2rem;
font-size: 5rem;
}
.features-section h5 {
padding-bottom: 2rem;
}
.features-section button {
padding: 0.5rem 1.5rem;
background-color: crimson;
color: white;
font-size: 20px;
}
.features-section button:hover {
opacity: 0.8;
transition: 0.3s ease-in;
}
.features-watch img {
width: 50rem;
max-width: 100%;
position: relative;
margin-top: -29rem;
top: 29rem;
right: 1rem;
}
.comfortable .container {
display: flex;
flex-direction: column;
padding-top: 30rem;
gap: 3rem;
text-align: center;
place-items: center;
}
.comfortable h3 {
font-size: 3rem;
}
.comfortable button {
margin-top: 1rem;
padding: 0.5rem 1.5rem;
background-color: #3498db;
color: white;
font-size: 2rem;
cursor: pointer;
}
.comfortable button:hover {
opacity: 0.8;
transition: 0.3s ease-in;
}
.comfortable img {
margin-top: 10rem;
max-width: 100%;
}
.fitness {
background-image: url(../images/fitness.jpg);
background-size: cover;
background-position: center;
min-height: 100vh;
margin-top: 7.5rem;
width: 100%;
}
.fitness .container {
flex-direction: column;
display: flex;
color: white;
padding: 10rem 0;
justify-content: center;
align-items: center;
text-align: center;
}
.fitness h3 {
font-size: 6.2rem;
padding-bottom: 1rem;
}
.fitness p {
font-size: 2rem;
}
.last-btn {
padding: 0.5rem 1.5rem;
background-color: #3498db;
color: white;
font-size: 2rem;
}
.last-btn:hover {
opacity: 0.8;
transition: 0.3s ease-in;
}
.stock-section {
display: flex;
justify-content: center;
margin: 5rem 0;
gap: 3rem;
}
.stock img {
width: 40rem;
max-width: 100%;
}
.stock-content {
display: flex;
flex-direction: column;
gap: 2rem;
}
.stock-content h3 {
font-size: 3rem;
}
.stock-content button {
place-self: start;
}
.footer-upper {
background-color: #4169e1;
padding: 2.5rem;
}
.footer-upper .container {
display: flex;
color: black;
justify-content: space-between;
}
.footer-upper h4 {
font-size: 2rem;
/* margin-top: -5px; */
border-bottom: 0.2rem solid #1b0058;
margin-bottom: 1rem;
position: relative;
padding-top: 0.5rem;
top: -1rem;
}
.footer-upper ul {
font-size: 2rem;
}
.footer-lower {
padding: 1rem;
background-color: #000080;
display: flex;
justify-content: center;
font-size: 2rem;
color: white;
}
.menu-bar {
display: none;
}
/* Media Queries */
#media (max-width: 768px) {
html {
font-size: 40%;
}
nav ul {
display: none;
}
.menu-bar i {
font-size: 2.4rem;
}
.menu-bar {
display: block;
}
/* Footer */
.footer-upper .container {
display: flex;
flex-wrap: wrap;
gap: 2rem;
}
.footer-upper .footer-links {
width: 15rem;
}
.hero-section-data p {
font-size: 3rem;
/* font-weight: 500;
line-height: 1.2; */
}
}
#media (max-width: 1024px) {
.hero-section .container {
display: flex;
/* justify-content: space-between;
place-items: center;
flex-direction: row;
padding: 3rem 1rem; */
flex-direction: column;
}
.logo {
padding-left: 2rem;
}
}
/* #media (max-width: 425px) {
.features-watch img {
margin-top: 20rem;
top: 20rem;
}
} */
#media (max-width: 1360px) {
nav ul {
padding-right: 2rem;
}
}
#media (max-width: 1305px) {
nav ul {
padding-right: 3rem;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Watch Website</title>
<link rel="StyleSheet" href="Css/Style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
/>
<!-- Font awesome link -->
<script
src="https://kit.fontawesome.com/a2e94f730a.js"
crossorigin="anonymous"
></script>
</head>
<body>
<header>
<nav class="container">
<div class="logo">Watch</div>
<div class="menu-bar">
<i class="fa-solid fa-bars"></i>
</div>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
<!-- menu button -->
</nav>
</header>
<main>
<section class="hero-section" id="hero">
<div class="container">
<div class="hero-section-data">
<h1>
Get your watch <br />
now!
</h1>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Error ex
ullam in, officiis modi sequi adipisci sed inventore molestias
numquam. Lorem ipsum dolor sit amet consectetur adipisicing elit.
Accusantium, ex?
</p>
<button>Order Now</button>
</div>
<div class="image">
<img src="images/smart_watch-removebg-preview.png" alt="" />
</div>
</div>
</section>
<section class="features-section" id="features">
<div class="container">
<div class="features-content">
<h2>Presenting</h2>
<h3>Apple Watch Series 9</h3>
<h5>
Presenting to you the most luxurious watch of the world with
unlimited features, which makes you'r life more easier.Available
in different colors- Features and much more. You can Detects if
you’ve been in a severe car crash, automatically connects you to
emergency services, and notifies your emergency contacts.
</h5>
<button>Visit More</button>
<div class="features-watch">
<img src="images/features watch.png" alt="" />
</div>
</div>
</div>
</section>
<section class="comfortable" id="comfortable">
<div class="container">
<h3>
Makes Your Life More Comfortable And Get Acess To The Wonderfull
Features
</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe earum
ipsum facilis nemo excepturi quaerat blanditiis fugiat atque, eius
quia libero nulla quis repellat, pariatur distinctio illo explicabo
totam dolores.
</p>
<button class="read-more">Read More</button>
<img src="images/threewatch.png" alt="" />
</div>
</section>
<section class="fitness" id="connect">
<div class="container">
<h3>Get your watch today!</h3>
<p>
Connectivity on your terms. The ultimate wearables experience.<br />
Always connected… and it’s beautiful.It’s time to step up your style
with a smartwatch that looks great with every outfit.
</p>
</div>
</section>
<section class="stock-section container" id="fitness">
<div class="stock-img">
<img src="images/stock.png" alt="" />
</div>
<div class="stock-content">
<h3>In Stock!</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam<br />
accusantium temporibus pariatur ab nemo,Lorem ipsum dolor, sit amet
consectetur adipisicing elit. Dolorem, debitis. Blanditiis libero ad
animi nam dolorem provident suscipit labore eligendi.
</p>
<p>
If you have any query about the "Apple Watch Series" so you can
contact our team.
</p>
<hr />
<button class="last-btn">Buy Now</button>
</div>
</section>
</main>
<footer>
<section class="footer-upper">
<div class="container">
<div class="footer-links">
<h4>Shop & Learn</h4>
<ul>
<li>Features</li>
<li>Pricing</li>
<li>Info</li>
<li>Apps</li>
<li>Connection</li>
</ul>
</div>
<div class="footer-links">
<h4>Our Branches</h4>
<ul>
<li>Pakistan</li>
<li>India</li>
<li>Usa</li>
<li>Nepal</li>
<li>Bangladesh</li>
</ul>
</div>
<div class="footer-links">
<h4>Why us?</h4>
<ul>
<li>Genuine Products</li>
<li>Accuracy</li>
<li>Discounts</li>
<li>Delivery</li>
<li>Gift Cards</li>
</ul>
</div>
<div class="footer-links">
<h4>Brands</h4>
<ul>
<li>Apple</li>
<li>Mi</li>
<li>Samsung</li>
<li>Huawei</li>
<li>Honor</li>
</ul>
</div>
</div>
</section>
<section class="footer-lower">
<p>All rights reserved #AnasSiddiqui 2022</p>
</section>
</footer>
</body>
</html>
My header is going up when scrolling. I have already add the position sticky. Its work fine for the desktop but when i switch on the mobile devices by clicking the inspect button when i scroll down the header goes up i am finding the answers since many days.
I want the header to go down with the scroll especially in mobile devices.

How to get second column in a row to go on top of the first column when the page shrinks using html/css?

below you'll see I have a div container that holds one row with two columns of equal width and height. The image is on the left side and the text is on the right. I'm currently using #media so that when the screen reaches a certain width, both columns will go on top of each other and they'll be one column. My question is, is there any way to make the second column go above the first column when my #media activates instead of vice-versa? Thanks in advance.
<div class="resources-flex-container" >
<div class="resources-img-section">
<img src="../images/resources.png" alt="" class="resources-img">
</div>
<div class="resources-main-content">
<p class="resources-section-title">Lorem Ipsum Dolor Sit</p>
<p class="resources-section-description">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla quibusdam rerum, saepe exercitationem earum quas architecto, autem, accusantium facere aliquam repellat minus quia quis eum ad? Cupiditate, corporis quae? Libero!
</p>
</div>
</div>
CSS
.resources-flex-container {
padding-left: 5%;
padding-right: 5%;
background-color: rgb(238,43,42, .15);
align-items: center;
padding-top: 2%;
padding-bottom: 2%;
}
#media (min-width: 56.25em){
.resources-flex-container {
display: flex;
}
}
.resources-main-content {
flex: 1;
padding: 20px;
border-radius: 12px;
}
.resources-section-title {
font-size: 30px;
font-weight: 600; text-align: center;
}
.resources-section-description {
font-size: 1.125rem;
}
.resources-button-section {
text-align: center;
}
.resources-button {
color:white;
width: 270px;
font-weight: 500;
background-color: #CE4A4A;
border-radius: 50px;
font-size: 1.75rem;
text-align: center;
text-decoration: none;
padding-top: .7%;
padding-bottom: .7%;
padding-right: 5%;
padding-left: 5%;
border: 0;
}
.resources-img-section {
flex: .75 0 300px;
padding: 20px;
border-radius: 12px;
}
.resources-img {
display: block;
margin-left: auto;
margin-right: auto;
width: 70%;
height: 80%;
border-radius: 10px;
box-shadow: 0px 0px 5px black;
}
You can add flex-direction: column-reverse; property in #media query class according to your min-width and max-width
h1, h2 {
font-family: Lato;
}
.resources-flex-container {
padding-left: 5%;
padding-right: 5%;
background-color: rgb(238,43,42, .15);
align-items: center;
padding-top: 2%;
padding-bottom: 2%;
display: flex;
flex-direction: row;
}
#media screen and (min-width: 56.25em ){
.resources-flex-container {
display: flex;
flex-direction: column-reverse;
}
}
#media screen and (max-width: 600px) {
.resources-flex-container {
display: flex;
flex-direction: column-reverse;
}
}
#media screen and (min-width: 601px) {
.resources-flex-container {
display: flex;
flex-direction: row;
}
}
.resources-main-content {
flex: 1;
padding: 20px;
border-radius: 12px;
}
.resources-section-title {
font-size: 30px;
font-weight: 600; text-align: center;
}
.resources-section-description {
font-size: 1.125rem;
}
.resources-button-section {
text-align: center;
}
.resources-button {
color:white;
width: 270px;
font-weight: 500;
background-color: #CE4A4A;
border-radius: 50px;
font-size: 1.75rem;
text-align: center;
text-decoration: none;
padding-top: .7%;
padding-bottom: .7%;
padding-right: 5%;
padding-left: 5%;
border: 0;
}
.resources-img-section {
flex: .75 0 300px;
padding: 20px;
border-radius: 12px;
}
.resources-img {
display: block;
margin-left: auto;
margin-right: auto;
width: 70%;
height: 80%;
border-radius: 10px;
box-shadow: 0px 0px 5px black;
}
<div class="resources-flex-container" >
<div class="resources-img-section">
<img src="../images/resources.png" alt="" class="resources-img">
</div>
<div class="resources-main-content">
<p class="resources-section-title">Lorem Ipsum Dolor Sit</p>
<p class="resources-section-description">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla quibusdam rerum, saepe exercitationem earum quas architecto, autem, accusantium facere aliquam repellat minus quia quis eum ad? Cupiditate, corporis quae? Libero!
</p>
</div>
</div>

Why are my heading elements overlapping on small screens?

I am new to frontend dev. When I reduce the browser window size the layout breaks. Elements overlap each other and height of section changes etc.
Here is my HTML code in which I have made a navbar and a section in which I created 3 items.
#import url('https://fonts.googleapis.com/css2?family=Dancing+Script&family=Lobster&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Dancing+Script&family=Lobster&family=Varela+Round&display=swap');
* {
margin: 0;
padding: 0;
}
ul li {
list-style-type: none;
text-decoration: none;
}
#navbar {
display: flex;
align-items: center;
position: relative;
top: 0;
/* justify-content: center; */
}
#navbar::before {
content: "";
background-color: black;
position: absolute;
height: 100%;
width: 100%;
z-index: -1;
opacity: 0.4;
}
/* Logo */
#logo {
margin: 10px 34px;
}
/* Logo and Image */
#logo img {
margin: 3px 6px;
height: 56px;
}
#navbar ul {
display: flex;
font-size: 1.3rem;
}
#navbar ul li a {
text-decoration: none;
display: block;
padding: 3px 23px;
border-radius: 20px;
color: white;
}
#navbar ul li a:hover {
background-color: white;
color: black;
}
/* Home section */
#home {
display: flex;
flex-direction: column;
padding: 3px 200px;
height: 278px;
justify-content: center;
align-items: center;
font-family: 'Lobster', cursive;
}
#home::before {
content: "";
background: url('../bg1.jpg') no-repeat center center/cover;
position: absolute;
height: 56%;
width: 100%;
z-index: -1;
opacity: 0.89;
top: 0px;
left: 0px;
}
#home h1 {
color: white;
text-align: center;
}
#home p {
color: white;
text-align: center;
font-size: 1.5rem;
}
.h-primary {
font-size: 3.8rem;
padding: 12px;
font-family: 'Varela Round', sans-serif;
}
.h-secondary {
font-size: 2.2rem;
padding: 12px;
font-family: 'Varela Round', sans-serif;
}
.h-tertiary {
font-size: 0.9rem;
padding: 12px;
font-family: 'Varela Round', sans-serif;
}
#services {
margin: 110px 0;
margin-left: 20px;
margin-right: 20px;
display: flex;
}
#services .box {
border: 2px solid brown;
padding: 20px;
margin: 3px 6px;
border-radius: 20px;
background-color: rgb(236, 229, 229);
}
#services .box img {
display: block;
height: 171px;
margin: auto;
}
.btn {
padding: 6px 20px;
border: 2px solid white;
background-color: brown;
color: white;
margin: 17px;
font-size: 1.5rem;
border-radius: 10px;
cursor: pointer;
}
.center {
text-align: center;
}
<nav id="navbar">
<div id="logo">
<img src="logo.png" alt="">
</div>
<ul>
<li class="items">Home</li>
<li class="items">Service</li>
<li class="items">About</li>
<li class="items">Contact</li>
</ul>
</nav>
<section id="home">
<h1 class="h-primary">Welcome to Myonline meal</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Voluptatem aperiam quaerat cumque consequatur quasi
</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Debitis consequatur </p>
<button class="btn">Order Now</button>
</section>
<section class="services-container">
<h1 class="h-primary center">Our Service</h1>
<div id="services">
<div class="box">
<img src="img/1.png" alt="">
<h2 class="h-secondary center">Food Ordering</h2>
<p class="center h-tertiary">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium quia atque, corrupti</p>
</div>
<div class="box">
<img src="img/2.png" alt="">
<h2 class="h-secondary center">Food Ordering</h2>
<p class="center h-tertiary">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium quia atque, corruptir</p>
</div>
<div class="box">
<img src="img/3.png" alt="">
<h2 class="h-secondary center">Food Ordering</h2>
<p class="center h-tertiary">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium quia atque, corruptir</p>
</div>
</div>
</section>
You should learn about responsiveness, when you make a website, it usually looks different on different screen sizes and devices, and in order to make it look better on smaller screens, you need to style your page differently according to the device's size, for example using media queries.
In your case you mostly use px unit to set sizes for margins, paddings and such in your css, but there are better units that are described as relative, such as %, em and rem.
You can learn more about all this just googling or watching tutorials, but in short, percentage unit is relative to the parent's size, em is relative to this element's font-size, and rem is relative to the root font-size (html tag) which is usually 16px, so for example if you set a font-size on a div of 3rem, that would mean 3 * 16px, which is 48px, but the difference between saying 3rem and just 48px, is that in some cases 3rem might become smaller or larger depending on the device or any other factor.
div {
display: flex;
flex-direction: column;
align-items: start;
margin: 1em 0;
}
.small button {
font-size: 16px;
}
.big button {
font-size: 48px;
}
.non-relative {
padding: 8px 16px;
}
.relative {
padding: 0.5em 1em;
}
<div class="small">
<button class="non-relative">Non-Relative</button>
<button class="relative">Relative</button>
</div>
<div class="big">
<button class="non-relative">Non-Relative</button>
<button class="relative">Relative</button>
</div>
Here you can see that, when I set the button's padding with px, it stays the same no matter the font size, but with the em unit, it will be relative to it, so proportionally it will be the same as the smaller version. Hope this is a good enough example, I am kind of sleepy and might've missed something, but hope this helps you!

Center div under section [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
I don't know what i'm missing here but i can't seem to center my div under a section. Whenever i try to put a margin on the div alone, it also applies a margin to the section tag.
What i want to do is very simple. Put <div class="container"> on the center of the <section id="main">, so the <div class="container"> has space at every side.
Here is my HTML code:
<body>
<section id="main">
<div class="container">
<nav><h2>ALEX\ALBARAN</h2><img src="icon_back.png"></nav><br><br><br>
<div class="box-1">
<h1> HELLO! I'M ALEX</h1>
</div> <br><br>
<div class="box-2">
<h3> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique inventore ipsa optio velit, neque, itaque quasi fugiat impedit libero, vitae temporibus? Quisquam libero voluptas, excepturi non fugiat, perferendis laborum magni!</h3><br><br>
</div>
<div class=box-3>
<i class="fas fa-arrow-circle-down"></i>
</div>
</div>
</section>
and here is my CSS code:
nav {
display: flex;
justify-content: space-between;
}
h2 {
font-family: 'Questrial', sans-serif;
font-weight: 200;
font-size: 15px;
color: white;
}
img {
width:40px;
height: 40px;
align-items: flex-end;
}
#main {
background-color: aqua;
font-family: 'Roboto', sans-serif;
font-weight: 100;
}
.container {
background-image:url(bg1.png);
background-repeat: no-repeat;
background-size: cover;
width: 80%;
justify-content: center;
text-align: center;
margin: 10% 10%;
}
.box-1 {
border: 3px solid white;
background-color: transparent;
color: white;
width: 50%;
padding: auto;
margin: auto;
text-align: center;
}
.box-2 {
font-size: 10px;
font-weight: 100;
color: white;
background-color: transparent;
width: 50%;
padding:auto;
margin:auto;
text-align: center;
}
.box-3 {
text-align: center;
color: white;
padding-bottom: 20px;
}
You can use display:flex on main div. Then center .container.
Here is a simplified snippet:
#main {
background-color: aqua;
font-family: 'Roboto', sans-serif;
font-weight: 100;
display: flex;
align-items: center;
justify-content: center;
height: 300px;
}
.container {
border: 1px solid red;
width: 80%;
height: 80px
}
<section id="main">
<div class="container">
</div>
</section>
To center your div, here are the attributes you have to add in the CSS:
.centered-div {
margin: 0 auto;
width: 80%; // specifies a custom width
}
The problem was the margin: 10% 10%. Replace it with the auto margin and the result will be this (run the snippet to see your HTML page displayed):
nav {
display: flex;
justify-content: space-between;
}
h2 {
font-family: 'Questrial', sans-serif;
font-weight: 200;
font-size: 15px;
color: white;
}
img {
width:40px;
height: 40px;
align-items: flex-end;
}
#main {
background-color: aqua;
font-family: 'Roboto', sans-serif;
font-weight: 100;
}
.container {
background-image:url(bg1.png);
background-repeat: no-repeat;
background-size: cover;
width: 80%;
justify-content: center;
text-align: center;
margin: 0 auto; ############# HERE IS THE MODIFIED LINE #############
}
.box-1 {
border: 3px solid white;
background-color: transparent;
color: white;
width: 50%;
padding: auto;
margin: auto;
text-align: center;
}
.box-2 {
font-size: 10px;
font-weight: 100;
color: white;
background-color: transparent;
width: 50%;
padding:auto;
margin:auto;
text-align: center;
}
.box-3 {
text-align: center;
color: white;
padding-bottom: 20px;
}
<body>
<section id="main">
<div class="container">
<nav><h2>ALEX\ALBARAN</h2><img src="icon_back.png"></nav><br><br><br>
<div class="box-1">
<h1> HELLO! I'M ALEX</h1>
</div> <br><br>
<div class="box-2">
<h3> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique inventore ipsa optio velit, neque, itaque quasi fugiat impedit libero, vitae temporibus? Quisquam libero voluptas, excepturi non fugiat, perferendis laborum magni!</h3><br><br>
</div>
<div class=box-3>
<i class="fas fa-arrow-circle-down"></i>
</div>
</div>
</section>
By the way, you forgot to close your <body>.

Images being squished in safari mobile

Forgive my if my html and css is bad this is my first page im doing alone. I have been working on this issue for atleast 3 hours I have my index page complete looks halfway decent but when I commit it to github and view it on my sons iphone the images look squished and the aspect ratio is off. If I can have any help thanks in advance!!
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA Compatible" content="ie=edge" />
<link rel="stylesheet" href="css/stylesheet.css" />
<title>RealtorsRUs</title>
</head>
<body>
<!-- Begin Navbar -->
<header class="hero">
<div id="navbar" class="navbar">
<h1 class="logo">
MReality
</h1>
<nav>
<ul>
<li>
<a class="current" href="index.html">Home</a></li>
<li>
About Us</li>
<li>
Contact Us</li>
</ul>
</nav>
</div>
<!-- End Navbar -->
<div class="content">
<h1>Welcome Home</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque vero
excepturi dolore sequi quibusdam nostrum aperiam voluptatum nihil
deserunt explicabo!
</p>
Read More
</div>
</header>
<main>
<!-- Begin Featured Listings -->
<section class="featuredlistings">
<h2>Featured Listings</h2>
<div class="flex-row">
<div class="item1">
<img
src="images/evelyn-paris-XJnP4L958ds-unsplash.jpg"
alt="Home"
/>
</div>
<div class="item2">
<img
src="images/jesse-roberts-561igiTyvSk-unsplash.jpg"
alt="Home"
/>
</div>
<div class="item3">
<img
src="images/daniel-barnes-RKdLlTyjm5g-unsplash.jpg"
alt="Home"
/>
</div>
</section>
<article id="section-1" class="flex-row-article">
<div class="article-1">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore mollitia, ipsa neque aliquid quod similique consequatur accusantium harum facere natus. Omnis blanditiis incidunt nobis similique reprehenderit illo quaerat, sed ad reiciendis fugit sequi molestias, inventore, exercitationem consectetur soluta. Quibusdam quod laborum eaque, perferendis fugit similique dolorem ipsum mollitia sunt incidunt?
</p>
</div>
<div class="article-2">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquam ut dignissimos vitae voluptatum, obcaecati quidem, eaque, amet cum illo eos numquam iste officiis quia aspernatur animi dicta consectetur nulla eligendi! Laboriosam quas sunt dolor dignissimos illo at porro asperiores, earum, cum sapiente voluptates nemo animi dolore repellat libero cupiditate nulla?
</p>
</div>
</article>
</main>
<footer id="mainfooter">
<p>MReality © 2020, All Rights Reserved</p>
</footer>
</body>
</html>
enter code here
css
* {
box-sizing: border-box;
padding: 0;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.btn {
cursor: pointer;
display: inline-block;
padding: 10px 60px;
color: #fff;
border: none;
border-radius: 5px;
background-color: #333;
font-size: 20px;
opacity: .95;
}
.flex-row {
display: flex;
text-align: center;
justify-content: center;
}
.flex-row div{
margin: 5px;
display: flex;
}
.flex-row h3{
font-size: 3rem;
}
.flex-row-article {
display: flex;
text-align: center;
justify-content: center;
flex-direction: column;
}
body {
background: #f9f9f9;
color: #333;
line-height: 1.6;
}
ul {
list-style: none;
}
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
background-color: #333;
color: #fff;
height: 50px;
width: 100%;
padding: 5px;
position: fixed;
top: 0px;
opacity: 0.9;
z-index: 2;
}
.navbar a {
color: #fff;
padding: 10px 10px;
margin: 0 5px;
}
.navbar a:hover {
border-bottom: #fff 2px solid;
}
.navbar ul {
display: flex;
position: sticky;
top: 0;
}
img {
max-width: 100%;
}
.logo{
font-size: 1.5rem;
}
a {
text-decoration: none;
color: #333;
}
.hero-aboutus {
background: url("../images/roger-starnes-sr-BNY7m7BhS2o-unsplash.jpg") no-repeat center
center/cover;
height: 100vh;
text-align: center;
}
.hero-contactus {
background: url("../images/bailey-anselme-Bkp3gLygyeA-unsplash\ \(2\).jpg")
no-repeat center center/cover;
height: 100vh;
text-align: center;
background-position-y: 40%;
}
.hero {
background: url("../images/francesca-tosolini-XAHSexPxSus-unsplash\ \(1\).jpg")
no-repeat center center/cover;
height: 100vh;
text-align: center;
position: relative;
width: 100%;
overflow: hidden;
}
.hero .content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
height: 100%;
color: #fff;
}
.hero .content h1 {
font-size: 3rem;
z-index: 1;
}
.hero .content p {
font-size: 1.5rem;
width: 100%;
margin: 10px 30px;
padding: 0 20px;
z-index: 1;
}
.hero:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.1);
}
.featuredlistings h2{
text-align: center;
font-size: 2rem;
margin: 5px;
padding: 10px;
}
.article-1 p, .article-2 p{
margin: 0 auto;
padding: 10px;
text-align: center;
font-size: 1.5rem;
width: 50%;
}
#mainfooter p{
text-align: center;
background: #333;
color: #fff;
padding: 20px;
}
#media(max-width: 768px) {
.navbar {
flex-direction: column;
height: 80px;
padding: 20px;
z-index: 100;
align-items: center;
justify-content: center;
}
.navbar a {
padding: 10px 10px;
margin: 0 3px;
}
.flex-row{
flex-wrap: wrap;
}
.featuredlistings h2{
text-align: center;
font-size: 2rem;
}
.article-1 p, .article-2 p{
margin: 0 auto;
padding: 10px;
text-align: center;
font-size: 1.5rem;
width: 100%;
}
img{
flex: 1;
}
.flex-row .item1 .item2 .item3{
Your problem may be fairly easy to solve. May be, as I am not on Safari, but IE11 seems to have the same problem.
Solution
img: { max-width: 100% } should be img: { width: 100% }. Because element width and height are CSS default auto, which means that the browser will try to fill all the space available with the image, fully disregarding its ratio (it stretches in every direction). width: 100% (OR height: 100%, not both!) will make sure that images fill the full width (OR height) of the available space and size its height (OR width) to ratio.
#media screen and (max-width: 768px) { .... img { flex: 1 } .... } should become #media screen and (max-width: 768px) { .... img { flex-grow: 1 } .... }. Especially IE11 cannot handle the shorthand property flex very well, so you need the individual properties instead CSS flex Property. I am not sure, but Safari may have the same problem (may need the vendor prefix -webkit-).
Before, IE11 did not show the images at all with a browser window smaller than 768px and did not preserve the image ratios when resizing, but with my changes everything works as expected. Hopefully, Safari too!
BTW Chrome, Edge and Firefox did not show the problem on W10.
The snippet (code copied from your Github site) with the two changes.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.btn {
cursor: pointer;
display: inline-block;
padding: 10px 60px;
color: #fff;
border: none;
border-radius: 5px;
background-color: #333;
font-size: 20px;
opacity: 0.95;
}
.flex-row {
display: flex;
text-align: center;
justify-content: center;
}
.flex-row div {
margin: 5px;
display: flex;
}
.flex-row h3 {
font-size: 3rem;
}
.flex-row-article {
display: flex;
text-align: center;
justify-content: center;
flex-direction: column;
}
body {
background: #f9f9f9;
color: #333;
line-height: 1.6;
}
ul {
list-style: none;
}
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
background-color: #333;
color: #fff;
height: 50px;
width: 100%;
padding: 5px;
position: fixed;
top: 0px;
opacity: 0.9;
z-index: 2;
}
.navbar a {
color: #fff;
padding: 10px 10px;
margin: 0 5px;
}
.navbar a:hover {
border-bottom: #fff 2px solid;
}
.navbar ul {
display: flex;
position: sticky;
top: 0;
}
.navbar h1 {}
img {
/* max-width: 100%;/* REMOVED */
width: 100%;
}
.logo {
font-size: 1.5rem;
position: relative;
}
a {
text-decoration: none;
color: #333;
}
.hero-aboutus {
background: url("https://amolina0116.github.io/MyProjects/realtorsite/images/roger-starnes-sr-BNY7m7BhS2o-unsplash.jpg") no-repeat center center/cover;
height: 100vh;
text-align: center;
}
.hero-contactus {
background: url("https://amolina0116.github.io/MyProjects/realtorsite/images/bailey-anselme-Bkp3gLygyeA-unsplash\ \(2\).jpg") no-repeat center center/cover;
height: 100vh;
text-align: center;
background-position-y: 40%;
}
.hero {
background: url("https://amolina0116.github.io/MyProjects/realtorsite/images/francesca-tosolini-XAHSexPxSus-unsplash\ \(1\).jpg") no-repeat center center/cover;
height: 100vh;
text-align: center;
position: relative;
width: 100%;
overflow: hidden;
}
.hero .content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
height: 100%;
color: #fff;
}
.hero .content h1 {
font-size: 3rem;
z-index: 1;
}
.hero .content p {
font-size: 1.5rem;
width: 100%;
margin: 10px 30px;
padding: 0 20px;
z-index: 1;
}
.hero:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.1);
}
.featuredlistings h2 {
text-align: center;
font-size: 2rem;
margin: 5px;
padding: 10px;
}
.article-1 p,
.article-2 p {
margin: 0 auto;
padding: 10px;
text-align: center;
font-size: 1.5rem;
width: 50%;
}
#mainfooter {
height: 50px;
background: #333;
text-align: center;
color: #fff;
width: 0 auto;
display: flex;
align-items: center;
justify-content: center;
}
#mainfooter p {}
.ourteam {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
color: #fff;
}
.fred {
background: #333;
opacity: 0.9;
margin: 5px;
padding: 10px;
/* height: ; /**/
}
.fred img {
height: 200px;
border-radius: 50%;
}
.sammy {
background: #333;
opacity: 0.9;
margin: 5px;
padding: 10px;
}
.sammy img {
border-radius: 50%;
}
.box {
display: flex;
align-items: center;
text-align: center;
justify-content: center;
align-content: center;
height: 100%;
background: #333;
color: #fff;
padding: 10px;
}
.box1 {
border-right: black solid 1px;
width: 33.3%;
}
.box2 {
width: 33.3%;
}
.box3 {
border-left: black solid 1px;
width: 33.3%;
}
input[type="text"],
select,
textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type="submit"] {
background-color: #4caf50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
position: relative;
top: 30%;
opacity: 0.85;
margin: 0 30%;
}
.contactform {
height: 60vh;
}
#subject {
height: 100px;
}
#media screen and (max-width: 768px) {
#icons {
display: none;
}
.contactform {
width: 100%;
line-height: 0.5;
}
.container {
margin: 0 auto;
top: 80px;
}
.fred {
position: relative;
top: 40px;
}
.navbar {
flex-direction: column;
height: 80px;
padding: 20px;
z-index: 100;
align-items: center;
justify-content: center;
}
.flex-row {
flex-wrap: wrap;
}
.featuredlistings h2 {
text-align: center;
font-size: 2rem;
}
.article-1 p,
.article-2 p {
margin: 0 auto;
padding: 10px;
text-align: center;
font-size: 1.5rem;
width: 100%;
}
img {
flex-grow: 1;
/* MODDED, was flex: 1 */
}
.fred img {
height: 80px;
}
}
.sammy img {}
<!-- Begin Navbar -->
<header class="hero">
<div id="navbar" class="navbar">
<h1 class="logo">
MReality
</h1>
<nav>
<ul>
<li>
<a class="current" href="index.html">Home</a>
</li>
<li>
About
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
<!-- End Navbar -->
<div class="content">
<h1>Welcome Home</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque vero excepturi dolore sequi quibusdam nostrum aperiam voluptatum nihil deserunt explicabo!
</p>
Read More
</div>
</header>
<main>
<!-- Begin Featured Listings -->
<section class="featuredlistings">
<h2>Featured Listings</h2>
<div class="flex-row">
<div class="item1">
<img src="https://amolina0116.github.io/MyProjects/realtorsite/images/evelyn-paris-XJnP4L958ds-unsplash.jpg" alt="Home" />
</div>
<div class="item2">
<img src="https://amolina0116.github.io/MyProjects/realtorsite/images/jesse-roberts-561igiTyvSk-unsplash.jpg" alt="Home" />
</div>
<div class="item3">
<img src="https://amolina0116.github.io/MyProjects/realtorsite/images/daniel-barnes-RKdLlTyjm5g-unsplash.jpg" alt="Home" />
</div>
</div>
</section>
<article id="section-1" class="flex-row-article">
<div class="article-1">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore mollitia, ipsa neque aliquid quod similique consequatur accusantium harum facere natus. Omnis blanditiis incidunt nobis similique reprehenderit illo quaerat, sed ad reiciendis fugit sequi
molestias, inventore, exercitationem consectetur soluta. Quibusdam quod laborum eaque, perferendis fugit similique dolorem ipsum mollitia sunt incidunt?
</p>
</div>
<div class="article-2">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquam ut dignissimos vitae voluptatum, obcaecati quidem, eaque, amet cum illo eos numquam iste officiis quia aspernatur animi dicta consectetur nulla eligendi! Laboriosam quas sunt dolor dignissimos
illo at porro asperiores, earum, cum sapiente voluptates nemo animi dolore repellat libero cupiditate nulla?
</p>
</div>
</article>
</main>
<footer id="mainfooter">
<p>MReality © 2020, All Rights Reserved</p>
</footer>