I am trying a make a toolbar using font awesome with a few icons and search text box at the start.
I would like this to be ideally aligned in a way that it has search on the left most followed by the icons to its right.
.icon-bar {
width: 40%;
text-align: center;
background-color: #555;
overflow: auto;
display:flex;
}
.icon-bar a {
width: 15%;
padding: 12px 0;
float: left;
transition: all 0.3s ease;
color: white;
font-size: 36px;
}
.icon-bar a:hover {
background-color: #000;
}
#filtersubmit {
position: relative;
z-index: 1;
left: -25px;
top: 1px;
color: #7B7B7B;
cursor: pointer;
width: 0;
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<div>
<div class="icon-bar">
<input id="searchInput" type="text" placeholder="Search" /><i id="filtersubmit" class="fa fa-search"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-globe"></i>
<i class="fa fa-trash"></i>
<a class="active" href="#"><i class="fa fa-home"></i></a>
</div>
</div>
Ideally I would like to be aligned like this image below:
Changes as per the solution below:
Menu with full browser screen:
Now when I minimize the browser the scroll comes which is because of overflow:auto.
Is their a way I can control the width of the search box for the icons I think changing the fontsize does the trick.
Add display flex to the .icon-bar div.
.icon-bar {
width: 30%;
text-align: center;
background-color: #555;
overflow: auto;
display:flex;
}
Also, as dipas noted remove that position left.
It is easier using inline-blocks:
.icon-bar {
text-align: center;
background-color: #555;
overflow: auto;
}
.icon-bar a {
padding: 12px 0;
transition: all 0.3s ease;
color: white;
font-size: 36px;
}
.icon-bar a:hover {
background-color: #000;
}
#filtersubmit {
color: #7B7B7B;
cursor: pointer;
}
.icon-bar > * {
display: inline-block;
vertical-align: middle;
padding: 10px;
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<div>
<div class="icon-bar">
<input id="searchInput" type="text" placeholder="Search" /><i id="filtersubmit" class="fa fa-search"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-globe"></i>
<i class="fa fa-trash"></i>
<a class="active" href="#"><i class="fa fa-home"></i></a>
</div>
</div>
You can use flexboxes too:
.icon-bar {
text-align: center;
background-color: #555;
overflow: auto;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-around;
width: 60%;
}
.icon-bar a {
padding: 12px 0;
transition: all 0.3s ease;
color: white;
font-size: 36px;
}
.icon-bar a:hover {
background-color: #000;
}
#filtersubmit {
color: #7B7B7B;
cursor: pointer;
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<div>
<div class="icon-bar">
<input id="searchInput" type="text" placeholder="Search" /><i id="filtersubmit" class="fa fa-search"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-globe"></i>
<i class="fa fa-trash"></i>
<a class="active" href="#"><i class="fa fa-home"></i></a>
</div>
</div>
Use display: table on parent .icon-bar and display: table-cell on children groups .search-bar and .button-wrapper
.icon-bar {
display: table;
padding: 0 20px;
background-color: #555;
overflow: auto;
}
.search-bar, .button-wrapper {
display: table-cell;
vertical-align: middle;
}
#filtersubmit {
color: #7B7B7B;
cursor: pointer;
}
.button-wrapper a {
display: inline-block;
padding: 12px;
transition: all 0.3s ease;
color: white;
font-size: 36px;
}
.button-wrapper a:hover {
background-color: #000;
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<div>
<div class="icon-bar">
<div class="search-bar">
<input id="searchInput" type="text" placeholder="Search" />
<i id="filtersubmit" class="fa fa-search"></i>
</div>
<div class="button-wrapper">
<i class="fa fa-envelope"></i>
<i class="fa fa-globe"></i>
<i class="fa fa-trash"></i>
<a class="active" href="#"><i class="fa fa-home"></i></a>
</div>
</div>
</div>
Related
I am trying to create an input field where user can increment or decrement the number. The input field should look like following design in a responsive way
However, it looks weird when I did the following way
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<div class="input-with-icon">
<div class="labelled-input">
<div class="labelling">
<div class="content">
<i class="fa fa-user fa-lg fa-fw" aria-hidden="true"></i>
<div class="text-wrapper">
<p class="adult">Adult</p>
<p>16+year</p>
</div>
</div>
</div>
<div class="augment">
<i class="fa fa-minus"></i>
</div>
<input type="text" class="input" disabled/>
<div class="augment">
<i class="fa fa-plus"></i>
</div>
</div>
</div>
Here is the demo
https://jsbin.com/fiwabararo/edit?html,css,output
Please check this code snippet
function counter(i){
var el =document.getElementsByClassName('input');
(i == '+')
? el[0].value = parseInt(el[0].value) + 1
: el[0].value = parseInt(el[0].value) - 1;
}
.input-with-icon {
position: relative;
width: 100%;
display: flex;
}
.labelled-input {
position: relative;
font-weight: 400;
font-style: normal;
display: inline-flex;
border: solid 1px #99acbd;
border-radius: 2px;
background:#eceef2;
}
.labelling {
display: inline-block;
line-height: 1;
vertical-align: baseline;
background-image: none;
color: rgba(0, 0, 0, 0.6);
text-transform: none;
font-weight: 700;
border: 0 solid transparent;
flex: 0 0 auto;
margin: 0;
}
.labelling:first-child {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.content {
display: flex;
align-items: center;
padding:0 12px
}
.augment {
background: #ccd5de;
text-align:center;
cursor: pointer;
height: 40px;
width: 40px;
border-radius: 50%;
margin: 10px;
margin-top:18px
}
.augment:hover {
background: #478dcf;
}
.augment i {
line-height:2.6;
color:#fff
}
.input {
margin: 0;
border: none;
outline: 0;
box-shadow: none;
font-size: 22px;
font-weight: bold;
text-align: center;
}
.input:disabled {
background: #fff;
}
#media(max-width:480px){
.input {
width:56%;
}
.augment {
width: 14%;
}
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<div class="input-with-icon">
<div class="labelled-input">
<div class="labelling">
<div class="content">
<i class="fa fa-user fa-lg fa-fw" aria-hidden="true"></i>
<div class="text-wrapper">
<p class="adult">Adult</p>
<p>16+year</p>
</div>
</div>
</div>
<div class="augment" onclick="counter('-')">
<i class="fa fa-minus"></i>
</div>
<input type="text" class="input" disabled value="0" />
<div class="augment" onclick="counter('+')">
<i class="fa fa-plus"></i>
</div>
</div>
</div>
I'm creating a nav bar with buttons using css that I'd like to have a background color on hover WITHOUT the div resizing. I want the buttons to stay in place, just have the background color behind them.
.topnav {
overflow: hidden;
background-color: #1C313A;
}
.topnav a {
float: left;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav-right {
float: right;
}
button {
padding: 0px 0px;
background-color: transparent;
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
margin-left: 20px;
}
button:hover {
width: 50px;
height: 50px;
background-color: #192C34;
border-radius: 50%;
padding: 0px 0px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="topnav">
<a href="#home">
<button>
<i class="fa fa-save fa-lg"></i>
</button>
</a>
<a href="#news"><button>
<i class="fa fa-upload fa-lg"></i>
</button></a>
<a href="#contact">
<button>
<i class="fa fa-save fa-lg"></i>
</button>
</a>
<div class="topnav-right">
<a class="logo" style="pointer-events:none;">TidyBlocks</a>
</div>
</div>
Current Output:
Desired Output
.topnav {
overflow: hidden;
background-color: #1C313A;
}
.topnav a {
float: left;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav-right {
float: right;
}
button {
padding: 0px 0px;
background-color: transparent;
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
margin-left: 20px;
width: 50px;
height: 50px;
}
button:hover {
background-color: #192C34;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="topnav">
<a href="#home">
<button>
<i class="fa fa-save fa-lg"></i>
</button>
</a>
<a href="#news"><button>
<i class="fa fa-upload fa-lg"></i>
</button></a>
<a href="#contact">
<button>
<i class="fa fa-save fa-lg"></i>
</button>
</a>
<div class="topnav-right">
<a class="logo" style="pointer-events:none;">TidyBlocks</a>
</div>
</div>
Please put height and width in button not hover.
And yes you can't put button element in a tag it's not validated.
Please check your code on https://validator.w3.org/.
.topnav {
overflow: hidden;
background-color: #1C313A;
}
.topnav a {
float: left;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav-right {
float: right;
}
button {
border-radius: 50%;
padding: 0px 0px;
background-color: transparent;
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
margin-left: 20px;
width: 50px;
height: 50px;
}
button:hover {
background-color: #192C34;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="topnav">
<a href="#home">
<button>
<i class="fa fa-save fa-lg"></i>
</button>
</a>
<a href="#news"><button>
<i class="fa fa-upload fa-lg"></i>
</button></a>
<a href="#contact">
<button>
<i class="fa fa-save fa-lg"></i>
</button>
</a>
<div class="topnav-right">
<a class="logo" style="pointer-events:none;">TidyBlocks</a>
</div>
</div>
Just doing some practice by recreating the tumblr website, Im having some issues with the right side where it says "Recommended Blogs". I want to implement the use of a small user icon logo instead of the list style bullet. Is it possible to resize the images in css? or would i have to resize the image in photoshop?
Take a look at My Code pen
HTML
<html>
<head>
<title>Tumblr</title>
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
<link rel="stylesheet" type="text/css" href="tumblrstyle.css">
</head>
<body>
<!-- Header Navigation -->
<div class="top-head">
<header>
<div id="top-head-left">
<h1>T</h1>
<input type="text" name="" placeholder="">
<i class="fas fa-search"></i>
</div>
<div id="top-head-right">
<i class="fas fa-home fa-2x"></i>
<i class="far fa-compass fa-2x"></i>
<i class="fas fa-envelope fa-2x"></i>
<i class="far fa-comment fa-2x"></i>
<i class="fas fa-bolt fa-2x"></i>
<i class="fas fa-user fa-2x"></i>
</div>
</header>
</div>
<!-- End Header -->
<!-- RightBar -->
<div class="container">
<div class="right-side">
<div class="right-side nav">
<h3>Recommended Blogs</h3>
<ul id="navi">
<li>empty</li>
<li>empty</li>
<li>empty</li>
<li>empty</li>
</ul>
</div>
<div class="radar">
<h3>radar</h3>
<ul>
<li>empty</li>
<p>
</p>
</ul>
</div>
</div>
<!-- Post Controls -->
<div class="controller">
<img src="https://image.freepik.com/free-vector/abstract-summer-sun-logo- design_1436-184.jpg">
<div class="post-group">
<div class="icons">
<i class="fas fa-home fa-5x"></i>
</div>
<div class="icons">
<i class="far fa-compass fa-5x"></i>
</div>
<div class="icons">
<i class="fas fa-envelope fa-5x"></i>
</div>
<div class="icons">
<i class="far fa-comment fa-5x"></i>
</div>
<div class="icons">
<i class="fas fa-bolt fa-5x"></i>
</div>
<div class="icons">
<i class="fas fa-user fa-5x"></i>
</div>
</div>
</div>
</body>
</html>
CSS
/*Reset*/
* {
margin: 0;
padding: 0;
}
body {
background: lightgray;
}
header {
padding: 0 10px;
}
header h1 {
display: inline;
margin-right: 15px;
}
.container {
width: 60%;
margin: auto;
overflow: visible;
}
div h3 {
border-bottom: 1px solid black;
}
/*Header*/
.top-head {
background: lightblue;
height: 60px;
border-bottom: 5px solid black;
padding: 0px 20px;
}
#top-head-left {
float: left;
padding-top: 5px;
}
#top-head-left input[type="text"] {
width: 200px;
background: yellow;
padding: 5px 0px;
}
#top-head-right {
float: right;
padding-top: 12px;
}
/*RightsideBar*/
.right-side {
float: right;
}
.nav ul {
list-style-image: url('https://78.media.tumblr.com/avatar_0f16d6a6a019_128.pnj');
}
.nav ul li {
}
.radar ul {
list-style: none;
}
/*Post Controller*/
.controller {
margin-top: 50px;
}
.controller img {
width: 10%;
float: left;
margin-right: 20px;
border-radius: 10px;
}
.post-group {
float: left;
background: white;
height: 68px;
border-radius: 10px;
padding-top: 8px;
padding-bottom: 22px;
}
.icons {
float: left;
}
.icons a {
color: orange;
padding: 0 12px;
}
/* https://78.media.tumblr.com/avatar_3aed9115be2f_128.pnj
https://78.media.tumblr.com/avatar_0f16d6a6a019_128.pnj
https://78.media.tumblr.com/avatar_0f16d6a6a019_128.pnj
https://78.media.tumblr.com/avatar_996dede0302e_128.pnj */
#navi {
list-style-type: none;
}
#navi > li::before {
content: '';
display: inline-block;
height: 40px;
width: 40px;
background-size: 40px;
background-image: url('https://78.media.tumblr.com/avatar_0f16d6a6a019_128.pnj');
background-repeat: no-repeat;
margin-right: 10px;
background-position: center center;
vertical-align: middle;
}
Please don't mind my selectors
I created this small icon menu with the help of a tutorial and I am trying to make it responsive, but it is not working.
When the width is 400px I want the menu to be vertical.
body {
margin: 0px;
}
.cuadro {
width: 100%;
background-color: pink;
overflow: auto;
}
.cuadro a {
float: left;
text-align: center;
width: 20%;
padding: 12px 0;
transition: all 0.3s ease;
color: white;
font-size: 36px;
}
.cuadro a:hover {
background-color: green;
}
.active {
background-color: purple !important;
}
#media only screen and (max-width: 414px) {
body {
margin: 0px;
}
.cuadro {
position: fixed;
width: 414px;
text-align: center;
color: white;
font-size: 36px
}
.cuadro a {
background-color: pink;
display: block;
padding: 16px;
color: white;
}
.cuadro a:hover {
transition: all 0.3s ease;
background-color: green;
}
.active {
background-color: purple !important;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="utf-8">
<meta content="viewport" content="width=device-width initial-scale=1">
<script src="https://use.fontawesome.com/ea180863a6.js"></script>
</head>
<body>
<div class="cuadro">
<a class="active" href="#"><i class="fa fa-skype" aria-hidden="true"></i></a>
<i class="fa fa-spotify" aria-hidden="true"></i>
<i class="fa fa-snapchat-ghost" aria-hidden="true"></i>
<i class="fa fa-whatsapp" aria-hidden="true"></i>
<i class="fa fa-vk" aria-hidden="true"></i>
</div>
</body>
</html>
What am I doing wrong?
You are almost good, simply make the menu item float:none and width:100% in the media query. You may also add box-sizing:border-box to avoid having overflow issue and you don't need to specify a width for .cuadro inside the media query :
body {
margin: 0px;
}
.cuadro {
width: 100%;
background-color: pink;
overflow: auto;
}
.cuadro a {
float: left;
text-align: center;
width: 20%;
padding: 12px 0;
transition: all 0.3s ease;
color: white;
font-size: 36px;
box-sizing:border-box;
}
.cuadro a:hover {
background-color: green;
}
.active {
background-color: purple !important;
}
#media all and (max-width: 414px) {
.cuadro {
position: fixed;
width: 100%;
text-align: center;
color: white;
font-size: 36px
}
.cuadro a {
background-color: pink;
display: block;
width:100%;
padding: 16px;
color: white;
float:none;
}
.cuadro a:hover {
transition: all 0.3s ease;
background-color: green;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="utf-8">
<meta content="viewport" content="width=device-width initial-scale=1">
<script src="https://use.fontawesome.com/ea180863a6.js"></script>
<style>
</style>
</head>
<body>
<div class="cuadro">
<a class="active" href="#"><i class="fa fa-skype" aria-hidden="true"></i></a>
<i class="fa fa-spotify" aria-hidden="true"></i>
<i class="fa fa-snapchat-ghost" aria-hidden="true"></i>
<i class="fa fa-whatsapp" aria-hidden="true"></i>
<i class="fa fa-vk" aria-hidden="true"></i>
</div>
</body>
</html>
There is a lot of repetition in your CSS. There's no need to declare rules twice.
An alternative to float is to use flexbox. Note that you only need to change the direction of the container for smaller screens.
Good introduction to flexbox
example
I've removed / changed a few styles.. let me know if you have questions.
body {
margin: 0;
}
.cuadro {
background-color: pink;
display: flex;
}
.cuadro a {
text-align: center;
flex: 1 0 20%;
transition: all 0.3s ease;
color: white;
font-size: 36px;
padding: 12px 0;
}
.cuadro a:not(.active):hover {
background-color: green;
}
.active {
background-color: purple;
}
#media only screen and (max-width: 414px) {
.cuadro {
flex-direction: column;
justify-content: center;
}
}
<script src="https://use.fontawesome.com/ea180863a6.js"></script>
<div class="cuadro">
<a class="active" href="#"><i class="fa fa-skype" aria-hidden="true"></i></a>
<i class="fa fa-spotify" aria-hidden="true"></i>
<i class="fa fa-snapchat-ghost" aria-hidden="true"></i>
<i class="fa fa-whatsapp" aria-hidden="true"></i>
<i class="fa fa-vk" aria-hidden="true"></i>
</div>
My icons look like this:
I need to create like this one:
Here is my HTML:
<aside class="social">
<span><i class="fa fa-instagram" aria-hidden="true"></i></span>
<span><i class="fa fa-facebook" aria-hidden="true"></i></span>
<span><i class="fa fa-pinterest" aria-hidden="true"></i></span>
</aside>
Here is my CSS:
aside.social a {
margin-left: 10px;
color: #fff;
font-size: 16px;
}
aside.social a span {
width: 25px;
display: inline-block;
height: 25px;
background-color: #aaa;
border-radius: 40%;
}
You don't need two separate elements, you can do that all on your a with an i.fa inside.
aside.social a {
color: #fff;
background: #aaa;
margin-left: 10px;
border-radius: 40%;
width: 25px;
height: 25px;
line-height: 25px; /* vertical alignment */
text-align: center;
font-size: 16px;
}
I would use inline-flex on that element, then you can use flex positioning to center. justify-content: center; align-items: center; will center horizontally and vertically. You can also change the border-radius to 50% for a true circle.
aside.social a {
margin-left: 10px;
color: #fff;
font-size: 16px;
text-decoration: none;
}
aside.social a span {
width: 25px;
height: 25px;
background-color: #aaa;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<aside class="social">
<span><i class="fa fa-instagram" aria-hidden="true"></i></span>
<span><i class="fa fa-facebook" aria-hidden="true"></i></span>
<span><i class="fa fa-pinterest" aria-hidden="true"></i></span>
</aside>
Try changing your code so it looks something like this
span {
display: block;
text-align: center;
line-height: 25px
}
And
a {
width: 25px;
height: 25px;
display: inline-block;
}
You can use flex:
aside.social a {
margin-left: 10px;
color: #fff;
font-size: 16px;
text-decoration: none;
}
aside.social a span {
display: inline-flex;
justify-content: center;
align-items: center;
width: 25px;
height: 25px;
background-color: #aaa;
border-radius: 40%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<aside class="social">
<a href="https://www.instagram.com/" class="inst">
<span>
<i class="fa fa-instagram" aria-hidden="true"></i>
</span>
</a>
<a href="https://www.facebook.com" class="facb">
<span>
<i class="fa fa-facebook" aria-hidden="true"></i>
</span>
</a>
<a href="https://www.pinterest.com/" class="pint">
<span>
<i class="fa fa-pinterest" aria-hidden="true"></i>
</span>
</a>
</aside>
add this in "aside.social a span", nothing else is required:
text-align:center;
padding-top:8px;
Try adding a position: absolute; to the css
Followed by margin-left: 20px, play with the pixels a little until you're satisfied :)