This question already has an answer here:
Pin a flex item to the bottom of the container
(1 answer)
Closed 5 years ago.
I have a series of cards using flexbox, and I'd like to have the bottom element (in this case a podcast widget) align to the bottom (flex-end) while the others align to the top.
I am fairly new to front-end web development and feel a bit like I'm just missing some fundamental idea to getting this to work. Thanks for your help!
Here is my current codepen where I'd like to get that to stick to the bottom.
html,
body {
font-family: sans-serif;
font-size: 16px;
}
/* Typography and Helpers */
.text-right {
text-align: right;
}
/* layout */
section {
display: block;
padding: 2rem 0;
}
.container {
width: 1200px;
max-width: 1200px;
margin: 0 auto;
position: relative;
}
.columns {
display: flex;
margin-left: -0.75rem;
margin-right: -0.75rem;
margin-top: -0.75rem;
/* - margins are for nesting */
}
.columns:last-child {
margin-bottom: -0.75rem;
}
.columns:not(:last-child) {
margin-bottom: 0.75rem;
}
.column {
display: block;
-ms-flex-preferred-size: 0;
flex-basis: 0;
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
-ms-flex-negative: 1;
flex-shrink: 1;
padding: 0.75rem;
}
.align-bottom-container {
margin-top: auto;
align-items: flex-end;
}
.align-bottom-item {
margin-top: auto;
display: block;
}
/* layout alignment */
.align-items-bottom {
align-items: flex-end;
display: flex;
justify-content: center;
}
.flex {
display: flex;
}
/* cards */
.flex-card {
border-left: .5em solid #0093d0;
background-color: #f7f7f7;
padding: 1em 1em 0 1em;
}
.two {
width: 50%;
flex-basis: 50%;
min-width: 50%;
}
.card-content {
padding: 1.5rem;
}
.blog-category {}
.blog-title {}
.blog-meta {}
.blog-description {}
<section class="container">
<div class="columns">
<div class="column">
<div class="flex-card">
<div class="card-content">
<p class="blog-category">Expert Strategies</p>
<div class="columns">
<p class="column blog-title">Pivot to Purchase</p>
<p class="column blog-meta text-right">August 8, 2017 <br>Podcast #18</p>
</div>
<p class="blog-description">If technology can be a disruptor - it will. Zillow has a pilot program that...</p>
<button>Read More</button>
</div>
</div>
<footer class="align-bottom-container">
<a class="spreaker-player" href="https://www.spreaker.com/user/kellyguest/expert-strategies-audit-your-brand" data-resource="episode_id=11390290" data-theme="light" data-autoplay="false" data-playlist="false" data-width="100%" data-height="200px">Listen to "Expert Strategies: Audit Your Brand" on Spreaker.</a>
<script async src="https://widget.spreaker.com/widgets.js"></script>
</footer>
</div>
<div class="column">
<div class="flex-card">
<div class="card-content">
<p class="blog-category">Expert Strategies</p>
<div class="columns">
<p class="column blog-title">Pivot to Purchase</p>
<p class="column blog-meta text-right">August 8, 2017 <br>Podcast #18</p>
</div>
<p class="blog-description">
<div>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Temporibus voluptatibus provident inventore velit impedit maxime asperiores consequuntur, ex veritatis libero aspernatur itaque quidem, harum accusamus dolorem, vel similique delectus
distinctio.
</div>
</p>
<button>Read More</button>
</div>
</div>
<footer><a class="spreaker-player" href="https://www.spreaker.com/user/kellyguest/expert-strategies-audit-your-brand" data-resource="episode_id=11390290" data-theme="light" data-autoplay="false" data-playlist="false" data-width="100%" data-height="200px">Listen to "Expert Strategies: Audit Your Brand" on Spreaker.</a>
<script async src="https://widget.spreaker.com/widgets.js"></script>
</footer>
</div>
</div>
</section>
The flex property of align-items: flex-end; belongs to the parent of flex items you are trying to align, the problem here is that you are trying to apply this property to your "footer", which is a child of what you assume is your flex parent. The parent of your footer is in fact the .column class which has the property of display: block;.
To achieve what you desire will only require the addition of these two lines to your .column class
display: flex;
flex-direction: column;
Which will then enable your margin-top: 0; property to take effect.
An alternative is to use the property justify-content: flex-end; which belongs to the parent of flex items/children. So your footer will align to the end of your parent. And then using the property margin-bottom: 0; on the flex-card to "float" it away from the footer.
.column {
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.flex-card {
margin-bottom: auto;
border-left: .5em solid #0093d0;
background-color: #f7f7f7;
padding: 1em 1em 0 1em;
}
html,
body {
font-family: sans-serif;
font-size: 16px;
}
/* Typography and Helpers */
.text-right {
text-align: right;
}
/* layout */
section {
display: block;
padding: 2rem 0;
}
.container {
width: 1200px;
max-width: 1200px;
margin: 0 auto;
position: relative;
}
.columns {
display: flex;
margin-left: -0.75rem;
margin-right: -0.75rem;
margin-top: -0.75rem;
/* - margins are for nesting */
}
.columns:last-child {
margin-bottom: -0.75rem;
}
.columns:not(:last-child) {
margin-bottom: 0.75rem;
}
.column {
display: flex;
flex-direction: column;
-ms-flex-preferred-size: 0;
flex-basis: 0;
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
-ms-flex-negative: 1;
flex-shrink: 1;
padding: 0.75rem;
}
.align-bottom-container {
margin-top: auto;
align-items: flex-end;
}
.align-bottom-item {
margin-top: auto;
display: block;
}
/* layout alignment */
.align-items-bottom {
display: flex;
justify-content: center;
}
.flex {
display: flex;
}
/* cards */
.flex-card {
border-left: .5em solid #0093d0;
background-color: #f7f7f7;
padding: 1em 1em 0 1em;
}
.two {
width: 50%;
flex-basis: 50%;
min-width: 50%;
}
.card-content {
padding: 1.5rem;
}
.blog-category {}
.blog-title {}
.blog-meta {}
.blog-description {}
<section class="container">
<div class="columns">
<div class="column">
<div class="flex-card">
<div class="card-content">
<p class="blog-category">Expert Strategies</p>
<div class="columns">
<p class="column blog-title">Pivot to Purchase</p>
<p class="column blog-meta text-right">August 8, 2017 <br>Podcast #18</p>
</div>
<p class="blog-description">If technology can be a disruptor - it will. Zillow has a pilot program that...</p>
<button>Read More</button>
</div>
</div>
<footer class="align-bottom-container">
<a class="spreaker-player" href="https://www.spreaker.com/user/kellyguest/expert-strategies-audit-your-brand" data-resource="episode_id=11390290" data-theme="light" data-autoplay="false" data-playlist="false" data-width="100%" data-height="200px">Listen to "Expert Strategies: Audit Your Brand" on Spreaker.</a>
<script async src="https://widget.spreaker.com/widgets.js"></script>
</footer>
</div>
<div class="column">
<div class="flex-card">
<div class="card-content">
<p class="blog-category">Expert Strategies</p>
<div class="columns">
<p class="column blog-title">Pivot to Purchase</p>
<p class="column blog-meta text-right">August 8, 2017 <br>Podcast #18</p>
</div>
<p class="blog-description">
<div>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Temporibus voluptatibus provident inventore velit impedit maxime asperiores consequuntur, ex veritatis libero aspernatur itaque quidem, harum accusamus dolorem, vel similique delectus
distinctio.
</div>
</p>
<button>Read More</button>
</div>
</div>
<footer><a class="spreaker-player" href="https://www.spreaker.com/user/kellyguest/expert-strategies-audit-your-brand" data-resource="episode_id=11390290" data-theme="light" data-autoplay="false" data-playlist="false" data-width="100%" data-height="200px">Listen to "Expert Strategies: Audit Your Brand" on Spreaker.</a>
<script async src="https://widget.spreaker.com/widgets.js"></script>
</footer>
</div>
</div>
</section>
Related
I am doing a side project about a movie website. I designed an RWD navbar as following. When I downsize the screen to the break point which is 576px, the mobile-version navbar would pop up automatically then hide. The result can be seen if running the snippet then expand and collapse the window. I guess the checkbox causes this issue but not really sure. Could someone help me with this issue, please? Thank you!
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Nunito', sans-serif;
}
.wrap {
width: 100%;
}
header {
height: 100px;
background: #000;
padding: 0 10px;
color: #fff;
display: flex;
align-items: center;
position: relative;
}
#checked {
visibility: hidden;
z-index: -9999;
position: absolute;
}
#checked:checked ~.navbar {
right: 0;
}
.logo {
height: 60%;
vertical-align: middle;
}
.navbar{
margin-left: auto;
font-size: 0;
position: fixed;
width: 100%;
height: 100vh;
background: #000;
right: -100%;
top: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
transition: .5s;
z-index: 999;
}
.navbar a {
display: block;
margin: 20px 0;
transition: .4s;
}
.navbar a:hover, .hideBtn:hover {
color: #3498db;
}
.navbar a,
.hideBtn, .showBtn {
font-size: 20px;
padding: 0 10px;
text-decoration: none;
color: #fff;
}
.showBtn {
position: absolute;
top: 37px;
right: 10px;
}
.showcase {
position: relative;
background: url("./image/photo-1517604931442-7e0c8ed2963c.jpg");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
width: 100%;
height: calc(100vh - 60px);
display: flex;
justify-content: center;
align-items: center;
}
.showcase .mask {
position: absolute;
width: 100%;
height: 100%;
background-color: #000;
z-index: 1;
opacity: 0.5;
}
.showcase .txt,
.showcase .slogan {
position: absolute;
color: #fff;
z-index: 2;
font-family: 'Nunito', sans-serif;
font-weight: bold;
font-size: 3em;
}
.showcase .slogan {
font-size: 1.2em;
bottom: 35%;
}
.service {
display: grid;
grid-template-rows: repeat(3, 1fr);
background-color: #000;
grid-gap:20px;
padding: 30px 50px;
}
.service a {
display: flex;
width: auto;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
cursor: pointer;
text-decoration: none;
}
.service a img {
width: 30%;
}
.service a p {
color: #fff;
font-size: 1.5em;
font-weight: bolder;
margin: 10px;
}
.content {
display: grid;
grid-template-rows: repeat(3, 1fr);
grid-template-columns: 1fr;
grid-gap: 0px;
}
.content div {
width: 100%;
text-align: center;
font-size: 1.5em;
}
.content div:nth-child(even) {
background-color: #000;
color: #fff;
}
.content div img {
width: 100%;
}
.content div p {
padding: 10px;
}
footer {
display: flex;
flex-direction: column;
width: 100%;
}
.contact-info {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 20px;
background-color: #000;
}
.contact-txt {
display: flex;
flex-flow: column nowrap;
width: 50%;
color: #fff;
}
footer #social-media img{
width: 30px;
margin: 0 5px;
}
.copyright {
text-align: center;
}
#media screen and (min-width: 576px) {
.showBtn, .navbar .hideBtn {
display: none;
}
.navbar{
margin-left: auto;
font-size: 0;
position: relative;
width: auto;
height: 100%;
background: #000;
right: 0;
top: 0;
display: flex;
justify-content: flex-end;
align-items: center;
flex-direction: row;
transition: none;
z-index: 0;
}
.showcase .txt {
font-size: 4em;
}
.showcase .slogan {
font-size: 2em;
}
.service {
display: grid;
grid-template-rows: 1fr;
grid-template-columns: repeat(3, 1fr);
}
.content {
display: grid;
grid-template-rows: repeat(3, 1fr);
}
.content div {
display: grid;
grid-template-columns: 1fr 1fr;
align-items: center;
font-size: 1.2em;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie List</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght#600&display=swap" rel="stylesheet">
</head>
<body>
<div class="wrap">
<header>
<img class="logo" src="./image/media.svg" />
<input type="checkbox" id="checked">
<label for="checked" class="showBtn">
<i class="fas fa-bars"></i>
</label>
<nav class="navbar">
About
Explore
Contact us
<label for="checked" class="hideBtn">
<i class="fas fa-times"></i>
</label>
</nav>
</header>
<div class="showcase">
<div class="mask"></div>
<h1 class="txt">HOME CINEMA</h1>
<h2 class="slogan">Experience Cinema at home</h2>
</div>
<div class="service">
<a href="#subscribe-info">
<img src="./image/communications.svg" alt="">
<p>$99 / month</p>
</a>
<a href="#vr-info">
<img src="./image/electronics.svg" alt="">
<p>Virtual Reality</p>
</a>
<a href="#unlimited-info">
<img src="./image/arrows.svg" alt="">
<p>Unlimited Watch</p>
</a>
</div>
<div class="content">
<div id="subscribe-info">
<img src="./image/photo-1543536448-d209d2d13a1c.jpg" alt="">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis necessitatibus ratione, ut sunt
voluptatibus totam a repudiandae enim nihil beatae ducimus aliquid! Et, beatae reprehenderit aspernatur est
hic commodi expedita.</p>
</div>
<div id="vr-info">
<img src="./image/pexels-photo-3391378.jpeg" alt="">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque possimus facere ipsum unde saepe maxime
voluptatem tempora sint pariatur at, nobis ipsam necessitatibus similique maiores, reiciendis repudiandae
voluptatum, cumque repellat.</p>
</div>
<div id="unlimited-info">
<img src="./image/pexels-photo-3912397.jpeg" alt="">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Est, nesciunt veniam, reprehenderit, fugiat nemo
fugit natus dicta maxime delectus ut quos et mollitia obcaecati pariatur. Rerum minima delectus sint ex?</p>
</div>
</div>
<footer>
<div class="contact-info">
<div class="contact-txt">
<p>hola#jamondetaiwan.com</p>
<p>+886 2771 5412</p>
<p>2F., No. 2, Ln. 179, Kanghu Rd., Neihu Dist., Taipei City 114, Taiwan (R.O.C.)</p>
</div>
<div id="social-media">
<img src="./image/fb.svg" alt="">
<img src="./image/ig.svg" alt="">
<img src="./image/youtube.svg" alt="">
</div>
</div>
<div class="copyright">
</div>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
</body>
</html>
This arises due to the CSS transition: .5s; in .navbar; when you reach the breakpoint, you are changing the right position and CSS is animating it. To avoid this, specify the properties you want to animate or add the transition property using JavaScript before you show the menu. For example, using jQuery:
$(".navbar").css("transition", ".5s");
Edit: I missed the CSS selector that is causing the animation and so assumed it was jQuery.
To address the issue with just HTML/CSS, you can create a copy of the navbar and use display: none;. The following snippet should work; I have added a copy of the navbar and added the classes .navbar-big and .navbar-small. This allow us to use the display property to hide the navbar we don't want to show based on the breakpoint, and set transition: right .5s; for .navbar-small.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Nunito', sans-serif;
}
.wrap {
width: 100%;
}
header {
height: 100px;
background: #000;
padding: 0 10px;
color: #fff;
display: flex;
align-items: center;
position: relative;
}
#checked {
visibility: hidden;
z-index: -9999;
position: absolute;
}
#checked:checked ~.navbar {
right: 0;
transition: .5s;
}
.logo {
height: 60%;
vertical-align: middle;
}
.navbar {
margin-left: auto;
font-size: 0;
position: fixed;
width: 100%;
height: 100vh;
background: #000;
right: -100%;
top: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
z-index: 999;
}
.navbar-small {
transition: right .5s;
}
.navbar-big {
display: none;
}
.navbar a {
display: block;
margin: 20px 0;
transition: .4s;
}
.navbar a:hover, .hideBtn:hover {
color: #3498db;
}
.navbar a,
.hideBtn, .showBtn {
font-size: 20px;
padding: 0 10px;
text-decoration: none;
color: #fff;
}
.showBtn {
position: absolute;
top: 37px;
right: 10px;
}
.showcase {
position: relative;
background: url("./image/photo-1517604931442-7e0c8ed2963c.jpg");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
width: 100%;
height: calc(100vh - 60px);
display: flex;
justify-content: center;
align-items: center;
}
.showcase .mask {
position: absolute;
width: 100%;
height: 100%;
background-color: #000;
z-index: 1;
opacity: 0.5;
}
.showcase .txt,
.showcase .slogan {
position: absolute;
color: #fff;
z-index: 2;
font-family: 'Nunito', sans-serif;
font-weight: bold;
font-size: 3em;
}
.showcase .slogan {
font-size: 1.2em;
bottom: 35%;
}
.service {
display: grid;
grid-template-rows: repeat(3, 1fr);
background-color: #000;
grid-gap:20px;
padding: 30px 50px;
}
.service a {
display: flex;
width: auto;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
cursor: pointer;
text-decoration: none;
}
.service a img {
width: 30%;
}
.service a p {
color: #fff;
font-size: 1.5em;
font-weight: bolder;
margin: 10px;
}
.content {
display: grid;
grid-template-rows: repeat(3, 1fr);
grid-template-columns: 1fr;
grid-gap: 0px;
}
.content div {
width: 100%;
text-align: center;
font-size: 1.5em;
}
.content div:nth-child(even) {
background-color: #000;
color: #fff;
}
.content div img {
width: 100%;
}
.content div p {
padding: 10px;
}
footer {
display: flex;
flex-direction: column;
width: 100%;
}
.contact-info {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 20px;
background-color: #000;
}
.contact-txt {
display: flex;
flex-flow: column nowrap;
width: 50%;
color: #fff;
}
footer #social-media img{
width: 30px;
margin: 0 5px;
}
.copyright {
text-align: center;
}
#media screen and (min-width: 576px) {
.showBtn, .navbar .hideBtn {
display: none;
}
.navbar {
margin-left: auto;
font-size: 0;
position: relative;
width: auto;
height: 100%;
background: #000;
right: 0;
top: 0;
display: flex;
justify-content: flex-end;
align-items: center;
flex-direction: row;
transition: none;
z-index: 0;
}
.navbar-small {
display: none;
}
.showcase .txt {
font-size: 4em;
}
.showcase .slogan {
font-size: 2em;
}
.service {
display: grid;
grid-template-rows: 1fr;
grid-template-columns: repeat(3, 1fr);
}
.content {
display: grid;
grid-template-rows: repeat(3, 1fr);
}
.content div {
display: grid;
grid-template-columns: 1fr 1fr;
align-items: center;
font-size: 1.2em;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie List</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght#600&display=swap" rel="stylesheet">
</head>
<body>
<div class="wrap">
<header>
<img class="logo" src="./image/media.svg" />
<input type="checkbox" id="checked">
<label for="checked" class="showBtn">
<i class="fas fa-bars"></i>
</label>
<nav class="navbar navbar-big">
About
Explore
Contact us
<label for="checked" class="hideBtn">
<i class="fas fa-times"></i>
</label>
</nav>
<nav class="navbar navbar-small">
About
Explore
Contact us
<label for="checked" class="hideBtn">
<i class="fas fa-times"></i>
</label>
</nav>
</header>
<div class="showcase">
<div class="mask"></div>
<h1 class="txt">HOME CINEMA</h1>
<h2 class="slogan">Experience Cinema at home</h2>
</div>
<div class="service">
<a href="#subscribe-info">
<img src="./image/communications.svg" alt="">
<p>$99 / month</p>
</a>
<a href="#vr-info">
<img src="./image/electronics.svg" alt="">
<p>Virtual Reality</p>
</a>
<a href="#unlimited-info">
<img src="./image/arrows.svg" alt="">
<p>Unlimited Watch</p>
</a>
</div>
<div class="content">
<div id="subscribe-info">
<img src="./image/photo-1543536448-d209d2d13a1c.jpg" alt="">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis necessitatibus ratione, ut sunt
voluptatibus totam a repudiandae enim nihil beatae ducimus aliquid! Et, beatae reprehenderit aspernatur est
hic commodi expedita.</p>
</div>
<div id="vr-info">
<img src="./image/pexels-photo-3391378.jpeg" alt="">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque possimus facere ipsum unde saepe maxime
voluptatem tempora sint pariatur at, nobis ipsam necessitatibus similique maiores, reiciendis repudiandae
voluptatum, cumque repellat.</p>
</div>
<div id="unlimited-info">
<img src="./image/pexels-photo-3912397.jpeg" alt="">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Est, nesciunt veniam, reprehenderit, fugiat nemo
fugit natus dicta maxime delectus ut quos et mollitia obcaecati pariatur. Rerum minima delectus sint ex?</p>
</div>
</div>
<footer>
<div class="contact-info">
<div class="contact-txt">
<p>hola#jamondetaiwan.com</p>
<p>+886 2771 5412</p>
<p>2F., No. 2, Ln. 179, Kanghu Rd., Neihu Dist., Taipei City 114, Taiwan (R.O.C.)</p>
</div>
<div id="social-media">
<img src="./image/fb.svg" alt="">
<img src="./image/ig.svg" alt="">
<img src="./image/youtube.svg" alt="">
</div>
</div>
<div class="copyright">
</div>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
</body>
</html>
I need to set a welcome section like the following:
I have set an absolute position just for the image, but I cannot make the image keeps horizontally align with the other column. Any ideas?
My code:
.img-welcome{
position: absolute;
top:10%;
right: 0;
bottom: 0;
margin: auto;
align-items: center;
display: flex;
height: max-content;
}
.container-relative{
position: relative;
height: 100%;
padding-bottom: 50px;
}
<div className='welcome-container d-flex align-items-center'>
<div className='container'>
<div className='pt-5 text-left pb-5 container-relative'>
<div class="col-6 pt-5 mb-5">
<h1 class="mb-3 row h1-text-style">Combine all your credit cards in one place</h1>
<h3 class="mb-5 row h3-text-style">We alow you to connect diferent bank cards, in one system, in which you will have the opportunity to manage to financial data and track the statistics of your costs.</h3>
<a class="button-gradient" href="#">Get Started</a>
</div>
</div>
</div>
<div class="img-welcome">
<img className='w-100' src={require('./img/img2.png')}></img>
</div>
</div>
You can use flexbox to easily achieve this.
You just need a container and the two sides:
body {
background-image: linear-gradient(to right, #00b795 , #0092a2);
height: 100vh;
margin: 0;
padding: 0;
}
.container {
height: 100%;
display: flex;
align-items: center;
}
.container > div {
flex: 50%;
}
.left {
padding: 20px;
font-family: Arial, Helvetica, sans-serif;
color: white;
display: flex;
flex-direction: column;
}
.right img {
height: 80vh;
width: 100%;
}
<div class="container">
<div class="left">
<strong>Combine all your credit cards in one place</strong>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Laborum architecto repellendus deserunt ex quo impedit in blanditiis facere, nisi quos, excepturi doloribus fuga expedita amet.</p>
</div>
<div class="right">
<img src="https://startbootstrap.com/assets/img/screenshots/themes/sb-admin-2.png">
</div>
</div>
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>
I made a second background image but no matter what elements I change it doesn't seem like I can position it at all. On top of that when I go into Chrome and use inspect then remove the layer it doesn't disappear?
And another problem I'm having is trying to figure out what code I need to change to get everything centered in the page layout. Like do I just have the numbers wrong or something?
If anyone could help me out I would be super grateful.
My Code:
/*The Main Background*/
body {
background-image: url(../img/background.png);
background-repeat: repeat-x
}
#HeaderBike {
background-image: url(..img/HeaderBike.png);
background-repeat: no-repeat;
z-index: 1;
float: left;
position: absolute height: 155px;
width: 155px;
}
.container {
width: 960px;
margin: 0 auto;
font-family: 'Montserrat', sans-serif;
font-size: 100%;
line-height: 1.5;
text-align: center;
}
/* Nav Element */
/*The Search Bar */
form div {
/*Margin Header */
48px;
float: left;
}
.site-navigation {
height: 155px;
}
.site-navigation img {
margin-top: 16px;
float: left;
}
.site-navigation ul {
width: 600px;
margin: 0 auto;
}
.site-navigation li {
margin: 35px 33px;
float: left;
}
.site-navigation a {
color: white;
text-decoration: none;
font-weight: bold;
}
.site-navigation a:hover {
padding-bottom: 2px;
border-bottom: 1px solid white;
}
/* Header Element */
h2 {
line-height: 0.8;
font-size: 72px;
font-weight: bold;
color: #fff;
width: 450px;
margin: left;
margin-top: 115px;
padding-bottom: 42px;
float: left;
text-align: left;
}
h1 {
text-align: left;
}
.SearchGlass {
margin: -142px 900px;
float: left;
}
/* Class For Articles*/
.article {
float: left;
width: 100%;
margin-bottom: 72px
}
.article img {
width: 20%;
margin-right: 1%
}
.article h1 {
float: left;
width: 70%;
margin: 5px 0;
text-align: left;
font-weight: bold;
font-size: 22.5px;
}
.article p {
float: left;
width: 70%;
margin: 5px 0;
text-align: left;
font-weight: bold;
font-size: 12px;
}
footer {
display: block;
width: 100%;
float: left;
}
.search {
margin: -141px 1125px;
float: left;
}
.RoadToYellow {}
<div class="container">
<header class="Team Sky">
<nav class="site-navigation">
<img src="img/TeamSkyLogo.png" alt="Team Sky Logo">
<ul class="clearfix">
<li>shop</li>
<li>checkout</li>
<li>video</li>
<li>
</div>
</ul>
<div class="SearchGlass" id="SearchGlass">
<img src="img/magnifyingglass.png" alt="Magnifying Glass">
</div>
<form>
<div class="search">
<input id="search" type="text" name="search" placeholder="search"><br>
</div>
<div id="HeaderBike">
<img src="img/HeaderBike.png" alt="Dude on a bike">
</div>
</nav>
</form>
<div class="TeamSkylogo">
<h2>Team Sky</h2>
</div>
<div class="RoadToYellow">
<P>the road to yellow</P>
</div>
<!--Shop Team Sky!-->
<main>
<h1> TEAM NEWS </h1>
<!-- each article/blog should be in it's own container -->
<div class="article">
<img src="img/ArticleImageOne.png" alt="Water">
<h1>Giro d'Italia</h1>
<P>Landa will lead the team on the back of his assured and impressive win at the giro del Trentino, and he returns to the race having excelled last year, when he won</P>
<!--readon !-->
</div>
<div class="article">
<img src="img/ArticleImageTwo.png" alt="Bikes by River">
<h1>Krudder Gets a Break</h1>
<P>The powerful German who was a rock in the beginning of the season will now get a break from and is expected to return for the Malecour at the end of the season</P>
<!--readon !-->
</div>
<div class="article">
<img src="img/ArticleImageThree.png" alt="Bike Dudes Biking">
<h1>Kinnick's New Contract</h1>
<P>Peter Kinnick contract is still not settled with the team manager Alistar McDowell saying that a new contract offer has been made</P>
<!--readon !-->
</div>
<div class="article">
<img src="img/ArticleImageFour.png" alt="Single Guy On Bike">
<h1>Froom In Third</h1>
<P>Chris Froom Finished Third in the opening prologue stage at the Criterium du Dauphine with a strong showing on the first day</P>
<!--readon !-->
</div>
</main>
<footer>
<img src="img/sponsor1.png" alt="Team Sky Sponsor">
<img src="img/sponsor2.png" alt="Pinarello">
<img src="img/sponsor3.png" alt="Shimano">
<img src="img/sponsor4.png" alt="Rayha">
<img src="img/sponsor5.png" alt="21ST Century Fox">
</footer>
</div>
What its suppose to look like
Vs.
What Mine Looks Like
Try using: background-size: cover;
What this will do is amplify the image enough so it covers the container is in.
Also, if you want to center the image you can use: background-position: center;
At the end it would look something like this:
#HeaderBike {
background-image: url(..img/HeaderBike.png);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
z-index: 1;
float: left;
position: absolute height: 155px;
width: 155px;
}
Or more simplified:
#HeaderBike {
background: url(..img/HeaderBike.png) no-repeat cover center;
z-index: 1;
float: left;
position: absolute height: 155px;
width: 155px;
}
Different approach (with flexbox)
Structure HTML
<!-- Header with logo, links and search -->
<header></header>
<!-- Intro section -->
<section></section>
<!-- Main with images and articles -->
<main></main>
<!-- Footer with customers and navigation -->
<footer></footer>
Think in sections, columns and rows.
<div class="section>
<div class="row">
<div class="column"></div>
</div>
</div>
Be consistent!
Give each section the padding you want. Make a row with
.row {
display: flex;
}
and a column with
.column {
flex: 1
}
so that every column has the same width.
Center horizontally and vertically as follows:
/* Center vertically */
.v-centered {
align-items: center;
}
/* Center horizontally */
.centered {
justify-content: center;
}
Example
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Montserrat', sans-serif;
}
a {
text-decoration: none;
}
.text-center {
text-align: center;
}
header {
background: #49B2CB;
}
header a {
color: white;
}
.container {
max-width: 960px;
margin: 0 auto;
border: 1px solid;
}
.section {
padding: 3rem 1.5rem;
}
/* Make header and footer padding not as big as normal */
header.section,
footer.section {
padding-top: 0.75rem;
padding-bottom: 0.75rem;
}
/* Row, centering, wrapping */
.row {
display: flex;
margin: 0 -0.75rem;
}
.row.v-centered {
align-items: center;
}
.row.centered {
justify-content: center;
}
.row.wrap {
flex-wrap: wrap;
}
.row>.column {
flex: 1;
}
.row>* {
padding: 0.75rem;
}
/* Navigation */
ul.nav {
padding: 0;
margin: 0;
list-style: none;
}
ul.nav li {
float: left;
padding: 5px;
}
ul.nav a {
color: #797979;
}
/* Buttons */
.btn {
text-decoration: none;
display: inline-block;
padding: 0.5rem;
border-radius: 0.5rem;
color: white;
}
.btn.light {
background: #49B2CB;
}
.btn.dark {
background: #000000;
}
/* Intro */
.intro {
background-image: url(http://lorempixel.com/960/400/sports/1);
color: white;
text-align: center;
}
.intro h1 {
font-size: 3rem;
margin: 0;
}
/* Main */
main h2 {
margin: 0.5rem 0;
}
/* Make main images responsive */
main img {
display: block;
height: auto;
max-width: 100%;
}
/* Footer */
footer figure {
margin: 0;
}
footer .nav {
text-align: center;
}
#media screen and (max-width: 767px) {
main .row {
flex-direction: column;
}
}
<div class="container">
<header class="section">
<div class="row v-centered centered">
<div class="column"><img src="http://via.placeholder.com/200x50?text=TEAM-SKY" alt=""></div>
<div class="column text-center">shop</div>
<div class="column text-center">checkout</div>
<div class="column text-center">video</div>
<div class="column"><input type="text" placeholder="Search ..."></div>
</div>
</header>
<section class="section intro">
<div class="row v-centered">
<div>
<h1>Team Sky</h1>
<p>the road to yellow</p>
shop team sky
</div>
</div>
</section>
<main class="section">
<h2>TEAM NEWS</h2>
<div class="row">
<div class="column"><img src="http://via.placeholder.com/400x200" alt="">
</div>
<div class="column">
<article>
<h3>Heading 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quaerat eligendi voluptas voluptate ut distinctio aspernatur perferendis minima, repellendus consequatur, incidunt, velit ipsum est suscipit veniam fugiat tempora, rem dolore! Commodi?</p>
More
</article>
</div>
</div>
<div class="row">
<div class="column"><img src="http://via.placeholder.com/400x200" alt="">
</div>
<div class="column">
<article>
<h3>Heading 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos, reiciendis dolor nulla maiores! Eaque quaerat quas optio quam odio inventore totam odit nobis blanditiis facere iure rem, praesentium et similique.</p>
More
</article>
</div>
</div>
<div class="row">
<div class="column"><img src="http://via.placeholder.com/400x200" alt="">
</div>
<div class="column">
<article>
<h3>Heading 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore illo mollitia consequatur laborum nulla, eos incidunt iusto explicabo voluptate molestias dolorum dolores, at, dolor temporibus ex tenetur quaerat, ducimus sequi.</p>
More
</article>
</div>
</div>
<div class="row">
<div class="column"><img src="http://via.placeholder.com/400x200" alt="">
</div>
<div class="column">
<article>
<h3>Heading 4</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit impedit amet odio quaerat sit voluptates aut quisquam tempore ipsa repellat ipsam atque deserunt, quis voluptatum quos aliquid laudantium dolorum accusamus.</p>
More
</article>
</div>
</div>
</main>
<footer class="section">
<div class="row centered wrap">
<figure><img src="http://via.placeholder.com/100x50?text=Customer 1" alt="">
</figure>
<figure><img src="http://via.placeholder.com/150x50?text=Customer 2" alt="">
</figure>
<figure><img src="http://via.placeholder.com/75x50?text=Customer 3" alt="">
</figure>
<figure><img src="http://via.placeholder.com/100x50?text=Customer 4" alt="">
</figure>
<figure><img src="http://via.placeholder.com/200x50?text=Customer 5" alt="">
</figure>
</div>
<div class="row centered">
<ul class="nav">
<li>Link 1
</li>
<li>Link 2
</li>
<li>Link 3
</li>
<li>Link 4
</li>
<li>Link 5
</li>
</ul>
</div>
</footer>
</div>
I'm not able to find a way to have one table with 4 rows having exactly the same height (without using table tag). This table is included in a div that has table-cell display.
I created this jsbin: https://jsbin.com/jejupogodi/edit?html,output
I want that the pink part to take all the available height and each row inside it should have 25% of the height (whatever the content length is).
I tidied up your code a bit. I used vh (vertical height) instead of percentage. You can run the code snippet but here is a fiddle
.container {
display: table;
width: 100%;
height: 100vh;
background: lightgreen;
}
.focus {
height: 500px;
}
.sliderContainer {
display: table-cell;
width: 40%;
height: 100%;
vertical-align: top;
background-color: white;
}
.slider {
margin: 0px;
padding: 0px;
list-style-type: none;
display: table;
height: 100%;
width: 100%;
}
.slider li {
display: table-row;
cursor: pointer;
height: 25vh;
background-color: pink;
overflow: hidden;
}
li .sliderImg{min-height:5vh; max-height:5vh;}
.sliderDetails {
border-bottom: 1px solid black;
padding-bottom: 5px;
min-height: 20vh;
max-height:20vh;
overflow-y: scroll;
overflow-x: hidden;
}
<body>
<div class="container">
<div class="focus">
<div>
<div class="focusDetails">
<div class="focusTitle"></div>
<div class="focusDesc"></div>
</div>
<div class="previous" style="display:none;"><span></span>
</div>
<div class="next"><span></span>
</div>
</div>
</div>
<div class="sliderContainer">
<ul class="slider">
<li>
<div class="sliderImg"></div>
<div class="sliderDetails">
<p class="sliderTitle">Town Hall Meeting Presentation - Sunstar Italiana</p>
<p class="sliderDesc">On Tuesday, June 30 all Sunstar Italiana employees took part to the Town Hall Meeting presentation made by the General Manager, Marco Bruscaini. Through his</p>
</div>
</li>
<li>
<div class="sliderImg"></div>
<div class="sliderDetails">
<p class="sliderTitle">Top Management Visits the HQ in Etoy</p>
<p class="sliderDesc">The welcome to the Sunstar Headquarter June Meetings' attendees from Asia, Japan, and the US was done as a tour to the Sunstar Campus' two buildings, the new and previous one The welcome to the Sunstar Headquarter June Meetings' attendees
from Asia, Japan, and the US was done as a tour to the Sunstar Campus' two buildings, the new and previous one</p>
</div>
</li>
<li>
<div class="sliderImg"></div>
<div class="sliderDetails">
<p class="sliderTitle">Distributor meeting</p>
<p class="sliderDesc">For the 3rd year we have organized our Distributor meeting taking place this time in our new building in Etoy, Switzerland.This year, we decided to extend our invitation to all the</p>
</div>
</li>
<li>
<div class="sliderImg"></div>
<div class="sliderDetails">
<p class="sliderTitle">Distributor meeting</p>
<p class="sliderDesc">For the 3rd year we have organized our Distributor meeting taking place this time in our new building in Etoy, Switzerland.This year, we decided to extend our invitation to all the</p>
</div>
</li>
</ul>
</div>
</div>
</body>
Solved by flexbox.
https://jsbin.com/yutucapuze/1/edit?output
/* **************
Quick Reset
************** */
html {
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
/* **********
Style
********** */
.Rows {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: box;
display: flex;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-o-box-orient: horizontal;
-webkit-box-lines: single;
-moz-box-lines: single;
-o-box-lines: single;
-webkit-flex-flow: row nowrap;
-ms-flex-flow: row nowrap;
flex-flow: row nowrap;
}
.Row {
-webkit-box-flex: 1;
-o-box-flex: 1;
box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
padding: 0;
margin: 0;
height: 500px;
}
.Slider {
background-color: #333;
position: relative;
}
.Slider:after {
content: '50% width & 500px heigth';
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
font-size: 2rem;
color: #3da7b4;
}
.List {
border: 1px solid #000;
}
.Item {
display: block;
min-height: 25%;
height: 25%;
max-height: 25%;
border: 1px solid #000;
position: relative;
overflow: auto;
background-color: #555;
}
.Item:after {
content: '25% heigth';
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
font-size: 1rem;
color: #3da7b4;
}
.Item__content {
padding: 0;
margin: 0;
opacity: 0.2;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";
filter: alpha(opacity=20);
}
<div class="Rows">
<div class="Row Slider"></div>
<div class="Row List">
<div class="Item">
<p class="Item__content">Lorem ipsum dolor</p>
</div>
<div class="Item">
<p class="Item__content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni illum fugiat velit a laborum harum molestias</p>
</div>
<div class="Item">
<p class="Item__content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni illum fugiat velit a laborum harum molestias saepe hic rerum. Aut omnis voluptatum placeat, amet aliquam, alias voluptatibus fugiat beatae quibusdam?</p>
</div>
<div class="Item">
<p class="Item__content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni illum fugiat velit a laborum harum molestias saepe</p>
</div>
</div>
</div>