Vertically align menu in CSS - html

Im stuck in creating the following menu. Cant get it to center. Seems like img inside span is breaking the display.
DESIRED RESULT:
HTML:
<ul id="rounded-cats" class="cleardiv">
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
</ul>
CSS:
#rounded-cats {
text-align: center;
//display: table;
border: 1px solid red;
width: 100%
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline;
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}
JSFIDDLE:
http://jsfiddle.net/gtux2snu/

Look at this demo
I have made changes to #rounded-cats li and #rounded-cats span img styles.
#rounded-cats {
text-align: center;
//display: table;
border: 1px solid red;
width: 100%
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline-block;
width:150px;//added some width to each li
float:left;//floated elements left
text-align:left;//aligned category name with image
padding:20px;//add padding so it looks good and separated.
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important;
margin-top:18px;//centered img inside circle
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}

Look at this Fiddle
li{
display: table;
}
span{
display: table-cell;
}
I now got exactly what you want. Just like you want it. Take a look at the fiddle and let me know if this is what you want.
UPDATED!!!!!!!!!!!!!!!!!!!!!

My solution is to use float: left to li elements and clear float after 5n:
#maintCont {
position:relative;
width: 100%;
margin: 0 auto;
text-align: center;
}
#rounded-cats {
text-align: center;
border: 1px solid red;
display: inline-block;
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline;
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}
#rounded-cats > li {
float: left;
margin: 20px;
}
#rounded-cats > li:nth-child(5n) {
clear: left;
padding-left: 65px;
}
<div id="maintCont">
<ul id="rounded-cats" class="cleardiv">
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
</ul>
</div>

You will have to make you li inline-block and give the span some padding :
demo
#rounded-cats li {
display: inline-block;
}
And the span :
#rounded-cats span {
width: 70px;
height: 70px;
padding: 21px; /* to get a span width and height of 112px */
/* code */
}

I think that this should do the trick:
http://jsfiddle.net/gtux2snu/15/
I added a div element to wrap the li content with relative position so the category name can be absolute positioned to the bottom. Also set the span circle to relative and the img to absolute with top: 50% and a negative half height margin-top.
<a href="#">
<div class="cats-wrap">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</div>
</a>
I changed this part of CSS:
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
position: relative; /* To contain the absolute positioned img */
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: inline-block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important;
position: absolute;
top: 50%; /* align all the img 50% top */
left: 50%;
margin-left: -35px;
margin-top: -35px; /* Half the img height so img is centered */
}
#rounded-cats .cats-wrap{ /* Wrapper element set to relative */
display: inline-block;
position: relative;
height: 140px; /* Add some height to the wrapper so the category name can fit */
}
#rounded-cats strong{
position: absolute;
bottom: 0; /* Category is aligned to the absolute bottom */
left: 0;
right: 0;
margin: auto; /* To center the category name */
}

I have fixed some issues in your css and you could simply do that like this:
DEMO
* {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
body {
margin:0;
}
#rounded-cats {
text-align: center;
border: 1px solid red;
width: 100%;
margin: 0;
padding: 0;
display: inline-block;
}
#rounded-cats li {
display: inline-block;
margin: 20px;
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span:before {
height: 100%;
content:" ";
vertical-align: middle;
display: inline-block;
}
#rounded-cats span img {
vertical-align: middle;
}
#rounded-cats a {
text-decoration: none;
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
<ul id="rounded-cats" class="cleardiv">
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
</ul>

Here's my code pen http://jsfiddle.net/dfrierson2/gtux2snu/19/
I seperated the elements into div's for centering, and I used lists for the inline display.
ul li {
list-style-type: none;
margin-left: 10px;
}
li {
display: inline-block;
}
li a {
color: #000;
text-decoration: none;
margin-bottom: 10px !important;
}
#rounded {
text-align: center;
//display: table-cell;
vertical-align: middle;
margin: 1em 0;
height: auto;
position: relative;
}
#rounded img {
margin-bottom: 55px;
position: relative;
}
#rounded-cats {
background: #c7c7c7;
width: 100px;
height: 100px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
text-align: center;
border-box: sizing;
margin-bottom: 45px;
padding: 20px;
position: relative;
}
<ul>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
</ul>

Related

I can't get the posts to be in the position I want

