I have a div (.news-container) display flex. Inside that div, I have 5 items, the first one is 100% width, the other 4 are 50% width. The problem is those 4 items don't have the same height even they are flex item with align-content: stretch. Are they supposed to have same height when we set parent display flex or did i do something wrong here?
body {
font-family: "Open Sans", Arial, sans-serif;
}
a {
text-decoration: none;
}
h1,
h2,
h3,
h4,
h5 {
margin: 0 0 20px 0;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
.content {
margin: 20px auto;
}
.float-content {
float: left;
}
.left-content {
width: 60%;
}
.right-content {
width: 40%;
}
.news-container {
display: flex;
flex-wrap: wrap;
padding-right: 5px;
overflow: hidden;
align-items: stretch;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
.news-list-container {
padding-left: 5px;
}
.news-container .item {
position: relative;
margin-bottom: 10px;
width: calc(50% - 5px);
padding: 0;
}
.news-container .item:nth-child(even) {
margin-right: 10px;
}
.news-container .item:first-child {
width: 100%;
margin-right: 0;
}
.news-container .item .news-link {
position: absolute;
top: 0;
left: 0;
z-index: 2;
background: #DC191B;
color: #fff;
padding: 10px;
text-transform: uppercase;
}
.news-container .item img {
width: 100%;
display: block;
margin-bottom: 0;
}
.news-container .item a.caption {
display: block;
padding: 10px 20px 13px 20px;
background-color: #000;
color: #fff;
font-family: 'Roboto Condensed', sans-serif;
font-size: 28px;
font-weight: bold;
}
#media screen and (min-width: 1200px) {
.content {
max-width: 970px;
}
}
<div class="wrapper">
<div class="content clearfix">
<div class="left-content float-content">
<div class="news-container">
<div class="item">
<a class="news-link" href="#">
New
</a>
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
<a class="caption" href="#" target="_blank">
Lorem ipsum
</a>
</div>
<div class="item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
<a class="caption" href="#" target="_blank">
Lorem ipsum dolor sit amet
</a>
</div>
<div class="item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
<a class="caption" href="#" target="_blank">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi a turpis sagittis, viverra nibh a, lobortis libero.
</a>
</div>
<div class="item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
<a class="caption" href="#" target="_blank">
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...
</a>
</div>
<div class="item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
<a class="caption" href="#" target="_blank">
Quisque sed tincidunt neque. Sed ut lacinia ex.
</a>
</div>
</div>
</div>
<div class="right-content float-content">
<div class="news-list-container">
<h2>
Latest update
</h2>
<ul>
<li>
News Number 1
</li>
<li>
News Number 2
</li>
<li>
News Number 3
</li>
<li>
News Number 4
</li>
</ul>
</div>
</div>
</div>
</div>
Actually, your items are the same height. It's just the content in each item isn't expanding to cover the height of the item. Here's an example:
As shown with the dev tools outline, the item on the left (with shorter content) is the same height as the item on the right.
You can use display: flex on the items, so align-items: stretch gets applied to the content.
Add this to your code:
.news-container .item:nth-child(2),
.news-container .item:nth-child(4),
.news-container .item:nth-child(5) {
display: flex;
flex-wrap: wrap;
}
Now the content fills each item.
jsFiddle demo
Related
Okay, I'll try to make this pretty quick. I'm working on upgrading my website's looks as a fun project. I used tables before as my site layout, but I'm trying to use CSS Grid as I've learned a lot since then. I'm using a CSS grid of just 3 columns, the outer two act as margins and the center is for content. Whenever there is enough content to make the page scroll down, the margins don't grow with it. In fact, neither does the center, because when I scroll to the bottom after putting something below a tall image it just shows the background color of my container.
To make the question simpler, how do I make the off white parts of my page black like the rest of the margins?
Scrolled to middle of page: Link to first picture
Scrolled all the way to the bottom: Link to second picture
I repeat, the off white color is not intentional, that's there because it's the color of the container. Everything that's the cream color should be black or gray!
body {
margin: 0;
width: 100vw;
height: 100vh;
font-family: Arial, Helvetica, sans-serif;
}
.content {
width: 70vw;
height: 100vh;
background-color: #252525;
}
.margin {
width: 15vw;
height: 100vh;
background-color: #000000;
}
table{
table-layout: fixed;
border-collapse: collapse;
width: 100%;
}
tr {
vertical-align: top;
}
a {
color: dodgerblue;
}
p {
color: #45d163;
font-size: 3.0vh;
text-align: left;
margin-left: 2.5vw;
font-family: Arial, bold;
font-weight: bold;
}
ol {
margin-left: 3.5vw;
}
ul{
}
li{
}
.fixed {
position: fixed;
}
.grid-container {
display: grid;
grid-template-columns: 15% 70% 15%;
background-color: #fceee3;
width: 100vw;
height: 100vh;
min-width: 0;
min-height: 100vh;
}
.grid-item {
background-color: #000000;
font-size: 5px;
text-align: left;
color: #f1f1f1;
min-height: 100vh;
margin-top: 0%;
}
.grid-center {
background-color: #252525;
color: blue;
font-size: 30vh;
text-align: left;
min-height: 100vh;
margin-top: 0%;
}
<!DOCTYPE html>
<html lang="en" >
<!-- partial:index.partial.html -->
<head>
<meta charset="UTF-8">
<title>Keyboard Mechanic</title>
<link rel="stylesheet" href="style.css"> </link>
<style>
.header {
overflow: hidden;
background-color: #171615;
padding: 1% 1%;
width: 100%;
position: fixed;
height: 7%;
}
.header a {
float: left;
color: #f1f1f1;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
width: max-content !important;
margin-right: 10px;
}
.header a.active {
background-color: dodgerblue;
color: white;
width: 8vw;
margin-right: 10px;
}
.header a.logo {
all: unset;
}
.login {
background-color: dodgerblue;
color: white;
width: 8vw;
margin-right: 10px;
}
.header a:hover {
background-color: #ddd;
color: black;
}
.header-right {
float: right;
}
#media screen and (max-width: 100%) {
.header a {
float: none;
display: block;
text-align: left;
}
}
</style>
<style>
.wrapper {
display: grid;
grid-template-columns: 15% 70% 15%;
grid-template-rows: 1fr;
background-color: #fceee3;
width: 100vw;
height: 100%;
overflow: scroll;
min-height: 100# !important;
}
.grid-item {
background-color: #000000;
font-size: 5px;
text-align: left;
color: #f1f1f1;
margin-top: 0%;
height: auto;
min-height: 100# !important;
}
.grid-center {
background-color: #252525;
margin-top: 0%;
width: 100%;
height: 100%;
min-height: 100# !important;
}
</style>
</head>
<body>
<div class="header">
<div class="header-right">
<a class="active" href="newLook.html">Home</a>
<a class="active" href="games.html">Games</a>
<a class="active" href="webprojects.html">Web Projects</a>
<a class="login" href="login.html">Login</a>
Contact
About
</div>
</div>
<div class="wrapper">
<div class="grid-item"> </div>
<div class="grid-center">
<p>Hello </p>
<img style="width: 100%;" src="https://i.imgur.com/DvlV8Sh.png" />
<p> Stuff outside the picture doesn't sit inside the center grid item, if it did, the background would be gray! </p>
</div>
<div class="grid-item"> </div>
</div>
</body>
</html>
<!-- partial -->
You could have done this with flex, To the best of my knowledge grid is not made for that purpose!
Here's an example made with flex
body {
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background: #171615;
}
.header {
/* If you don't want the header to be sticky on scroll remove these lines */
position: sticky;
top: 0;
/* If you don't want the header to be sticky on scroll remove these lines */
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
width: 100%;
background: #171615;
}
.header-logo {
height: 55px;
}
.logo {
height: 100%;
width: 135px;
object-fit: cover;
}
.header-menu {
display: flex;
flex-flow: row wrap;
}
.header-menu a {
color: #f1f1f1;
padding: 12px;
text-decoration: none;
border-radius: 4px;
margin-right: 8px;
white-space: nowrap;
}
.header a.active {
background: dodgerblue;
}
.login {
background-color: dodgerblue;
}
.header-menu a:hover {
background-color: #ddd;
color: black;
}
.wrapper {
width: 70%;
color: white;
}
/* you can remove this part */
.white-space {
display: flex;
height: 800px;
font-size: 3rem;
background: darkgray;
}
/* you can remove this part */
<div class="header">
<div class="header-logo">
<img class="logo" src="https://via.placeholder.com/135x55" alt="Logo" />
</div>
<div class="header-menu">
<a class="active" href="#">Home</a>
<a class="active" href="#">Games</a>
<a class="active" href="#">Web Projects</a>
<a class="login" href="#">Login</a>
Contact
About
</div>
</div>
<div class="wrapper">
<!-- put your content here -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ac ut consequat semper viverra. Eget nunc scelerisque viverra mauris in aliquam sem fringilla ut.</p>
<div class="white-space">
<h2 style="margin: auto">White Space</h2>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ac ut consequat semper viverra. Eget nunc scelerisque viverra mauris in aliquam sem fringilla ut.</p>
<!-- put your content here -->
</div>
Updated:
added custom height to the header
body {
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background: #171615;
}
.header {
/* If you don't want the header to be sticky on scroll remove these lines */
position: sticky;
top: 0;
/* If you don't want the header to be sticky on scroll remove these lines */
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
width: 100%;
background: #171615;
}
.header-logo {
height: 55px;
}
.logo {
height: 100%;
width: 135px;
object-fit: cover;
}
.header-menu {
display: flex;
flex-flow: row wrap;
height: 100px;
align-items: center;
}
.header-menu a {
color: #f1f1f1;
padding: 12px;
text-decoration: none;
border-radius: 4px;
margin-right: 8px;
white-space: nowrap;
}
.header a.active {
background: dodgerblue;
}
.login {
background-color: dodgerblue;
}
.header-menu a:hover {
background-color: #ddd;
color: black;
}
.wrapper {
width: 70%;
color: white;
}
/* you can remove this part */
.white-space {
display: flex;
height: 800px;
font-size: 3rem;
background: darkgray;
}
/* you can remove this part */
<div class="header">
<div class="header-logo">
<img class="logo" src="https://via.placeholder.com/135x55" alt="Logo" />
</div>
<div class="header-menu">
<a class="active" href="#">Home</a>
<a class="active" href="#">Games</a>
<a class="active" href="#">Web Projects</a>
<a class="login" href="#">Login</a>
Contact
About
</div>
</div>
<div class="wrapper">
<!-- put your content here -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ac ut consequat semper viverra. Eget nunc scelerisque viverra mauris in aliquam sem fringilla ut.</p>
<div class="white-space">
<h2 style="margin: auto">White Space</h2>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ac ut consequat semper viverra. Eget nunc scelerisque viverra mauris in aliquam sem fringilla ut.</p>
<!-- put your content here -->
</div>
Remove the min-height for .grid-center and .grid-item:
.grid-item {
background-color: #000000;
font-size: 5px;
text-align: left;
color: #f1f1f1;
margin-top: 0%;
}
.grid-center {
background-color: #252525;
color: blue;
font-size: 30vh;
text-align: left;
margin-top: 0%;
}
I'm trying to make a dropdown menu using html and css. However, when I change something in media query it also affects the same elements that's outside of it. Specifically,I have a horizontal navigation bar and I have sentered the links
vertically using "align-items:center".It works, but it also align my items the same way inside the media query.(on the dropdown, they appear in the middle"vertically" while I want them to me on top(x,y = 0).
I basically want my links inside media to be placed at the top while the same link outside the media to stay aligned.
Thank you..
* {
box-sizing: border-box;
font-family: sans-serif;
}
#media screen and (max-width:650px) {
#links{
background-color:red;
position:fixed;
inset:0 0 0 50%;
z-index:20;
align-self: flex-end;
}
#links ul{
flex-direction:column;
background-color: white;
}
}
#img{
width:3em;
height:3em;
}
#header-img{
display:flex;
}
#header{
display:flex;
justify-content: space-around;
}
#nav-bar{
display:flex;
justify-content: flex-end;
}
a{
text-decoration:none;
}
#links{
display:flex;
align-items:center;
}
#links ul{
list-style-type: none;
margin:0;
display:flex;
gap:5rem;
}
html {
height: 100%;
}
body {
margin: 0;
}
.main {
margin: 0;
padding-top: 68px;
background-color: #eee;
width: 98%;
margin-left: auto;
margin-right: auto;
}
.plans {
position: relative;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.column {
width: 90%;
max-width:280px;
background-color: white;
height: 30em;
border-style: solid;
border-width: 1px;
border-radius: 5px;
box-shadow: 0 0 10px grey;
}
.column_3,
.column_2,
.column_1 {
margin: 20px 20px;
}
.column h5 {
text-align: center;
background-color: lightgrey;
margin-top: 0;
padding: 10px 0;
}
.column h5 p {
margin-top: 5px;
margin-bottom: 0;
font-size: 18px;
}
.pricing {
height: 52%;
margin-top: -22px;
width: 80%;
margin-left: auto;
margin-right: auto;
}
.pricing_content {
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
padding-top: 40px;
}
#link_one {
font-weight: bold;
font-size: .8em;
width: 45%;
padding: 10px 10px;
margin-left: auto;
margin-right: auto;
background-color: black;
border-radius: 3px;
border-style: solid;
border-width: 1px;
border-color: transparent;
}
#link_one:hover {
background-color: white;
border-style: solid;
border-width: 1px;
border-color: black;
color: black;
font-weight: bold;
}
#link_two {
font-size:.8em;
color: black;
font-weight: bold;
margin-top: 25px;
background-color: #eee;
width: 45%;
padding: 10px 10px;
margin-left: auto;
margin-right: auto;
}
#link_two:hover {
background-color: lightgrey;
}
#below_button {
margin-top: 60px;
}
.checks {
width: 100%;
}
.checks ul {
list-style-type: none;
}
.checks ul li:before {
content: "✓";
padding-right: 8px;
color: rgb(0, 230, 0);
}
ul li {
text-indent: -1.25em;
}
.separator {
height: 1px;
width: 80%;
margin-left: auto;
margin-right: auto;
background-color: lightgrey;
}
.benefits {
width: 100%;
min-height: 300px;
display: flex;
flex-wrap: wrap;
justify-content: center;
text-align: center;
background-color: #f4f4f4;
}
.fa-solid {
padding: 5px 5px;
color: rgb(0, 250, 0);
}
.rectangle {
display: flex;
flex-direction: column;
justify-content: center;
margin: 0 auto;
height: 300px;
min-width: 200px;
max-width:300px;
}
.footer {
width: 75%;
height: 200px;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
bottom: 0;
position: static;
}
.contact_info {
background-color: black;
width: 100%;
height: 120px;
margin: 0 auto;
display: flex;
justify-content: space-between;
}
.icons_left ul {
list-style: none;
display: flex;
margin: 0;
padding: 40px 30px;
}
.icons_left ul li {
padding: 0 40px;
color: white;
}
.contact_right {
font-size: 1.05em;
padding: 10px 30px;
color: white;
}
.footer .fa-2x:hover {
color: rgb(0, 250, 0);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="styles.css" />
<script
src="https://kit.fontawesome.com/1724737a9d.js"
crossorigin="anonymous"
></script>
<title>Document</title>
</head>
<body>
<div class="wrap">
<div id="header">
<div id="header-img">
<img
id="img"
src="https://pngimg.com/uploads/gorilla/gorilla_PNG18705.png"
alt=""
/>
<h2>Gorilla Drive</h2>
</div>
<div id="nav-bar">
<nav id="links">
<ul>
<li class="nav-link">Deals</li>
<li class="nav-link">Benefits</li>
<li class="nav-link">Contact</li>
</ul>
</nav>
</div>
</div>
<div class="main">
<div class="plans">
<div class="column column_1">
<h5>
Basic<br />
<p>100 GB</p>
</h5>
<div class="pricing">
<div class="pricing_content">
<a id="link_one" href="#">$2,99/month</a>
<i id="below_button">Pay annualy (save 100%)</i>
<a id="link_two" href="">$20,99/year</a>
</div>
</div>
<div class="separator"></div>
<div class="checks">
<ul class="check_links">
<li>Lorem ipsum.</li>
<li>Lorem ipsum dolor.</li>
<li>Lorem ipsum dolor lahim.</li>
</ul>
</div>
</div>
<div class="column column_2">
<h5>
Standard<br />
<p>1 TB</p>
</h5>
<div class="pricing">
<div class="pricing_content">
<a id="link_one" href="#">$2,99/month</a>
<i id="below_button">Pay annualy (save 100%)</i>
<a id="link_two" href="">$20,99/year</a>
</div>
</div>
<div class="separator"></div>
<div class="checks">
<ul class="check_links">
<li>Lorem ipsum.</li>
<li>Lorem ipsum dolor.</li>
<li>Lorem ipsum dolor lahim.</li>
<li>Lorem ipsum dolor lahim baban.</li>
</ul>
</div>
</div>
<div class="column column_3">
<h5>
Premium<br />
<p>2 TB</p>
</h5>
<div class="pricing">
<div class="pricing_content">
<a id="link_one" href="#">$2,99/month</a>
<i id="below_button">Pay annualy (save 100%)</i>
<a id="link_two" href="">$20,99/year</a>
</div>
</div>
<div class="separator"></div>
<div class="checks">
<ul class="check_links">
<li>Lorem ipsum.</li>
<li>Lorem ipsum dolor.</li>
<li>Lorem ipsum dolor lahim.</li>
<li>Lorem ipsum dolor lahim baban.</li>
<li>Lorem ipsum dolor lahim baban sahim.</li>
</ul>
</div>
</div>
</div>
<div class="benefits">
<div class="rectangle rectangle_1">
<i class="fa-solid fa-fire fa-4x"></i>
<h4><b>High quality!</b></h4>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis
ullamcorper posuere nisi eu finibus.
</p>
</div>
<div class="rectangle rectangle_2">
<i class="fa-solid fa-jet-fighter-up fa-4x"></i>
<h4><b>Jet Fast support!</b></h4>
<p>
Proin feugiat sem tellus, commodo lacinia dui viverra ac. Sed
sollicitudin non metus sed sagittis. Nunc at tincidunt magna.
</p>
</div>
<div class="rectangle rectangle_3">
<i class="fa-solid fa-user-group fa-4x"></i>
<h4><b>Share with your family!</b></h4>
<p>
Aliquam vel mi blandit, venenatis risus vel, pellentesque nisl.
Suspendisse et sem leo.
</p>
</div>
</div>
</div>
</div>
<div class="footer"></div>
</body>
</html>
enter image description here
Add the flowing to the #links ul directly
#links ul {
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
}
and remove
ul li {
text-indent: -1.25em;
}
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 have 2 section on a home page, both with a picture and some text. I want to get the picture and the text of the top section next to each other (picture on left and text on the right). And then in the bottom section the text on the left and the picture to the right of the text.
Snippet
.alignnone {
width: 20%;
display: inline-block;
height: 20px;
padding: 13px;
box-sizing: border-box;
}
.first {}
.button {
text-decoration: none;
color: #000;
border-radius: 5px;
border: 1px solid;
padding: 10px;
background-color: #43dbdb;
margin: 1%;
float: left;
}
.drop {
width: 30% !important;
border: none;
padding: 0%;
float: right;
}
.top {
display: inline-block;
vertical-align: top;
padding: 2%;
}
.bottom {
display: inline-block;
vertical-align: bottom;
padding: 2%;
}
#content {
background-color: #D7DBDD;
background-size: 90%;
padding: 6%;
margin: -2%;
}
h2 {
text-align: center;
}
<div class="top">
<img src="https://privatechefanna.co.za/wp-content/uploads/2018/01/IMG_3695.jpg" height="99" width="99" alt="Anna" class="alignnone " />
<h3>ABOUT ME</h3>
<p class="first ">.....</p>
</div>
<div class="bottom">
<img src="https://privatechefanna.co.za/wp-content/uploads/2018/01/IMG_3713.jpg" height="99" width="99" alt="Anna" class="drop" />
<h3>WHAT I DO</h3>
<p class="second">.....</p>
</div>
Is this (created a codepen) something you are looking for?
<div class="top">
<div class="clearfix">
<img class="img1" src="https://privatechefanna.co.za/wp-content/uploads/2018/01/IMG_3713.jpg" width="99" height="99">
<h3>ABOUT ME</h3>
<p class="first ">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...</p>
</div>
</div>
<div class="bottom">
<div class="clearfix">
<img class="img2" src="https://privatechefanna.co.za/wp-content/uploads/2018/01/IMG_3713.jpg" width="99" height="99">
<h3>WHAT I DO</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum...</p></div>
</div>
CSS:
.drop {
width: 30% !important;
border: none;
padding: 0%;
}
.top {
vertical-align: top;
padding: 2%;
}
.bottom {
vertical-align: bottom;
padding: 2%;
}
.clearfix {
overflow: auto;
}
.img2 {
float: right;
margin-left: 15px;
}
.img1{
float: left;
margin-right: 15px;
}
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>