How to stack social icons - html

I'm having a brain fart. I apologize if this question has been answered before, but I don't really know developer lingo so I'm not sure what to type in.
I have built my own social icons, which will sit on the right of the screen. Currently, I'm using a seperate class for each icon with height: number vh; to make them stacked on top. I'm sure this isn't the correct way. Could anyone point me in the right direction?
Here is my current code:
.fa-facebook {
background: purple;
opacity: 0.5;
color: white !important;
border: 2px solid white;
}
.fa-twitter {
background: purple;
opacity: 0.5;
color: white !important;
border: 2px solid white;
}
/*social*/
.fa-social {
padding: 10px;
font-size: 30px;
width: 50px;
text-align: center;
text-decoration: none;
margin: 0;
position: fixed;
right: 10px;
}
p.social {
position: fixed;
right: 13px;
top:30vh;
text-align: center;
font-weight: 800;
}
.fa-social-1{
top:35vh;
}
.fa-social-2{
top:45vh;
}
.fa:hover {
opacity: 0.9;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-social-1 fa-facebook"></a>
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-social-2 fa-twitter"></a>

You can use flexbox. It will clean up most of your css.
<div class="social-group">
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-social-1 fa-facebook"></a>
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-social-2 fa-twitter"></a>
</div>
Css..
/* Only CSS */
.fa-facebook, .fa-twitter {
background: purple;
opacity: 0.5;
color: white !important;
border: 2px solid white;
padding: 10px;
font-size: 30px;
width: 50px;
text-align: center;
text-decoration: none;
margin: 0;
}
/* Extra CSS */
.social-group {
display: flex;
justify-content: flex-end;
margin-top: 30vh;
}
.fa:hover {
opacity: 0.9;
}
Working example
https://jsfiddle.net/khvrLyon/

Best not to use fixed position for the items individually - better to put them in a container, position that and let the browser handle the layout.
.fa-facebook {
background: purple;
opacity: 0.5;
color: white !important;
border: 2px solid white;
}
.fa-twitter {
background: purple;
opacity: 0.5;
color: white !important;
border: 2px solid white;
}
/*social*/
.fa-social {
padding: 10px;
font-size: 30px;
width: 50px;
text-align: center;
text-decoration: none;
margin: 0;
right: 10px;
}
.fa:hover {
opacity: 0.9;
}
#social-container{
position:fixed;
right:0;
top:35vh;
display:flex;
flex-direction:column;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="social-container">
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-social-1 fa-facebook"></a>
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-social-2 fa-twitter"></a>
</div>

You need to add padding in the Tags, here is an example:
<a style="text-decoration: none; padding-bottom: 10px" target="_blank"
class="fa fa-social fa-social-1 fa-facebook"></a>
<a style="text-decoration: none; padding-top: 10px" target="_blank"
class="fa fa-social fa-social-2 fa-twitter"></a>
If this does not work try:
<div class="container" style="padding-bottom: 10px;">
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-
social-1 fa-facebook"></a>
</div>
<div class="container" style="padding-top: 10px;">
<a style="text-decoration: none;" target="_blank" class="fa fa-social fa-
social-2 fa-twitter"></a>
</div>

Related

CSS & HTML Button Under each other adding text in between [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
I'm trying to create 2 buttons with different links and have the second button be a clickable image. For some reason the text in between the buttons acts as a hyperlink. How do I fix this?
.button1 {
background-color: #E44040;
border: none;
color: white;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button2 {
border: none;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {
border-radius: 2px;
}
.button2 {
border-radius: 12px;
}
<body style="font-family: arial">
<p>Click the button below For youtube</p>
<div>
<a href="https://www.youtube.com/" method="get" target="_blank">
<button class="button button1">Youtube</button>
</div>
<div>
<p>Click the button below fork Reddit</p>
<a href="https://www.reddit.com/" method="get" target="_blank">
<button class="button button2" style="border: 0; background: transparent">
<img src="https://toppng.com/uploads/preview/reddit-icon-reddit-logo-transparent-115628752708pqmsy4kgm.png" width="90" height="90"></button>
</div>
You forgot to close the a tags. Try this:
Edit: changed the buttons to divs, see comment of user cloned.
body {
font-family: arial, sans-serif;
}
.button1 {
background-color: #E44040;
border: none;
color: white;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button2 {
border: none;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {border-radius: 2px;}
.button2 {border-radius: 12px;}
<p>Click the button below For youtube</p>
<div>
<a href="https://www.youtube.com/" method="get" target="_blank">
<div class="button button1">Youtube</div>
</a>
</div>
<div>
<p>Click the button below fork Reddit</p>
<a href="https://www.reddit.com/" method="get" target="_blank">
<div class="button button2" style="border: 0; background: transparent">
<img src="https://toppng.com/uploads/preview/reddit-icon-reddit-logo-transparent-115628752708pqmsy4kgm.png" width="90" height="90">
</div>
</a>
</div>
You have not closed the <a> tag.
This is the corrected code:
.button1 {
background-color: #E44040;
border: none;
color: white;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button2 {
border: none;
padding: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {border-radius: 2px;}
.button2 {border-radius: 12px;}
<body style="font-family: arial">
<p>Click the button below For youtube</p>
<div>
<a href="https://www.youtube.com/" method="get" target="_blank">
<button class="button button1">Youtube</button>
</a>
</div>
<div>
<p>Click the button below fork Reddit</p>
<a href="https://www.reddit.com/" method="get" target="_blank">
<button class="button button2" style="border: 0; background: transparent">
<img src="https://toppng.com/uploads/preview/reddit-icon-reddit-logo-transparent-115628752708pqmsy4kgm.png" width="90" height="90">
</button>
</a>
</div>
</body>

Creating a clickable dropdown menu with HTML & CSS [duplicate]

This question already has answers here:
Javascript onclick simulation using only css and html (without javascript)
(3 answers)
Closed last year.
I am currently working on a project using only HTML & CSS. I am wanting to make the menu button only display the dropdown items when it is clicked, and have an "x" button that will close them when it is clicked. I am able to make the menu dropdown on hover but am having no luck with it on click without JavaScript.
Does anyone know how I might be able to do this with just HTML & CSS? Here is the HTML & CSS that I have as of right now:
.header-menu {
background-color: #fff;
font-family: "Noto Sans", sans-serif;
font-size: 18px;
}
.header-menu-items {
display: none;
z-index: 1;
max-width: 100%;
overflow-wrap: break-word;
font-weight: 900;
}
.a {
color: #000;
padding: 10px;
text-decoration: none;
}
.search {
display: none;
}
.search-icon {
display: none;
}
.header-menu-items hr {
color: #d0d0d0;
background-color: #d0d0d0;
height: 1px;
border: none;
}
.header-menu-btn {
text-align: left;
background-color: #ff3b3b;
color: #fff;
font-size: 20px;
font-weight: 600;
padding: 10px 0;
border: none;
cursor: pointer;
width: 100%;
margin-bottom: 10px;
padding-left: 10px;
}
.header-menu:hover .header-menu-items {
display: block;
}
<div className="header-menu">
<button className="header-menu-btn">Menu</button>
<div className="header-menu-items">
<div>
<a className="a" href="">
Shirts
</a>
<hr />
<a className="a" href="">
Pants
</a>
<hr />
<a className="a" href="">
Shoes
</a>
<hr />
<a className="a" href="">
T-shirts
</a>
<hr />
<a className="a" href="">
Accessories
</a>
<hr />
</div>
</div>
</div>
Javascript onclick simulation using only css and html (without javascript)
I know your answer is in the answer to this post but I can't really figure out how to do it myself.
It would require changing your button to an input tag of checkbox type and going from there.
First of all it has to be class and not className.
What you want to do can be achieved with a checkbox and the sibling selector ~.
.header-menu {
background-color: #fff;
font-family: "Noto Sans", sans-serif;
font-size: 18px;
}
.header-menu-items {
display: none;
z-index: 1;
max-width: 100%;
overflow-wrap: break-word;
font-weight: 900;
}
.a {
color: #000;
padding: 10px;
text-decoration: none;
}
.search {
display: none;
}
.search-icon {
display: none;
}
.header-menu-items hr {
color: #d0d0d0;
background-color: #d0d0d0;
height: 1px;
border: none;
}
.header-menu-btn {
text-align: left;
background-color: #ff3b3b;
color: #fff;
font-size: 20px;
font-weight: 600;
padding: 10px 0;
border: none;
cursor: pointer;
width: 100%;
margin-bottom: 10px;
padding-left: 10px;
display: block;
}
#toggle-menu {
display: none;
}
#toggle-menu:checked ~ .header-menu-items {
display: block;
}
#toggle-menu ~ label .hide {
display: none;
}
#toggle-menu:checked ~ label .show {
display: none;
}
#toggle-menu:checked ~ label .hide {
display: inline;
}
<div class="header-menu">
<input type="checkbox" id="toggle-menu"><label for="toggle-menu" class="header-menu-btn">Menu <span class="show">show</span><span class="hide">hide<span></label>
<div class="header-menu-items">
<div>
<a class="a" href="">
Shirts
</a>
<hr />
<a class="a" href="">
Pants
</a>
<hr />
<a class="a" href="">
Shoes
</a>
<hr />
<a class="a" href="">
T-shirts
</a>
<hr />
<a class="a" href="">
Accessories
</a>
<hr />
</div>
</div>
</div>

Making clickable div

I want to make clickable div. Currently, it is only working when I click the red rectangle. How can I make the entire div clickable?
HTML
<div class="button">
<a href="#">
<p class="instagram-button">
<i class="fab fa-instagram"></i>
<span>Instagram Page</span>
</p>
</a>
</div>
CSS
.button {
background-color: transparent;
cursor: pointer;
border: 2px solid #737373;
margin: 20px auto 0;
display: flex;
align-items: center;
justify-content: center;
width: 200px;
height: 40px;
}
.button span {
font-size: 14px;
color: #737373;
text-transform: uppercase;
}
.fab {
color: #737373;
padding-right: 5px;
}
Make your <a> tag display:block and 100% height & width so the <a> tag has the same size your <div> tag
function redirect(){
window.location = "yourWebsite";
}
.button {
background-color: transparent;
cursor: pointer;
border: 2px solid #737373;
margin: 20px auto 0;
display: flex;
align-items: center;
justify-content: center;
width: 200px;
height: 40px;
}
.button span {
font-size: 14px;
color: #737373;
text-transform: uppercase;
}
.fab {
color: #737373;
padding-right: 5px;
}
<div onclick='redirect()' class="button">
<a href="#">
<p class="instagram-button">
<i class="fab fa-instagram"></i>
<span>Instagram Page</span>
</p>
</a>
</div>
Simple. Just redirect with the whole 'division' instead of just the 'anchor'.
(yes. it is supposed to throw a 404 error, I set window.location to 'yourWebsite' which is invalid.)
Suggestion: To make your anchor look more like a button, remove that underline from it with text-descoration: none.
If you can use JQuery, do
$(".button").click(function (){window.location.href="/wherever/you/wish/to/go"})
also, what's wrong with an onclick attribute?
Simply add an event listener to the button .div and assign a function to the event that redirects the window to a new location.

How to align text in button and align button to input feild

I have a input field & button. However, there are two problems.
The text in the button is not centered.
The button is never the same height as the input.
To visualize it:
Ok, I also put together a super convenient fiddle to play with this.
How can I fix these problems? Make it look "perfectly aligned". I tried fiddling around with height settings, though was unsuccessful.
Code in that fiddle:
HTML:
<body style="background-color: #5a6b7d">
<div style="text-align: center">
<h1 id='format' style="margin-top: 50px;">Welcome to our site</h1>
<p id='format' style="">this is a site</p>
<br>
<h2 id="format"><i class="fa fa-chevron-down" aria-hidden="true"></i> Type your username <i class="fa fa-chevron-down" aria-hidden="true"></i></h2>
<input type="text" placeholder="Type a username" style="font-size: 140%; text-align: center;" align="center">
<button id="playbutton">Play</button>
</div>
</body>
CSS:
button[id=playbutton]{
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
height: 40px;
}
button:hover{
background-color: darkgreen;
}
try this css for your green button :
button[id=playbutton]{
background-color: #4CAF50;
border: none;
color: white;
padding: 8px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 5px;
position: relative;
top: -2px;
}
use position: relative; top:1px; /* adjust this top to repositioning the button
button[id=playbutton]{
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
height: 40px;
}
button:hover{
background-color: darkgreen;
}
#username{
height: 40px;
padding:0px;
margin-right: 10px;
}
.input-fields{
display:inline-flex;
}
<body style="background-color: #5a6b7d">
<div style="text-align: center">
<h1 id='format' style="margin-top: 50px;">Welcome to our site</h1>
<p id='format' style="">this is a site</p>
<br>
<h2 id="format"><i class="fa fa-chevron-down" aria-hidden="true"></i> Type your username <i class="fa fa-chevron-down" aria-hidden="true"></i></h2>
<div class="input-fields">
<input id="username" type="text" placeholder="Type a username" style="font-size: 140%; text-align: center;" align="center">
<button id="playbutton">Play</button>
<div>
</div>
</body>
Just replace your button CSS with this:
button[id=playbutton]{
background-color: #4CAF50;
border: none;
color: white;
text-align: center;
text-decoration: none;
font-size: 16px;
cursor: pointer;
border-radius: 3px;
line-height: 35px;
width: 80px;
}
How about this:
button[id=playbutton]{
background-color: #4CAF50;
border: none;
color: white;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
height: 40px;
/* New */
padding: 0px;
width: 50px;
height: 20px;
}
The padding 0px will center the text inside the button and the width and height you can use to define the button size. This is an good option for centering if you dont know the exact size of a picture or other things.
Here is the JSFiddle:
https://jsfiddle.net/vLbbkcna/3/

Change Font Awesome's icon color with hover

I just started programming and i need some help.
I'm using Font Awesome icons and i'm trying to change it's color when hovered but don't know why it isn't working. I looked up for other people having the same problem here, tried their solutions but it's still not working :(
here's part of my HTML code:
<footer>
<div class="row container">
<div class="logo-rodape col-md-2">
<img src="img/logo-principal-white-gota.png" alt="Logo Picada Zero">
</div>
<div class="r-content col-md-4">
<p class="slogan-title">CLEAN AND PROTECTION</p>
<p class="slogan-sub">Proteção e limpeza para sua família</p>
</div>
<div class="r-social col-md-5">
<i class="fa fa-facebook fa-2x" aria-hidden="true" style="color:#fff"></i>
<i class="fa fa-vimeo fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
</div>
</footer>
And here's all my footer's CSS:
footer{
background: url(../img/rodape-background.png);
clear: both;
padding: 50px 0;
}
footer .container{
position: relative;
margin-left: 80px;
box-sizing: border-box;
margin-top: 50px;
}
.logo-rodape {
padding: 0;
margin: 0 auto;
box-sizing: border-box;
display: inline-block;
}
.r-content {
padding: 0;
box-sizing: border-box;
display: inline-block;
text-align: left;
margin-left: 30px;
margin-top: 20px;
}
.slogan-title {
font-family: "avenir next condensed";
font-size: 0.3em;
font-size: calc(0.3em + 1vw);
#include screen-above(800px) {
font-size: 0.4em;
}
font-weight: 600;
letter-spacing: 1.5px;
margin-bottom: -2px;
color: #fff;
}
.slogan-sub {
font-family: 'Lato', sans-serif;
font-size: 0.2em;
font-size: calc(0.2em + 1vw);
#include screen-above(800px) {
font-size: 0.3em;
}
font-weight: 300;
letter-spacing: 1px;
color: #fff;
}
.r-social {
text-align: right;
box-sizing: border-box;
display: inline-block;
margin-top: 40px;
margin-left: 60px;
}
.fa-facebook {
padding-right: 20px;
}
.fa-facebook:hover {
color: #57cdf7;
}
I'll be really glad with any suggestions, I tried out everything I know so far and couldn't get it right.
Thanks!
Looks like it's because you use inline style. It always has a higher priority. Also you're trying to change style on hover of an <i> tag, but you should do this with an <a>
Take a look:
a {
display: block;
}
.test1 {
color: red;
}
.test1:hover {
color: #57cdf7;
}
.test2 .fa-facebook:hover {
color: #57cdf7;
}
.test3 .fa-facebook:hover {
color: #57cdf7;
}
<a href="#" class="test1">
<i class="fa fa-vimeo fa-2x">facebook</i>
</a>
<a href="#" class="test2">
<i class="fa fa-facebook fa-2x">facebook</i>
</a>
<a href="#" class="test3">
<i class="fa fa-facebook fa-2x" style="color:green">facebook</i>
</a>
I recommend to assign a single class for <a> tags of your font awesome buttons, remove inline styles and move it to your css file.
As it is in the anchor tag you should be writing the CSS on hover with anchor tag. a:hover .fa-facebook { color: #57cdf7}
You can use this and check on your browser
for example :
i.fa.fa-facebook.fa-2x:hover {
color: red;
background-color: red;
}
/* hover state */
a:hover .far, a:hover .fas {
color:white;
}
/* normal state */
li a .far , li a .fas {
color:red;
}
it work for me.... thanks guy.