How to vertical allign list items with icons - html

Can someone help me understand how can I vertical align this?
JSFIDDLE
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/2.0.46/css/materialdesignicons.css"
></link>
<aside class="menu column is-2 full-height">
<ul class="menu-list">
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
</ul>
</aside>
I need align icon and text next to it?
there is some more css since I'm using bulma.io and something custom but not so relevant I think
You can delete that css and create new one if it is not ok

There's a few options at your disposal, depending on your needs.
Updated jsFiddle
Use display: inline-block; on the element(s) that are next to each other and need to be aligned. Then you can use vertical-align: [top|middle|baseline] as needed for each element
i, span {
display: inline-block;
vertical-align: middle;
}
If that alignment doesn't work for you, then you should set the vertical-align to top, to get them positioned how you like, and then you can use line-height to fine-tune the vertical positioning of each element. Example:
i, span {
display: inline-block;
vertical-align: top;
}
i {
line-height: 39px;
}
span {
line-height: 39px;
}

You can add display: flex and align-items: center rules to li a
fiddle
aside {
background-color: #0067ad;
height: 100%;
}
li a {
display: flex;
align-items: center;
}
.menu-list {
list-style: none;
}
i {
color: white;
}
a:hover,
a:active,
.router-link-active {
background-color: black;
}
span {
color: white;
}
}
a {
color: white
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/2.0.46/css/materialdesignicons.css" rel="stylesheet"/>
<aside class="menu column is-2 full-height">
<ul class="menu-list">
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
<li>
<a href="#" class="">
<i class="mdi mdi-file-document-box mdi-48px"></i>
<span>Document</span>
</a>
</li>
</ul>
</aside>

Related

Styling list item in HTML

I have written the following HTML code :
My main focus is to align the list items - HOME | All About Kittens | Feeding Your Kitten
properly. It's currently appearing as a simple list. I want to make it like :
Here the list items are Home, Shop and collections and they are aligned horizontally
Plus when you hover over an item it changes in color and a line appears below it
Any ideas how should I go about implementing this way
a {
color: black;
text-decoration: none;
}
.promo_banner {
background-color: #333;
text-align: center;
color: #fff;
font-size: 12px;
position: relative;
width: 100%;
z-index: 5000;
top: 0;
overflow: hidden;
}
div.logo img {
max-width: 205px;
width: 100%;
margin: 0 auto;
display: block;
max-width: 100%;
height: auto;
}
<html>
<head>
<link rel="stylesheet" href="home.css" />
</head>
<div class="promo_banner">
<div class="promo_banner__content">
<p>
<strong>Our Guide on Caring for Your Furry Feline Friend</strong>
</p>
</div>
<div class="promo_banner-close"></div>
</div>
<div class="top_bar clearfix">
<ul class="social_icons">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<div class="container">
<span><i class="fab fa-twitter"></i><a href="https://www.twitter.com"></span>
<span><i class="fab fa-facebook-f"></i></span>
<span><i class="fab fa-youtube"></i></span>
<span><i class="fab fa-instagram"></i></span>
</div>
</ul>
</div>
<div class="logo text-align--center">
<a href="https://store.linefriends.com" title="LINE FRIENDS INC">
<img
src="logo.jpeg"
class="primary_logo lazyloaded"
alt="LINE FRIENDS INC"
/></a>
</div>
<div class="nav">
<ul class="menu center">
<li >
<span>HOME</span>
</li>
<li >
<span>All About Kittens</span>
</li>
<li >
<span>Feeding Your Kitten</span>
</li>
</ul>
</ul>
</div>
</html>
This is the logo.jpeg I am using in the HTML.
I wanted to make it like How the image line items appears in middle
You can use display: flex; to show navigation like the UI you mentioned.
Here's the demo: https://codepen.io/shubhamp-developer/pen/gOmmxOg
.nav .menu{
display: flex;
list-style: none;
}
Preview:
To learn more about display flex, I would prefer to follow this super helpful link: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Basically these two properties will fix this.
display: flex;
justify-content: center;
Add these classes and remove background color from .nav .menu
.nav .menu{
display: flex;
gap: 1rem;
list-style: none;
}
.nav{
display: flex;
justify-content: center;
}
.nav_wrapper {
background: #f1f1f1;
}
Also wrap your <div class="nav"></div> in another div.nav_wrapper
<div class="nav_wrapper">
<div class="nav">
</div>
</div>

I have a problem about rtl my page in css, can anyone help me?

I face the problem of creating a rtl(right to left) stylesheet when I want to rtl Elements include <i> tag beside any texts or spans.
For example, there is something like this:
There are three elements inside this tag:
<li><i class="sl sl-icon-docs"></i>Requests<span>2</span></li>
First image: this is showing my theme before rtl:
An icon located before the main button title
Button title
a tag for showing number of new requests as a label.
an order should reverse and show all items inside <a> tag from the right, it means from the right we will have 1.icon 2.title 3.label
Second image: rtl by using flex-direction: row-reverse; on main content:
I applied direction: rtl; to the <li> element but nothing works, you can see the changes on second image.
You can reverse the content of the link <a> by using flex-direction: row-reverse on it :
.reverse{
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
}
<ul>
<li><i class="sl sl-icon-docs">Icon</i>Requests<span>2</span></li>
<li><i class="sl sl-icon-docs">Icon</i>Requests<span>2</span></li>
</ul>
<!-- Other examples -->
<a class="reverse">(1) Click me<i class="sl sl-icon-docs">(2) icon</i></a>
<h3 class="reverse">(1) Title example<i class="sl sl-icon-docs">(2) icon</i></h3>
RTL works but not on the <span> part. If you can change span into a division then it'll work.
Else you can use flex-direction: row-reverse after making <li> a display:flex
Here's my code:
#rtl {
direction: rtl;
}
#flex>a {
display: flex;
flex-direction: row-reverse;
}
li {
background: red;
padding: 1em;
border-radius: 3em;
margin: 1em;
text-decoration: none;
width: 200px;
text-align: center;
}
span {
background: white;
border-radius: 10em;
padding: 0 0.7em;
}
ul {
list-style-type: none;
}
<ul>
<li id="normal">
<a href="#">
<img src="https://picsum.photos/30/30?image=0" />Normal <span>1</span>
</a>
</li>
<li id="rtl">
<a href="#">
<img src="https://picsum.photos/30/30?image=0" />RTL <span>2</span>
</a>
</li>
<li id="flex">
<a href="#">
<img src="https://picsum.photos/30/30?image=0" />Row-Reverse <span>3</span>
</a>
</li>
</ul>
The code needs some polishing but I think you've got what you were looking for.
I hope this helps.
Peace 🖖

