Text wont align on horizontal and vertical centers - css

I am trying to work on the following example for a user profile.
I have a problem with the text on my various fields though. I would like them to be centered horizontally and vertically.
Using
vertical-align: middle;
Did not work for me, or I did something wrong.
How can I make it so each text snippet is perfectly centered on its respective container?

Here's the solution:
/* --------------------------------
Primary style
-------------------------------- */
#font-face {
font-family: 'Roboto';
src: url('../fonts/roboto/Roboto-Regular.ttf');
font-weight: normal;
font-style: normal;
}
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
div {
display: block;
}
html,
body {
background: #f1f1f1;
font-family: 'Roboto', sans-serif;
padding: 1em;
}
h1 {
text-align: center;
color: #a8a8a8;
font-size: 200%;
}
.user-data {
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
position: relative;
overflow: hidden;
cursor: pointer;
display: table;
width: 100%;
height: 85px;
background: white;
margin: 0 auto;
margin-top: 1em;
margin-bottom: 20px;
border-radius: 8px;
-webkit-transition: all 250ms;
transition: all 250ms;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.response-layer {
vertical-align: middle;
display: table-cell;
text-align: center;
font-size: 200%;
color: #a8a8a8;
}
#user-action-text {
color: #f1f1f1;
font-size: 400%;
}
#user-name {
border: 0;
outline: 0;
padding: 0;
margin: 0px;
margin-top: 10px;
width: 304px;
height: 55px;
color: white;
}
#user-action {
background: #e74c3c;
height: 134px;
}
#user-position {
height: 74px;
}
#user-uuid {
height: 54px;
}
section {
max-width: 650px;
text-align: center;
margin: 20px auto;
}
section img {
border: 0;
outline: 0;
padding: 0;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
display: block;
width: 100%;
margin-top: 1em;
-webkit-transition: all 250ms;
transition: all 250ms;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
resize: none;
}
.half {
float: left;
width: 48%;
margin-bottom: 1em;
}
.right {
width: 50%;
}
.left {
margin-right: 2%;
}
.user-data:hover {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
section img:hover {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
#-webkit-keyframes loading {
0%, 100% {
margin-top: -50px;
box-shadow: 0px 55px 40px 0px rgba(0, 0, 0, 0.3);
}
30%,
80% {
margin-top: 0px;
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.5);
}
}
#keyframes loading {
0%, 100% {
margin-top: -50px;
box-shadow: 0px 55px 40px 0px rgba(0, 0, 0, 0.3);
}
30%,
80% {
margin-top: 0px;
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.5);
}
}
#media (max-width: 690px) {
.half {
width: 304px;
float: none;
margin-bottom: 0;
}
}
/* Clearfix */
.activity-detail:before,
.activity-detail:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}
.activity-detail:after {
clear: both;
}
<h1>New Activity Details</h1>
<section class="activity-detail">
<div class="half right" id="image-data">
<img src="img/default-avatar.png" alt="Profile Photo" style="width:304px;height:304px;" id="profile-photo">
<a class="user-data" id="user-name">
<div class="response-layer">Green Leaf</div>
</a>
</div>
<div class="half left" id="general-data">
<a class="user-data" id="user-action">
<div class="response-layer" id="user-action-text">Greetings</div>
</a>
<a class="user-data" id="user-position">
<div class="response-layer">Developer</div>
</a>
<a class="user-data" id="user-uuid">
<div class="response-layer">324124535345</div>
</a>
</div>
</section>
On the parent div .user-data I changed display to table.
On the child div .response-layer (the one containing "Greetings") I changed the display to table-cell. Now the vertical align works.
Here's the link to the codepen: Codepen

Replacing
vertical-align: middle;
with
position: relative;
top: 25%;
does the trick.
Edit: The answer above is much cleaner

Related

CSS transition - invert the origin/direction

