I'm trying to make a linktree type of website with HTML. It's going fine but I'm not sure how to add an icon to the left of my button.
Here's what I have so far:
.button {
transition: all .2s ease-in-out;
background-color: #3481b4;
opacity: 0.8;
border-radius: 12px;
border-color: white;
border-style: double;
color: white;
padding: 14px 28px;
padding-left: 48px;
text-align: center;
text-decoration: none;
display: inline-block;
max-width: 85%;
min-width: 80%;
font-size: 18px;
}
button:hover {
transform: scale(1.1);
}
<button class="button" onclick="function()">Twitter</button>
Another helpful method is to use a library for Icons, such as Font Awesome or a similar kind, where you can use it as a font in CSS, and it will keep your code cleaner in case you have too many elements.
The following technique consists in leaving padding to your button and using ::before to insert the icon:
.button {
padding-left: 80px;
}
.button::before {
font-family: "Font Awesome 5 Brands";
font-weight: 400;
content: "\f099";
width: 80px;
height: 80px;
}
.button {
transition: all .2s ease-in-out;
background-color: #3481b4;
opacity: 0.8;
border-radius: 12px;
border-color: white;
border-style: double;
color: white;
padding: 14px 28px;
padding-left: 48px;
text-align: center;
text-decoration: none;
display: inline-block;
max-width: 85%;
min-width: 80%;
font-size: 18px;
}
button:hover {
transform: scale(1.1);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<button class="button" onclick="function()"> Twitter </button>
.button {
transition: all .2s ease-in-out;
background-color: #3481b4;
opacity: 0.8;
border-radius: 12px;
border-color: white;
border-style: double;
color: white;
padding: 14px 28px;
padding-left: 48px;
text-align: center;
text-decoration: none;
display: inline-block;
max-width: 85%;
min-width: 80%;
font-size: 18px;
}
<script src="https://use.fontawesome.com/f9acb8e72a.js"></script>
<button class="button" onclick="function()"><i class="fa fa-twitter"></i> Twitter</button>
you can use position relative to set your icon in left of the button
<button class="button" onclick="function()"><i class="fa-brands fa-twitter"></i> Twitter</button>
CSS
button{
width:100px;
padding:10px;
}
i{
position:absolute;
left:15px
}
Add the icon just inside the button element.
<button class="button" onclick="function()"><img src="path or url of the icon"></img>Twitter</button>
But The best way to do it is to use the fontawsome library here it is super easy to use and provide a lot of commercial icons.
This can be super simple like this or more complicated - so NOT attractive but this is simply one alterative to "how" rather than "looking great" here.
I added a third example to more closely match the updated OP question with the image on the left and wrapped some style around things.
Created to twitter for the svg image: https://about.twitter.com/en/who-we-are/brand-toolkit
.content-container {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 1rem;
row-gap: 1rem;
}
img {
display: inline-block;
background-color: pink;
}
.button {
transition: all .2s ease-in-out;
background-color: #3481b4;
opacity: 0.8;
border-radius: 0.75rem;
border-color: white;
border-style: double;
color: white;
padding: 1rem 2rem;
padding-left: 4rem;
text-align: center;
text-decoration: none;
display: inline-block;
max-width: 85%;
min-width: 80%;
font-size: 1.25rem;
}
.button button {
color: #ffffff;
background-color: #3481b4;
border: none;
font-size: 1em;
}
.button button::before {
content: url('blacktweet.png');
alt: "My Tweet:";
}
#supports (content: "x" / "y") {
.button button::before {
content: "★" / "tweet Text:";
}
}
#supports not (content: "x" / "y") {
.button button::before {
content: "★";
alt: "tweet Text:";
}
}
.button:hover {
transform: scale(1.1);
}
.modern-container {
display: flex;
flex-direction: column;
row-gap: 1rem;
border: solid 1px #22ff22;
padding-left: 1.5rem;
}
.modern-container>div:first-child {
border-bottom: 2px solid #2222ff;
padding: 0.25rem;
}
.modern-button-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
padding: 0.5rem;
}
.modern-button-container:hover {
transform: scale(1.1);
}
.modern-button-container {
/* just styling */
transition: all .2s ease-in-out;
background-color: #3481b4;
opacity: 0.8;
border-radius: 0.75rem;
border-color: white;
border-style: double;
color: white;
text-decoration: none;
max-width: 85%;
min-width: 80%;
font-size: 1.25rem;
}
.modern-button-container:last-child: {
margin-left: auto;
}
.flex-button-img {
margin-left: 0.5rem;
height: 1em;
width: 1em;
}
.flex-button {
display: flex;
align-items: center;
color: #ffffff;
}
.flex-button button {
color: #ffffff;
background-color: #3481b4;
border: none;
font-size: 1em;
}
<div class="content-container">
<div>
<button class="button" onclick="function()"><img src="some.png" alt="bird tweet button">Twitter</button>
</div>
<div>
<div>Here we place a character "icon" on this:</div>
<div class="button">
<button class="xxx">Twitter</button>
</div>
</div>
<div class="modern-container">
<div>Here we have an image icon but using some grid and flex css</div>
<div class="modern-button-container">
<div class="flex-button-img">
<svg version="1.1" id="White" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 400 400" style="enable-background:new 0 0 400 400;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<path class="st0" d="M400,400H0V0h400V400z M153.6,301.6c94.3,0,145.9-78.2,145.9-145.9c0-2.2,0-4.4-0.1-6.6
c10-7.2,18.7-16.3,25.6-26.6c-9.2,4.1-19.1,6.8-29.5,8.1c10.6-6.3,18.7-16.4,22.6-28.4c-9.9,5.9-20.9,10.1-32.6,12.4
c-9.4-10-22.7-16.2-37.4-16.2c-28.3,0-51.3,23-51.3,51.3c0,4,0.5,7.9,1.3,11.7c-42.6-2.1-80.4-22.6-105.7-53.6
c-4.4,7.6-6.9,16.4-6.9,25.8c0,17.8,9.1,33.5,22.8,42.7c-8.4-0.3-16.3-2.6-23.2-6.4c0,0.2,0,0.4,0,0.7c0,24.8,17.7,45.6,41.1,50.3
c-4.3,1.2-8.8,1.8-13.5,1.8c-3.3,0-6.5-0.3-9.6-0.9c6.5,20.4,25.5,35.2,47.9,35.6c-17.6,13.8-39.7,22-63.7,22
c-4.1,0-8.2-0.2-12.2-0.7C97.7,293.1,124.7,301.6,153.6,301.6"/>
</svg>
</div>
<div class="flex-button">
<button class="tweet-btn">Twitter!</button>
</div>
<div></div>
</div>
</div>
</div>
Related
So actually, I use boxicons to display an arrow icon.
<ul class="nav-links">
<li >
<a class="item" >
<i></i>
<span class="links_name">Portfolio</span>
<i class="fa fa-chevron-down"></i>
</a>
<ul class="submenu" #submenu></ul>
</li>
</ul>
I would like the arrow to be red, so I downloaded the icon and changed the image to red using an image editor.
Here is the code SVM
<svg xmlns="http://www.w3.org/2000/svg" xmlns:svgjs="http://svgjs.com/svgjs" xmlns:xlink="http://www.w3.org/1999/xlink" width="288" height="288">
<svg xmlns="http://www.w3.org/2000/svg" width="288" height="288" viewBox="0 0 24 24">
<path fill="#ff3e2b" id="arrow" d="M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z" class="color000 svgShape"/>
</svg>
</svg>
I don't know where I have to include #arrow in CSS ? I think the class fa-chevron-down should be deleted but I'm not sure where/how to add #arrow
Thank you in advance for your help.
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
list-style: none;
text-decoration: none;
}
.sidebar {
position: fixed;
height: 100%;
width: 240px;
background: #0a2558;
transition: all 0.5s ease;
}
.sidebar.active {
width: 60px;
}
.sidebar .logo-details {
height: 100px;
display: flex;
align-items: center;
background-color: #fff;
}
.sidebar .logo-details i {
font-size: 28px;
font-weight: 500;
color: #fff;
min-width: 60px;
text-align: center;
}
.sidebar .logo-details .logo_name img {
height: 100px;
margin-left: 18px;
}
.sidebar .nav-links {
margin-top: 10px;
}
.sidebar .nav-links li {
position: relative;
list-style: none;
}
.sidebar .nav-links li a {
display: flex;
justify-content: start;
text-decoration: none;
transition: all 0.4s ease;
border-bottom: 1px solid #ccc;
padding: 13px 0;
}
.sidebar .nav-links li a.active {
background: #081d45;
}
.sidebar .nav-links li a:hover {
background: #081d45;
}
.sidebar .nav-links li i {
min-width: 60px;
text-align: center;
font-size: 18px;
color: #fff;
}
.sidebar .nav-links .item {
text-transform: uppercase;
}
.sidebar .nav-links li i.fa-chevron-down {
right: 0;
position: absolute;
}
.sidebar .nav-links li.active i.fa-chevron-down {
transform: rotate(180deg);
}
.sidebar .nav-links li.active i {
color: white;
}
.sidebar .nav-links li a .links_name {
color: #fff;
font-size: 15px;
font-weight: 400;
white-space: nowrap;
}
.sidebar .nav-links .submenu {
height: 0;
overflow: hidden;
background: #239cd3;
transition: height 0.4s ease;
text-transform: uppercase;
white-space: nowrap;
}
.sidebar .nav-links .submenu a:hover {
background: #198ac1;
color: #fff;
}
.sidebar .nav-links .submenu .links_subname {
color: #fff;
font-size: 12px;
margin-left: 50px;
}
.sidebar .nav-links .log_out {
position: absolute;
bottom: 0;
width: 100%;
}
.home-section {
position: relative;
background: #f5f5f5;
min-height: 100vh;
width: calc(100% - 240px);
left: 240px;
transition: all 0.5s ease;
}
.sidebar.active ~ .home-section {
width: calc(100% - -30px);
left: -30px;
}
.home-section nav {
display: flex;
justify-content: space-between;
height: 100px;
background: #fff;
display: flex;
align-items: center;
position: fixed;
width: calc(100% - 240px);
left: 240px;
z-index: 100;
padding: 0 20px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
transition: all 0.5s ease;
}
.sidebar.active ~ .home-section nav {
left: 0px;
width: calc(100% - 0px);
}
.home-section nav .sidebar-button {
display: flex;
align-items: center;
font-size: 24px;
font-weight: 500;
}
nav .sidebar-button i {
font-size: 35px;
margin-right: 10px;
}
.home-section nav .search-box {
position: relative;
height: 50px;
max-width: 550px;
width: 100%;
margin: 0 20px;
}
nav .search-box input {
height: 100%;
width: 100%;
outline: none;
background: #f5f6fa;
border: 2px solid #efeef1;
border-radius: 6px;
font-size: 18px;
padding: 0 15px;
}
nav .search-box .bx-search {
position: absolute;
height: 40px;
width: 40px;
background: #2697ff;
right: 5px;
top: 50%;
transform: translateY(-50%);
border-radius: 4px;
line-height: 40px;
text-align: center;
color: #fff;
font-size: 22px;
transition: all 0.4 ease;
}
.home-section .home-content {
position: relative;
padding-top: 104px;
}
.home-content .overview-boxes {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
padding: 0 20px;
margin-bottom: 26px;
}
.overview-boxes .box {
display: flex;
align-items: center;
justify-content: center;
width: calc(100% / 4 - 15px);
background: #fff;
padding: 15px 14px;
border-radius: 12px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}
.overview-boxes .box-topic {
font-size: 20px;
font-weight: 500;
}
.home-content .box .number {
display: inline-block;
font-size: 35px;
margin-top: -6px;
font-weight: 500;
}
.home-content .box .indicator {
display: flex;
align-items: center;
}
.home-content .box .indicator i {
height: 20px;
width: 20px;
background: #8fdacb;
line-height: 20px;
text-align: center;
border-radius: 50%;
color: #fff;
font-size: 20px;
margin-right: 5px;
}
.box .indicator i.down {
background: #e87d88;
}
.home-content .box .indicator .text {
font-size: 12px;
}
.home-content .box .cart {
display: inline-block;
font-size: 32px;
height: 50px;
width: 50px;
background: #cce5ff;
line-height: 50px;
text-align: center;
color: #66b0ff;
border-radius: 12px;
margin: -15px 0 0 6px;
}
.home-content .box .cart.two {
color: #2bd47d;
background: #c0f2d8;
}
.home-content .box .cart.three {
color: #ffc233;
background: #ffe8b3;
}
.home-content .box .cart.four {
color: #e05260;
background: #f7d4d7;
}
.home-content .total-order {
font-size: 20px;
font-weight: 500;
}
.home-content .sales-boxes {
display: flex;
justify-content: space-between;
/* padding: 0 20px; */
}
/* left box */
.home-content .sales-boxes .recent-sales {
width: 65%;
background: #fff;
padding: 20px 30px;
margin: 0 20px;
border-radius: 12px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}
.home-content .sales-boxes .sales-details {
display: flex;
align-items: center;
justify-content: space-between;
}
.sales-boxes .box .title {
font-size: 24px;
font-weight: 500;
/* margin-bottom: 10px; */
}
.sales-boxes .sales-details li.topic {
font-size: 20px;
font-weight: 500;
}
.sales-boxes .sales-details li {
list-style: none;
margin: 8px 0;
}
.sales-boxes .sales-details li a {
font-size: 18px;
color: #333;
font-size: 400;
text-decoration: none;
}
.sales-boxes .box .button {
width: 100%;
display: flex;
justify-content: flex-end;
}
.sales-boxes .box .button a {
color: #fff;
background: #0a2558;
padding: 4px 12px;
font-size: 15px;
font-weight: 400;
border-radius: 4px;
text-decoration: none;
transition: all 0.3s ease;
}
.sales-boxes .box .button a:hover {
background: #0d3073;
}
/* Right box */
.home-content .sales-boxes .top-sales {
width: 35%;
background: #fff;
padding: 20px 30px;
margin: 0 20px 0 0;
border-radius: 12px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}
.sales-boxes .top-sales li {
display: flex;
align-items: center;
justify-content: space-between;
margin: 10px 0;
}
.sales-boxes .top-sales li a img {
height: 40px;
width: 40px;
object-fit: cover;
border-radius: 12px;
margin-right: 10px;
background: #333;
}
.sales-boxes .top-sales li a {
display: flex;
align-items: center;
text-decoration: none;
}
.sales-boxes .top-sales li .product,
.price {
font-size: 17px;
font-weight: 400;
color: #333;
}
.menu-summary-container {
display: grid;
margin: 0 auto;
text-align: center;
width: 100%;
}
.menu-summary-container .user,
.menu-summary-container .last-connection {
font-size: 22px;
}
<!DOCTYPE html>
<html>
<head>
<title>HTML CSS JS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://unpkg.com/boxicons#2.0.7/css/boxicons.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" />
</head>
<body>
<div class="sidebar" >
<div class="logo-details">
<span class="logo_name">
<img src="https://zupimages.net/up/22/30/27uw.png" />
</span>
</div>
<ul class="nav-links">
<li >
<a class="item" >
<i></i>
<span class="links_name">Portfolio</span>
<i class="fa fa-chevron-down"></i>
</a>
<ul class="submenu" #submenu></ul>
</li>
</ul>
</div>
<section class="home-section">
<nav>
<div class="sidebar-button">
<i class="sidebarBtn"></i>
</div>
<div class="menu-summary-container">
<span class="user">User: </span>
<span class="last-connection">last connection: </span>
</div>
</nav>
</section>
</body>
</html>
i.fa.fa-chevron-down{
color: red!important;
}
If you don't mind adding !important attribute, this is how you can perform the action with CSS only
You're mixing different icon libraries.
If you need to use boxicons you should delete fontAwesome elements like:
<i class="fa fa-chevron-down"></i>
Either replace this element with the svg directly:
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
list-style: none;
text-decoration: none;
}
.sidebar {
height: 100%;
width: 240px;
background: #0a2558;
transition: all 0.5s ease;
border: 4px solid #ccc;
}
li a {
color: #fff;
display: flex;
padding: 0.2em;
}
.svgItem {
height: 1.3em;
margin-left: auto;
}
.color000 {
color: red
}
.box-icon {
fill: red;
margin-left: auto;
}
<link href="https://unpkg.com/boxicons#2.0.7/css/boxicons.min.css" rel="stylesheet" />
<script src="https://unpkg.com/boxicons#2.1.2/dist/boxicons.js"></script>
<body>
<div class="sidebar">
<ul class="nav-links">
<li>
<a class="item">
<span class="links_name">Portfolio</span>
<svg class="svgItem" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path fill="currentColor" id="arrow" d="M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z" class="color000 svgShape"/>
</svg>
</a>
<ul class="submenu" #submenu></ul>
</li>
<li>
<a>Rocket <box-icon class="box-icon" name="chevron-down"></box-icon></a>
</li>
</ul>
</div>
Or use the web component approach described here
<box-icon class="box-icon" name="chevron-down"></box-icon>
If you're using the svg icon as an inlined element, you would change the icon color via fill attribute.
path{fill:red}
It's recommended to strip the fill attribute in your svg markup to avoid unnecessary high specificity.
<svg viewBox="0 0 24 24">
<path d="M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z" />
</svg>
However you can make a path inherit a font/text color by using the currentColor keyword:
path{color: red}
<svg viewBox="0 0 24 24">
<path fill="currentColor" d="M16.293 9.293 12 13.586 7.707 9.293l-1.414 1.414L12 16.414l5.707-5.707z" />
</svg>
I'm trying to make a dropdown menu to my navigation bar but when I hover over the London tab, the dropdown menu is slightly placed to the right. I have no idea as to why this is happening, and I've tried some solutions but they have not been successful.
I dont know how to make the dropdown menu centered so its just below the London tab. Any help or advice would be appriciated!
body {
font-family: Arial;
}
.navbar {
display: flex;
margin-bottom: 0px;
justify-content: center;
gap: 50px;
padding: 1em;
padding-bottom: 4em;
padding-top: 1.5em;
}
.navbar a {
color: white;
padding: 14px 20px;
text-decoration: none;
padding: 2em;
padding-top: 1em;
padding-bottom: 1em;
background-color: #333;
border-radius: 5px;
transition: 0.2s;
}
.navbar a:hover {
background-color: whitesmoke;
color: black;
}
.active-dropdown {
display: flex;
flex-wrap: wrap;
flex-direction: column;
position: relative;
}
.active-dropdown {
color: white;
padding: 14px 20px;
text-decoration: none;
padding: 2em;
padding-top: 1em;
padding-bottom: 1em;
background-color: #04AA6D !important;
border-radius: 5px;
transition: 0.2s;
}
.active-dropdown a{
display: block;
background-color: #11c784 !important;
color: white;
text-decoration: none;
padding: 2em;
padding-top: 1em;
padding-bottom: 1em;
border-radius: 5px;
transition: 0.2s;
}
.active-dropdown > .dropdown-sub{
display: none;
z-index: 1;
flex-direction: column;
position: absolute;
top: 50px;
background: rgb(4, 199, 129);
color: white;
border-radius: 5px;
transition: 0.2s;
width: 100%;
}
.active-dropdown:hover > .dropdown-sub {
display: flex;
}
.dropdown-option a:hover{
background-color: #abcdef !important;
}
.active-dropdown a:hover {
color: white;
transform: scale(1);
}
<!DOCTYPE html>
<html>
<head>
<title>City</title>
<link href="london.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="navbar">
<div class="active-dropdown">
<div class="dropdown-title">London</div>
<div class="dropdown-sub">
<div class="dropdown-option">Overview</div>
<div class="dropdown-option">Wikipedia</div>
<div class="dropdown-option">Pictures</div>
</div>
</div>
<a style="align-self: flex-start" href="#">Paris</a>
<a style="align-self: flex-start" href="#">Tokyo</a>
</div>
The problem is, when position:absolute is used, the default for "right" is not 0.
Source:
What are the default top, left, botton or right values when position:absolute is used?
This should fix the problem:
.active-dropdown > .dropdown-sub {
right: 0px;
}
A very simple solution would be to add this to your code:
.active-dropdown > .dropdown-sub{
display: none;
z-index: 1;
flex-direction: column;
position: absolute;
top: 50px;
background: rgb(4, 199, 129);
color: white;
border-radius: 5px;
transition: 0.2s;
width: 100%;
left: 0px; /* add this */
}
At first, you should add left:0px. I recommend using percentages instead. In the future, you do not need to edit again if the size or padding changes.
.active-dropdown > .dropdown-sub{
display: none;
z-index: 1;
flex-direction: column;
position: absolute;
top: 100%; /* Changed */
left: 0%; /* Changed */
background: rgb(4, 199, 129);
color: white;
border-radius: 5px;
transition: 0.2s;
width: 100%;
}
I'm first making the static html design and css for my Todo list app and then passing them into react components.
I can't figure why does the span in the li doesn't move to the right, but after trying deleting things and figuring out what works and what doesn't work i found that the li css doesn't change anything more than the color, so if for example i tried changing the line height or height nothing changed and thaught that the whole style wasn't working, but the color does work but everything else doesn't. Is there some style that's blocking the ability to change sizes and placement of things?
Here is the app.js:
import React, { useState } from "react";
import "./App.css";
import axios from "axios";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
import { faTrash, faPlus } from "#fortawesome/free-solid-svg-icons";
function App() {
return (
<>
<div className="backgound">
<div className="wrapper">
<header>Todo app MERN</header>
<div className="inputField">
<input type="text" placeholder="Add your new task"></input>
<button>
<FontAwesomeIcon icon={faPlus} />
</button>
</div>
<ul className="todoList">
<li>
Do something
<span>
<FontAwesomeIcon icon={faTrash} />
</span>
</li>
<li>
Buy something
<span>
<FontAwesomeIcon icon={faTrash} />
</span>
</li>
<li>
Learn something
<span>
<FontAwesomeIcon icon={faTrash} />
</span>
</li>
</ul>
<div class="footer">
<span> You have 3 pending tasks</span>
<button>Clear</button>
</div>
</div>
</div>
</>
);
}
export default App;
And here is the css, the two styles that are causing me problems are .todoList li and .todoList li span:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
::selection {
color: #ffff;
background: rgb(142, 73, 232);
}
body {
width: 100%;
height: 100vh;
padding: 10px;
background: linear-gradient(to bottom, #68EACC 0%, #497BE8 100%);
}
.wrapper {
background: #fff;
max-width: 400px;
width: 100%;
margin: 120px auto;
padding: 25px;
border-radius: 5px;
box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.1);
}
.wrapper header {
font-size: 30px;
font-weight: 600;
}
.wrapper .inputField {
margin: 20px 0;
width: 100%;
display: flex;
height: 45px;
}
.inputField input {
width: 85%;
height: 100%;
outline: none;
border-radius: 3px;
border: 1px solid #ccc;
font-size: 17px;
padding-left: 15px;
transition: all 0.3s ease;
}
.inputField input:focus {
border-color: #8E49E8;
}
.inputField button {
width: 50px;
height: 100%;
border: none;
color: #fff;
margin-left: 5px;
font-size: 21px;
outline: none;
background: #8E49E8;
cursor: pointer;
border-radius: 3px;
opacity: 0.6;
pointer-events: none;
transition: all 0.3s ease;
}
.inputField button:hover,
.footer button:hover {
background: #721ce3;
}
.inputField button.active {
opacity: 1;
pointer-events: auto;
}
.wrapper .todoList {
max-height: 250px;
overflow-y: auto;
}
.todoList li {
list-style: none;
height: 45 px;
line-height: 45 px;
position: relative;
background: #f2f2f2;
border-radius: 3px;
margin-bottom: 8 px;
padding: 0 15 px;
}
.todoList li span {
position: absolute;
right: 0 px;
color: #e74c3c;
}
.wrapper .footer {
display: flex;
width: 100%;
margin-top: 20px;
align-items: center;
justify-content: space-between;
}
.footer button {
padding: 6px 10px;
border-radius: 3px;
border: none;
outline: none;
color: #fff;
font-weight: 400;
font-size: 16px;
margin-left: 5px;
background: #8E49E8;
cursor: pointer;
user-select: none;
opacity: 0.6;
pointer-events: none;
transition: all 0.3s ease;
}
.footer button.active {
opacity: 1;
pointer-events: auto;
}
You should not add spaces before "px" in your CSS code. height: 45 px; should be height: 45px;
You can always inspect elements in web browser and see which stylesheets are applied and in what priority.
I have a animation where when i hover the icons swing from the right, i want to have it for both of my icons, the delete and edit, but i can't find out which style should i use to separate them and change colors indivitually without messing up the sizing of the icons or the placement.
Html:
import React, { useState } from "react";
import "./App.css";
import axios from "axios";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
import { faTrash, faPlus, faEdit } from "#fortawesome/free-solid-svg-icons";
function App() {
return (
<>
<div className="backgound">
<div className="wrapper">
<header>Todo app MERN</header>
<div className="inputField">
<input type="text" placeholder="Add your new task"></input>
<button>
<FontAwesomeIcon icon={faPlus} />
</button>
</div>
<ul className="todoList">
<li>
Do something
<span>
<FontAwesomeIcon icon={faTrash} />
<FontAwesomeIcon icon={faEdit} />
</span>
</li>
<li>
Buy something
<span>
<FontAwesomeIcon icon={faTrash} />
<FontAwesomeIcon icon={faEdit} />
</span>
</li>
<li>
Learn something
<span>
<FontAwesomeIcon icon={faTrash} />
<FontAwesomeIcon icon={faEdit} />
</span>
</li>
</ul>
<div class="footer">
<span> You have 3 pending tasks</span>
<button>Clear</button>
</div>
</div>
</div>
</>
);
}
export default App;
The classes i been trying to change to separate them are the .todoList li and .todoList li span
CSS:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
::selection {
color: #ffff;
background: rgb(142, 73, 232);
}
body {
width: 100%;
height: 100vh;
padding: 10px;
background: linear-gradient(to bottom, #68EACC 0%, #497BE8 100%);
}
.wrapper {
background: #fff;
max-width: 400px;
width: 100%;
margin: 120px auto;
padding: 25px;
border-radius: 5px;
box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.1);
}
.wrapper header {
font-size: 30px;
font-weight: 600;
}
.wrapper .inputField {
margin: 20px 0;
width: 100%;
display: flex;
height: 45px;
}
.inputField input {
width: 85%;
height: 100%;
outline: none;
border-radius: 3px;
border: 1px solid #ccc;
font-size: 17px;
padding-left: 15px;
transition: all 0.3s ease;
}
.inputField input:focus {
border-color: #8E49E8;
}
.inputField button {
width: 50px;
height: 100%;
border: none;
color: #fff;
margin-left: 5px;
font-size: 21px;
outline: none;
background: #8E49E8;
cursor: pointer;
border-radius: 3px;
opacity: 0.6;
pointer-events: none;
transition: all 0.3s ease;
}
.inputField button:hover,
.footer button:hover {
background: #721ce3;
}
.inputField button.active {
opacity: 1;
pointer-events: auto;
}
.wrapper .todoList {
max-height: 250px;
overflow-y: auto;
}
.todoList li {
list-style: none;
height: 45px;
line-height: 45px;
position: relative;
background: #f2f2f2;
border-radius: 3px;
margin-bottom: 8px;
padding: 0 15px;
cursor: default;
overflow: hidden;
}
.todoList li span {
position: absolute;
right: -60px;
color: #fff;
width: 45px;
text-align: center;
background: #e74c3c;
border-radius: 0 3px 3px 0;
cursor: pointer;
transition: all 0.3s ease;
}
.todoList li:hover span {
right: 0px;
}
.wrapper .footer {
display: flex;
width: 100%;
margin-top: 20px;
align-items: center;
justify-content: space-between;
}
.footer button {
padding: 6px 10px;
border-radius: 3px;
border: none;
outline: none;
color: #fff;
font-weight: 400;
font-size: 16px;
margin-left: 5px;
background: #8E49E8;
cursor: pointer;
user-select: none;
opacity: 0.6;
pointer-events: none;
transition: all 0.3s ease;
}
.footer button.active {
opacity: 1;
pointer-events: auto;
}
you forgot a principle:
single responsible principle
So the best way is the component is only responsible for one thing.
So let's make a separate component that gets a conditional rendering based on prop and then be responsible for its own behavior.
You can then wrap them with an element and use flexbox in css.
solution :
1-add "icon_container" className to span
<span className="icon_container">
...
</span>
2-add "font_custom_class" className to FontAwesome
<FontAwsome className="font_custom_class" .../>
3.change some style in css file:
.todoList li {
display : flex;
flex-flow : row;
justify-content : space-between;
list-style: none;
height: 45px;
line-height: 45px;
position: relative;
background: #f2f2f2;
border-radius: 3px;
margin-bottom: 8px;
cursor: default;
overflow: hidden;
padding-left: 15px !important;
}
.icon_container {
width : 100px;
background : red;
display : flex;
flex-flow : row nowrap;
justify-content : center;
align-items : center;
transform : translateX(100px);
transition : all 0.5s;
}
.icon_container > .font_custom_class {
flex-grow: 1;
text-align: center;
}
.todoList li:hover .icon_container {
transform : translateX(0);
}
I am trying to keep the the form elements in one line and as to keep it exactly like this way for all type of resolutions i.e to keep it responsive in the same state but whenever I try to minimize the screen resolution so the form contents get messed up and the Search button goes to the second line as I do not want it to be like that..I simply want it to be in the same state i.e the Search button to stay along next to the input even when the window is minimized so how easily that would be achievable??? As I do know that it can be achieved with the use of CSS Media Queries..!
Here is the GIF :
LIVE PAGE LINK : http://huntedhunter.com/extratorrent/
Here is Code :
HTML :
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div style="padding: 7%;margin-top: 100px;">
<h1>E<span>XTRATORRENT</span> A<span>UTOMATIC</span> D<span>OWNLOADER</span></h1>
<form>
<input class="icon" name="search" placeholder="Search Torrent Name" type="text"> <input class="btn btn-secondary" name="search" type="submit" value="Search">
</form>
</div>
<footer class="footer">
<p>Copyrighted By <strong>Hunted Hunter Solutions</strong>.A Script By <strong>Umair Shah Yousafzai</strong></p>
</footer>
</body>
</html>
CSS :
input[type=text].icon {
width: 89%;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url(searchicon.png);
background-position: 10px 13px;
background-repeat: no-repeat;
padding-left: 42px;
}
h1 {
font-family: Arial;
opacity: 0.6;
text-align: center;
}
span {
font-size: 70%;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #eee2e2;
margin-left: -0.5%;
}
body {
overflow-x: hidden;
}
p {
text-align: center;
font-family: Arial;
opacity: 0.7;
}
a {
text-decoration: none;
}
.btn-secondary:hover {
color: #292b2c;
background-color: #e6e6e6;
border-color: #adadad;
cursor: pointer;
}
.btn:focus, .btn:hover {
text-decoration: none;
}
[type=reset], [type=submit], button, html [type=button] {
-webkit-appearance: button;
}
.btn-secondary {
color: #292b2c;
background-color: #fff;
border-color: #adadad;
}
.btn {
border: 1px solid turquoise;
padding: 1.2% 1.5rem;
font-size: 1rem;
border-radius: .25rem;
-webkit-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
}
You could use a flex-box for this.
Add the .flex class to your <form> tag, along with the rules:
.flex {
display:flex;
flex-wrap:nowrap;
justify-content:center;
}
replace width: 89%; with flex-grow:4; on the input[type=text].icon selector,
Finally add flex-grow:1; and margin-left:5px; to the .btn selector
input[type=text].icon {
flex-grow: 4;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url(searchicon.png);
background-position: 10px 13px;
background-repeat: no-repeat;
padding-left: 42px;
}
h1 {
font-family: Arial;
opacity: 0.6;
text-align: center;
}
span {
font-size: 70%;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #eee2e2;
margin-left: -0.5%;
}
body {
overflow-x: hidden;
}
p {
text-align: center;
font-family: Arial;
opacity: 0.7;
}
a {
text-decoration: none;
}
.btn-secondary:hover {
color: #292b2c;
background-color: #e6e6e6;
border-color: #adadad;
cursor: pointer;
}
.btn:focus,
.btn:hover {
text-decoration: none;
}
[type=reset],
[type=submit],
button,
html [type=button] {
-webkit-appearance: button;
}
.btn-secondary {
color: #292b2c;
background-color: #fff;
border-color: #adadad;
}
.btn {
flex-grow: 1;
margin-left: 5px;
border: 1px solid turquoise;
padding: 1.2% 1.5rem;
font-size: 1rem;
border-radius: .25rem;
-webkit-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
}
.flex {
display: flex;
flex-wrap: nowrap;
justify-content: center;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div style="padding: 7%;margin-top: 100px;">
<h1>E<span>XTRATORRENT</span> A<span>UTOMATIC</span> D<span>OWNLOADER</span></h1>
<form class="flex">
<input class="icon" name="search" placeholder="Search Torrent Name" type="text" /> <input class="btn btn-secondary" name="search" type="submit" value="Search" />
</form>
</div>
<footer class="footer">
<p>Provided without garanties by a <strong>Welldoer</strong>. A Script By <strong>Lars</strong></p>
</footer>
</body>
</html>