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>
Related
Can someone please help me?!
I'm trying to code a PSD file to HTML and CSS, but I'm struggling with one of the sections. Here's an image of what I want to do:
Click Here
The problem is I don't know how to put the image in the timeline line. I tried to add the image in the ::after psuedo, but I don't think this is the right way of doing that.
This is my HTML Code :
<section class="about">
<div class="wrapper">
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
<div class="container left">
<div class="content">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
<div class="container right">
<div class="content">
<h5>January 2011<br> Facing Startups Battles</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</section>
This is my CSS code:
.about .wrapper{
padding: 80px 10%;
text-align: center;
position: relative;
}
.about .wrapper::after{
content: '';
position: absolute;
top: 200px;
bottom: 0;
width: 6px;
background: red;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.about .container{
position: relative;
width: 50%;
top: 60px;
margin: 0 0 60px 0;
}
.about .container::after{
content: 'How Can I Add an Image Here in this circle?';
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
top: 20px;
right: -104px;
background-color: blue; /* Just because there is no image */
background-image: url(assets/img/about-1.png);
background-repeat: no-repeat;
background-size: cover;
z-index: 2;
}
.left{
text-align: right;
}
.right{
text-align: right;
}
.content{
padding: 30px 0px 80px 0px;
}
.left .content{
padding-right: 140px;
}
.right .content{
padding-left: 140px
}
.right{
text-align: left;
left: 50%;
}
.right:after {
left: -104px;
}
I think this is called a timeline, there is a lot of tutorials talking about how to do something like this, but I don't know how to make the images in the timeline line. Can you please help me do this?
Thanks
To build this, you could use css grid layout (guide: https://css-tricks.com/snippets/css/complete-guide-grid/)
Treat each of the content+image as a row in the layout. And each row as a container for a grid.
You can visually break every row down to 3 columns. One column for left-side content, the second one for the image and the third one for right-side content.
Example css grid for a layout like this:
.grid-container {
display: grid;
grid-template-columns: 1fr 10em 1fr;
grid-template-rows: 1fr;
grid-template-areas: "content-left image content-right";
text-align: center;
}
.content-left { grid-area: content-left; background: lightblue; }
.image { grid-area: image; background: lightgreen; }
.content-right { grid-area: content-right; background: lightblue; }
<div class="grid-container">
<div class="content-left">Left content</div>
<div class="image">Image</div>
<div class="content-right">Right content</div>
</div>
(grid generated with: https://grid.layoutit.com/)
To alternate between content on the left and on the right, you can use css even/odd selectors (How can I style even and odd elements?) to set which grid area is used for the element.
Example:
I've built an example of a timeline layout for this answer which you can find at https://codepen.io/hendrysadrak/pen/VwLEraz
Try this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="main.css" />
<title></title>
</head>
<body>
<section class="about">
<div class="wrapper">
<div>
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div id="container">
<div class="row">
<div id="col1" class="col right">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
<div id="col2" class="col"><img class="img" src="assets/img/about-1.png"/></div>
</div>
<div class="row2" >
<div id="col3" class="col"><img class="img" src="assets/img/about-1.png"/></div>
<div id="col4" class="col left">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
in main.css file:
.about .wrapper{
padding: 80px 10%;
text-align: center;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.row {
width: 59%;
margin-right: 41%;
display: flex;
}
.row2 {
width: 59%;
display: flex;
margin-left: 41%;
}
.col {
flex:1;
}
.col.left {
text-align: left;
}
.col.right {
text-align: right;
}
#col2 {
flex-basis: 30%;
}
#col1 {
flex-basis: 70%;
}
#col3 {
flex-basis: 30%;
}
#col4 {
flex-basis: 70%;
}
.img {
margin: 10% 5%;
width: 90%;
border-radius: 50%;
}
#container {
background-image: linear-gradient(lightgrey,lightgrey);
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
put this in assets/img/about-1.png
Used a css template and edited, now between the 3 columns there is a small margin gap which id like to get rid of. tried readjusting the columun sizes but the margin gap still exists. Is there a more simple way I could have achieved the same page, if so how?? Yes im a newbie :P
* {
box-sizing: border-box;
}
body {
margin: 0;
}
/* Style the header */
.header {
background-color: #F1C40F;
padding: 20px;
text-align: center;
}
/* Style the footer */
.footer {
background-color: #F1C40F;
padding: 10px;
text-align: center;
/* Create three unequal columns that floats next to each other */
.column {
float: left;
padding: 10px;
}
/* top, middle and bottom column */
.columntopmiddlebottom {
width: 30%;
}
/* Responsive layout - makes the three columns stack on top of each other
instead of next to each other */
#media screen and (max-width: 600px) {
.column.side,
.column.middle {
width: 100%;
}
}
.auto-style2 {
text-align: center;
}
}
.auto-style2 {
margin-top: 31px;
}
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="row" style="height: 717px">
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 211px>
<h2>People</h2>
<p style="height: 214px">1</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 21px">2</h2>
<p style="height: 171px">info</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 37px">3</h2>
<p style="height: 193px">info</p>
</div>
</div>
Gaps under and above each column appears, dont want the gaps.
Try this:
.columntopmiddlebottom * {
margin-block-start: 0;
margin-block-end: 0;
}
A usefull trick when writing CSS is using the browsers development tools:
In Google when you right click on an element and press Inspect you can see which CSS is on that element. If you can't find the problem you are looking for you can try pressing CTRL + SHIFT + C and go over the elements to find your problem.
Good luck!
It is about https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing
The top and bottom margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as margin collapsing. Note that the margins of floating and absolutely positioned elements never collapse.
reset margin to hn and p .
* {
box-sizing: border-box;
}
h2,
p {
margin: 0;/* reset margin to avoid collapsing . Note , padding or border on the parent will keep margin inside*/
}
body {
margin: 0;
}
/* Style the header */
.header {
background-color: #F1C40F;
padding: 20px;
text-align: center;
}
/* Style the footer */
.footer {
background-color: #F1C40F;
padding: 10px;
text-align: center;
/* Create three unequal columns that floats next to each other */
.column {
float: left;
padding: 10px;
}
/* top, middle and bottom column */
.columntopmiddlebottom {
width: 30%;
}
/* Responsive layout - makes the three columns stack on top of each other
instead of next to each other */
#media screen and (max-width: 600px) {
.column.side,
.column.middle {
width: 100%;
}
}
.auto-style2 {
text-align: center;
}
}
.auto-style2 {
margin-top: 31px;
}
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="row" style="height: 717px">
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 211px>
<h2>People</h2>
<p style="height: 214px">1</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 21px">2</h2>
<p style="height: 171px">info</p>
</div>
<div class="columntopmiddlebottom" style="background-color:#F7DC6F;
style=" height: 212px>
<h2 style="height: 37px">3</h2>
<p style="height: 193px">info</p>
</div>
</div>
you can use this package https://necolas.github.io/normalize.css/ in css to remove margin and padding for element
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
header {
background-color: #F1C40F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.one {
background-color: #F7DC6F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.two {
background-color: #F1C40F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.three {
background-color: #F7DC6F;
height: 200px;
text-align: center;
padding: 50px 0;
}
.four {
background-color: #F1C40F;
height: 200px;
text-align: center;
padding: 50px 0;
}
footer{
background-color: #F7DC6F;
height: 200px;
text-align: center;
padding: 50px 0;
}
<header>
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</header>
<section class="one">
<h2>Section One</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</section>
<div class="two">
<h2>Gallery</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</div>
<article class="three">
<h2>News</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</article>
<aside class="four">
<h2>Aside NavBar</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</aside>
<footer >
<h2>Aside NavBar</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Earum eum minus aliquam dolorum sit molestiae architecto.</p>
</footer>
Another simple version using Flexbox.
* {
box-sizing: border-box;
margin: 0;
}
.header {
background-color: #F1C40F;
padding: 20px;
text-align: center;
}
.row {
background-color: #fff;
text-align: center;
display: flex;
flex-direction: row;
}
.column {
flex-grow: 1;
padding: 10px;
background-color:#F7DC6F;
height: 200px
}
#media screen and (max-width: 800px) {
.row {
flex-direction: column;
}
}
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="row">
<div class="column">
<h2>People</h2>
<p>1</p>
</div>
<div class="column">
<h2>2</h2>
<p>info</p>
</div>
<div class="column">
<h2>3</h2>
<p>info</p>
</div>
</div>
I need help in centering my image gallery, i cant make it to work how i want, gutters are being pain in the ass and so are calculating margins and widths. I want images centered, so three images per row, with one image being all the way to the left, second image being centered and third image being all the way to the right, using margins and padding with floats individually I believe is a bad practice, there has to be a better way to do this. Each image is 295px width I changed their widths in photoshop. I don't wish to use css grid, flexbox etc… I just want to do it in basic way with floats and box model. If there is any good way to center these images with some space in between them.
/* CSS Document */
/*body {
margin: 20px 250px;
}*/
#wrapper {
width: 1000px;
margin: 20px auto;
}
header {
background-image: url("../Images/view2.jpg");
background-repeat: no-repeat;
text-align: center;
padding-top: 30px;
padding-bottom: 20px;
}
header #navbar {
margin-top: 35px;
}
#navbar a {
padding: 30px 35px;
}
header h1 {
margin: 0;
}
main {
background: rgba(211, 204, 38, 1.00);
overflow: hidden;
padding: 20px;
}
main #page {
text-align: center;
}
main #inner-content ul {
list-style: none;
}
main #inner-content {
overflow: hidden;
padding-left: 17.7px;
}
main #inner-content #block1 {
float: left;
padding: 0;
width: 33.33%;
}
main #inner-content #block2 {
float: left;
padding: 0;
width: 33.33%;
}
main #inner-content #block3 {
float: left;
padding: 0;
width: 33.33%;
}
main #inner-content #block1 li {
margin-left: 12.5px;
}
main #inner-content #block2 li {
margin-left: 12.5px;
}
main #inner-content #block3 li {
margin-left: 12.5px;
}
#about-text {
margin-bottom: 50px;
text-align: center;
}
footer {
background: rgba(96, 96, 96, 1.00);
padding: 20px;
overflow: hidden;
clear: left;
}
footer #contact {
float: left;
margin-left: 200px;
}
footer #form {
float: right;
margin-right: 200px;
}
<div id="wrapper">
<header id="header">
<h1>ISMAR PHOTOGRAPHY</h1>
<nav id="navbar">
HOME
ABOUT
SERVICES
CONTACT
PORTFOLIO
</nav>
</header>
<main>
<p id="about-text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil error aspernatur vitae illo animi aliquam perferendis dicta, temporibus, dolores suscipit accusantium cumque voluptas nesciunt pariatur numquam omnis quo sunt minus voluptatum vero odio
ipsam mollitia. Itaque consequatur non harum molestias quibusdam voluptatem provident, eius, aliquam magnam, nesciunt ipsum est maiores! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sed beatae veritatis provident expedita facere dolore
saepe autem cupiditate voluptas assumenda enim odit illum et placeat amet officiis, accusamus adipisci veniam, hic. Velit fugiat vitae, laboriosam omnis voluptates rem, totam esse quisquam sunt hic voluptatum amet quam repudiandae sequi incidunt
nam!</p>
<p id="page">01</p>
<div id="inner-content">
<ul id="block1">
<li><img src="Images/nature.jpg"></li>
<li><img src="Images/panorama.jpg"></li>
<li><img src="Images/self.jpg"></li>
</ul>
<ul id="block2">
<li><img src="Images/self2.jpg"></li>
<li><img src="Images/sky.jpg"></li>
<li><img src="Images/telex.jpg"></li>
</ul>
<ul id="block3">
<li><img src="Images/urban-beatz.jpg"></li>
<li><img src="Images/urban-beatz2.jpg"></li>
<li><img src="Images/view.jpg"></li>
</ul>
</div>
</main>
<footer>
<div id="contact">
<h2>CONTACT ME</h2>
<p>randomemail#gmail.com</p>
<p>+456 34 55 5567</p>
</div>
<form action="#" name="form" id="form">
<label for="name">Name</label><br>
<input type="text" id="name"><br>
<label for="last-name">Last name</label><br>
<input type="text" id="last-name"><br>
<label for="email">Email</label><br>
<input type="text" id="email"><br>
<label for="message">Message</label><br>
<input type="text" id="message"><br>
</form>
</footer>
</div>
Okay, if you don't want to use grid or flexbox, then I'd suggest the old school table is a good option.
.my-table {
width: 100%;
}
.my-table td {
/* Change this padding to add gutters of desirable size*/
padding: 20px;
}
.my-table img {
width: 100%;
height: auto;
}
<table class="my-table">
<tr>
<td><img src="image_1_location.jpg" /></td>
<td><img src="image_2_location.jpg" /></td>
<td><img src="image_3_location.jpg" /></td>
</tr>
<tr>
<td><img src="image_4_location.jpg" /></td>
<td><img src="image_5_location.jpg" /></td>
<td><img src="image_6_location.jpg" /></td>
</tr>
</table>
Option 2
There is another way you can achieve this with floats if you want.
The only thing is that you'll have to make multiple containers to accommodate for the floats.
Here's how you can do it
.my-image-gallery {
position: relative;
}
.clearfix:after {
content: " ";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.floating-element {
float: left;
width: 33.33%;
}
.image-container {
padding: 10px;
}
.image-container>img {
width: 100%;
height: auto;
}
<div class="my-image-gallery">
<div id="row-1" class="clearfix">
<!-- You'll need to make a container for each image -->
<div class="floating-element">
<div class="image-container">
<img src="google-logo.png" />
</div>
</div>
<div class="floating-element">
<div class="image-container">
<img src="google-logo.png" />
</div>
</div>
<div class="floating-element">
<div class="image-container">
<img src="google-logo.png" />
</div>
</div>
</div>
</div>
While I think this is a riduculous way of doing this. You can use calc() to add a margin on both sides of the center img this example is using your current markup with no flex:
li:nth-child(2) {
margin: 0 calc(50% - 408px);
}
li {
width: 259px;
height: 259px;
list-style-type: none;
background-color: lightblue;
display: inline-block;
}
https://jsfiddle.net/DIRTY_SMITH/0f78ksvx/12/
The better way that you don't want to do would be to use flex:
#block1{
display: flex;
justify-content: space-between;
}
https://jsfiddle.net/DIRTY_SMITH/0f78ksvx/3/
Below are some minimal examples of how to implement your gallery. The concept is the same for both the Flexbox and Float approaches. Tell each image that it should be 1/3 the width of the container element (including margin) and allow the images to wrap inside their container element.
The overflow and negative margin properties used in both "remove" the outermost margins and may not be something that you desire or are concerned with.
Using Flexbox
body {
margin: 2rem;
}
.container {
margin-left: auto;
margin-right: auto;
width: 75%;
overflow: hidden;
}
.gallery {
display: flex;
flex-wrap: wrap;
align-items: center;
margin: -1rem;
background-color: rgba( 111, 222, 50, 0.15);
}
.gallery img {
display: flex;
margin: 1rem;
width: calc( 33.33333% - 2rem );
}
<div class="container">
<div class="gallery">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/">
</div>
</div>
Using Floats
I highly recommend moving away from floats and using Flexbox or CSS Grid unless there is a specific behavior that floats provide that favors some requirement.
body {
margin: 2rem;
}
.container {
margin-left: auto;
margin-right: auto;
width: 75%;
overflow: hidden;
}
.gallery {
margin: -1rem;
overflow: hidden;
background-color: rgba( 111, 222, 50, 0.15 ); /* For illustrative purposes. */
}
.gallery img {
float: left;
margin: 1rem;
max-width: calc( 33.33333% - 2rem); /* Subtract left and right margins */
}
<div class="container">
<div class="gallery">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/">
</div>
</div>
body {
margin: 2rem;
}
.container {
margin-left: auto;
margin-right: auto;
width: 75%;
overflow: hidden;
}
.gallery {
overflow: hidden; /* For illustrative purposes. */
background-color: rgba( 111, 222, 50, 0.15 ); /* For illustrative purposes. */
}
.gallery img {
float: left;
margin: 1rem;
max-width: calc( 33.33333% - 2rem); /* Subtract left and right margins */
}
<div class="container">
<div class="gallery">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/d10">
<img src="https://via.placeholder.com/300x300/fc0">
<img src="https://via.placeholder.com/300x300/">
</div>
</div>
use the html
<center>
image code here
</center>
<right>
and
<left>
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>
Update Please note kukkuz's answer is a nice hack but it is NOT working 100% if the first box becomes more content see this fiddle then the center box starts moving to the right
What I need is something like this:
Where:
First box "Lorem ipsumd dolor sit amet" has always to be left positioned
Second box "center content" has always to be centered
Third box "float left after center" has to be right after the center box
All of those boxes will have variable content length so it can be less content then shown in picture or much more. For every single of those 3 tomato colored boxes
This is what I have
.flex-container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
background-color: powderblue;
}
.flex-item {
background: tomato;
padding: 5px;
height: 100px;
line-height: 100px;
color: white;
text-align: left;
}
<div class="flex-container">
<div class="flex-item">Lorem ipsumd dolor sit amet</div>
<div class="flex-item">center content</div>
<div class="flex-item">float left after center</div>
</div>
Now not sure how to achieve the desired result. Is flex-box the right way to go or should I use display-table? I'm 97% sure it doesn't work with floating. How can I achieve the desired result?
Update from question in comments
Q: suppose the first box has large content such that the second box will overlap the first, if it is at the center... how do you look to
handle that?
A: probably with overflow hidden and z-index. It will be a toolbar underneath a gallery. Left box will describe something of the image,
middle box is the gallery navigation, and the right box will display
some "helper" text. so the gallery navigation is the most important
which must always be visible (and centered)
I certainly miss justify-self but you can try a hack: add margin-right: auto to the first and third flex-items - see demo below:
.flex-container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
background-color: powderblue;
}
.flex-item {
background: tomato;
padding: 5px;
height: 100px;
line-height: 100px;
color: white;
text-align: left;
}
.auto {
margin-right: auto;
}
<div class="flex-container">
<div class="flex-item auto">Lorem ipsumd dolor sit amet</div>
<div class="flex-item">center content</div>
<div class="flex-item auto">float left after center</div>
</div>
I think this would be a solution. But I needed an auxiliar wrapper for the side elements.
You cant set a minimum width (arbitrary) on the side containers. I have set this to 10px, just to give the idea.
.flex-container {
display: flex;
overflow: hidden;
}
.side {
flex: 10px 1 0;
background-color: powderblue;
}
.center {
flex: auto 0 0;
background: tomato;
}
.side div {
background: tomato;
display: inline-block;
}
.flex-item {
padding: 5px;
height: 100px;
line-height: 100px;
color: white;
text-align: left;
}
<div class="flex-container">
<div class="flex-item side">
<div>Lorem ipsumd dolor sit amet</div>
</div>
<div class="flex-item center">center content</div>
<div class="flex-item side">
<div>float left after center</div>
</div>
</div>
Not sure if using display-table might be the better solution for my problem. It seems to look good with all different content lengths. Not sure how the
max-width: 10px;
works on the .table-cell but seems to do the job..
.display-table {
display: table;
height: 70px;
background-color: powderblue;
width: 100%;
margin: 10px 0;
}
.table-row {
display: table-row;
}
.table-cell {
border: solid 1px black;
display: table-cell;
text-align: center;
vertical-align: middle;
background: tomato;
max-width: 10px;
}
.table-cell:first-child,
.table-cell:last-child {
text-align: left;
}
<div class="display-table">
<div class="table-row">
<div class="table-cell">Lorem ipsumd dolor sit amet</div>
<div class="table-cell">center content</div>
<div class="table-cell">float left after center</div>
</div>
</div>
<div class="display-table">
<div class="table-row">
<div class="table-cell">Lorem ipsum dolor sit amet</div>
<div class="table-cell">center content center content center content</div>
<div class="table-cell">float left after center</div>
</div>
</div>
<div class="display-table">
<div class="table-row">
<div class="table-cell">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat asperiores aliquid rerum optio perferendis aut debitis delectus. Rerum, facilis pariatur debitis libero accusantium numquam expedita ratione aliquid quae temporibus excepturi! ipsumd dolor sit amet</div>
<div class="table-cell">center content</div>
<div class="table-cell">float left after center</div>
</div>
</div>
<div class="display-table">
<div class="table-row">
<div class="table-cell">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat asperiores aliquid rerum optio perferendis aut debitis delectus. Rerum, facilis pariatur debitis libero accusantium numquam expedita ratione aliquid quae temporibus excepturi! ipsumd dolor sit amet</div>
<div class="table-cell">center</div>
<div class="table-cell">float left after center float left after center periores aliquid rerum optio perferendis aut debitis delectus. Rerum, facilis pariatur debitis libero accusantium numquam expedita ratione aliquid quae temporibus excepturi! ipsumd dolor sit amet
</div>
</div>
I'm don't think it is possible with CSS alone to suit all your conditions and without adding a wrapper div - using any method.
You can get pretty close using a combination of position:absolute and margin-left except that the middle element won't be exactly in the centre.
.container {
background-color: powderblue;
margin: 40px;
white-space: nowrap;
}
.item1, .item2, .item3 {
background: tomato;
padding: 5px;
height: 100px;
line-height: 100px;
color: white;
text-align: left;
display: inline-block;
position: relative;
z-index: 1;
}
.item1 {
position: absolute;
background: green;
z-index: 0;
}
.item2 {
margin-left: 50%;
//transform: translateX(-50%); /* will center, but then no way to pull item3 back */
z-index:1;
}
.item3 {
z-index:1;
}
<div class="container">
<div class="item1"> Lorem ipsumd dolor heth ehe h </div>
<div class="item2">center content</div>
<div class="item3">float left after center</div>
</div>
position the first item with a lower z-index - incase the first item is really long
<div class="container">
<div class="item1"> Lorem ipsumd dolor sit amet fgfdg theth ehe h Lorem ipsumd dolor sit amet fgfdg theth ehe h </div>
<div class="item2">center content</div>
<div class="item3">float left after center</div>
</div>
Just add this to your CSS
.flex-item:nth-of-type(1),.flex-item:nth-of-type(3)
{
margin-right:auto;
}
.flex-container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
background-color: powderblue;
}
.flex-item:nth-of-type(1),.flex-item:nth-of-type(3)
{
margin-right:auto;
}
.flex-item {
background: tomato;
padding: 5px;
height: 100px;
line-height: 100px;
color: white;
text-align: left;
}
<div class="flex-container">
<div class="flex-item">Lorem ipsumd dolor sit amet</div>
<div class="flex-item">center content</div>
<div class="flex-item">float left after center</div>
</div>