Who could help me to vertically align 2 divs inside a button element with these properties :
height of button is known
height of orange div is unknown
one of the div contain text (orange div), with 1 or 2 lines (number of lines is unknown)
.
Here is html code :
<button style="width: calc(125px * 1); height: calc(30px + 24px); margin-top: 0;margin-bottom: 0;">
<div id='bt_icon'></div>
<div id='bt_text'>Fermer</div>
</button>
CSS :
button {
display: inline-block;
border: 1px solid rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-left: 5px;
padding-right: 5px;
color: black;
font-family:'Tahoma', 'Arial', 'Helvetica', sans-serif;
font-size: 13px;
cursor: pointer;
background: linear-gradient(to bottom right, #EDDDB5, #D5C59D);
box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.3) inset, -1px -1px 0 rgba(0, 0, 0, 0.3) inset, 2px 2px 8px rgba(0, 0, 0, 0.3);
}
#bt_icon {
float: left;
width: 34px;
height: 34px;
background-color: green;
}
#bt_text {
float: right;
width: calc(100% - 10px - 34px);
background-color: orange;
}
And the fiddle :
https://jsfiddle.net/15xceg8p/1/
The green square will contain an icon and is well vertically centered. The orange rectangle will contain text and is not vertically centered :(
Please update code
button {
display: inline-block;
border: 1px solid rgba(0, 0, 0, 0.5);
border-radius: 3px;
padding-left: 5px;
padding-right: 5px;
color: black;
font-family:'Tahoma', 'Arial', 'Helvetica', sans-serif;
font-size: 13px;
cursor: pointer;
background: linear-gradient(to bottom right, #EDDDB5, #D5C59D);
box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.3) inset, -1px -1px 0 rgba(0, 0, 0, 0.3) inset, 2px 2px 8px rgba(0, 0, 0, 0.3);
}
#bt_icon {
width: 34px;
height: 34px;
background-color: green;
display: inline-block;
vertical-align: middle;
}
#bt_text {
display: inline-block;
vertical-align: middle;
width: calc(100% - 10px - 34px);
background-color: orange;
}
<button style="width: calc(125px * 1); height: calc(30px + 24px); margin-top: 0;margin-bottom: 0;">
<div id='bt_icon'></div>
<div id='bt_text'>Fermer</div>
</button>
try below styles and remove all css style from button
button{display: table-cell;}
button>div{display: table-cell;vertical-align: middle;}
Also remove float from both div's.
https://jsfiddle.net/t698pL8j/
Related
I designed this button in Figma but when I copy the CSS properties from the inspect section from Figma I won't get the same output, what I'm doing wrong here?
Figma file: https://www.figma.com/file/r3z3qwUsYGsn9SVDefWVoM/problem?node-id=2%3A6
div {
display: flex;
justify-content: center;
align-items: left;
height: 100%;
text-align: center;
}
button {
width: 300px;
height: 64px;
border: none;
line-height: 23px;
text-align: center;
letter-spacing: 0.666667px;
color: #000000;
font-weight: 400;
font-size: 16px;
background: linear-gradient(135.37deg, rgba(0, 0, 0, 0.35) 4.29%, rgba(255, 255, 255, 0.35) 95.6%);
background-blend-mode: soft-light;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.15), -5px -5px 10px #FAFBFF, 5px 5px 10px rgba(190, 106, 255, 0.3);
border-radius: 20px;
}
<div>
<button>Wednesday</button>
</div>
I want the button to be like that
and this is what i'm getting right now
Unfortunately, button shadows won't show through the button's body, even if the body is transparent. You will have to find another way to render a very rich button like that.
See my proof of concept below.
You can also find a detailed explanation at https://stackoverflow.com/a/9573440/46915
body {
background: #777;
}
div {
display: flex;
justify-content: center;
align-items: left;
height: 100%;
text-align: center;
}
button {
position: absolute;
width: 300px;
height: 64px;
background-color: transparent;
background-repeat: no-repeat;
border: none !important;
/*background: linear-gradient(135.37deg, rgba(0, 0, 0, 0.35) 4.29%, rgba(255, 255, 255, 0.35) 95.6%);*/
background-blend-mode: soft-light;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.15), -5px -5px 10px #FAFBFF, 5px 5px 10px rgba(190, 106, 255, 0.3);
border-radius: 20px;
}
<div>
<button>Wednesday</button>
</div>
I have a button which I have put two icons, one grey and one blue. I have hidden the blue image by add display: none; and when I hover over the button I change the css to display: block;. The blue image shows but is not directly over the grey image.
.page-btn-icon {
vertical-align: middle;
width: 36px;
height: 36px;
margin: 0 4px;
background-color: #ffffff;
border: 1px solid #dee2e6;
border-radius: 18px;
-webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
cursor: pointer;
outline: 0 none !important;
}
.page-btn-icon .icon {
width: 16px;
height: 16px;
}
.page-btn-icon .img-top {
display: none;
}
.page-btn-icon:hover .img-top {
display: block;
}
<button class="page-btn-icon">
<!--<img class="icon" src="{% static 'img/icons/filter_g.png' %}">
<img class="icon img-top" src="{% static 'img/icons/filter_b.png' %}">-->
<img class="icon" src="https://dummyimage.com/16x16/fff/aaa">
<img class="icon img-top" src="https://dummyimage.com/16x16/aaa/fff">
</button>
Screenshot:
This fixes the problem by making it so the first image is display:none when hovered, and the second image is changed from display:none to display:inline-block.
.page-btn-icon {
vertical-align: middle;
width: 36px;
height: 36px;
margin: 0 4px;
background-color: #ffffff;
border: 1px solid #dee2e6;
border-radius: 18px;
-webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
cursor: pointer;
outline: 0 none !important;
}
.page-btn-icon .icon {
width: 16px;
height: 16px;
}
.page-btn-icon .img-top,
.page-btn-icon:hover .icon {
display: none;
}
.page-btn-icon:hover .img-top {
display: inline-block;
}
<button class="page-btn-icon">
<img class="icon" src="https://dummyimage.com/16x16/fff/aaa">
<img class="icon img-top" src="https://dummyimage.com/16x16/aaa/fff">
</button>
I would get rid of the two images, and just flip the background image of the button based on the hover state. Much cleaner.
.page-btn-icon {
vertical-align: middle;
width: 36px;
height: 36px;
margin: 0 4px;
background-color: #ffffff;
border: 1px solid #dee2e6;
border-radius: 18px;
-webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
cursor: pointer;
outline: 0 none !important;
background-image: url('https://dummyimage.com/16x16/fff/aaa');
background-position: center center;
background-repeat: no-repeat;
}
.page-btn-icon:hover {
background-image: url('https://dummyimage.com/16x16/aaa/fff');
}
<button class="page-btn-icon">
</button>
I want to put 2 divs next to each other centered, like described here. The problem is that it seems that my right div is always a bit under the left one when I put a <span> and a heading into the right div. Why does this happen and how can I avoid this?
#right {
display: inline-block;
width: 100px;
height: 160px;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
#wrapper {
text-align: center;
padding: 40px;
height: 160px;
max-height: 160px;
}
#left {
display: inline-block;
width: 100px;
height: 160px;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
<div align="center" id="wrapper">
<div id="left"></div>
<div id="right">
<span style="text-decoration: underline;">Heading</span>
<div id="some-content"></div>
</div>
</div>
Use vertical-align:top; on the #right and #left divs to get the wanted result
#right {
display: inline-block;
width: 100px;
height: 160px;
vertical-align:top;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
#wrapper {
text-align: center;
padding: 40px;
height: 160px;
max-height: 160px;
}
#left {
display: inline-block;
vertical-align:top;
width: 100px;
height: 160px;
padding: 15px;
background: rgba(0, 0, 0, .4);
border-radius: 1px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
<div align="center" id="wrapper">
<div id="left"></div>
<div id="right">
<span style="text-decoration: underline;">Heading</span>
<div id="some-content"></div>
</div>
</div>
inline-blockelements are aligned according to the baseline of the included text. If there is no text, the bottom border will act as the baseline. In you example, the bottom border of the left DIV is aligned with the baseline of the text in the right div. If you erase the text (independently from the span tag), they are aligned. If there is text in both boxes, they will be aligned by their lowest text lines (see here: http://codepen.io/anon/pen/YqpJRg)
To align both boxes, use display: block and float: lefton the two DIVs, and for the wrapper position: relative; and margin:auto PLUS a fixed width (the sum of both DIV widths) to center it.
Here's a codepen of the result: http://codepen.io/anon/pen/mPOzaZ
i've been trying all night to center this elements without having them stacked on each other:
I've tried floating them to the left it works, but, they stick to the left side no matter what i did.
HTML:
<div class="center pages clearfix">
<buuton class="center page-number">1</buuton>
<buuton class="center page-number">2</buuton>
<buuton class="center page-number">3</buuton>
</div>
CSS:
.center {
margin-left: auto;
margin-right: auto;
}
.page-number {
display: block;
float: none;
width: 28px;
height: auto;
border-radius: 3px;
background-color: rgba(0, 0, 0, 0.47);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.34);
text-shadow: 0 2px 5px rgba(0, 0, 0, .5);
font-weight: 400;
line-height: 1.5;
text-align: center;
color: rgba(255, 255, 255, 0.47);
}
just update "display:block" to "display:inline-block" like the below updated css
updated css
.center {
margin-left: auto;
margin-right: auto;
text-align:center;
}
.page-number {
display: inline-block;
float: none;
width: 28px;
height: auto;
border-radius: 3px;
background-color: rgba(0, 0, 0, 0.47);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.34);
text-shadow: 0 2px 5px rgba(0, 0, 0, .5);
font-weight: 400;
line-height: 1.5;
text-align: center;
color: rgba(255, 255, 255, 0.47);
}
demo
Try this: https://jsfiddle.net/uo23L4n4/
use inline-block instead of block for the buttons.
use text-align:center
<button class=" page-number">1</button>
.center {
margin-left: auto;
margin-right: auto;
text-align: center;
}
.page-number {
display: inline-block;
float: none;
width: 28px;
height: auto;
border-radius: 3px;
background-color: rgba(0, 0, 0, 0.47);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.34);
text-shadow: 0 2px 5px rgba(0, 0, 0, .5);
font-weight: 400;
line-height: 1.5;
text-align: center;
color: rgba(255, 255, 255, 0.47);
}
Change your mark up to a list, makes it very easy to do this.
<ul class="center pages clearfix">
<li><buuton class="center page-number">1</buuton></li>
<li><buuton class="center page-number">2</buuton></li>
<li><buuton class="center page-number">3</buuton></li>
</ul>
Use this css
ul{
list-style:none;
}
li{
display:inline-block;
}
I made a horizontal progress bar that does not have a problem with it
But the progress bar's vertical lines are not correct.
I put a picture of the problem.
jsfiddle.net/post98/juGXZ/1/
HTML
<body>
<div class="progress-bar horizontale">
<div class="inner"><span>|||||||</span></div>
</div>
<div class="progress-bar verticale">
<div class="inner"><span>___ ___ ___ ___ ___</span></div>
</div>
</body>
CSS
body {
background: url('https://www.dropbox.com/s/8g7pf7ig7fw5e0v/main_bg.png') repeat;
}
.progress-bar.verticale {
width: 24px;
height: 300px;
/*border: 1px solid #060707;*/
margin: 10px auto;
background-color: rgba(0, 0, 0, 0.25);
box-shadow: 0 0 3px #000000 inset, 0 0 2px rgba(255,255,255,0.1);
border-radius: 10px;
padding: 4px;
transform: rotate(180deg);
display: inline-block;
}
.progress-bar.horizontale {
width: 300px;
height: 24px;
/*border: 1px solid #060707;*/
margin: auto;
background-color: rgba(0, 0, 0, 0.25);
box-shadow: 0 0 3px #000000 inset, 0 0 2px rgba(255,255,255,0.1);
border-radius: 10px;
padding: 4px;
display: inline-block;
}
.progress-bar.horizontale .inner {
background: linear-gradient(#FFCC33, #CC9900);
border-radius: 12px;
position: absolute;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 -1px 3px rgba(0, 0, 0, 0.4) inset, 0 1px 1px #000000;
height: 24px;
width: 200px;
}
.progress-bar.horizontale .inner span {
background: repeat scroll 0 0 #999999;
position: absolute;
font: bold 120px/40px sans-serif ;
letter-spacing: -6px;
height: 24px;
opacity: 0.06;
overflow: hidden;
transform: skewX(-30deg);
}
.progress-bar.verticale .inner {
background: linear-gradient(#FFCC33, #CC9900);
border-radius: 12px;
position: absolute;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 -1px 3px rgba(0, 0, 0, 0.4) inset, 0 1px 1px #000000;
height: 200px;
width: 24px;
}
.progress-bar.verticale .inner span {
background: repeat scroll 0 0 #999999;
position: absolute;
font: bold 20px/30px sans-serif ;
letter-spacing: -6px;
height: 200px;
width: 20px;
opacity: 0.06;
overflow: hidden;
transform: skewY(30deg);
}
Here the Picture
You can make the lines thick by replacing the underscores _ by a thick character like this one: ▀
A demo.
Edit:
ASCII code of the character: 223 (Top half block).
You can thicken the lines like this:
.progress-bar.verticale .inner span {
background: repeat scroll 0 0 #999999;
position: absolute;
font: bold 120px/30px sans-serif ; //thicken lines to same width as horizontal progress bar.
letter-spacing: -6px;
height: 200px;
width: 25px; //change width to fit width of div.
opacity: 0.06;
overflow: hidden;
transform: skewY(30deg);
margin:0px 0px 0px 0px;
bottom: 35px; //Position revision to justify font resizing.
}