I'm trying to add a little design flourish to some tabs.
The tabs are contained inside a tab bar, which has a bottom border.
When a tab is active I want it to appear as if it's on the same level of the content, with the other tabs appearing set back.
To do this, I need to make the section of border beneath the active tab disappear - my first thought was to set the tab background white and overlap the parent - but this doesn't work.
Anyone got any ideas as to how to get the effect I'm looking for?
.container {
padding: 30px;
}
.tab-bar {
display: flex;
background-color: #fff;
border-bottom: solid 1px rgba(0,0,0, .12);
height: 48px;
overflow: hidden;
}
.tab {
flex: 1 1 0;
display: flex;
align-items: center;
justify-content: center;
height: 48px;
max-width: 200px;
min-width: 100px;
padding: 0 16px;
}
.tab[data-state="active"] {
box-shadow: 0 2px 4px -1px rgba(0,0,0,0.2), 0 4px 5px 0 rgba(0,0,0,0.14), 0 1px 1px 0 rgba(0,0,0,0.12);
color: red;
}
<div class="container">
<div class="tab-bar">
<div class="tab" data-state="active">Active</div>
<div class="tab">Not Active</div>
</div>
</div>
Link to JsFiddle
from earlier comment
draw the bottom border from the non active tabs
add eventually a pseudo element to fill the room left.
overflow:hidden on the parent hides shadows and also do not allow children to stand on top of the border in order to hide it
What you could do :
.container {
padding: 30px;
}
.tab-bar {
display: flex;
background-color: #fff;
height: 48px;
}
.tab {
flex: 1 1 0;
display: flex;
align-items: center;
justify-content: center;
max-width: 200px;
min-width: 100px;
padding: 0 16px;
border-bottom: solid 1px rgba(0, 0, 0, .12);
}
.tab-bar::after {
content: '';
flex: 1;
border-bottom: solid 1px rgba(0, 0, 0, .12);
}
.tab[data-state="active"] {
box-shadow: 0 -2px 4px -1px rgba(0, 0, 0, 0.2), 0 -4px 5px 0 rgba(0, 0, 0, 0.14), 0 -1px 1px 0 rgba(0, 0, 0, 0.12);
color: red;
border-bottom: none;
}
<div class="container">
<div class="tab-bar">
<div class="tab" data-state="active">Active</div>
<div class="tab">Not Active</div>
</div>
</div>
You should overflow: hidden from .tab-bar.
But after you remove it. It seems not to be as you wanted ("the same level of the content").
So I edited box-shadow of active tab. to make it with no box-shadowfrom button.
border-bottom: 1px solid white is responsible to override tab-bar border
See Full Example here:
.container {
padding: 30px;
}
.tab-bar {
display: flex;
background-color: #fff;
border-bottom: solid 1px rgba(0,0,0, .12);
height: 48px;
}
.tab {
flex: 1 1 0;
display: flex;
align-items: center;
justify-content: center;
height: 48px;
max-width: 200px;
min-width: 100px;
padding: 0 16px;
}
.tab[data-state="active"] {
box-shadow: -4px -2px 4px -1px rgba(0,0,0,0.1), 4px -2px 4px -1px rgba(0,0,0,0.1);
color: red;
border-bottom: 1px solid white;
}
<div class="container">
<div class="tab-bar">
<div class="tab" data-state="active">Active</div>
<div class="tab">Not Active</div>
</div>
</div>
Related
I have to align a child div which is inside a div of flex box container to bottom. I tried different options like setting bottom to 0 or margin-top but none of them are working.
<style>
.flex-container {
display: flex;
height: 500px;
background-color: #f1f1f1;
}
.flex-container > div {
color: white;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
.vertical
{
box-shadow: inset 0px 4px 6px #ccc;
}
.progress {
background-color: #f5f5f5;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 2px rgb(0 0 0 / 10%);
box-shadow: inset 0px 4px 6px rgba(100,100,100,0.6);
}
.progress-bar-info {
background-color: #5bc0de;
}
.progress-bar {
box-shadow: inset 0px 4px 6px rgb(100 100 100 / 60%);
}
</style>
<div class="flex-container">
<div class= "progress vertical" >1
<div class="progress-bar progress-bar-info" style="height: 35%;">
how to align this div to bottom..... ?
</div>
</div>
</div>
You can add flex properties on flex-container>div like below:
.flex-container {
display: flex;
height: 500px;
background-color: #f1f1f1;
}
.flex-container>div {
color: red;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.vertical {
box-shadow: inset 0px 4px 6px #ccc;
}
.progress {
background-color: #f5f5f5;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 2px rgb(0 0 0 / 10%);
box-shadow: inset 0px 4px 6px rgba(100, 100, 100, 0.6);
}
.progress-bar-info {
background-color: #5bc0de;
}
.progress-bar {
box-shadow: inset 0px 4px 6px rgb(100 100 100 / 60%);
}
<div class="flex-container">
<div class="progress vertical">
<div>1</div>
<div class="progress-bar progress-bar-info" style="height: 35%;">Bottom</div>
</div>
</div>
I am trying to make a progress bar as is shown here in the about section however I am just lost.
I can make a bar and a box but neither look anywhere near as good as that and I cannot for the life of me get them to be beside each other with equal height. I just keep getting something along the lines of
What I am trying to achieve in case website goes down:
.myskills {
width: 45vw;
height: 100%;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
justify-content: center;
height: 2vh;
}
.skillName {
background-color: blue;
width: 5vw;
float: left;
height: 100%;
font-size: 2em;
}
.meter {
float: left;
width: 80%;
height: 100%;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
position: relative;
overflow: hidden;
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
This code below will give you the percentage sign on the right of the percentage bar. A lot of this is purely layering with hmtl/css.
Here are some links for layering and z-index:
https://www.tutorialspoint.com/css/css_layers.htm#:~:text=The%20CSS%20layers%20refer%20to,element%20should%20come%20at%20bottom.
https://www.w3schools.com/cssref/pr_pos_z-index.asp
https://css-tricks.com/almanac/properties/z/z-index/
.myskills {
width: 90%%;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillLevel{
right: 0;
font-size: 1.7em;
position: absolute;
}
.skillName {
background-color: rgb(77, 252, 208);
float: left;
font-size: 2em;
}
.meter {
float: left;
width: 100%;
/* Can be anything */
position: relative;
background: rgb(218, 217, 217);
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: rgb(31, 134, 117);
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"><span class="skillLevel">90%</span></span>
</div>
</div>
</div>
Well, IMO you should use less vh and vw. Your font simply defines the height and the width of the text part. By removing them, you get something as you want as I understood (I also removed useless properties) :
.myskills {
width: 45vw;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillName {
background-color: blue;
font-size: 2em;
}
.meter {
float: left;
width: 100%;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
Now, if it was my progress bar I'd use flex instead of width for .meter, I'd take a smaller font size and put padding to the text :
.myskills {
width: 45vw;
background: red;
margin: 1em;
}
.skillbarContainer {
display: flex;
}
.skillName {
background-color: blue;
font-size: 18px;
padding: 3px 10px;
}
.meter {
float: left;
flex: 1;
/* Can be anything */
position: relative;
background: #555;
padding: 3px;
}
.meter>span {
display: block;
height: 100%;
background-color: hotpink;
box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);
}
<div class="myskills">
<div class="skillbarContainer">
<div class="skillName">HTML</div>
<div class="meter">
<span style="width: 80%"></span>
</div>
</div>
</div>
Problem :
To make a vertical line which separates two objects but it won't appear because it doesn't have height although I added height: 100%.
Why isn't it filling up the space from the top to the bottom of my
div? Is it because .card-body has height: auto?
Tried Cases :
I already tried adding width, disabling flex-box but nothing of that worked, but if I add a specific height to my .card-body it works.
Do you
know a solution how it could work without adding a specific height?
.card {
margin-bottom: 30px;
}
.card > .card-header {
font-weight: 500;
text-transform: uppercase;
font-size: 15px;
margin-bottom: 6px;
}
.card > .card-header.light {
color: #fff;
}
.card > .card-body {
background-color: #fff;
border-radius: 12px;
padding: 24px;
-webkit-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
-moz-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
}
.card > .card-body.server-status {
display: flex;
align-items: center;
}
.card > .card-body.server-status > .counter {
width: 50%;
font-weight: 500;
color: #95a0b7;
font-size: 32px;
display: flex;
flex-direction: column;
align-items: center;
}
.card > .card-body.server-status > .counter > span {
font-size: 15px!important;
color: #0d2c4a!important;
text-transform: capitalize;
}
<div class="card">
<div class="card-header light">
Active Services
</div>
<div class="card-body server-status">
<div class="counter">
7/9
<span>
Servers running
</span>
</div>
<div style="border-left:1px solid #0d2c4a;height:100%;"></div>
<div class="chart">
</div>
</div>
</div>
You need to make it stretch since your flex container is align-items: center
You can remove the height 100%, I added a class to the divider, it comes down to this
.divider {
align-self: stretch;
}
If you did not have the align center, it would of worked by default because the align items defaults to stretch but since you changed it to center and your divider has no content so the line does not show. Setting the divider itself to stretch again solves the problem and no need for the extra css
.card {
margin-bottom: 30px;
}
.card>.card-header {
font-weight: 500;
text-transform: uppercase;
font-size: 15px;
margin-bottom: 6px;
}
.card>.card-header.light {
color: #fff;
}
.card>.card-body {
background-color: #fff;
border-radius: 12px;
padding: 24px;
-webkit-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
-moz-box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
box-shadow: -2px 4px 34px 1px rgba(0, 0, 0, 0.15);
}
.card>.card-body.server-status {
display: flex;
align-items: center;
}
.card>.card-body.server-status>.counter {
width: 50%;
font-weight: 500;
color: #95a0b7;
font-size: 32px;
display: flex;
flex-direction: column;
align-items: center;
}
.card>.card-body.server-status>.counter>span {
font-size: 15px!important;
color: #0d2c4a!important;
text-transform: capitalize;
}
.divider {
align-self: stretch;
}
<div class="card">
<div class="card-header light">
Active Services
</div>
<div class="card-body server-status">
<div class="counter">
7/9
<span>
Servers running
</span>
</div>
<div class="divider" style="border-left:1px solid #0d2c4a;"></div>
<div class="chart"></div>
</div>
</div>
Also you can add this css property to your css ...
.counter{
border-right: 1px solid black;
}
Instead of using a <div>, try using an <hr> and rotating it with css. Something along the lines of:
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 1px;
transform: rotate(90deg);
}
See this documentation for help: https://www.w3schools.com/tags/tag_hr.asp
This question already has answers here:
How to center a flex container but left-align flex items
(9 answers)
Closed 5 years ago.
Hello I have the following bit of code but i'm struggling to sort out a layout issue. Ideally i would like the rows to go from left to right as shown in the picture but I would like to center the entire structure.
Currently have
But I would like this
This is the css and code i'm currently using.
<div class="service_list_container">
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
</div>
.service_list_container {
background: blue;
display: flex; /* or inline-flex */
flex-wrap: wrap;
justify-content: space-evenly;
}
.service_tab {
flex-basis: 300px;
flex-grow: 0;
flex-shrink: 0;
height: 400px;
background: #fff;
margin: 10px 20px;
-webkit-box-shadow: -2px -1px 5px 0px #efefef;
-moz-box-shadow: -2px -1px 5px 0px #efefef;
box-shadow: -2px -1px 5px 0px #efefef;
border: solid 1px #e8e8e8;
}
Is it possible using flexbox to achieve what I am after?
Thanks
You need to use flex-basis: 30%; instead of flex-basis: 300px;
.service_list_container {
background: blue;
display: flex; /* or inline-flex */
flex-wrap: wrap;
justify-content: space-evenly;
}
.service_tab {
flex-basis: 30%;
flex-grow: 0;
flex-shrink: 0;
height: 400px;
background: #fff;
margin: 10px 1.5%;
-webkit-box-shadow: -2px -1px 5px 0px #efefef;
-moz-box-shadow: -2px -1px 5px 0px #efefef;
box-shadow: -2px -1px 5px 0px #efefef;
border: solid 1px #e8e8e8;
}
<div class="service_list_container">
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
</div>
.service_tab { flex-grow: 1; }
instead of
.service_tab { flex-grow: 1; }
.service_list_container {
background: blue;
display: flex; /* or inline-flex */
flex-wrap: wrap;
justify-content: space-evenly;
}
.service_tab {
flex-basis: 300px;
flex-grow: 1;
flex-shrink: 0;
height: 400px;
background: #fff;
margin: 10px 20px;
-webkit-box-shadow: -2px -1px 5px 0px #efefef;
-moz-box-shadow: -2px -1px 5px 0px #efefef;
box-shadow: -2px -1px 5px 0px #efefef;
border: solid 1px #e8e8e8;
}
<div class="service_list_container">
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
<div class="service_tab"></div>
</div>
I'd like to know why my class .top does not work for my second DIV wrapper top? I would expect to have 200px between the bottom of the picture on the right and the top of the red DIV but it's not working. See JSFIddle
HTML
<div class="wrapper top">
<div class="block-1">
<p><span>ddfsfsdsfds</p>
<p>fdsfsdfs.</p>
<p>dfsdfdsfds.</p>
</div>
<div class="block-2"><img src="images/136147555-e1329752650296-287x300.jpg" alt="136147555-e1329752650296-287x300" width="287" height="300"></div>
</div><!-- End wrapper -->
<div class="wrapper top">
<div class="block-100pc">
block-100pc
</div>
</div>
CSS
body {
background: #F2F2F2;
}
.top {
margin-top: 200px;
}
.wrapper {
position: relative;
display: block;
margin-right: auto;
margin-left: auto;
width: 980px;
}
.block-1 {
float: left;
box-sizing: border-box;
padding: 20px;
width: 60%;
text-align: justify;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.block-1 span {
color: #124191;
font-weight: bold;
}
.block-2 {
float: right;
overflow: hidden;
box-sizing: border-box;
width: 35%;
padding: 20px;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
text-align: justify;
}
.block-100pc {
overflow: hidden;
box-sizing: border-box;
width: 100%;
padding: 20px;
background-clip: border-box;
background: #fff;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
text-align: justify;
clear: both;
background: red;
}
That is because of the floated elements. They do not "count into" the height of their container, unless they are cleared.
There are several clearing techniques you can use, for example setting overflow: hidden on the container:
.wrapper {
overflow: hidden;
}
jsFiddle Demo
.block-1 {
margin-top: 200px;
}
or
.top {
margin-bottom: 200px;
}
either one should work
The margin-top doesn't work in your case because the two block that are above it are floated. the margin-top property applies to the top of the parent.
In order to see a top margin, you will have to apply a margin-top= height of the hieghest floated div + the margin you want.
You have some broken code in your fiddle, I've updated it with some fixes. Another thing is that you are not taking into account your padding when you've set the width of block-1 and block-2, therefor they are overlapping. Fix your block-1 width down to a lower percent to allow for the padding on the blocks. Here is an updated fiddle: http://jsfiddle.net/pB5kq/5/
<div class="wrapper top">
<div class="block-1">
<p><span>ddfsfsdsfds</span></p>
<p>fdsfsdfs.</p>
<p>dfsdfdsfds.</p>
</div>
<div class="block-2">
<img src="images/136147555-e1329752650296-287x300.jpg" alt="136147555-e1329752650296-287x300" width="287" height="300"></img>
</div>
<div class="wrapper top">
<div class="block-100pc">
block-100pc
</div>
</div>
Along with the other answers regarding floating divs and clearing, this should help.