Align li containing svg, with other li containing font-awesome icons [duplicate] - html

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 1 year ago.
FontAwesome is missing one Icon and as such I have to fall back to using an svg.
<ul class="icons other">
<li><a>
<svg width="50" height="50">...</svg>
</a></li>
<li><a class="fab fa-soundcloud"></a></li>
<li><a class="fab fa-spotify"></a></li>
</ul>
with the following styling (scss),
.icons {
>li {
display: inline-block;
padding: 0;
>a, svg {
height: 50px;
width: 50px;
line-height: 50px;
font-size: 1.8em;
text-align: center;
border-radius: 50%;
color: rgba(255, 255, 255, 0.8);
box-shadow: 0 0px 2px rgba(255, 255, 255, 0.56);
}
.fab {
background-color: black;
}
}
}
Here is a demo fiddle: https://jsfiddle.net/Cains/owarL5p1/

As li are inline items, make them vertically middle, and make a as block elements because height width won't work on inline elements.
.icons {
>li {
display: inline-block;
padding: 0;
vertical-align:middle; /*** added this ***/
>a, svg {
height: 50px;
width: 50px;
line-height: 50px;
font-size: 1.8em;
text-align: center;
border-radius: 50%;
color: rgba(255, 255, 255, 0.8);
box-shadow: 0 0px 2px rgba(255, 255, 255, 0.56);
display:block; /*** added this ***/
}
.fab {
background-color: black;
}
}
}
https://jsfiddle.net/dk8eLcfm/
Edit: after #TemaniAfif comment.
Though above solution also worked, but I agree with Temani afif's point that, we can give vertical-align:top to svg, as it's also an inline element and can remove display block from a.
.icons {
>li {
display: inline-block;
padding: 0;
vertical-align:middle;
>a, svg {
height: 50px;
width: 50px;
line-height: 50px;
font-size: 1.8em;
text-align: center;
border-radius: 50%;
color: rgba(255, 255, 255, 0.8);
box-shadow: 0 0px 2px rgba(255, 255, 255, 0.56);
svg{
vertical-align:top;
}
}
.fab {
background-color: black;
}
}
}
https://jsfiddle.net/2bcamf86/1/

You can simply use display: flex to ul.icons
ul.icons.other { display: flex; }

Related

CSS Head Nav and Dropdown Menu Alignment problem

