Maintain aspect ratio in horizontal flex card - html

I am able to make a vertical flex card with an image on top and it will maintain 16:9 aspect ratio always. My vertical flex card code
.card {
display: flex;
flex-direction: column;
margin: 0.75rem;
}
.card .card-img {
position: relative;
padding-bottom: 56.25%;
}
.card .card-img img {
position: absolute;
object-fit: cover;
width: 100%;
height: 100%;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.card .card-body {
margin-bottom: 0.75rem;
display: flex;
flex-direction: column;
}
.card .card-body a {
text-decoration: none;
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
color: #3e3700;
font-weight: 500;
}
.card .card-body .card-title {
font-size: clamp(1.125rem, 0.5133rem + 1.699vw, 2rem);
font-weight: 500;
line-height: 1;
}
.card .card-body .card-description {
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
font-weight: 300;
margin-bottom: 0.75rem;
}
<div class="card">
<div class="card-img">
<img
src="https://via.placeholder.com/150"
alt="img"
/>
</div>
<div class="card-body">
<h2 class="card-title">
Lorem ipsum dolor sit, amet consectetur
adipisicing elit. Ratione, cumque?
</h2>
</div>
</div>
But I want to make it horizontal and I am stuck. Whenever I change the flex-direction to row flex-direction: row; it does not work. I always want the image to be in a 16:9 aspect ratio. My progress
.card {
display: flex;
flex-direction: row;
margin: 0.75rem;
}
.card.card-h .card-img {
width: 40%;
}
.card.card-h .card-body {
width: 60%;
}
.card .card-img {
position: relative;
padding-bottom: 56.25%;
}
.card .card-img img {
position: absolute;
object-fit: cover;
width: 100%;
height: 100%;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.card .card-body {
margin-bottom: 0.75rem;
display: flex;
flex-direction: column;
}
.card .card-body a {
text-decoration: none;
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
color: #3e3700;
font-weight: 500;
}
.card .card-body .card-title {
font-size: clamp(1.125rem, 0.5133rem + 1.699vw, 2rem);
font-weight: 500;
line-height: 1;
}
.card .card-body .card-description {
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
font-weight: 300;
margin-bottom: 0.75rem;
}
<div class="card card-h">
<div class="card-img">
<img
src="https://via.placeholder.com/150"
alt="img"
/>
</div>
<div class="card-body">
<h2 class="card-title">
Lorem ipsum dolor sit, amet consectetur
adipisicing elit. Ratione, cumque?
</h2>
</div>
</div>

Here is the aspect-ratio example with old browser support. I copied the card layout from bootstrap.
Please view in "Full Page"
.mycard .card-img {
aspect-ratio: 16 / 9;
object-fit: cover;
}
/*Old Browser Support*/
#supports not (aspect-ratio: 16 / 9) {
.mycard {
position: relative;
height: 0;
padding-bottom: 56.25%;
}
.mycard .card-img {
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
background: red;
/* just for illustration */
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="card mb-3" style="max-width: 540px;">
<div class="row no-gutters">
<div class="col-md-4">
<div class="mycard">
<img src="https://via.placeholder.com/150" class="card-img" alt="">
</div>
</div>
<div class="col-md-8">
<div class="card-body">
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>

Related

Image disappears as i decrease height in responsive view

I have the following:
HTML...
<div className="header">
<div className="container header__container">
<h5>Hello I'm</h5>
<h1>John Doe</h1>
<h5 className="text-light">Software Engineer</h5>
<CTA />
<HeaderSocials />
<div className="me">
<img src={ME} alt="me" />
</div>
<a href="#contact" className='scroll__down'>Scroll Down</a>
</div>
</div>
CSS for the image...
.me {
background: linear-gradient(var(--color-primary), transparent);
width: 22rem;
height: 33rem;
position: absolute;
left: calc(50% - 11rem);
margin-top: 4rem;
border-radius: 12rem 12rem 0 0;
overflow: hidden;
padding: 1rem 3.0rem 1.5rem 1.9rem;
}
CSS in entirety...
.header {
height: 100vh;
padding-top: 7rem;
overflow: hidden;
}
.header__container {
text-align: center;
height: 100%;
position: relative;
}
.cta {
margin-top: 2.5rem;
display: flex;
gap: 1.2rem;
justify-content: center;
}
.header__socials {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.8rem;
position: absolute;
left: 0;
bottom: 15rem;
}
.header__socials::after {
content: "";
width: 1px;
height: 2rem;
background: var(--color-primary);
}
.me {
background: linear-gradient(var(--color-primary), transparent);
width: 22rem;
height: 33rem;
position: absolute;
left: calc(50% - 11rem);
margin-top: 4rem;
border-radius: 12rem 12rem 0 0;
overflow: hidden;
padding: 1rem 3.0rem 1.5rem 1.9rem;
}
.scroll__down {
position: absolute;
right: -2.3rem;
bottom: 18rem;
transform: rotate(90deg);
font-weight: 300;
font-size: 0.9rem
}
/*MEDIA QUERIES (MEDIUM DEVICES)*/
#media screen and (max-width: 1024px) {
.header {
height: 100vh;
}
}
/*MEDIA QUERIES (SMALL DEVICES)*/
#media screen and (max-width: 600px) {
.header{
height: 100vh;
}
.header__socials,
.scroll__down{
display: none;
}
}
The width aspects are pretty responsive and work well enough. But when I adjust the height, the image slowly disappears as I make the height shorter and shorter. All of the other elements in this section/component move along with the height adjustment, but the image does not. Any suggestions?
If you are using CSS classes, you need to replace className by class in your HTML file.
Try this:
.me {
background: linear-gradient(var(--color-primary), transparent);
width: 22rem;
height: 33rem;
position: absolute;
left: calc(50% - 11rem);
margin-top: 4rem;
border-radius: 12rem 12rem 0 0;
overflow: hidden;
padding: 1rem 3.0rem 1.5rem 1.9rem;
}
.me img {
width: 50%;
height: 50%;
max-height: 50vh;
}
<div class="header">
<div class="container header__container">
<h5>Hello I'm</h5>
<h1>John Doe</h1>
<h5 className="text-light">Software Engineer</h5>
<CTA />
<HeaderSocials />
<div class="me">
<img src="https://www.thespruce.com/thmb/7GW0WNhJ5VrLdTJDP7RXJPPbVaY=/4505x2534/smart/filters:no_upscale()/the-most-beautiful-garden-flowers-4690011-7-f6963a3136ee47dba5f85d786b31ac7d.jpg" alt="me" />
</div>
<a href="#contact" className='scroll__down'>Scroll Down</a>
</div>
</div>

Image disappearing when adding position relative

I am using ReactJS. This is the Page component part
<div className="animated main">
<div className="title text">Lorem ipsum dolor sit amet consectetur </div>
<div className="image"></div>
</div>
And this is the page.css component
*{
box-sizing: border-box;
}
.main{
display: flex;
flex-wrap: wrap;
height: fit-content;
}
.title{
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
text-align: left;
font-size: 4em;
font-weight: bold;
padding: 5%;
}
.image{
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
background-image: url(../images/image1.png);
background-repeat: no-repeat;
border: 1px solid black;
position: absolute ;
}
* {
box-sizing: border-box;
}
.main {
display: flex;
flex-wrap: wrap;
height: fit-content;
}
.title {
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
text-align: left;
font-size: 4em;
font-weight: bold;
padding: 5%;
}
.image {
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
background-image: url(../images/image1.png);
background-repeat: no-repeat;
border: 1px solid black;
position: absolute;
}
<div class="animated main">
<div class="title text">Lorem ipsum dolor sit amet consectetur </div>
<div class="image"></div>
</div>
I am trying to position the image of the right side of the screen but it disappears whenever i add the position : relative / absolute feature.

Sticky Sidebar with parent Div

I know there are similar questions but I can't seem to implement the answers successfully so i'd thought i'd ask to try get an answer for my context.
I'm trying to keep a div with class .product-info fixed on the screen as you scroll down the page, with in it's parent div (.product-info-container). Once the fixed div reaches the bottom of the parent it should stop, i've tried using position:fixed but it fixes the div to the window, not the parent div.
Any help would be appreciated.
HTML:
/* Container */
.product-wrapper {
width: 100vw;
margin: auto;
}
.product-introduction {
height: auto;
min-height: calc(100vh - 140px);
width: 70vw;
min-width: 1400px;
margin: auto;
margin-top: 140px;
margin-bottom: 0;
display: flex;
flex-direction: row;
position: relative;
}
.product-image-grid {
height: auto;
width: 60%;
display: flex;
flex-direction: row;
flex-grow: 1;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: flex-start
}
.image-container {
margin: 10px;
padding: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: whitesmoke;
}
.image-container.small {
width: calc(50% - 40px);
height: 500px
}
.Product-Image {
height: 100%;
}
.image-container.large {
width: calc(100% - 10px);
height: 1000px;
}
.product-info-container {
height: 1500px;
min-height: calc(10vh - 140px);
width: calc(550px - 25px);
min-width: calc(550px - 25px);
position: relative;
padding-left: 25px;
}
.product-info {
position: fixed;
height: auto;
width: calc(550px - 20px);
padding: 10px;
}
h1.product-title {
font-family: "Magistral_Bold";
font-size: 32px;
letter-spacing: 0.05em;
text-transform: uppercase;
margin-top: 0;
margin-bottom: 0;
}
.icon-bar {
width: 50%;
min-width: 300px;
height: auto;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 25px;
margin-bottom: 25px;
}
.intro-feature-icon {
width: 150px;
}
.intro-feature-icon:first-child {
margin-left: 0;
}
.intro-feature-icon:nth-of-type(2) {
width: 100px;
}
.price-bar {
width: 50%;
height: auto;
display: flex;
flex-direction: row;
justify-content: unset;
align-items: flex-end;
}
.price-bar h2 {
margin-left: 0;
margin-right: 50px;
}
.currency-selector {
color: #919191;
font-size: 18px;
margin-bottom: 5px !important;
margin-right: 15px;
cursor: pointer;
}
.currency-selector.selected {
color: black !important;
}
.currency-selector:hover {
text-decoration: underline;
}
.wtb-cta {
width: auto;
padding: 16px 32px;
background: black;
text-align: center;
margin-top: 50px;
margin-bottom: 0;
}
.accordion {
cursor: pointer;
padding: 0;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 50px;
border-bottom: 1px solid black;
}
.accordion:after {
content: '\02795';
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
.active,
.accordion:hover {}
.active:after {
content: "\2796";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
<div class="product-wrapper">
<div class="product-introduction">
<div class="product-image-grid">
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-1.png" alt="Test Image 1" class="Product-Image One">
</div>
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-2.png" alt="Test Image 2" class="Product-Image Two">
</div>
<div class="image-container large">
<img src="Images/01-Product-Images/Test-image-3.png" alt="Test Image 3" class="Product-Image Three">
</div>
</div>
<div class="product-info-container">
<div class="product-info">
<h1 class="product-title no-shadow">Hinterland</h1>
<h4 class="h4-black no-shadow">DRY2DRY™ TRI-LAMINATE JACKET</h4>
<div class="icon-bar">
<img src="Images/02-Icons/Tech-Icons/Materials/TriLaminate/TriLaminateD2D-square-black.png" alt="Tri Laminate Logo" class="intro-feature-icon">
<img src="Images/02-Icons/Tech-Icons/CE-Icons/ce-approved.png" alt="CE Approved Logo" class="intro-feature-icon">
</div>
<p class="black no-shadow">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis velit aperiam soluta maiores fugiat facere dolorum obcaecati, repellat commodi eveniet deserunt doloribus, esse magnam alias qui eos officia reprehenderit? Dolorum.
</p>
<div class="price-bar">
<h2 class="h2-min black no-shadow">£299.99</h2>
<p class="currency-selector no-shadow selected"> £ </p>
<p class="currency-selector no-shadow "> $ </p>
</div>
<a href="#">
<div class="wtb-cta">
<h3>WHERE TO BUY</h2>
</div>
</a>
<button class="accordion">
<h3 class="black no-shadow">DESCRIPTION</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
<button class="accordion">
<h3 class="black no-shadow">ADDITIONAL INFO</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
</div>
</div>
</div>
</div>
I hope this is what u r expecting.
Add position:sticky and top:0 to .product-info class.
.product-info {
position:sticky;
top:0px;
height: auto;
width: calc(550px - 20px);
padding: 10px;
}
/* Container */
.product-wrapper {
width: 100vw;
margin: auto;
}
.product-introduction {
height: auto;
min-height: calc(100vh - 140px);
width: 70vw;
min-width: 1400px;
margin: auto;
margin-top: 140px;
margin-bottom: 0;
display: flex;
flex-direction: row;
position: relative;
}
.product-image-grid {
height: auto;
width: 60%;
display: flex;
flex-direction: row;
flex-grow: 1;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: flex-start
}
.image-container {
margin: 10px;
padding: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: whitesmoke;
}
.image-container.small {
width: calc(50% - 40px);
height: 500px
}
.Product-Image {
height: 100%;
}
.image-container.large {
width: calc(100% - 10px);
height: 1000px;
}
.product-info-container {
height: 1500px;
min-height: calc(10vh - 140px);
width: calc(550px - 25px);
min-width: calc(550px - 25px);
position: relative;
padding-left: 25px;
}
.product-info {
position:sticky;
top:0px;
height: auto;
width: calc(550px - 20px);
padding: 10px;
}
h1.product-title {
font-family: "Magistral_Bold";
font-size: 32px;
letter-spacing: 0.05em;
text-transform: uppercase;
margin-top: 0;
margin-bottom: 0;
}
.icon-bar {
width: 50%;
min-width: 300px;
height: auto;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 25px;
margin-bottom: 25px;
}
.intro-feature-icon {
width: 150px;
}
.intro-feature-icon:first-child {
margin-left: 0;
}
.intro-feature-icon:nth-of-type(2) {
width: 100px;
}
.price-bar {
width: 50%;
height: auto;
display: flex;
flex-direction: row;
justify-content: unset;
align-items: flex-end;
}
.price-bar h2 {
margin-left: 0;
margin-right: 50px;
}
.currency-selector {
color: #919191;
font-size: 18px;
margin-bottom: 5px !important;
margin-right: 15px;
cursor: pointer;
}
.currency-selector.selected {
color: black !important;
}
.currency-selector:hover {
text-decoration: underline;
}
.wtb-cta {
width: auto;
padding: 16px 32px;
background: black;
text-align: center;
margin-top: 50px;
margin-bottom: 0;
}
.accordion {
cursor: pointer;
padding: 0;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 50px;
border-bottom: 1px solid black;
}
.accordion:after {
content: '\02795';
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
.active,
.accordion:hover {}
.active:after {
content: "\2796";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
<div class="product-wrapper">
<div class="product-introduction">
<div class="product-image-grid">
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-1.png" alt="Test Image 1" class="Product-Image One">
</div>
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-2.png" alt="Test Image 2" class="Product-Image Two">
</div>
<div class="image-container large">
<img src="Images/01-Product-Images/Test-image-3.png" alt="Test Image 3" class="Product-Image Three">
</div>
</div>
<div class="product-info-container">
<div class="product-info">
<h1 class="product-title no-shadow">Hinterland</h1>
<h4 class="h4-black no-shadow">DRY2DRY™ TRI-LAMINATE JACKET</h4>
<div class="icon-bar">
<img src="Images/02-Icons/Tech-Icons/Materials/TriLaminate/TriLaminateD2D-square-black.png" alt="Tri Laminate Logo" class="intro-feature-icon">
<img src="Images/02-Icons/Tech-Icons/CE-Icons/ce-approved.png" alt="CE Approved Logo" class="intro-feature-icon">
</div>
<p class="black no-shadow">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis velit aperiam soluta maiores fugiat facere dolorum obcaecati, repellat commodi eveniet deserunt doloribus, esse magnam alias qui eos officia reprehenderit? Dolorum.
</p>
<div class="price-bar">
<h2 class="h2-min black no-shadow">£299.99</h2>
<p class="currency-selector no-shadow selected"> £ </p>
<p class="currency-selector no-shadow "> $ </p>
</div>
<a href="#">
<div class="wtb-cta">
<h3>WHERE TO BUY</h2>
</div>
</a>
<button class="accordion">
<h3 class="black no-shadow">DESCRIPTION</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
<button class="accordion">
<h3 class="black no-shadow">ADDITIONAL INFO</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
</div>
</div>
</div>
</div>

Image ignore max-width on load, but accepts it after toggling the max-width, or resizing the window

I have some divs and an image inside, and the css is working as I want it (almost), except that when I refresh the page or load it for the first time, the image width takes the entire div width, which ignores the css properties. It only notices the css properties when the window is resized (e.g. by 1px), or if in google developer tools, I toggle the max-width off and then back on, or if I toggle the parent div display off and then back on.
You can see this is the case in this video I just took:
https://youtu.be/YLx4NjKuzMo
Bear in mind, this issue occurs after about 880px width.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
width: 100%;
}
header {
height: 15vh;
min-height: 80px;
background-color: #262626;
}
h2 {
font-size: 3vw;
color: #f60;
}
ul {
line-height: 3.5vw;
}
.white-text {
color: #fff;
}
.orange-text {
color: #f60;
}
.page-container {
width: 100%;
height: 85vh;
min-height: 460px;
display: flex;
justify-content: space-between;
font-size: 2vw;
position: relative;
}
#logo {
position: relative;
height: 100%;
padding: 3vh;
}
.landing-section {
width: 33.3%;
height: 100%;
padding: 4vw;
padding-top: 0;
display: flex;
flex-direction: column;
justify-content: space-around;
}
#employees {
background-color: #fff;
}
#employers {
background-color: #fff;
}
.values-list {
margin-left: 7vw;
margin-top: 2vw;
}
.rounded {
border-radius: 100%;
}
.div-call-to-action {
width: 100%;
height: 15vw;
display: flex;
justify-content: space-between;
}
.landing-icon {
width: 15vw;
height: 15vw;
}
.p-see-how {
margin: auto 0;
color: #f60;
}
.arrow-icon {
margin: auto 1.5vw;
min-width: 45px;
min-height: 45px;
width: 4vw;
height: 4vw;
background-size: contain;
background-color: #f60 /*in case image doesn't load*/;
border-radius: 5px;
}
.arrow-icon:active {
background-color: #fff /*in case image doesn't load*/;
border: 1px solid #f60;
}
.is-flex {
display: flex;
}
/*#media (max-width: 1000px) and (max-height: 1000px)
#logo
width 320px
height initial
padding 0*/
#img-screen-chat-top-parent {
width: 33.3%;
padding: 2.5%;
}
#img-screen-chat-btm-parent {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
#img-screen-chat {
display: block;
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
}
<header>
<img id="logo" src="http://via.placeholder.com/350x150" alt="ratedby">
</header>
<section class="page-container">
<section class="landing-section" id="employees">
<div class="div-why">
<h2>Lorem ipsum</h2>
<ul class="values-list">
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
</ul>
</div>
<div class="div-call-to-action">
<img class="rounded landing-icon" id="chef-icon" src="http://via.placeholder.com/150x150" alt="Looking for work?">
<div class="is-flex">
<p class="p-see-how">Lorem</p>
<div class="arrow-icon" id="arrow-employees"></div>
</div>
</div>
</section>
<section id="img-screen-chat-top-parent">
<div id="img-screen-chat-btm-parent">
<img id="img-screen-chat" alt="Mobile app screen" src="http://via.placeholder.com/729x1530">
</div>
</section>
<section class="landing-section" id="employers">
<div class="div-why">
<h2>Lorem ipsum</h2>
<ul class="values-list">
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
</ul>
</div>
<div class="div-call-to-action">
<img class="rounded landing-icon" id="hire-icon" src="http://via.placeholder.com/150x150" alt="Looking for work?">
<div class="is-flex">
<p class="p-see-how">Lorem</p>
<div class="arrow-icon" id="arrow-employers"></div>
</div>
</div>
</section>
</section>

Remove whitespace below flexbox container

I am trying to design a landing page where different sections have different background-colors. The first section container (brown background) is a Flexbox to position the child elements. Below the first section comes another container (blue background) that also spans the whole width of the page.
Problem: There is some whitespace between the two containers, that I can't remove.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
}
.section-container {
background: #8EB8E5;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
JSFiddle: https://jsfiddle.net/z4oecan1/
Your <h3> elements have a default margin; remove it. use padding on the <h3> instead if you need to push it down.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
margin: 0;
}
.section-container {
background: #8EB8E5;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
Another option is to leave the margins as-is and add overflow:auto to the section-container div to fix the collapsed margins.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
}
.section-container {
background: #8EB8E5;
overflow:auto;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
It's due to the default margin-top of the h3 in the second section, which exceeds its container (collapsing margins....)
To avoid that, set margin-top: 0 for that h3, and to recreate the space above it, add a padding-top to it.
https://jsfiddle.net/031p3m04/1/