I'd like to make my label animation from top to bottom instead of from bottom to top. So the top is going to open and the bottom stay there:
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
vertical-align: middle;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
float: left;
transition: width 1.5s, height 1.5s;
transition-duration: 1.5s
}
div.label4:hover {
height: 194px;
}
<div class="label4"></div>
Just wrap it in a parent with flex-direction: column-reverse and you're done:
.parent {
display: flex;
flex-direction: column-reverse;
height: 388px;
width: 278px;
}
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
vertical-align: middle;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
float: left;
transition: width 1.5s, height 1.5s;
transition-duration: 1.5s
}
div.label4:hover {
height: 194px;
}
.parent {
display: flex;
flex-direction: column-reverse;
height: 388px;
width: 278px;
}
<div class="parent">
<div class="label4"></div>
</div>
If you can alter the HTML you could create a container, and then position .label4 using position: absolute and bottom
.parent {
height: 388px;
padding-top: 10px;
position: relative;
}
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
vertical-align: middle;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
float: left;
transition: width 1.5s, height 1.5s;
transition-duration: 1.5s;
position: absolute;
bottom: 0;
}
div.label4:hover {
height: 194px;
}
<div class="parent">
<div class="label4"></div>
</div>
You can achieve your desire animation by transform which is more flexible and better and set transform-origin to each side your element,
div.label4 {
background-color: #4D6EF6;
width: 278px;
height: 388px;
margin: 10px auto;
text-align: center;
color: #4D6EF6;
font-size: 30px;
font-weight: bold;
border-radius: 4px;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-decoration: none;
border: transparent;
transition: transform 1.5s;
transform: scaleY(1);
transform-origin: bottom center;
}
div.label4:hover {
transform: scaleY(0.5);
}
<div class="label4"></div>

Click the circle after hovernig to direct to a url