z-index doesn't work on my menu

I have a menu icon that when I click on it my list items appear;
but it pushes down other elements. I want to set my z-index to it hasn't any effect on other element. but it doesn't work.
<div class="dropdown hidden-md hidden-lg ">
<ul>
<li>
<div class="dropbtn">
<span class="bar1"></span>
<span class="bar2"></span>
<span class="bar3"></span>
</div>
</li>
<li class="dropdown-content">
<ul>
<li>خانه</li>
<li>توانایی ها</li>
<li> <a href='products.php'>محصولات</a></li>
<li><a href='projects.php'>پروژه ها</a></li>
<li><a href='aboutus.php'>درباره ما</a></li>
<li><a href='contactus.php'>تماس با ما</a></li>
</ul>
</li>
</ul>
</div>
CSS:
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
clear: both;
float: right;
direction: rtl;
background-color: #f9f9f9;
min-width: 75px;
font: 1.2em Yekan;
}
.dropdown {
position: relative;
z-index: 999999999999;
float: right;
text-align: right;
}
JS
$(".dropbtn").on("click",
function() {
$(".dropdown-content").toggle();
}
);
z-index is a relative property that display your index according to the order where you put your element in your page.
<div>here the z-index is equal to 1</div>
<div>here the z-index is equal to 2</div>
If you want to be sure that your z-index is take in consideration you can put an absolute position to your html element but you break the index stack of your element.
For sample in your case if you want to do that your .dropdown is still above all the other element you can do :
.dropdown {
position: absolute;
z-index:999999999999;
float: right;
text-align: right;
}
But it's will also run with a relative element position and in than case you have to be careful of teh impact because you break the "z-index stack". One advice is that case is to set all the z-index of all your element impact by your design.
First, I put your code on embed and add some style to see your btn.
Second, I fix your bug by replacing position:relative by position:absolute
$(".dropbtn").on("click", function(){
$(".dropdown-content").toggle();
});
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display:none;
clear: both;
float: right;
direction: rtl;
background-color: #f9f9f9;
min-width: 75px;
font:1.2em Yekan;
}
.dropdown {
position: absolute;
z-index:999999999999;
float: right;
text-align: right;
}
ul {
list-style-type:none
}
.dropbtn {
cursor:pointer;
}
.bar {
display:block;
height: 4px;
width: 24px;
background: black;
margin-bottom: 5px;
border-radius: 2px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dropdown hidden-md hidden-lg ">
<ul>
<li>
<div class="dropbtn">
<span class="bar1 bar"></span>
<span class="bar2 bar"></span>
<span class="bar3 bar"></span>
</div>
</li>
<li class="dropdown-content">
<ul>
<li>خانه</li>
<li>توانایی ها</li>
<li> <a href='products.php'>محصولات</a></li>
<li><a href='projects.php'>پروژه ها</a></li>
<li><a href='aboutus.php'>درباره ما</a></li>
<li><a href='contactus.php'>تماس با ما</a></li>
</ul>
</li>
</ul>
</div>

How can I make floated link clickable for whole row?

CodePen is here: http://codepen.io/anon/pen/BKVMoY
ul {
width: 40%;
border: 1px solid black;
list-style: none;
padding: 0;
}
span:last-of-type {
float: right;
}
<ul>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
Why isn't the floated element underlined?
How can I make it clickable for space between the spans?
Why isn't the floated element underlined?
16.3.1 Underlining, overlining, striking, and blinking: the 'text-decoration' property
Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.
To fix that, you can set text-decoration: inherit on the floated span.
span:last-of-type {
float: right;
text-decoration: inherit;
}
How can I make it clickable for space between the spans?
You can set the <a> to display:block, it will the occupies the entire width available.
a {
display: block;
}
ul {
width: 40%;
border: 1px solid black;
list-style: none;
padding: 0;
}
a {
display: block;
}
span:last-of-type {
float: right;
text-decoration: inherit;
}
<ul>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<a href="#">
<span>New York</span>
<span>$489</span>
</a>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
I think you can just add display: block; to the anchor tags in order to make the entire row clickable. I'm not exactly sure why the floated element removes the underline.
<ul class="whole-row-link">
<li>
<span>New York</span>
<span>$489</span>
</li>
<li>
<span>New York</span>
<span>$489</span>
</li>
</ul>
ul.whole-row-link li {
position: relative;
}
ul.whole-row-link li a {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0
}
I was able to make the space between the link clickable but it stillls looks weird when you dont have underline.
I used the flexbox to acheive the effect of the clickable.
`http://codepen.io/Ebeldev/pen/BKVMwP`

How to get icons to you the top of the main container

hey guys i am new to css in general , I am having a small problem with positioning a couple of social icons, basicaly , all i want to acheive is the following :
the social icons should be centered.
the social icons should touch the top of the main container div .
the 1st objective i have acheived , but i am having difficulty with the secound . , below is the HTML and CSS code :
HTML ::
<section id="contact-us" class="contact-us">
<div class="overlay">
<div class="social-icons">
<ul>
<li>
<a href="">
<i class="fa fa-twitter"></i>
</a>
</li>
<li>
<a href="">
<i>|</i>
</a>
</li>
<li>
<a href="">
<i class="fa fa-facebook"></i>
</a>
</li>
</ul>
</div>
</div>
</section>
CSS ::
html,body {
height: 100%;
}
.contact-us {
background: url(http://wallpaperswiki.com/wallpapers/2012/12/Abstract-Color-Point-1050x1400.jpg);
height: 100%;
}
.overlay {
height: 100%;
background: rgba(146,39,143,.5);
}
.social-icons {
text-align: center;
}
.social-icons ul {
list-style: none;
padding:0;
margin: 0;
display: inline-block;
}
.social-icons ul li {
margin-left: 5px;
margin-right: 5px;
display: inline-block;
}
.social-icons li a {
color: #fff;
}
.social-icons li a i {
font-size: 2em;
}
FIDDLE HERE
notice how the social icons are not touching the top of the main container. actually , all three elements , the 2 social icons and the line inbetween them should touch the top of the main container.
ON inspection :: i am using bootstap , and bootstap has a line-height of 1.42857 as default , if i make the line-height on social-icons to 0 the socia icons get closer to the top , NEARLY SOLVES MY PROBLEM . but still not all three icons are touching the top ? WHY ? and how do i solve this problem ?
EDIT ::
The output i want is the following :
Thank you.
Alex-z.