I am working on a project for school and am trying to add a drop down menu to my head navigation. I am still pretty new to css but had fun playing with the styling to get an interesting alignment that would work with the vision I had for the page (this is part of a larger piece that I didn't include to keep it relevant to the question)
I wanted to create a right aligned menu that was set to the bottom of the head div. I got everything to work by using absolute positioning but now that I am trying to add a fancy multi level drop down menu things aren't working. I have tried combinations of inline block and relative and absolute positioning but the dropdown does not align correctly. It just bunches up at the bottom offset to the right.
When I try styling the nav bar like people do in tutorials it gets messed up when I remove the absolute positioning.
Is there a way to get the dropdown to work with the current method of styling? I don't have any hover effects or visibility yet because I can't even get it lined up! That part should be pretty straight forward for the dropdown and submenus.
and probably more importantly
Is there a better way to accomplish this visual goal? (right-aligned at the bottom of the white div)
This is not a dynamic styling yet so you have to stretch the viewport for it to make sense.
/*====================================MAIN=================================*/
body {
background-color: #d5d3d5;
font-family: 'Gill Sans', 'Gill Sans MT', 'Calibri', 'Trebuchet MS', sans-serif;
margin: 0px;
padding: 0px;
}
.flex_body {
background: linear-gradient(90deg, rgba(255, 255, 255, .0), rgba(255, 255, 255, 1) 20%);
display: flex;
margin: 0px;
padding: 0px;
height: 800px;
}
.page_body {
background: linear-gradient(90deg, rgba(255, 255, 255, .0), rgba(255, 255, 255, 1) 15%);
margin: 0px 0px 0px 30px;
padding: 0px 0px 0px 20px;
height: 800px;
overflow: hidden;
}
/*=============================MAIN=NAVIGATION=================================*/
#header {
background-color: #ffffff;
height: 130px;
margin: 0px;
padding-bottom: 0px;
position: relative;
box-shadow: inset 0px -15px 18px -6px rgba(121, 104, 124, 0.678);
}
#headNAV ul {
list-style-type: none;
position: absolute;
text-align: right;
bottom: 0;
right: 0;
margin: 8px;
}
#headNAV ul li {
display: inline;
position: relative;
font-size: 18px;
padding: 5px 0px 15px 0px;
margin: 0px 0px 0px -5px;
}
#headNAV ul li:not(:last-child) {
border-right: 1px solid #8f85a1dc;
}
#headNAV ul li a {
display: inline-block;
padding: 5px 40px 10px 40px;
margin: 0px 0px -2px 0px;
text-decoration: none;
color: #353138;
}
#headNAV ul li a:hover {
background-color: #50328ddc;
color: white;
text-decoration: underline;
box-shadow: 0px 5px 3px 1px #50328ddc;
}
#search_icon {
max-width: 5%;
max-height: 5%;
margin: 0px;
padding: 0px;
display: inline;
}
#headNAV ul li input {
margin: 5px 35px 10px 35px;
}
/*======================myPage-Nav============================*/
#myPage_button:hover>#myPage {
color: white;
}
#myPage_button {
text-decoration: underline;
}
#myPage {
color: #50328ddc;
font-size: 22px;
font-weight: bold;
text-decoration: underline;
}
#dropdown-btn {
padding: 0px 10px;
}
#myPage-menu {
margin: auto;
}
#headNAV ul li #myPage-menu li {
position: absolute;
background-color: #fff;
display: inline-block;
padding: 0px;
border: none;
}
<header id="header">
<nav id="headNAV">
<ul>
<li>Mission</li>
<li>News</li>
<li>Events</li>
<li>Forums</li>
<li><a id='myPage_button' href="#">My<span id='myPage'>Page</span><span id = "dropdown-btn" class="fas fa-caret-down"></span></a>
<ul id="myPage-menu">
<li>Main Feed</li>
<li>Projects</li>
<li>Messages</li>
<li>Profile</li>
<li>Search</li>
</ul>
</li>
<li><input type="text" name="search" placeholder="Search..."></li>
<li><a id="header_login" href="#">Login/SignUp</a></li>
</ul>
</nav>
</header>
Thank you for any input!
Kevin

Preventing dropdown from hiding without JavaScript

An onClick and hover dropdown menu in pure CSS (no JavaScript) displays the items at first, but the menu doesn't stay open when I put my mouse over the dropdown items (but it does stay open onClick).
Here it is:
.acn-menu {
text-align: center;
background-color: rgba(0, 0, 0, 0.9);
}
.label_openclose {
display: none;
}
.menu-tabs {
height: 100%;
padding-left: 0;
padding-right: 0;
padding-top: 0;
padding-bottom: 0;
}
#media (min-width: 320px) {
.menu-tabs {
position: absolute;
}
}
.menu-tabs .elem {
box-sizing: border-box;
padding: 0 20px;
float: left;
height: 100%;
line-height: 70px;
background-color: rgb(30, 30, 30);
color: white;
}
.menu-check {
display: none;
}
label {
margin-bottom: 0;
}
.label_openclose {
display: inline-block;
width: 60px;
min-height: 50px;
background-color: transparent;
cursor: pointer;
overflow:hidden;
display:block;
}
.menu-tabs .elem {
line-height: initial;
float: initial;
height: 0px;
cursor: pointer;
border-top: 0px solid #000;
overflow: hidden;
}
.menu-check:checked~.menu-tabs .elem {
height: 25px;
color: white;
border-top: 2px solid rgba(255, 255, 255, 0.2);
}
.label_openclose:hover~.menu-tabs .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
Here is a fiddle:
https://jsfiddle.net/Lwjvwcva/
You have to add a rule that tells the browser to show .menu-tabs while hovering on it, so I added this rule:
.label_openclose~.menu-tabs:hover .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
check the updated fiddle here.
hope this helps :)
In order for the submenu to remain open, the item where the submenu sits INSIDE needs to be the one selected on hover. In this case .acn-menu or .nav (I used .nav in my code). To make the hover submenu stay open, I removed and added a few lines in the css:
Removed:
.label_openclose:hover~.menu-tabs .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
Added:
.nav .menu-tabs {
display:none;
}
.nav:hover .menu-tabs {
display:block;
}
.menu-tabs .elem {
height:25px;
border-top: 2px solid rgba(255, 255, 255, 0.2);
}

