I'm trying to create a footer
using CSS flex
, with the following conditions :
- 3 elements (links)
- the first 2 must be at the left of the screen
- the last one must be perfectly centered
Live snippet
* {
box-sizing: border-box;
text-decoration: none;
}
html, body {
margin: 0;
padding: 0;
}
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
main {
width: 100%;
height: 100%;
display: flex;
flex: 1;
}
footer {
background: black;
}
a {
color: inherit;
}
ul {
margin: 0;
display: flex;
height: 66px;
list-style: none;
align-items: center;
justify-content: center;
}
li {
flex: 1;
color: white;
height: 100%;
display: flex;
align-items: center;
justify-content: flex-start;
}
li div {
padding: 1em;
}
li.centered {
justify-content: center;
}
li.centered div {
background: lightgrey;
color: black;
height: 100%;
padding: 1em;
display: flex;
align-items: center;
justify-content: center;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
</head>
<body>
<main></main>
<footer>
<ul>
<li>
<div>
<a href="http://google.fr">First</a>
</div>
<div>
<a href="http://google.fr">Second, large, full of text element</a>
</div>
</li>
<li class="centered">
<div>
<a href="http://google.fr">Centered element</a>
</div>
</li>
<li></li>
</ul>
</footer>
</body>
</html>
This is working fine, but I dislike the last empty li element (use to add a 3rd columns).
Does anyone have a solution for this, without an empty element in dom ?