https://jsfiddle.net/qd2o38fp/1/
I want the user to be able to hover over the circle, and then click the circle itself to be directed to another link. (not the text when hovered)
.ch-item {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
position: relative;
cursor: default;
box-shadow:
inset 0 0 0 16px rgba(255,255,255,0.6),
0 1px 2px rgba(0,0,0,0.1);
transition: all 0.4s ease-in-out;
content: url(www.yahoo.com);
}
I tried to put
content: url(www.yahoo.com);
but this makes the text disappear for some reason.
If you want to be able to click it, it must be a link:
<a href="//www.yahoo.com" class="ch-info">
<h3>See Portfolio</h3>
</a>
Just display it as a block, and your current code will work:
.ch-info {
display: block;
}
.ch-grid {
margin: 20px 0 0 0;
padding: 0;
list-style: none;
display: block;
text-align: center;
width: 100%;
}
.ch-grid::after {
clear: both;
}
.ch-grid li {
width: 220px;
height: 220px;
display: inline-block;
margin: 20px;
}
.ch-item {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
position: relative;
cursor: default;
box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.1);
transition: all 0.4s ease-in-out;
}
.ch-img-1 {
background-image: url(http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg);
}
.ch-img-2 {
background-image: url(../images/2.jpg);
}
.ch-img-3 {
background-image: url(../images/3.jpg);
}
.ch-info {
position: absolute;
background: rgba(63, 147, 147, 0.8);
width: inherit;
height: inherit;
border-radius: 50%;
overflow: hidden;
opacity: 0;
transition: all 0.4s ease-in-out;
transform: scale(0);
display: block;
}
.ch-info h3 {
color: #fff;
text-transform: uppercase;
letter-spacing: 2px;
font-size: 22px;
margin: 0 30px;
padding: 45px 0 0 0;
height: 140px;
font-family: 'Open Sans', Arial, sans-serif;
text-shadow: 0 0 1px #fff, 0 1px 2px rgba(0, 0, 0, 0.3);
}
.ch-info p {
color: #fff;
padding: 10px 5px;
font-style: italic;
margin: 0 30px;
font-size: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.5);
opacity: 0;
transition: all 1s ease-in-out 0.4s;
}
.ch-info p a {
display: block;
color: rgba(255, 255, 255, 0.7);
font-style: normal;
font-weight: 700;
text-transform: uppercase;
font-size: 9px;
letter-spacing: 1px;
padding-top: 4px;
font-family: 'Open Sans', Arial, sans-serif;
}
.ch-info p a:hover {
color: rgba(255, 242, 34, 0.8);
}
.ch-item:hover {
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 1px 2px rgba(0, 0, 0, 0.1);
}
.ch-item:hover .ch-info {
transform: scale(1);
opacity: 1;
}
.ch-item:hover .ch-info p {
opacity: 1;
}
.ch-item::before {
content: "P";
position: absolute;
font-size: 180px;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
<ul class="ch-grid">
<li>
<div class="ch-item ch-img-1">
<a href="//www.yahoo.com" class="ch-info">
<h3>See Portfolio</h3>
</a>
</div>
</li>
</ul>
extending Oriol's you could also use clip-path: circle(110px at center);
to limit :hover selection
.ch-grid {
margin: 20px 0 0 0;
padding: 0;
list-style: none;
display: block;
text-align: center;
width: 100%;
}
.ch-grid::after {
clear: both;
}
.ch-grid li {
width: 220px;
height: 220px;
display: inline-block;
margin: 20px;
}
.ch-item {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
position: relative;
cursor: default;
box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.1);
transition: all 0.4s ease-in-out;
}
.ch-img-1 {
background-image: url(http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg);
}
.ch-img-2 {
background-image: url(../images/2.jpg);
}
.ch-img-3 {
background-image: url(../images/3.jpg);
}
.ch-info {
position: absolute;
background: rgba(63, 147, 147, 0.8);
width: inherit;
height: inherit;
border-radius: 50%;
overflow: hidden;
opacity: 0;
transition: all 0.4s ease-in-out;
transform: scale(0);
display: block;
}
.ch-info h3 {
color: #fff;
text-transform: uppercase;
letter-spacing: 2px;
font-size: 22px;
margin: 0 30px;
padding: 45px 0 0 0;
height: 140px;
font-family: 'Open Sans', Arial, sans-serif;
text-shadow: 0 0 1px #fff, 0 1px 2px rgba(0, 0, 0, 0.3);
}
.ch-info p {
color: #fff;
padding: 10px 5px;
font-style: italic;
margin: 0 30px;
font-size: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.5);
opacity: 0;
transition: all 1s ease-in-out 0.4s;
}
.ch-info p a {
display: block;
color: rgba(255, 255, 255, 0.7);
font-style: normal;
font-weight: 700;
text-transform: uppercase;
font-size: 9px;
letter-spacing: 1px;
padding-top: 4px;
font-family: 'Open Sans', Arial, sans-serif;
clip-path: circle(110px at center);
}
.ch-info p a:hover {
color: rgba(255, 242, 34, 0.8);
clip-path: circle(110px at center);
}
.ch-item:hover {
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 1px 2px rgba(0, 0, 0, 0.1);
clip-path: circle(110px at center);
}
.ch-item:hover .ch-info {
transform: scale(1);
opacity: 1;
}
.ch-item:hover .ch-info p {
opacity: 1;
}
.ch-item::before {
content: "P";
position: absolute;
font-size: 180px;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
<ul class="ch-grid">
<li>
<div class="ch-item ch-img-1">
<a href="//www.yahoo.com" class="ch-info">
<h3>See Portfolio</h3>
</a>
</div>
</li>
</ul>

How center two elements vertically in a navbar with different heights?

I am trying to center my logo and a button in a navbar but without success, i already try use vertical-align, position absolute, padding in both, display table, table cell, etc... but anything works!
I can't use CSS3 unfortunately :[.
https://jsfiddle.net/cn23acef/1/embedded/result/
HTML:
<header class="header">
<div class="container">
<div class="header__logo">
<img src="https://pc-celicoo1.c9.io/little-stuffs/client/public/images/main/logos/pubcrawl2.png" height="25" />
</div>
<div class="header__cta">
<a href="#" class="cta">
Reserve <span class="wide__up">seu ingresso</span>
</a>
</div>
</div>
</header>
CSS:
.container {
padding-left: 2%;
padding-right: 2%;
margin-left: auto;
margin-right: auto;
height: 100%;
}
#media only screen and (min-width: 620px) {
.container {
padding-left: 1.8%;
padding-right: 1.8%;
max-width: 688px;
}
}
#media only screen and (min-width: 800px) {
.container {
padding-left: 1.4%;
padding-right: 1.4%;
max-width: 1180px;
}
}
body {
background: black;
margin: 0 auto;
}
.header {
background: #fff;
position: fixed;
z-index: 99999;
width: 100%;
/* -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
/* -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
/* box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
}
.header__logo {
float: left;
}
.header__cta {
float: right;
}
.cta {
display: block;
background: #52C0C2;
color: #fff;
font-family: Oswald, Helvetica, sans-serif;
font-weight: 400;
padding: .735rem 1.25rem;
border-radius: 3px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
}
.cta [class^=i-],
.cta--big [class^=i-] {
margin-right: 1rem;
}
See this code
.container {
padding-left: 2%;
padding-right: 2%;
margin-left: auto;
margin-right: auto;
height: 100%;
}
#media only screen and (min-width: 620px) {
.container {
padding-left: 1.8%;
padding-right: 1.8%;
max-width: 688px;
}
}
#media only screen and (min-width: 800px) {
.container {
padding-left: 1.4%;
padding-right: 1.4%;
max-width: 1180px;
}
}
body {
background: black;
margin: 0 auto;
}
.header {
background: #fff;
position: fixed;
z-index: 99999;
width: 100%;
/* -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
/* -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
/* box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
}
.header__logo {
float: left;
}
.header__cta {
float: right;
}
.cta {
display: block;
background: #52C0C2;
color: #fff;
font-family: Oswald, Helvetica, sans-serif;
font-weight: 400;
padding: .735rem 1.25rem;
border-radius: 3px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
}
.cta [class^=i-],
.cta--big [class^=i-] {
margin-right: 1rem;
}
#media (max-width: 767px){
.header__logo {
float: none;
text-align: center;
}
.header__cta {
float: none;
text-align: center;
}
.header__cta a{
display: inline-block;
}
}
<header class="header">
<div class="container">
<div class="header__logo">
<img src="https://pc-celicoo1.c9.io/little-stuffs/client/public/images/main/logos/pubcrawl2.png" height="25" />
</div>
<div class="header__cta">
<a href="#" class="cta">
Reserve <span class="wide__up">seu ingresso</span>
</a>
</div>
</div>
</header>
.container {
padding-left: 2%;
padding-right: 2%;
margin-left: auto;
margin-right: auto;
height: 100%;
}
#media only screen and (min-width: 620px) {
.container {
padding-left: 1.8%;
padding-right: 1.8%;
max-width: 688px;
}
}
#media only screen and (min-width: 800px) {
.container {
padding-left: 1.4%;
padding-right: 1.4%;
max-width: 1180px;
}
}
body {
background: black;
margin: 0 auto;
}
.header {
background: #fff;
position: fixed;
z-index: 99999;
width: 100%;
/* -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
/* -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
/* box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); */
}
.header__logo {
float: left;
text-align:right;
width:50%;
}
.header__cta {
float: left;
}
.cta {
display: block;
background: #52C0C2;
color: #fff;
font-family: Oswald, Helvetica, sans-serif;
font-weight: 400;
padding: .735rem 1.25rem;
border-radius: 3px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
}
.cta [class^=i-],
.cta--big [class^=i-] {
margin-right: 1rem;
}
#media (max-width: 767px) {
.header__cta a {
display: inline-block;
}
}
<header class="header">
<div class="container">
<div class="header__logo">
<a href="">
<img src="https://pc-celicoo1.c9.io/little-stuffs/client/public/images/main/logos/pubcrawl2.png" height="25" />
</a>
</div>
<div class="header__cta">
<a href="#" class="cta">
Reserve <span class="wide__up">seu ingresso</span>
</a>
</div>
</div>
</header>
If I am understanding you correctly. When you say center my logo you mean vertically correct?
Like this?
In order to do this all you need to do is paste this code in place of your current img tag.
<img style="margin: 7px 0px 0px;" src="https://pc-celicoo1.c9.io/little-stuffs/client/public/images/main/logos/pubcrawl2.png" height="25">
To vertically adjust all you have to do is play with the margin 7px.
If this does not solve the issue please be more specific and if it is what you were looking for please accept it as the correct answer.
Hope This Helps!