Im using django to create a website but I have limited knowledge about CSS and HTML , Im trying to create some new styling and posts in the page but somehow I could not manage to eliminate the blank which can be seen in picture.The posts are starting from bottom of the page no matter what I do. Im new at Django and CSS please instead of judging , guide me. Thank you!
<!DOCTYPE html>
<!-- Created by CodingLab |www.youtube.com/CodingLabYT-->
<html lang="en" dir="ltr">
{% load static %}
<head>
<meta charset="UTF-8">
<title>EBOT Maintenance </title>
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<!-- Boxiocns CDN Link -->
<link href='https://unpkg.com/boxicons#2.0.7/css/boxicons.min.css' rel='stylesheet'>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="sidebar close">
<div class="logo-details">
<i class='bx bx-menu'></i>
<span class="logo_name">EBOT</span>
</div>
<ul class="nav-links">
<li>
<a href="{% url 'home' %}">
<i class='bx bx-grid-alt' ></i>
<span class="link_name">Anasayfa</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="{% url 'home' %}">Anasayfa</a></li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="{% url 'userSettings' %}">
<i class='bx bx-collection' ></i>
<span class="link_name">Kullanıcı Ayarları</span>
</a>
<i class='bx bxs-chevron-down arrow' ></i>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="{% url 'userSettings' %}">Kullanıcı Ayarları</a></li>
<li>Kullanıcı Ekle</li>
<li>Kullanıcı Sil</li>
<li>Şifre Reset</li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="{% url 'users' %}">
<i class='bx bx-collection' ></i>
<span class="link_name">Kullanıcılar</span>
</a>
<i class='bx bxs-chevron-down arrow' ></i>
</div>
<ul class="sub-menu">
<li class="list-group-item"><a href="{% url 'users' %}">
{% for user in users %}
<div>
{{ user.username }}
</div>
{% endfor %}
</a></li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="{% url 'parameters' %}">
<i class='bx bx-book-alt' ></i>
<span class="link_name">Parametreler</span>
</a>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="{% url 'parameters' %}">Parametreler</a></li>
</ul>
</li>
<li>
<a href="{% url 'EbotManual' %}">
<i class='bx bx-pie-chart-alt-2' ></i>
<span class="link_name">EBOT Manual</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="{% url 'EbotManual' %}">EBOT Manual</a></li>
</ul>
</li>
<li>
<a href="{% url 'LedManual' %}">
<i class='bx bx-plug' ></i>
<span class="link_name">Led Manual</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="{% url 'LedManual' %}">Led Manual</a></li>
</ul>
</li>
<li>
<div class="iocn-link">
<a href="{% url 'TestRutins' %}">
<i class='bx bx-cog' ></i>
<span class="link_name">Test Rutinleri</span>
</a>
</div>
<ul class="sub-menu">
<li><a class="link_name" href="{% url 'TestRutins' %}">Test Rutinleri</a></li>
</ul>
</li>
<li>
<!--
<a href="#">
<i class='bx bx-compass' ></i>
<span class="link_name">Explore</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">Explore</a></li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-history'></i>
<span class="link_name">History</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">History</a></li>
</ul>
</li>
<li>
<a href="#">
<i class='bx bx-cog' ></i>
<span class="link_name">Setting</span>
</a>
<ul class="sub-menu blank">
<li><a class="link_name" href="#">Setting</a></li>
</ul>-->
</li>
<li>
<div class="profile-details">
<div class="profile-content">
</div>
<div class="name-job">
<div class="profile_name">{{ user.username }}</div>
<div class="job">{{ user.first_name }} {{ user.last_name }}</div> <!--şuanda login type atalı değil halledilecek-->
</div>
<i class='bx bx-log-out' ></i>
</div>
</li>
</ul>
</div>
<section class="home-section">
<div class="home-content">
<span class="text">EBOT Maintenance </span>
</div>
</section>
<script>
let arrow = document.querySelectorAll(".arrow");
for (var i = 0; i < arrow.length; i++) {
arrow[i].addEventListener("click", (e)=>{
let arrowParent = e.target.parentElement.parentElement;//selecting main parent of arrow
arrowParent.classList.toggle("showMenu");
});
}
let sidebar = document.querySelector(".sidebar");
let sidebarBtn = document.querySelector(".bx-menu");
console.log(sidebarBtn);
sidebarBtn.addEventListener("click", ()=>{
sidebar.classList.toggle("close");
});
</script>
{% block content %}
{% endblock content %}
</body>
</html>
{% extends 'index.html' %}
{% block content %}
<style>
.home-page{
position:relative;
text-align:center;
margin-left: 50px;
}
</style>
<section class="home-section">
<div class="home-container">
<div class="home-page">
<h2>
EBOT Maintenance Hoş geldiniz.
</h2>
<p>lwrgkwrkgşlwrkgşl gwrlşkgşlwrkglşwr gkwrşlgkwrlş gkwrlşgkwr gkwrlşkg wşrkglwşrgk wrlkg şwrlgklşwrkglşwr kgşlwrkg wrkglşwr gkwrşlgkwr </p>
İlerlemek için herhangi bir şeye tıklayın
</div>
</div>
</section>
{% endblock content %}
/* Google Fonts Import Link */
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;600;700&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
.sidebar{
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 260px;
background: #11101d;
z-index: 100;
transition: all 0.5s ease;
}
.sidebar.close{
width: 78px;
}
.sidebar .logo-details{
height: 60px;
width: 100%;
display: flex;
align-items: center;
}
.sidebar .logo-details i{
font-size: 30px;
color: #fff;
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
}
.sidebar .logo-details .logo_name{
font-size: 22px;
color: #fff;
font-weight: 600;
transition: 0.3s ease;
transition-delay: 0.1s;
}
.sidebar.close .logo-details .logo_name{
transition-delay: 0s;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links{
height: 100%;
padding: 30px 0 150px 0;
overflow: auto;
}
.sidebar.close .nav-links{
overflow: visible;
}
.sidebar .nav-links::-webkit-scrollbar{
display: none;
}
.sidebar .nav-links li{
position: relative;
list-style: none;
transition: all 0.4s ease;
}
.sidebar .nav-links li:hover{
background: #1d1b31;
}
.sidebar .nav-links li .iocn-link{
display: flex;
align-items: center;
justify-content: space-between;
}
.sidebar.close .nav-links li .iocn-link{
display: block
}
.sidebar .nav-links li i{
height: 50px;
min-width: 78px;
text-align: center;
line-height: 50px;
color: #fff;
font-size: 20px;
cursor: pointer;
transition: all 0.3s ease;
}
.sidebar .nav-links li.showMenu i.arrow{
transform: rotate(-180deg);
}
.sidebar.close .nav-links i.arrow{
display: none;
}
.sidebar .nav-links li a{
display: flex;
align-items: center;
text-decoration: none;
}
.sidebar .nav-links li a .link_name{
font-size: 18px;
font-weight: 400;
color: #fff;
transition: all 0.4s ease;
}
.sidebar.close .nav-links li a .link_name{
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li .sub-menu{
padding: 6px 6px 14px 80px;
margin-top: -10px;
background: #1d1b31;
display: none;
}
.sidebar .nav-links li.showMenu .sub-menu{
display: block;
}
.sidebar .nav-links li .sub-menu a{
color: #fff;
font-size: 15px;
padding: 5px 0;
white-space: nowrap;
opacity: 0.6;
transition: all 0.3s ease;
}
.sidebar .nav-links li .sub-menu a:hover{
opacity: 1;
}
.sidebar.close .nav-links li .sub-menu{
position: absolute;
left: 100%;
top: -10px;
margin-top: 0;
padding: 10px 20px;
border-radius: 0 6px 6px 0;
opacity: 0;
display: block;
pointer-events: none;
transition: 0s;
}
.sidebar.close .nav-links li:hover .sub-menu{
top: 0;
opacity: 1;
pointer-events: auto;
transition: all 0.4s ease;
}
.sidebar .nav-links li .sub-menu .link_name{
display: none;
}
.sidebar.close .nav-links li .sub-menu .link_name{
font-size: 18px;
opacity: 1;
display: block;
}
.sidebar .nav-links li .sub-menu.blank{
opacity: 1;
pointer-events: auto;
padding: 3px 20px 6px 16px;
opacity: 0;
pointer-events: none;
}
.sidebar .nav-links li:hover .sub-menu.blank{
top: 50%;
transform: translateY(-50%);
}
.sidebar .profile-details{
position: fixed;
bottom: 0;
width: 260px;
display: flex;
align-items: center;
justify-content: space-between;
background: #1d1b31;
padding: 12px 0;
transition: all 0.5s ease;
}
.sidebar.close .profile-details{
background: none;
}
.sidebar.close .profile-details{
width: 78px;
}
.sidebar .profile-details .profile-content{
display: flex;
align-items: center;
}
.sidebar .profile-details img{
height: 52px;
width: 52px;
object-fit: cover;
border-radius: 16px;
margin: 0 14px 0 12px;
background: #1d1b31;
transition: all 0.5s ease;
}
.sidebar.close .profile-details img{
padding: 10px;
}
.sidebar .profile-details .profile_name,
.sidebar .profile-details .job{
color: #fff;
font-size: 18px;
font-weight: 500;
white-space: nowrap;
}
.sidebar.close .profile-details i,
.sidebar.close .profile-details .profile_name,
.sidebar.close .profile-details .job{
display: none;
}
.sidebar .profile-details .job{
font-size: 12px;
}
.home-section{
position: relative;
background: #E4E9F7;
height: 100vh;
left: 260px;
width: calc(100% - 260px);
transition: all 0.5s ease;
}
.sidebar.close ~ .home-section{
left: 78px;
width: calc(100% - 78px);
}
.home-section .home-content{
height: 60px;
display: flex;
align-items: center;
}
.home-section .home-content .bx-menu,
.home-section .home-content .text{
color: #11101d;
font-size: 35px;
}
.home-section .home-content .bx-menu{
margin: 0 15px;
cursor: pointer;
}
.home-section .home-content .text{
font-size: 26px;
font-weight: 600;
}
#media (max-width: 400px) {
.sidebar.close .nav-links li .sub-menu{
display: none;
}
.sidebar{
width: 78px;
}
.sidebar.close{
width: 0;
}
.home-section{
left: 78px;
width: calc(100% - 78px);
z-index: 100;
}
.sidebar.close ~ .home-section{
width: 100%;
left: 0;
}
}
enter image description here
You have two divs with class="home-section", one in your {% block content %} and one in your index.html. As this class has a vh of 100 the first will force the second to the bottom.

Display element only when transition is finished

When nav-toggle is checked sidebar reduces width and span is not displayed. When nav-toggle is unchecked it all comes back, but span displays the moment nav-toggle is unchecked and takes vertical space until sidebar is wide enough.
.sidebar {
width: 345px;
transition: width 300ms;
}
#nav-toggle:checked+.sidebar {
width: 70px;
}
#nav-toggle:checked+.sidebar li a span:last-child {
display: none;
}
<input type="checkbox" name="" id="nav-toggle">
<div class="sidebar">
<div class="sidebar-brand">
<h2><span class="lab la-accusoft"></span> <span>Acusoft</span></h2>
</div>
<div class="sidebar-menu">
<ul>
<li>
<a href="" class="active"><span class="las la-igloo"></span>
<span>Dashboard</span>
</a>
</li>
<li>
<a href=""><span class="las la-users"></span>
<span>Customers</span>
</a>
</li>
</ul>
</div>
</div>
I need to delay displaying 'span' until after transition is finished or sidebar is wide enough.
You could try changing the display: none into an opacity: 0, and have another transition with a transition-delay
This may not be an exact answer but could help you in the right direction. https://jsfiddle.net/treckstar/9uqgmnfk/16/
body {
font-size: 16px;
}
.app {
display: flex;
flex-flow: row nowrap;
max-width: 100%;
padding: 20px 0px 0px 0px;
position: relative;
}
#nav-toggle {
position: absolute;
top: 0px;
left: 0px;
}
.nav-toggle-label {
position: absolute;
top: 0px;
left: 20px;
}
.main-content {
flex: 1 0 auto;
height: 50vh;
background: #eee;
padding: .5rem 2rem;
}
.sidebar {
flex: 0 0 20%;
padding: .5rem 2rem;
height: 50vh;
transition: all 1s ease;
background-color: #ccc;
}
#nav-toggle:checked+.sidebar {
flex: 0 0 5%;
padding: .5rem .5rem;
}
.sidebar ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.sidebar li a span {
opacity: 1;
transition: opacity .2s ease;
transition-delay: 1.25s;
}
#nav-toggle:checked+.sidebar li a span:last-child {
opacity: 0;
}
<div class="app">
<label class="nav-toggle-label" for="nav-toggle">Toggle</label>
<input type="checkbox" name="cb" id="nav-toggle">
<div class="sidebar">
<div class="sidebar-brand">
<h2><span class="lab la-accusoft"></span> <span>Acusoft</span></h2>
</div>
<div class="sidebar-menu">
<ul>
<li>
<a href="" class="active"><span class="las la-igloo"></span>
<span>Dashboard</span>
</a>
</li>
<li>
<a href=""><span class="las la-users"></span>
<span>Customers</span>
</a>
</li>
</ul>
</div>
</div>
<main class="main-content" role="main">
<h2>
Main Content
</h2>
</main>
</div>