Activating one button also affects the other?

Here's the demo: https://jsfiddle.net/krycLxb0/
The way this is set up is so that to create the illusion that the button is pressed, the padding of the outer container (.button) is changed, making the top padding more than the bottom. However, when this is activated, the other button seems to shrink down as well. Why does this happen, and how do I fix it?
Here's the source:
header {
letter-spacing: .04em;
font-weight: 900;
font-family: sans-serif;
}
.button {
padding: 4px;
padding-bottom: 12px;
border-radius: 6px;
display: inline-block;
transition: 300ms ease;
will-change: auto;
text-transform: uppercase;
text-align: center;
font-size: 14px;
text-shadow: 0px 4px 0px rgba(0, 0, 0, 0.2);
}
.button span {
display: inline-block;
width: 10em;
padding: 1.2em;
border-radius: 2px;
background: #FF4A50;
}
.button:hover {
box-shadow: 0px 6px 0px 0px rgba(0, 0, 0, 0.2);
}
.button:active {
transition: none;
padding-top: 12px;
padding-bottom: 4px;
}
.button--filled {
background: #BC2E56;
color: white;
}
.button--filled span {
background: #FF4A50;
}
.button--dark {
background: rgba(65, 57, 76, 0.6);
}
.button--dark span {
background: #FFF8F2;
}
<header>
<a class="button button--filled" href="#"><span>Get Started</span></a>
<a class="button button--dark" href="#"><span>Learn more</span></a>
</header>
Because your buttons are now vertical-align: baseline. Just add vertical-align: top; to your .button. See fiddle

Input placeholder vertical align

How to properly vertically center placeholder in an input field?
input[type='text']{
background-color: rgba(255,255,255,.4);
border:3px solid rgba(0,0,0,.5);
min-height: 45px;
border-radius: 6px;
color:#fff;
}
input[type='text']::-webkit-input-placeholder {
font-size: 30px;
color: rgba(255, 255, 255, 0.4);
line-height: 30px;
text-transform: uppercase;
vertical-align: middle;
}
Here is the code https://jsfiddle.net/u6qfwg3w/
You forgot to add this css to input element:
input[type='text']{
font-size: 30px;
color: rgba(255, 255, 255, 0.4);
line-height: 30px;
}
Here is the fiddle: fiddle link
I believe that as you have set min-height: 45px you should set line-height: 45px too in input[type=text].
See that for the placeholder if you vary font-size, the placeholder will stay vertically centered.
Please let me know your feedback. Thanks!
input[type='text']{
background-color: rgba(255,255,255,.4);
border:3px solid rgba(0,0,0,.5);
min-height: 45px;
line-height: 45px;
border-radius: 6px;
color:#fff;
}
input[type='text']::-webkit-input-placeholder {
font-size: 25px;
color: rgba(255, 255, 255, 0.4);
text-transform: uppercase;
vertical-align: middle;
}
fiddle here

Why are the spans not centering within this div?

i have 2 spans within a span to center next to eachother, class inside_span up and inside_span down, they are aligned to the left of the pulse_result_format span, i have tried margin: 0 auto on the pulse result format span, does not work, and display: inline-block;
HTML:
<div class="pulse_votes_container thumb1">
<span class="pulse_vote_buttons">
</span>
<span class="pulse_result_format">
<span class='inside_span up'>{up}</span>
<span class='inside_span down'>{down}</span>
</span>
</div>
CSS:
.inside_span {
display: inline-block;
width:40%;
border-radius: 3px 3px 3px 3px;
margin: 10% auto 0px 0px;
float:left;
}
.down {
background-color:#FF6E25;
}
.up {
background-color: rgb(70, 136, 71);
}
.pulse_result_format {
display: inline-block;
float: left;
width: 100%;
text-align: center;
font-weight: bold;
color: rgb(255, 255, 255);
text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.25);
white-space: nowrap;
vertical-align: baseline;
}
.pulse_votes_container {
width:100%;
height:100%;
display: inline-block;
text-align: center;
}
Remove the float:left from .inside_span
.inside_span {
display: inline-block;
width:40%;
border-radius: 3px 3px 3px 3px;
margin: 10% auto 0px 0px;
}
jsFiddle example