I am trying to achieve the following layout:
What I've now is:
How do I get li.company under the li.name?
I have tried to float the company li to the left and and making it the last li but that doesn't work keeps going to the same line. Any help will be appreciated.
Here is my code:
#flip {
padding: 5px;
background-color: #4d4d4f;
border: solid 1px #c3c3c3;
width: 33vw;
}
.contact-widget-list,
.sender-info {
list-style: none;
display: inline;
margin: 0;
padding: 0;
}
.sender-info {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 30%;
}
.clearfix::after {
clear: both;
}
.sender-info li {
display: inline-block;
margin: 5px;
padding-bottom: 5px;
margin-bottom: 5px;
}
.email-icon,
.calander-icon,
.dropdown-icon {
float: right;
}
<div id="flip">
<ul class="sender-info">
<li class="name">Name 123123</li>
<li class="company">Company 123123</li>
<li class="dropdown-icon"><i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
</li>
<li class="calander-icon"><i class="fa fa-calendar" aria-hidden="true"></i>
</li>
<li class="email-icon"><i class="fa fa-envelope" aria-hidden="true"></i>
</li>
<li class="clearfix"></li>
</ul>
</div>
Just change the order of your HTML a bit. Place icons first in HTML and other items after it.
HTML:
<div id="flip">
<ul class="sender-info">
<!-- Following icons should come first in HTML -->
<li class="dropdown-icon"><i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
</li>
<li class="calander-icon"><i class="fa fa-calendar" aria-hidden="true"></i>
</li>
<li class="email-icon"><i class="fa fa-envelope" aria-hidden="true"></i>
</li>
<!-- Place following code after icons in HTML -->
<li class="name">Name 123123</li>
<li class="company">Company 123123</li>
</ul>
</div>
And add following css:
.sender-info .name,
.sender-info .company {
background: white;
overflow: hidden;
width: 200px;
}
#import url("https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css");
#flip {
padding: 5px;
background-color: #4d4d4f;
border: solid 1px #c3c3c3;
}
.contact-widget-list,
.sender-info {
list-style: none;
display: inline;
overflow: hidden;
margin: 0;
padding: 0;
}
.sender-info {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 30%;
}
.sender-info li {
margin: 5px;
padding-bottom: 5px;
}
.sender-info .name,
.sender-info .company {
background: white;
overflow: hidden;
width: 200px;
}
.email-icon,
.calander-icon,
.dropdown-icon {
float: right;
}
<div id="flip">
<ul class="sender-info">
<li class="dropdown-icon"><i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
</li>
<li class="calander-icon"><i class="fa fa-calendar" aria-hidden="true"></i>
</li>
<li class="email-icon"><i class="fa fa-envelope" aria-hidden="true"></i>
</li>
<li class="name">Name 123123</li>
<li class="company">Company 123123</li>
</ul>
</div>
Related
This is the website I'm currently have to work with: https://www.mpc.gov.my/home. Everything seems fine when you view using a desktop or big screen, but when you try to browse it using a mobile/smaller screen the navigation menu is giving the user a headache.
How can I fix it? I don't want the menu to disappear if I scroll down. Anyone get any ideas?
$(document).ready(function() {
"use strict";
$('.menu > ul > li:has( > ul)').addClass('menu-dropdown-icon');
$('.menu > ul > li > ul:not(:has(ul))').addClass('normal-sub');
$(".menu > ul").before(" ");
$(".menu > ul > li").hover(function(e) {
if ($(window).width() > 943) {
$(this).children("ul").stop(true, false).fadeToggle(150);
e.preventDefault();
}
});
$(".menu > ul > li").click(function() {
if ($(window).width() <= 943) {
$(this).children("ul").fadeToggle(150);
}
});
$(".menu-mobile").click(function(e) {
$(".menu > ul").toggleClass('show-on-mobile');
e.preventDefault();
});
});
$(window).resize(function() {
$(".menu > ul > li").children("ul").hide();
$(".menu > ul").removeClass('show-on-mobile');
});
/*===================================
Third Mega Menu
=====================================*/
.menu {
width: 100%;
}
.menu-container {
margin: 0 auto;
background: #e9e9e9;
}
.menu a.logo {
display: inline-block;
padding: 1.5em 3em;
width: 19%;
float: left;
}
.menu img {
max-width: 100%;
}
.menu-mobile {
display: none;
padding: 20px;
}
.menu-mobile:after {
content: "\f0c9";
font-family: "Font Awesome 5 Pro";
font-size: 2.5rem;
padding: 0;
float: right;
position: relative;
top: 50%;
-webkit-transform: translateY(-25%);
transform: translateY(-25%);
}
.menu-dropdown-icon:before {
content: "\f0c9";
font-family: "Font Awesome 5 Pro";
display: none;
cursor: pointer;
float: right;
padding: 1.5em 2em;
background: #fff;
color: #333;
}
.menu>ul {
margin: 0 auto;
width: 100%;
list-style: none;
padding: 0;
position: relative;
/* IF .menu position=relative -> ul = container width, ELSE ul = 100% width */
box-sizing: border-box;
clear: right;
}
.menu>ul:before,
.menu>ul:after {
content: "";
display: table;
}
.menu>ul:after {
clear: both;
}
.menu>ul>li {
float: left;
background: #e9e9e9;
padding: 0;
width: 25%;
/* added- aidan */
margin: 0;
list-style: none!important;
}
.menu>ul>li a {
text-decoration: none;
padding: 1.5em 3em;
display: block;
}
.menu>ul>li:hover {
background: #f0f0f0;
}
.menu>ul>li>ul {
display: none;
width: 100%;
background: #f0f0f0;
padding: 20px;
position: absolute;
z-index: 99;
left: 0;
margin: 0;
list-style: none;
box-sizing: border-box;
}
.menu>ul>li>ul:before,
.menu>ul>li>ul:after {
content: "";
display: table;
}
.menu>ul>li>ul:after {
clear: both;
}
.menu>ul>li>ul>li {
margin: 0;
padding-bottom: 0;
list-style: none;
width: 25%;
background: none;
float: left;
list-style: none!important;
/* added - aidan */
}
.menu>ul>li>ul>li a {
color: #777;
padding: .2em 0;
width: 95%;
display: block;
border-bottom: 1px solid #ccc;
}
.menu>ul>li>ul>li a:hover {
color: #03a9f4;
}
.menu>ul>li>ul>li>ul {
display: block;
padding: 0;
margin: 10px 0 0;
list-style: none;
box-sizing: border-box;
margin-left: 20px;
text-indent: -10px;
}
.menu>ul>li>ul>li>ul:before,
.menu>ul>li>ul>li>ul:after {
content: "";
display: table;
}
.menu>ul>li>ul>li>ul:after {
clear: both;
}
.menu>ul>li>ul>li>ul>li {
float: left;
width: 100%;
padding: 0px 0;
/*reduced to 0px - aidan */
list-style: none!important;
/*added -aidan */
margin: 0!important;
/*added !important - aidan*/
font-size: .8em;
}
.menu>ul>li>ul>li>ul>li a {
border: 0;
font-size: 14px;
}
.menu>ul>li>ul.normal-sub {
width: 300px;
left: auto;
padding: 10px 20px;
}
.menu>ul>li>ul.normal-sub>li {
width: 100%;
}
.menu>ul>li>ul.normal-sub>li a {
border: 0;
padding: 1em 0;
}
.head-sub {
font-weight: 700;
/* added - aidan */
color: #be1621!important;
/* added - aidan */
}
.mobile-vue {
display: none!important;
}
.desktop-vue {
display: block!important;
padding: 0px!important;
}
li.menu-dropdown-icon {
margin: 0px!important;
}
.img-desktop-vue {
max-width: 70%!important;
}
.tertiary-menu {
background-color: #e3e3e3;
/* added - aidan */
}
/* ––––––––––––––––––––––––––––––––––––––––––––––––––
Mobile style's
–––––––––––––––––––––––––––––––––––––––––––––––––– */
#media only screen and (max-width: 991px) {
.mobile-vue {
display: block!important;
/*added - aidan*/
}
.desktop-vue {
display: none!important;
/*added - aidan*/
padding: unset;
}
li.menu-dropdown-icon {
margin: unset!important;
/*added - aidan*/
}
.menu-container {
width: 100%;
display: block;
}
.menu-container .menu {
display: inline-block;
}
.menu-mobile {
display: block;
float: right;
padding: 20px 20px 0;
}
.menu-dropdown-icon:before {
display: block;
}
.menu>ul {
display: none;
width: 100%;
}
.menu>ul>li {
width: 100%;
float: none;
display: block;
margin: 0!important;
/* added - aidan */
}
.menu>ul>li a {
padding: 1.5em;
width: 100%;
display: block;
color: #000000;
}
.menu>ul>li>ul {
position: relative;
padding: 0 40px;
}
.menu>ul>li>ul.normal-sub {
width: 100%;
}
.menu>ul>li>ul>li {
float: none;
width: 100%;
margin-top: 20px;
margin: 0!important;
/* added - aidan*/
}
.menu>ul>li>ul>li a {
width: 90%;
/* added - aidan */
}
.menu>ul>li>ul>li:first-child {
margin: 0;
}
.menu>ul>li>ul>li>ul {
position: relative;
}
.menu>ul>li>ul>li>ul>li {
float: none;
}
.menu .show-on-mobile {
display: block;
}
.container-mobil {
padding-left: unset!important;
padding-right: unset!important;
}
}
.fas,
.far {
padding-right: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="menu-container">
<div class="menu">
<ul class="clearfix">
<li>
<img src="/static_files/media_manager/1/Index-About-EN-1.png" class="img-desktop-vue">
ABOUT MPC
<ul>
<li>Corporate Info
<ul>
<li><i class="fas fa-building"></i> Background</li>
<li><i class="fas fa-bullseye"></i> Vision, Mission & Objectives</li>
<li><i class="fas fa-sitemap"></i> Board of Directors</li>
<li><i class="fas fa-sitemap"></i> MPC Management</li>
<li><i class="fas fa-sitemap"></i> Organisational Structure</li>
<li><i class="fas fa-file-contract"></i> Quality Policy</li>
<li><i class="fas fa-list-alt"></i> Client Charter</li>
<li><i class="fas fa-file-contract"></i> No Gift Policy</li>
<li><i class="fas fa-file-contract"></i> Anti-Corruption Plan</li>
</ul>
</li>
<li>Contact Us
<ul>
<li><i class="fas fa-address-book"></i> How To Contact Us?</li>
<li><i class="fas fa-users"></i> Staff Directory</li>
<li><i class="fas fa-tasks"></i> Frequently Asked Question</li>
<li><i class="fas fa-briefcase"></i> Career</li>
<li><i class="fas fa-chart-area"></i> Procurement</li>
</ul>
</li>
<li>Staff Access
<ul>
<li><i class="fas fa-globe"></i> Staff Portal</li>
<li><i class="fas fa-globe"></i> Procurement Information Center (PRINCE)</li>
<li><i class="fas fa-globe"></i> Finance Portal</li>
</ul>
</li>
</ul>
</li>
<li>
<img src="/static_files/media_manager/1/Index-Programme-EN-1.png" class="img-desktop-vue">
PROGRAMMES & SERVICES
<ul>
<li>Productivity Initiatives
<ul>
<li><i class="fas fa-passport"></i> Industry4WRD Readiness Assessment</li>
<li><i class="fas fa-clipboard-check"></i> Team Excellence Convention</li>
<li><i class="fas fa-briefcase"></i> Lean Management</li>
<li><i class="fas fa-cubes"></i> Enterprise Business Excellence</li>
<li><i class="fas fa-award"></i> Productivity Excellence Recognition</li>
<li><i class="fas fa-user-tie"></i> MPC Certified Productivity Specialist Programme</li>
<li><i class="fas fa-poll"></i> Productivity Best Practices Case Studies and Sharing</li>
<li><i class="fas fa-balance-scale"></i> Productivity 1010</li>
<li><i class="fas fa-quote-left"></i> Negeri Produktif</li>
<li><i class="fas fa-puzzle-piece"></i> Malaysia Productivity Blueprint</li>
<li><i class="fas fa-people-carry"></i> Productivity Nexus</li>
</ul>
</li>
<li>Productivity Online Services
<ul>
<li><i class="fas fa-globe"></i> Digital Regulatory Notification</li>
<li><i class="fas fa-globe"></i> QE Audit Application (Quality Environment)</li>
<li><i class="fas fa-globe"></i> Benchmarking Online Networking Database (BOND) Portal</li>
<li><i class="fas fa-globe"></i> ezBE Assessment Tool</li>
<li><i class="fas fa-globe"></i> Unified Public Consultation (UPC) Portal</li>
<li><i class="fas fa-globe"></i> WayUp Portal</li>
<li><i class="fas fa-globe"></i> Smart Regulation (#MyMudah)</li>
</ul>
</li>
<li>Business Virtual Advisory Services (VAS)
<ul>
<li><i class="fas fa-business-time"></i> Business Virtual Advisory Clinics (VAC)</li>
</ul>
</li>
<li>MPC Webinar Sessions With Experts
<ul>
<li><i class="fas fa-chalkboard-teacher"></i> MPC Webinar Sessions With Experts</li>
</ul>
</li>
<li>P&I Associate Membership
<ul>
<li><i class="fas fa-users"></i> P&I Associate Membership</li>
</ul>
</li>
<li>Events Calendar
<ul>
<li><i class="far fa-calendar-alt"></i> Events Calendar</li>
</ul>
</li>
</ul>
</li>
<li>
<img src="/static_files/media_manager/1/Index-Productivity-EN-1.png" class="img-desktop-vue">
PRODUCTIVITY & COMPETITIVENESS
<ul>
<li>Smart Regulation Towards A Robust Ecosystem
<ul>
<li><i class="fas fa-business-time"></i> Business Regulation Virtual Advisory Clinic</li>
<li><i class="fas fa-landmark"></i> Good Regulatory Practice (GRP)</li>
</ul>
</li>
<li>Workforce Of The Future
<ul>
<li class="menushow"><i class="fas fa-thumbs-up"></i> e-Shared Prosperity Organization (eSPO)</li>
</ul>
</li>
<li>Digitalisation And Technology
<ul>
<li><i class="fas fa-chalkboard-teacher"></i> Digitalisation And Technology</li>
</ul>
</li>
<li>Productivity Mindset
<ul>
<li><i class="fas fa-user-friends"></i> Programme and Activity</li>
<li><i class="fas fa-users-cog"></i> Sejahtera Productivity Culture Index</li>
</ul>
</li>
<li>Incentive Structure
<ul>
<li><i class="fas fa-gifts"></i> Incentive Structure</li>
</ul>
</li>
</ul>
</li>
<li>
<img src="/static_files/media_manager/1/Index-Media-EN-1.png" class="img-desktop-vue">
MEDIA & PUBLICATION
<ul>
<li>Media
<ul>
<li><i class="far fa-newspaper"></i> Press Release</li>
<li><i class="far fa-comment-alt"></i> Speeches</li>
<li><i class="fas fa-music"></i> Audio Gallery</li>
<li><i class="fas fa-video"></i> Video Gallery</li>
<li><i class="fas fa-envelope-open-text"></i> e-Newsletter</li>
</ul>
</li>
<li>Publication
<ul>
<li><i class="fas fa-network-wired"></i> Productivity Performance</li>
<li><i class="fas fa-chart-bar"></i> Competitiveness Report</li>
<li><i class="fas fa-chart-line"></i> Annual Report</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
Here is what happen when I scroll when in mobile view: https://youtu.be/UzLTU-Dzhes
if you inspect in your website, you can see that there is a display none in the menu :
.menu-container {
width: 100%;
display: none;
}
remove it and everything will work fine
I have a problem linking html(<li class="active"></li>) to icons and I do not know how to make icons different color after I click on them (color of an icon is black, when I click on an icon it does not stay white). I tried another way to get html in but then the animation did not work. I looked at millions of pages and I could not find an answer. On top of that, I am new to coding.
body
{
margin: 0;
padding: 0;
font-family: sans-serif;
background: #273847;
}
ul
{
justify-content: center;
text-align: center;
min-width: 100%;
position: fixed;
top: 100%;
left: 50%;
transform: translate(-50%,-50%);
margin: 0;
padding: 15px 0;
background: #2b3e4f;
display: flex;
border-radius: 10px;
}
ul li
{
list-style: none;
text-align: center;
display: block;
}
ul li:last-child
{
border-right: none;
}
ul li a
{
text-decoration: none;
padding: 0 27px;
display: block;
}
ul li a .icon
{
width: 40px;
height: 90px;
text-align: center;
overflow: hidden;
margin: 0 auto 10px;
}
ul li a .icon .fa
{
width: 100%;
height: 100%;
line-height: 40px;
font-size: 40px;
transition: 0.5s;
color: #0a0e12;
}
ul li a .icon .fa:last-child
{
color: #eeeeee;
}
ul li a:hover .icon .fa
{
transform: translateY(-100%);
}
/*
ul li a .name
{
position: relative;
height: 20px;
width: 100%;
display: block;
overflow: hidden;
}
ul li a .name span
{
display: block;
position: relative;
color: #000;
font-size: 18px;
line-height: 20px;
transition: 0.5s;
}
ul li a .name span:before
{
content: attr(data-text);
position: absolute;
top: -100%;
left 0;
width: 100%;
height: 100%;
color: #eeeeee;
}
ul li a:hover .name span
{
transform: translateY(20px);
}
*/
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<ul>
<div>
<ul>
<li class="active"></li>
</ul>
</div>
<li>
<a>
<div class="icon">
<i class="fa fa-home" aria-hidden="true"></i>
<i class="fa fa-home" aria-hidden="true"></i>
</div>
<!-- <div class="icon"><span data-text="Home">Home</span></div> -->
</a>
</li>
<div>
<ul>
<li></li>
</ul>
</div>
<li>
<a>
<div class="icon">
<i class="fa fa-tag" aria-hidden="true"></i>
<i class="fa fa-tag" aria-hidden="true"></i>
</div>
<!-- <div class="icon"><span data-text="About">About</span></div> -->
</a>
</li>
<div>
<ul>
<li></li>
</ul>
</div>
<li>
<a>
<div class="icon">
<i class="fa fa-envelope" aria-hidden="true"></i>
<i class="fa fa-envelope" aria-hidden="true"></i>
</div>
<!-- <div class="icon"><span data-text="Contact">Contact</span></div> -->
</a>
</li>
<div>
<ul>
<li></li>
</ul>
</div>
<li>
<a>
<div class="icon">
<i class="fa fa-cog" aria-hidden="true"></i>
<i class="fa fa-cog" aria-hidden="true"></i>
</div>
<!-- <div class="icon"><span data-text="Settings">Settings</span></div> -->
</a>
</li>
</ul>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
I doubt you can solve this issue with a css-only solution - I might be wrong though.
Nevertheless you can do it with some Javascript trickery which goes a little like this:
layer an additional icon on top of your current icons, give it the desired color e.g. red and make it invisible by setting it's css opacity property to 0
attach a click event listener to the freshly created icons
inside the callback handler reset the opacity of all the red active icons to 0, reset the opacity of all the icons below (those that are used for the CSS animation effect) to 1, make the clicked icon visible and finally the two icons in the background invisible.
Here's an example (just click on 'Run code snippet'):
var buttons = document.getElementsByClassName("active");
buttons[0].addEventListener("click", clicked);
function clicked(e) {
var iconsToShow = document.querySelectorAll(`[class*="icon"]`);
iconsToShow.forEach(
function(currentValue, currentIndex, listObj) {
currentValue.style.opacity = 1;
});
var iconsToHide = document.querySelectorAll(`[class*="active"]`);
iconsToHide.forEach(
function(currentValue, currentIndex, listObj) {
currentValue.firstElementChild.style.opacity = 0;
});
var iconToHide = e.target.parentElement.parentElement.querySelectorAll(`[class*="icon"]`)[0];
iconToHide.style.opacity = 0;
e.target.style.opacity = 1;
}
for (var a = 0; a < buttons.length; a++) {
buttons[a].addEventListener("click", clicked);
}
body {
margin: 0;
padding: 0;
font-family: sans-serif;
background: #273847;
}
ul {
justify-content: center;
text-align: center;
min-width: 100%;
position: fixed;
top: 100%;
left: 50%;
transform: translate(-50%, -50%);
margin: 0;
padding: 15px 0;
background: #2b3e4f;
display: flex;
border-radius: 10px;
}
ul li {
list-style: none;
text-align: center;
display: block;
}
ul li:last-child {
border-right: none;
}
ul li a {
text-decoration: none;
padding: 0 27px;
display: block;
}
ul li a .icon {
width: 40px;
height: 90px;
text-align: center;
overflow: hidden;
margin: 0 auto 10px;
}
ul li a .icon .fa {
width: 100%;
height: 100%;
line-height: 40px;
font-size: 40px;
transition: 0.5s;
color: #0a0e12;
}
ul li a .active .fa {
font-size: 40px;
transform: translateY(-250%);
color: #ff0e12;
opacity: 0;
}
ul li a .icon .fa:last-child {
color: #eeeeee;
}
ul li a:hover .icon .fa {
transform: translateY(-100%);
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<body>
<ul>
<div>
<ul>
<li>
</li>
</ul>
</div>
<li>
<a class="button">
<div class="icon">
<i class="fa fa-home" aria-hidden="true"></i>
<i class="fa fa-home" aria-hidden="true"></i>
</div>
<div class="active">
<i class="fa fa-home" aria-hidden="true"></i>
</div>
</a>
</li>
<div>
<ul>
<li>
</li>
</ul>
</div>
<li>
<a>
<div class="icon">
<i class="fa fa-tag" aria-hidden="true"></i>
<i class="fa fa-tag" aria-hidden="true"></i>
</div>
<div class="active">
<i class="fa fa-tag" aria-hidden="true"></i>
</div>
</a>
</li>
<div>
<ul>
<li>
</li>
</ul>
</div>
<li>
<a>
<div class="icon">
<i class="fa fa-envelope" aria-hidden="true"></i>
<i class="fa fa-envelope" aria-hidden="true"></i>
</div>
<div class="active">
<i class="fa fa-envelope" aria-hidden="true"></i>
</div>
</a>
</li>
<div>
<ul>
<li>
</li>
</ul>
</div>
<li>
<a>
<div class="icon">
<i class="fa fa-cog" aria-hidden="true"></i>
<i class="fa fa-cog" aria-hidden="true"></i>
</div>
<div class="active">
<i class="fa fa-cog" aria-hidden="true"></i>
</div>
</a>
</li>
</ul>
</body>
Please check the below snippet.
When a link goes on multiple lines, I'd like the text from all lines below the first one to be aligned with the start (left position) of the first line. The icon should still be vertically aligned with the first line (as it is now).
In other words, in the below example, the word "longer" should be aligned below the word "This".
I have tried playing with paddings and text-indents without success. Does anyone have a solution?
.column {
width: 150px;
background-color: lightgrey;
padding: 10px;
}
ul {
list-style: none;
padding-left: 0;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="column">
<ul>
<li><span class="fa fa-fw fa-tree"></span> Hello</li>
<li><span class="fa fa-fw fa-car"></span> This is a much longer link</li>
<li><span class="fa fa-fw fa-book"></span> Hello again</li>
</ul>
</div>
Add this code in css..
.column li {
position: relative;
padding-left: 25px;
}
li span {
position: absolute;
left: 0;
top: 0;
}
.column {
width: 150px;
background-color: lightgrey;
padding: 10px;
}
ul {
list-style: none;
padding-left: 0;
}
.column li {
position: relative;
padding-left: 25px;
}
li span {
position: absolute;
left: 0;
top: 0;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="column">
<ul>
<li><span class="fa fa-fw fa-tree"></span> Hello</li>
<li><span class="fa fa-fw fa-car"></span> This is a much longer link</li>
<li><span class="fa fa-fw fa-book"></span> Hello again</li>
</ul>
</div>
Just add display:flex to your li and it will work if you want the text to move further away from the icon then use margins too.
Hope this is what you are looking for.
.column {
width: 150px;
background-color: lightgrey;
padding: 10px;
}
ul {
list-style: none;
padding-left: 0;
}
li {
display: flex;
}
a {
margin-left: 10px;
}
.n {
width: 20px;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="column">
<ul>
<li>
<div class="n"><span class="fa fa-fw fa-tree"></span></div> Hello</li>
<li>
<div class="n"><span class="fa fa-fw fa-car"></span></div> This is a much longer link</li>
<li>
<div class="n"><span class="fa fa-fw fa-book"></span></div> Hello again</li>
</ul>
</div>
If we dont add width to icons and there is flex
.column {
width: 150px;
background-color: lightgrey;
padding: 10px;
}
ul {
list-style: none;
padding-left: 0;
}
li
{
display:flex;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="column">
<ul>
<li><span class="fa fa-fw fa-tree" style="background-color:blue;"></span> Hello</li>
<li><span class="fa fa-fw fa-car" style="background-color:blue;"></span> This is a much longer link</li>
<li><span class="fa fa-fw fa-book" style="background-color:blue;"></span> Hello again</li>
</ul>
</div>
As an alternative, you can also use a display: grid; layout on your li tag.
.column {
width: 150px;
background-color: lightgrey;
padding: 10px;
}
ul {
list-style: none;
padding-left: 0;
}
.column li {
display: grid;
grid-template-columns: auto 1fr;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="column">
<ul>
<li><span class="fa fa-fw fa-tree"></span> Hello</li>
<li><span class="fa fa-fw fa-car"></span> This is a much longer link</li>
<li><span class="fa fa-fw fa-book"></span> Hello again</li>
</ul>
</div>
I am designing an electron application with a tabpane. However when the user makes the window smaller or adds more tabs the scrollbar that is supposed to let users see all the tabs does not work correctly. The scrollbar allows for a little movement but most of the tabs overflow regardless. I have uploaded a stripped down code snippet version of the app here so you can see my problem in more detail.
body {
margin: 0;
width: 100vw;
height: 100vh;
overflow-x: hidden;
display: flex;
flex-direction: column;
}
.window {
position: relative;
display: flex;
flex-grow: 1;
}
.window__content {
display: flex;
flex-direction: column;
flex-grow: 1;
}
ul {
padding: 0;
margin: 0;
list-style: none;
}
.action-bar {
display: flex;
flex-shrink: 0;
flex-direction: column;
overflow: hidden;
width: 44px;
transition: width 0.2s ease;
}
.action-bar .action-bar__item {
white-space: nowrap;
padding: 6px 12px;
}
.action-bar i {
font-size: 20px;
margin-right: 22px;
}
.action-bar__spacer {
flex-grow: 1;
}
.console {
position: relative;
height: 44px;
transition: all 0.5s ease;
min-height: 44px;
max-height: 50%;
overflow: hidden;
font-size: 13px;
}
.tabpane {
display: flex;
flex-grow: 1;
flex-direction: column;
height: 100%;
position: relative;
}
.tabpane .tabpane__tabs {
position: relative;
white-space: nowrap;
flex-shrink: 0;
overflow-x: auto;
}
.tabpane .tabpane__tabs li {
position: relative;
display: inline-block;
padding: 8px;
font-size: 13px;
min-width: 80px;
max-width: 160px;
border: solid #1E1E1E;
border-width: 0 1px;
margin-right: -5px;
color: #8D8D8D;
background: #333333;
}
.tabpane .tabpane__tabs li:hover {
cursor: pointer;
}
.tabpane .tabpane__tabs li.tab--active {
border-top-width: 1px;
padding-top: 7px;
background: #1E1E1E;
color: white;
z-index: 2;
}
.tabpane .tabpane__tabs li i {
float: right;
visibility: hidden;
}
.tabpane .tabpane__tabs li:hover i, .tabpane .tabpane__tabs li.tab--active i {
visibility: visible;
}
#draggableTab {
color: #8D8D8D;
background-color: rgba(51,51,51,0.9);
outline: 1px solid rgba(64,64,64,0.9);
padding: 7px 8px;
font-size: 13px;
min-width: 80px;
cursor: pointer;
position: fixed;
z-index: 10030;
pointer-events: none;
white-space: nowrap;
}
#draggableTab i {
color: white;
float: right;
opacity: 0.3;
position: relative;
z-index: 9999;
}
.tabpane__panes {
position: relative;
display: flex;
flex-grow: 1;
overflow-y: scroll;
}
.tabpane__panes li {
display: none;
}
.tabpane__panes li.pane--active {
display: initial;
flex: 1;
padding: 0 44px;
background: #1E1E1E;
}
/* Colors */
.theme--dark {
color: white;
}
.shade--light {
background: #333333;
}
.shade--neutral {
background: #252526;
}
.shade--dark {
background: #1E1E1E;
}
.shade--darker {
background: #141516;
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="UTF-8">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
</head>
<body class="theme--dark shade--dark">
<div class="window">
<ul class="action-bar shade--neutral">
<li class="action-bar__item" title="Expand"><i class="fa fa-bars" aria-hidden="true"></i></li>
<li class="action-bar__item" title="Home" data-template="home"><i class="fa fa-home" aria-hidden="true"></i>Home</li>
<li class="action-bar__item" title="Search" data-template="search"><i class="fa fa-search" aria-hidden="true"></i>Search</li>
<li class="action-bar__item" title="Download" data-template="download"><i class="fa fa-download" aria-hidden="true"></i>Download</li>
<li class="action-bar__item" title="Statistics" data-template="statistics"><i class="fa fa-pie-chart" aria-hidden="true"></i>Statistics</li>
<li class="action-bar__item" title="Help" data-template="help"><i class="fa fa-question-circle" aria-hidden="true"></i>Help</li>
<li class="action-bar__divider shade--light"></li>
<li class="action-bar__item" title="Lights On"><i class="fa fa-sun-o" aria-hidden="true"></i>Lights On</li>
<li class="action-bar__item" title="Console"><i class="fa fa-code" aria-hidden="true"></i>Console</li>
<li class="action-bar__spacer"></li>
<li class="action-bar__item" title="Lock"><i class="fa fa-lock" aria-hidden="true"></i>Lock</li>
<li class="action-bar__item" title="Settings" data-template="settings"><i class="fa fa-cog" aria-hidden="true"></i>Settings</li>
</ul>
<div class="window__content">
<div class="tabpane">
<ul class="tabpane__tabs shade--neutral">
<li template="home" source="undefined" class="tab--active left">
Home
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_1" source="undefined" class="">
page 1
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_2" source="undefined" class="">
page 2
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_3" source="undefined" class="">
page 3
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_4" source="undefined" class="">
page 4
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_5" source="undefined" class="">
page 5
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_6" source="undefined" class="">
page 6
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_7" source="undefined" class="">
page 7
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_8" source="undefined" class="">
page 8
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
</ul>
<ul class="tabpane__panes">
<li class="pane--active">
<h1>Hello</h1>
<div style="max-width: 400px;">
<p>Try resizing your browser window until some tabs are hidden and a scrollbar appears.</p>
<p>I have removed the JavaScript for this example don't expect buttons to work. The scrollbar however needs to work no matter the height of the console window below the tabs or the width of the action bar to the left.</p>
</div>
</li>
<li>page for page 2</li>
<li>page for page 3</li>
<li>page for page 4</li>
<li>page for page 5</li>
<li>page for page 6</li>
<li>page for page 7</li>
<li>page for page 8</li>
</ul>
</div>
<div class="console console--is-closed shade--darker">
<div class="console__close"><span class="lnr lnr-cross"></span></div>
<div class="console__area">
<div class="console__resize-bar"></div>
<p><span class="console__point">Console> </span><input type="text" class="console__input"></p>
</div>
</div>
</div>
</div>
</body>
</html>
I think this would work for you.
just remove the flex-grow: 1; from .window__content and add width: calc(100% - 44px);
width: calc(100% - 44px); == width: calc(100% - .action-bar[width]);
body {
margin: 0;
width: 100vw;
height: 100vh;
overflow-x: hidden;
display: flex;
flex-direction: column;
}
.window {
position: relative;
display: flex;
flex-grow: 1;
}
.window__content {
display: flex;
flex-direction: column;
width: calc(100% - 44px);
}
ul {
padding: 0;
margin: 0;
list-style: none;
}
.action-bar {
display: flex;
flex-shrink: 0;
flex-direction: column;
overflow: hidden;
width: 44px;
transition: width 0.2s ease;
}
.action-bar .action-bar__item {
white-space: nowrap;
padding: 6px 12px;
}
.action-bar i {
font-size: 20px;
margin-right: 22px;
}
.action-bar__spacer {
flex-grow: 1;
}
.console {
position: relative;
height: 44px;
transition: all 0.5s ease;
min-height: 44px;
max-height: 50%;
overflow: hidden;
font-size: 13px;
}
.tabpane {
display: flex;
flex-grow: 1;
flex-direction: column;
height: 100%;
position: relative;
}
.tabpane .tabpane__tabs {
position: relative;
white-space: nowrap;
flex-shrink: 0;
overflow-x: auto;
}
.tabpane .tabpane__tabs li {
position: relative;
display: inline-block;
padding: 8px;
font-size: 13px;
min-width: 80px;
max-width: 160px;
border: solid #1E1E1E;
border-width: 0 1px;
margin-right: -5px;
color: #8D8D8D;
background: #333333;
}
.tabpane .tabpane__tabs li:hover {
cursor: pointer;
}
.tabpane .tabpane__tabs li.tab--active {
border-top-width: 1px;
padding-top: 7px;
background: #1E1E1E;
color: white;
z-index: 2;
}
.tabpane .tabpane__tabs li i {
float: right;
visibility: hidden;
}
.tabpane .tabpane__tabs li:hover i, .tabpane .tabpane__tabs li.tab--active i {
visibility: visible;
}
#draggableTab {
color: #8D8D8D;
background-color: rgba(51,51,51,0.9);
outline: 1px solid rgba(64,64,64,0.9);
padding: 7px 8px;
font-size: 13px;
min-width: 80px;
cursor: pointer;
position: fixed;
z-index: 10030;
pointer-events: none;
white-space: nowrap;
}
#draggableTab i {
color: white;
float: right;
opacity: 0.3;
position: relative;
z-index: 9999;
}
.tabpane__panes {
position: relative;
display: flex;
flex-grow: 1;
overflow-y: scroll;
}
.tabpane__panes li {
display: none;
}
.tabpane__panes li.pane--active {
display: initial;
flex: 1;
padding: 0 44px;
background: #1E1E1E;
}
/* Colors */
.theme--dark {
color: white;
}
.shade--light {
background: #333333;
}
.shade--neutral {
background: #252526;
}
.shade--dark {
background: #1E1E1E;
}
.shade--darker {
background: #141516;
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="UTF-8">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
</head>
<body class="theme--dark shade--dark">
<div class="window">
<ul class="action-bar shade--neutral">
<li class="action-bar__item" title="Expand"><i class="fa fa-bars" aria-hidden="true"></i></li>
<li class="action-bar__item" title="Home" data-template="home"><i class="fa fa-home" aria-hidden="true"></i>Home</li>
<li class="action-bar__item" title="Search" data-template="search"><i class="fa fa-search" aria-hidden="true"></i>Search</li>
<li class="action-bar__item" title="Download" data-template="download"><i class="fa fa-download" aria-hidden="true"></i>Download</li>
<li class="action-bar__item" title="Statistics" data-template="statistics"><i class="fa fa-pie-chart" aria-hidden="true"></i>Statistics</li>
<li class="action-bar__item" title="Help" data-template="help"><i class="fa fa-question-circle" aria-hidden="true"></i>Help</li>
<li class="action-bar__divider shade--light"></li>
<li class="action-bar__item" title="Lights On"><i class="fa fa-sun-o" aria-hidden="true"></i>Lights On</li>
<li class="action-bar__item" title="Console"><i class="fa fa-code" aria-hidden="true"></i>Console</li>
<li class="action-bar__spacer"></li>
<li class="action-bar__item" title="Lock"><i class="fa fa-lock" aria-hidden="true"></i>Lock</li>
<li class="action-bar__item" title="Settings" data-template="settings"><i class="fa fa-cog" aria-hidden="true"></i>Settings</li>
</ul>
<div class="window__content">
<div class="tabpane">
<ul class="tabpane__tabs shade--neutral">
<li template="home" source="undefined" class="tab--active left">
Home
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_1" source="undefined" class="">
page 1
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_2" source="undefined" class="">
page 2
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_3" source="undefined" class="">
page 3
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_4" source="undefined" class="">
page 4
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_5" source="undefined" class="">
page 5
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_6" source="undefined" class="">
page 6
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_7" source="undefined" class="">
page 7
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
<li template="page_8" source="undefined" class="">
page 8
<i class="fa fa-times" aria-hidden="true" title="Close (Ctrl+W)"></i>
</li>
</ul>
<ul class="tabpane__panes">
<li class="pane--active">
<h1>Hello</h1>
<div style="max-width: 400px;">
<p>Try resizing your browser window until some tabs are hidden and a scrollbar appears.</p>
<p>I have removed the JavaScript for this example don't expect buttons to work. The scrollbar however needs to work no matter the height of the console window below the tabs or the width of the action bar to the left.</p>
</div>
</li>
<li>page for page 2</li>
<li>page for page 3</li>
<li>page for page 4</li>
<li>page for page 5</li>
<li>page for page 6</li>
<li>page for page 7</li>
<li>page for page 8</li>
</ul>
</div>
<div class="console console--is-closed shade--darker">
<div class="console__close"><span class="lnr lnr-cross"></span></div>
<div class="console__area">
<div class="console__resize-bar"></div>
<p><span class="console__point">Console> </span><input type="text" class="console__input"></p>
</div>
</div>
</div>
</div>
</body>
</html>
Hope this was helpfull for you.
The problem is the width of your tabpane. It should not be 100% (default), since there is the action bar on the left side
.tabpane {
display: flex;
flex-grow: 1;
flex-direction: column;
height: 100%;
position: relative;
}
add
width:90%;
or whatever 100% - 44px would be
I think;
.window__content {
width: 90%; // add
}
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