Position font awesome span icon above text within an anchor

I'm trying to make some buttons with text positioned below a font awesome icon where both are positioned centrally inside a list item, and I need the anchor element, which also contains the span element for the font awesome icon, to fill the entire size of the list item.
I can fill the list item with the anchor no problem, but I'm having trouble positioning the icon's span above the text in the anchor that contains it.
JSFiddle: https://jsfiddle.net/qod142fz/.
HTML:
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><span class="fa fa-home"></span>Home</li>
<li class="navButton"><span class="fa fa-user"></span>Personal Details</li>
<li class="navButton"><span class="fa fa-briefcase"></span>Company</li>
<li class="navButton"><span class="fa fa-gbp"></span>Invoices</li>
<li class="navButton"><span class="fa fa-address-book"></span>Contacts</li>
<li class="navButton"><span class="fa fa-minus"></span>Expenses</li>
<li class="navButton"><span class="fa fa-list"></span>Payslips</li>
<li class="navButton"><span class="fa fa-cog"></span>Settings</li>
</ul>
</div>
CSS:
/* SIDEBAR PRIMARY */
#sidebarPrimary
{
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary > ul
{
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary > ul > li.navButton
{
width: 100%;
height: 15vw;
}
#sidebarPrimary > ul > li.navButton > a
{
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary > ul > li.navButton > a:hover
{
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary > ul > li.navButton > a > span
{
display: block;
text-align: center;
margin-bottom: 5px;
}
Problem is coming from flex. I recommend wrapping another div around the elements that should be centered inside the a tags
/* SIDEBAR PRIMARY */
#sidebarPrimary {
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary > ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary > ul > li.navButton {
width: 100%;
height: 15vw;
}
#sidebarPrimary > ul > li.navButton > a {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
text-decoration: none;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary > ul > li.navButton > a:hover {
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary > ul > li.navButton > a .fa {
display: block;
height: 1em;
margin: 0 auto 5px;
text-align: center;
width: 1em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-home"></span>Home
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-user"></span>Personal Details
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-briefcase"></span>Company
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-gbp"></span>Invoices
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-address-book"></span>Contacts
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-minus"></span>Expenses
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-list"></span>Payslips
</div>
</a></li>
<li class="navButton"><a href="#">
<div class="navButtonContent">
<span class="fa fa-cog"></span>Settings
</div>
</a></li>
</ul>
</div>
#sidebarPrimary {
position: fixed;
width: 15vw;
height: 100%;
top: 0;
left: 0;
background: #2F323E;
}
#sidebarPrimary>ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#sidebarPrimary>ul>li.navButton {
width: 100%;
height: 15vw;
}
#sidebarPrimary>ul>li.navButton>a {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
color: #687381;
font-size: 12px;
font-weight: 500;
transition: all linear 0.05s;
-webkit-transition: all linear 0.05s;
-moz-transition: all linear 0.05s;
}
#sidebarPrimary>ul>li.navButton>a:hover {
text-decoration: none;
color: #fff;
background: #E95656;
}
#sidebarPrimary>ul>li.navButton>a>span {
display: block;
text-align: center;
margin-bottom: 5px;
width: 20px;
height: 20px;
background-color: red;
position: absolute;
top: 10px;
}
<div id="sidebarPrimary">
<ul id="sidebarPrimaryNav">
<li class="navButton"><span class="fa fa-home"></span>Home</li>
<li class="navButton"><span class="fa fa-user"></span>Personal Details</li>
<li class="navButton"><span class="fa fa-briefcase"></span>Company</li>
<li class="navButton"><span class="fa fa-gbp"></span>Invoices</li>
<li class="navButton"><span class="fa fa-address-book"></span>Contacts</li>
<li class="navButton"><span class="fa fa-minus"></span>Expenses</li>
<li class="navButton"><span class="fa fa-list"></span>Payslips</li>
<li class="navButton"><span class="fa fa-cog"></span>Settings</li>
</ul>
</div>
Just add position: absolute; top: 40px; to font-awesome icons

Transition not aligning properly

I'm trying to make it so that you get an explanation of my project when you hover over the image. If I set the span.text-content position to absolute, all of my list items align properly, but i get one box in the upper left corner and I can't see it at all once I scroll to lower images.
When I set the position to relative, it separates all of my images and the text box appears on the left side and below the image, but at least I get one for every image. I've been playing with the z-index because, at first, you could only see the word "Explanation" as a sliver behind the top image.
Finally, my -o-transition won't gray out and I'm not sure what that's about? I've checked jshint and I'm not throwing any errors. Thanks in advance for the help!
HTML
<li>
<!--Dance Class-->
<img src="images/dance.jpg" id="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food-->
<img src="images/tnf.png" id="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food Pitch-->
<img src="images/tnf-pitch.png" id="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Coaches Corner-->
<img src="images/coach.jpg" id="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Singularity2045-->
<img src="images/Singularity2045.png" id="port-img" width="697px" height="733px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Overtime-->
<img src="images/overtime.png" id="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
</ul>
**CSS:**
span.text-content {
/* allows me to adjust the filters and transparency of the outer span/image */
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
font-size: 1.5em;
height: 300px;
left: 0;
position:absolute;
top: 0;
width: 500px;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
z-index: 1;
}
span.text-content span {
/* For text alignment */
display: table-cell;
text-align: center;
vertical-align: middle;
}
ul.img-list li:hover span.text-content{
opacity: 1;
}
#port-img{
z-index: 1;
position: relative;
top: 69px
}
Codepen: http://codepen.io/anon/pen/wWPpQZ
HTML
<ul class="img-list">
<li>
<!--Dance Class-->
<img src="images/dance.jpg" class="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food-->
<img src="images/tnf.png" class="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food Pitch-->
<img src="images/tnf-pitch.png" class="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Coaches Corner-->
<img src="images/coach.jpg" class="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Singularity2045-->
<img src="images/Singularity2045.png" class="port-img" width="697px" height="733px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Overtime-->
<img src="images/overtime.png" class="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
</ul>
CSS
li {
position: relative;
display: inline-block;
}
.text-content {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
font-size: 1.5em;
position:absolute;
display: block;
top: 0;
right: 0;
bottom:0;
left: 0;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
.text-content span {
display: block;
/* For text alignment */
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
.img-list li:hover .text-content{
opacity: 1;
}
.port-img{
display: block;
}
Explanation
Changed id="port-img" to class as you should not have multiple elements with same id.
Anyway the most important part is that li element have position relative so all child elements positioned absolutely are positioned to each li element.
Different way to position text verticaly is used as it was easier to make explanation box 100% height.

<li> hover effect, pretty sure it's something to do with :after

I have an UL menu, I want to animate a line underneath a LI when hovered, I'm trying to start with this:
.menu-container li:after {
content: "";
width: 0px;
height: 4px;
position: absolute;
bottom: 0;
left: 0;
display: block;
z-index: 2;
background: #fff;
-webkit-transition: width 0.3s;
transition: width 0.3s;
}
a:hover .menu-container li:after {
width: 100%;
}
<div class="menu-container">
<ul>
<a href="#">
<li>About</li>
</a>
<a href="#">
<li>Food & Farming</li>
</a>
<a href="#">
<li>Cookbook</li>
</a>
<a href="#">
<li>Schools</li>
</a>
<a href="#">
<li>Get Involved</li>
</a>
</ul>
</div>
It's not working though...
Any help on this would be awesome!!
Cheers
try this
.menu-container li:after {
content: "";
width: 0px;
height: 4px;
bottom: 0;
/* position: absolute; remove */
left: 0;
display: block;
z-index: 2;
background: #fff;
-webkit-transition: width 0.3s;
transition: width 0.3s;
width: 0%;
/* add */
background: red;
/* add */
}
.menu-container a:hover li:after {
/* change */
width: 100%;
}
<div class="menu-container">
<ul>
<a href="#">
<li>About</li>
</a>
<a href="#">
<li>Food & Farming</li>
</a>
<a href="#">
<li>Cookbook</li>
</a>
<a href="#">
<li>Schools</li>
</a>
<a href="#">
<li>Get Involved</li>
</a>
</ul>
</div>
Is this what you are looking for??
<html>
<head>
<style type="text/css">
.menu-container li:after {
content: "";
width: 0px;
height: 4px;
position: absolute;
bottom: 0;
left: 0;
display: block;
z-index: 2;
background: #fff;
-webkit-transition: width 0.3s;
transition: width 0.3s;
}
a:hover .menu-container li:after {
width: 100%;
}
.menu-container a {
text-decoration: none;
}
.menu-container a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="menu-container">
<ul>
<a href="#">
<li>About</li>
</a>
<a href="#">
<li>Food & Farming</li>
</a>
<a href="#">
<li>Cookbook</li>
</a>
<a href="#">
<li>Schools</li>
</a>
<a href="#">
<li>Get Involved</li>
</a>
</ul>
</div>
</body>
</html>
Try targeting it with .menu-container li:hover a:after {} or .menu-container li a:hover:after {}