Is it possible to use something similar to toggle on/off or show/hide but rather than using panels or accordion menu, use icon-blocks instead?
There are 4 icons arranged in a row, clicking each icon should display the contents below the icon row, but only one content should be displayed at any given time.
I'm looking for CSS/HTML solution only - no javascript.
Icons are arranged in a row, using grid
<!--display icons in a row, 4 columns-->
<div class="quarter">
<span class="icon1"></span>
</div>
Below the 4th 'quarter' div is where the contents should be displayed.
Edit: Final Code
I replaced the position: absolute with float to display all the text below the icons.
.iconBlock{
display: inline-block;
margin: 20px;
padding: 0px 40px 15px 40px;
cursor: pointer;
outline: none !important;
}
.iconBlock a{
font-size: 40px;
color: #000;
}
.contentBlock {
display: none;
height: auto !important;
opacity: 0;
}
.iconBlock:hover a{
color: #444;
}
.iconBlock:focus a{
color: #ff4455;
}
.iconBlock:focus + .contentBlock{
opacity: 1;
display: block;
float: left;
top: 0;
left: 0;
}
I'd recommend using javascript. But here's how to do it without js:
.icon{
display: inline-block;
margin: 20px;
cursor: pointer;
outline: none;
}
.icon i{
font-size: 40px;
color: #000;
}
.content{
position: absolute;
opacity: 0;
}
.icon:hover i{
color: #444;
}
.icon:focus i{
color: #ff4455;
}
.icon:focus + .content{
opacity: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="quarter">
<i class="fa fa-cog"></i>
<div class="content">Content for icon 1</div>
<i class="fa fa-trash"></i>
<div class="content">Content for icon 2</div>
<i class="fa fa-pencil"></i>
<div class="content">Content for icon 3</div>
<i class="fa fa-user"></i>
<div class="content">Content for icon 4</div>
</div>
Related
I would like to move the words "Social Media", above the two icons as a title. The problem I'm having is moving the title without moving the icons and the book button.
Could you please help?
.icons{
font-size: 50px;
color: blue;
padding-top: 250px;
padding-left: 110px;
}
.book {
padding-left: 43.5%;
}
.book button {
background-color: #F6B2A2;
border: none;
color: black;
text-decoration: none;
font-size: 16px;
height: 50px;
width: 100px;
}
.book a {
color: black;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<div class="socialm">
<h2>Social Media</h2>
</div>
<div class="icons">
<i class="fab fa-facebook-square"></i>
<i class="fab fa-instagram"></i>
</div>
<div class="book">
<button>Book</button>
</div>
You can add a display: block and a display: inline-block for your icons in your css:
.socialm {
display: block;
}
.icons{
display: inline-block;
font-size: 50px;
color: blue;
padding-top: 250px;
padding-left: 110px;
}
.book {
display: block;
padding-left: 43.5%;
}
.book button {
background-color: #F6B2A2;
border: none;
color: black;
text-decoration: none;
font-size: 16px;
height: 50px;
width: 100px;
}
.book a {
color: black;
}
Add another div that wraps both the header tag and the icons. Add your padding to that div to keep the two pieces together and move them both at the same time.
.top{
padding-left: 43.5%;
}
.icons{
font-size: 50px;
color: blue;
padding-top: 250px;
}
.book {
padding-left: 43.5%;
}
.book button {
background-color: #F6B2A2;
border: none;
color: black;
text-decoration: none;
font-size: 16px;
height: 50px;
width: 100px;
}
.book a {
color: black;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet" />
<div class="top">
<div class="socialm">
<h2>Social Media</h2>
</div>
<div class="icons">
<i class="fab fa-facebook-square"></i>
<i class="fab fa-instagram"></i>
</div>
</div>
<div class="book">
<button>Book</button>
</div>
In my header I have 4 elements which are:
"Running Days" - "admin#email.com" - "Deposit" - "Paidout".
My 4 elements are separated into 2.
"Deposit" and "Paidout" are in right in my header.
I made a float:right!
Except that the order is inverted namely I have "Paidout" before "Deposit".
header {
width: 100%;
height: 38px;
background-color: #CEECE8;
}
.subtitles {
font-size: 13px;
font-family: 'Roboto Slab', serif;
padding-top: 8px;
padding-left: 80px;
padding-right: 80px;
text-transform: uppercase;
}
.subtile-left {
display: inline-block;
padding-left: 18px;
}
.subtile-right {
display: inline-block;
padding-left: 18px;
float: right;
}
<header>
<div class="subtitles">
<div class="subtile-left"><i class="far fa-calendar"></i> 137 Running Days </div>
<div class="subtile-left"><i class="far fa-envelope"></i> Admin#superbtc.biz </div>
<div class="subtile-right"><i class="fas fa-caret-right"></i> Deposit </div>
<div class="subtile-right"><i class="fas fa-caret-right"></i> Paidout </div>
</div>
</header>
Use float:left with the left elements instead and adjust text-align to align the other to the right:
header {
width: 100%;
height: 38px;
background-color: #CEECE8;
}
.subtitles {
font-size: 13px;
font-family: 'Roboto Slab', serif;
padding-top: 8px;
padding-left: 80px;
padding-right: 80px;
text-transform: uppercase;
text-align:right;
}
.subtile-left {
display: inline-block;
padding-left: 18px;
float: left;
}
.subtile-right {
display: inline-block;
padding-left: 18px;
}
<header>
<div class="subtitles">
<div class="subtile-left"><i class="far fa-calendar"></i> 137 Running Days </div>
<div class="subtile-left"><i class="far fa-envelope"></i> Admin#superbtc.biz </div>
<div class="subtile-right"><i class="fas fa-caret-right"></i> Deposit </div>
<div class="subtile-right"><i class="fas fa-caret-right"></i> Paidout </div>
</div>
</header>
A better way would be to consider flexbox to avoid having the whitespace issue between inline-block elements:
header {
width: 100%;
height: 38px;
background-color: #CEECE8;
}
.subtitles {
font-size: 13px;
font-family: 'Roboto Slab', serif;
padding-top: 8px;
padding-left: 80px;
padding-right: 80px;
text-transform: uppercase;
display:flex;
}
.subtitles :nth-child(2) {
margin-right:auto;
}
.subtile-left {
padding-left: 18px;
}
.subtile-right {
padding-left: 18px;
}
<header>
<div class="subtitles">
<div class="subtile-left"><i class="far fa-calendar"></i> 137 Running Days </div>
<div class="subtile-left"><i class="far fa-envelope"></i> Admin#superbtc.biz </div>
<div class="subtile-right"><i class="fas fa-caret-right"></i> Deposit </div>
<div class="subtile-right"><i class="fas fa-caret-right"></i> Paidout </div>
</div>
</header>
Elements are floated in order of source appearance.
Check this example:
.container {
background-color: #ddd;
}
.container::after { /* clearfix */
display: block;
content: "";
clear: both;
}
[id] {
background-color: #f0f0f0;
border: 3px dotted #999;
text-align: center;
width: 2em;
}
#a {
float: right;
}
<div class="container">
<div id="a">A</div>
<div id="b">B</div>
<div id="c">C</div>
</div>
div#a floats right, which means it is moved as far to the right of its container as possible.
Now let's make div#b float to the right as well:
.container {
background-color: #ddd;
}
.container::after { /* clearfix */
display: block;
content: "";
clear: both;
}
[id] {
background-color: #f0f0f0;
border: 3px dotted #999;
text-align: center;
width: 2em;
}
#a,
#b {
float: right;
}
<div class="container">
<div id="a">A</div>
<div id="b">B</div>
<div id="c">C</div>
</div>
Now when the layout engine parses the layout, the first element that is floated is div#a (because it comes before div#b in the source), moving it to the very right side of div.container.
Next comes div#b, which is now also floated to the right. Since div#a is already taking space at the right side of div.container, div#b can only float until its right border touches the left border of div#a.
This obviously makes it so visual appearance of div#a and div#b is inverted compared to source order.
When the viewport is rendering the HTML it reads the elements from top bottom.
This means the following:
1) 'Deposit' is seen before 'Paidout' and thus is floated to the right part of the container div first
2) Paidout is seen and floats to the right, but bumps into deposit and thus finds its place to the left of it
I am making a sidebar and am new to css. I created a div which represents a closed sidebar. It is supposed to only show the icons. Unfortunately the icons come in a misaligned manner inside the div based on their size. How do I fix this?
.sidenav {
height: 492px;
width: 300px;
background-color: #db3d44;
}
.data-icon {
font-size: 45px;
color: black;
opacity: 0.5;
float: left;
margin-left: 9px;
margin-top: 5px;
margin-bottom: 10px;
}
.hamburger {
background-color: transparent;
border-color: transparent;
color: white;
margin-left: 10px;
margin-top: 4px;
font-size: 25px;
}
.hamburger:hover {
color: black;
}
.sidenav-closed {
width: 65px;
float: left;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="sidenav-closed sidenav">
<button class="hamburger data-disappear">☰</button>
<div class="icons-only">
<div class="data-icon">
<i class="fa fa-home"></i>
</div>
<div class="data-icon">
<i class="fa fa-car"></i>
</div>
<div class="data-icon">
<i class="fa fa-home"></i>
</div>
</div>
</div>
The car icon is misaligned here. What's the solution?
You could try to align all the icons to the center so your .data-icon class could look like this:
.data-icon {
font-size: 45px;
color: black;
opacity: 0.5;
display: block;
width: 100%;
text-align: center;
}
Your div elements doesn't have set width and height in CSS - so the icons are strictly aligned inside them.
If you want to vertically center them and learn something new use flexbox:
.icons-only {
display: flex;
flex-direction: column;
align-items: center;
}
and
.data-icon {
...
margin-left:0
}
Your car icon is also a little bit bigger than house - you can a little change it size by add new class to it or use this:
.data-icon:nth-child(2) {
font-size: 40px;
}
This CSS code will take second (=2) element with class .data-icon and set different font size for it
The icons are inline elements so they will be left aligned by default. Add in that the icons are not that same size (this is normal), you get an uneven alignment.
To remedy this, add text-align: center to .icons-only.
Note: Given the layout in the example, it does not appear necessary to float .data-icon to the left.
.sidenav {
height: 492px;
width: 300px;
background-color: #db3d44;
}
.icons-only {
text-align: center;
}
.data-icon {
color: rgba( 0, 0, 0, 0.5 );
font-size: 45px;
}
.hamburger {
background-color: transparent;
border-color: transparent;
color: white;
margin-left: 10px;
margin-top: 4px;
font-size: 25px;
}
.hamburger:hover {
color: black;
}
.sidenav-closed {
width: 65px;
float: left;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="sidenav-closed sidenav">
<button class="hamburger data-disappear">☰</button>
<div class="icons-only">
<div class="data-icon">
<i class="fa fa-home"></i>
</div>
<div class="data-icon">
<i class="fa fa-car"></i>
</div>
<div class="data-icon">
<i class="fa fa-home"></i>
</div>
</div>
</div>
I want to create a button like this one :
but bigger, resizable and to function properly on bootstrap.
Here's what I've done so far:
I've tried with display: inline-block; on download-btn-icon and download-btn-text then I wanted to center the .fa using http://www.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/ but the .fa displays way out of download-btn.
This is the html:
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
<div class="download-btn">
<div class="download-btn-icon">
<i class="fa fa-cloud-download fa-3x"></i>
</div>
<div class="download-btn-text">
<h3>Download Client</h3>
<h5>Get the latest full updated client.</h5>
</div>
</div>
</div>
and this is the less:
.download-btn {
width: 100%;
height: 70px;
background-color: #000;
.download-btn-icon {
display: inline-block;
float: left;
width: 25%;
height: 100%;
border-right: 1px solid #fff;
.fa{
padding-top: 14px;
padding-left: 23px;
}
}
.download-btn-text {
display: inline-block;
width: 75%;
float: right;
padding-left: 15px;
}
}
I'm clueless I don't know how to align the divs properly, I need some advice.
You can use display: table-cell and vertical-align: middle to achieve this effect. This solves the alignment issue and forces both elements to have the same height.
h3, h5 {
margin: 0;
line-height: 1.5em;
}
.download-btn-icon,
.download-btn-text {
display: table-cell;
background: #222;
vertical-align: middle;
padding: 7.5px 15px;
color: #999;
}
.download-btn-icon {
border-right: 1px solid #444;
}
<div class="download-btn">
<div class="download-btn-icon">
<i class="fa fa-cloud-download fa-3x"></i>
</div>
<div class="download-btn-text">
<h3>Download Client</h3>
<h5>Get the latest full updated client.</h5>
</div>
</div>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
(The title might sound stupid but I don't know how to put it more sophisticated.)
As you can see in the follwing screenshots, I have 3 stacked divs.
<div class="col-xs-3">
<div class="center-horizontal-inline">
<a class="upvote" href="#" data-id="iZheLNnewWtMhPTQd">
</div>
<div class="score">
115
<span class="badge score-diff vertical-align"> +5 </span>
</div>
<div class="center-horizontal-inline">
</div>
The one in the middle contains the number (115). The other two the vote-arrows. For the one containing the number, I want to add a "badge" (in bootstrap context) right next to the number, let's say to the right. You can see my attempt shining through the colored overlay.
The goal is to leave the number centered respectively to the arrow-icons, while placing the badge with an offset (or "right next to") respectively to the number.
My attempt was to set a float: right; for the badge, but as you can see, the number has an offset now. When I try position: absolute; on the badge, there is no offset (as wanted), but I can't get the badge right next to the number, I can only attach it to the right border because I don't have the number as positioning-reference anymore.
Hope my explanation was clear enough. I also didn't know how to search for that problem...
EDIT 1:
As I want it to look like (positioning-wise):
Here we go, using relative and absolute positions together:
DEMO: http://jsfiddle.net/1qbo7uwn/
HTML
<div class="score">
<span class="score-wrap">
<span class="score-main">123</span>
<span class="score-diff">8</span>
</span>
</div>
CSS
.score {
width: 80px;
border: 2px solid blue;
padding: 10px 0;
text-align: center;
}
.score-wrap {
display: inline-block;
position: relative;
}
.score-main {
border: 2px solid green;
}
.score-diff {
position: absolute;
border: 2px solid red;
left: 100%;
top: -2px;
}
Added some span tags in the HTML.
EDIT: vertical align of everything, by setting line height.
http://jsfiddle.net/1qbo7uwn/1/
As you said you are okay with HTML modification. Here's my attempt:
Demo Fiddle
HTML
<div class="wrap">
<div class="vote up">
<i class="fa fa-angle-up"></i>
</div>
<div class="stat">
<span class="score">115
<span class="badge">+5</span>
</span>
</div>
<div class="vote inactive">
<i class="fa fa-angle-down"></i>
</div>
</div>
CSS
.wrap{
margin: 100px;
text-align:center;
}
.vote{
font-size:36px;
}
.up{
color:green;
}
.down{
color:red;
}
.inactive{
color:gray;
}
.score{
position: relative;
display:block;
padding: 5px 0;
}
.badge{
background: #eee;
padding:5px 10px;
border-radius: 30px;
position: absolute;
top:0;
margin-left:10px;
}
Try
Demo: http://jsfiddle.net/tamilcselvan/rjv1xxo2/1/
.center-horizontal-inline {
font-size: 2em;
text-align: center;
}
.score {
text-align: center;
}
.score:after {
content:attr(data-badge);
position: absolute;
margin-left: .4em;
font-size: x-small;
min-width: 10px;
padding: 3px 7px;
font-size: 12px;
font-weight: 700;
line-height: 1;
color: #FFF;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
background-color: #777;
border-radius: 10px;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-3">
<div class="center-horizontal-inline vote"> <i class="glyphicon glyphicon-chevron-up"></i>
</div>
<div class="score" data-badge="+5">115</div>
<div class="center-horizontal-inline"> <i class="glyphicon glyphicon-chevron-down"></i>
</div>
</div>