Button changes shape after reload

First of all, I'm running Meteor with neo64:Bootstrap and a custom theme.
I've got a button which shows like this after I make an arbitrary change in my css and it hotpushes the new code:
Then after a page reload the button looks like this:
Both times chrome shows this as the computed values:
-webkit-box-shadow: rgba(0, 0, 0, 0.227451) 0px 6px 10px 0px, rgba(0, 0, 0, 0.188235) 0px 10px 30px 0px;
-webkit-font-smoothing: antialiased;
-webkit-transform: matrix(1, 0, 0, 1, 0, 0);
background-color: rgb(255, 152, 0);
border-bottom-left-radius: 100%;
border-bottom-right-radius: 100%;
border-top-left-radius: 100%;
border-top-right-radius: 100%;
bottom: -28px;
box-shadow: rgba(0, 0, 0, 0.227451) 0px 6px 10px 0px, rgba(0, 0, 0, 0.188235) 0px 10px 30px 0px;
box-sizing: border-box;
color: rgb(255, 255, 255);
cursor: pointer;
display: inline-block;
font-family: FontAwesome;
font-size: 32px;
font-stretch: normal;
font-style: normal;
font-variant: normal;
font-weight: normal;
height: 56px;
line-height: 32px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
padding-top: 15px;
position: relative;
text-align: center;
text-rendering: auto;
transform: matrix(1, 0, 0, 1, 0, 0);
width: 41.140625px;
This is the code that makes up the button:
// BUTTONS
.fab {
margin: 0;
padding: 15px;
width: 56px;
height: 56px;
border-radius: 100%;
cursor: pointer;
transform: none;
& {
.shadow-z-3();
}
&:hover {
.shadow-z-4();
background-color: lighten(#brand-primary, 40%);
}
&:active {
.shadow-z-5();
}
&.fab-mini {
width: 40px;
height: 40px;
padding: 13px;
font-size: 15px;
}
&.fab-bottom {
position: relative;
bottom: -28px;
}
&.inverse {
background-color: #brand-primary;
color: #white;
&:hover {
background-color: lighten(#brand-primary, 10%);
}
}
i {
position: relative;
top: -5px;
}
}
The plus is a Font Awesome fa-plus.
These are the classes for my button (in Jade):
i.fa.fa-fw.fa-2x.fa-plus.fab.inverse.fab-bottom(data-toggle="modal"
data-target="#createModal" data-backdrop="static" data-keyboard="false")
Added the Jade of the page:
.row
.col-sm-6
.panel.panel-default
.panel-heading
h2.panel-title {{_ "dataA"}}
.list-group
.list-group-item
+each availableShifts
+availableShiftCard
.col-sm-6
.panel.panel-default
.panel-heading
h2.panel-title {{_ "dataB"}}
.list-group
.list-group-item
+each ownShifts
+ownShiftCard
.text-center
i.fa.fa-fw.fa-2x.fa-plus.fab.inverse.fab-bottom(data-toggle="modal"
data-target="#createModal" data-backdrop="static" data-keyboard="false")
What am I doing wrong?

checkbox use label without id (label css can change)

<style>
input[type=checkbox]{display:none}
label{color: black;}
input[type=checkbox]:checked + label{color:red;}
</style>
<label><input type="checkbox">Click</label>
I have a checkbox use label to click, when check box clicked, the label should change the color. What I try to achieve is do it without for="id". I place input inside of label, but the color wont change.
Is any way to do this without id?
It's a bit of a hack but you can use something like this:
With input outside label..
<input type="checkbox"><label>Click</label>
input[type=checkbox] {
display: inline-block;
width: 100%;
position: relative;
z-index: 1;
opacity: 0;
}
label {
position: absolute;
top: 8px;
color: black;
}
input[type=checkbox]:checked + label {
color: red;
}
An example: http://jsfiddle.net/96v7C/
If anyone stumbles over this old question I'd like to pick up Vangel Tzo's answer and optimize it a bit. I would recommend to switch position:absolute; and position:relative; for the label and input fields to allow longer text to wrap properly without overlapping any content below it:
.hidden-checkboxes {
font: 14px 'Open Sans', sans-serif;
}
.hidden-checkboxes input[type=checkbox] {
position: absolute;
left: 0;
top: 0;
display: inline-block;
width: 100%;
z-index: 1;
opacity: 0;
height: 30px;
}
.hidden-checkboxes label {
position: relative;
left: 0;
top: 0;
padding: 5px;
display: inline-block;
width: 100%;
}
.hidden-checkboxes input[type=checkbox]:checked + label {
background: #3298dc;
color: white;
}
.hidden-checkboxes div {
position: relative;
margin-bottom: 1px;
}
<div class="hidden-checkboxes" style="width:300px;">
<div>
<input type="checkbox"><label>Check me please.</label>
</div>
<div>
<input type="checkbox"><label>Or how about me?</label>
</div>
<div>
<input type="checkbox"><label>How about some long text that will cause wrapping of text?</label>
</div>
</div>
Remark: Font and margin-bottom are only used for styling the demo.
Here is a compleat radio butons and checkbox example.
jsFiddle
/*style for iinpul checkbox*/
input[type=radio], input[type=checkbox] {
display:none;
}
input[type=radio] + label, input[type=checkbox] + label {
display:inline-block;
line-height: 20px;
color: #333;
text-align: center;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
vertical-align: middle;
cursor: pointer;
background: -moz-linear-gradient(center top, #FFFFFF 20%, #F6F6F6 50%, #EEEEEE 52%, #F4F4F4 100%) repeat scroll 0 0 padding-box rgba(0, 0, 0, 0);
border: 1px solid #AAAAAA;
border-radius: 5px;
box-shadow: 0 0 3px #FFFFFF inset, 0 1px 1px rgba(0, 0, 0, 0.1);
color: #444444;
display: block;
height: 34px;
line-height: 34px;
overflow: hidden;
position: relative;
text-decoration: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 13px;
}
input[type=radio]:checked + label, input[type=checkbox]:checked + label {
background-image: none;
outline: 0;
-webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
-moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
background-color:#e0e0e0;
}
.c-custom-checkbox {
padding-left: 20px;
position: relative;
cursor: pointer;
}
.c-custom-checkbox input[type=checkbox] {
position: absolute;
opacity: 0;
overflow: hidden;
clip: rect(0 0 0 0);
height: 15px;
width: 15px;
padding: 0;
border: 0;
left: 0;
}
.c-custom-checkbox .c-custom-checkbox__img {
display: inline;
position: absolute;
left: 0;
width: 15px;
height: 15px;
background-image: none;
background-color: #fff;
color: #000;
border: 1px solid #333;
border-radius: 3px;
cursor: pointer;
}
.c-custom-checkbox input[type=checkbox]:checked + .c-custom-checkbox__img {
background-position: 0 0;
background-color: tomato;
}
<label class="c-custom-checkbox">
<input type="checkbox" id="valueCheck" />
<i class="c-custom-checkbox__img"></i>Some Label
</label>

Resources