I'm creating a pixel grid to represent a count (see image) and wondering what's the best way to go about it.
These tiles will need to be responsive (1px, 2px, 4px). I could build a super large sprite that contains all 196 combinations that is #4X so it scales perfectly to 2px and 1px and then build a css class...
<div class="pixel-block c-000"></div>
<div class="pixel-block c-001"></div>
...there has to be a better way?
Any ideas appreciated.
Here is a example of how it can be done without using a sprite with the 196 combinations, just a grid image and CSS.
The idea is simple:
Have a container that will hold:
The grid image (on top)
A "big" bar that will cover the whole height of the container.
A "small" bar that will cover only the remainder.
The "big bar" will have a width equal to the (count value / 14) * width of the hole in the grid.
The "low bar" will have a height equal to (count value % 14) * height of the hole in the grid.
I used a grid with 3px holes (2px + 1px separation), and the data- attributes to set the values of the count, and an indicator for the big bar (count / 14) and low bar (count % 14).
Here is a demo:
.box {
border:1px solid #6699aa;
width:43px;
height:43px;
position:relative;
background:#aaccff;
overflow:hidden;
display:inline-block;
}
.grid { background:url(http://i.imgur.com/w0jBLzK.png) no-repeat top left;
width:43px;
height:43px;
position:absolute;
top:0;
left:0;
z-index:3;
}
.bigbar {
height:43px;
width:0px;
background:black;
z-index:2;
float:left;
}
.lowbar {
float:left;
width:3px;
height:0px;
position:relative;
background:black;
}
.box[data-big="1"] .bigbar { width:3px; }
.box[data-big="2"] .bigbar { width:6px; }
.box[data-big="3"] .bigbar { width:9px; }
.box[data-big="4"] .bigbar { width:12px; }
.box[data-big="5"] .bigbar { width:15px; }
.box[data-big="6"] .bigbar { width:18px; }
.box[data-big="7"] .bigbar { width:21px; }
.box[data-big="8"] .bigbar { width:24px; }
.box[data-big="9"] .bigbar { width:27px; }
.box[data-big="10"] .bigbar { width:30px; }
.box[data-big="11"] .bigbar { width:33px; }
.box[data-big="12"] .bigbar { width:36px; }
.box[data-big="13"] .bigbar { width:39px; }
.box[data-big="14"] .bigbar { width:42px; }
.box[data-low="1"] .lowbar { height:3px; margin-top:39px; }
.box[data-low="2"] .lowbar { height:6px; margin-top:36px; }
.box[data-low="3"] .lowbar { height:9px; margin-top:33px; }
.box[data-low="4"] .lowbar { height:12px; margin-top:30px; }
.box[data-low="5"] .lowbar { height:15px; margin-top:27px; }
.box[data-low="6"] .lowbar { height:18px; margin-top:24px; }
.box[data-low="7"] .lowbar { height:21px; margin-top:21px; }
.box[data-low="8"] .lowbar { height:24px; margin-top:18px; }
.box[data-low="9"] .lowbar { height:27px; margin-top:15px; }
.box[data-low="10"] .lowbar { height:30px; margin-top:12px; }
.box[data-low="11"] .lowbar { height:33px; margin-top:9px; }
.box[data-low="12"] .lowbar { height:36px; margin-top:6px; }
.box[data-low="13"] .lowbar { height:39px; margin-top:3px; }
.box[data-low="14"] .lowbar { height:42px; margin-top:0px; }
<div class="box" data-count="0" data-big="0" data-low="0">
<div class="grid"></div>
<div class="bigbar"></div>
<div class="lowbar"></div>
</div>
<div class="box" data-count="5" data-big="0" data-low="5">
<div class="grid"></div>
<div class="bigbar"></div>
<div class="lowbar"></div>
</div>
<div class="box" data-count="34" data-big="2" data-low="10">
<div class="grid"></div>
<div class="bigbar"></div>
<div class="lowbar"></div>
</div>
<div class="box" data-count="196" data-big="14" data-low="0">
<div class="grid"></div>
<div class="bigbar"></div>
<div class="lowbar"></div>
</div>
Related
I am trying to create the 'Google Now' microphone icon using pure CSS3.
The icon features a white microphone on a red circular background.
I tried font-awesome but in vain
I need your help to complete this task
No animations or functionality, just the icon
Google Now Icon Only with CSS
DEMO
output :
HTML :
<div class="gn"><div class="mc"></div></div>
CSS :
body{font-size: 15px;}
.gn{
position:relative;
margin: 5% auto;
background-color:#FE2222;
border-radius:50%;
width:10em; height:10em;
}
:before, :after{
content:'';
position:absolute;
background-color:#fff;
}
.gn:after{
top:30%; left:43%;
height:15%; width:14%;
border-top-left-radius:50%;
border-top-right-radius:50%;
}
.gn:before{
top:40%; left:43%;
height:15%; width:14%;
border-bottom-left-radius:50%;
border-bottom-right-radius:50%;
}
.mc{
position:absolute;
top:50%; left:37%;
height:24%;
width:26.5%;
overflow:hidden;
}
.mc:before{
bottom:50%;
width:100%; height:100%;
box-sizing:border-box;
border-radius:50%;
border:0.5em solid #fff;
background:none;
}
.mc:after{
top:50%; left:40%;
width:20%; height:25%;
}
Demo
html
<div class=container><i class=icon-microphone></i></div>
css
#import url(http://thecodeplayer.com/uploads/fonts/fontawesome/css/font-awesome.min.css);
* {
margin:0;
padding:0;
}
.container {
width:150px;
background-color:#e74c3c;
display:block;
margin:100px auto 0px auto;
border-radius:100%;
box-shadow:0px 0px 15px 2px #bdc3c7;
cursor:pointer;
transition:.3s all ease-in;
position:relative;
}
.icon-microphone {
color:white;
font-size:60px;
line-height:150px;
display:block;
text-align:center;
transition:.1s all ease-in;
}
.container:hover {
background-color:#27ae60;
}
.container:active {
background-color:#e74c3c;
}
.container:active .icon-microphone {
color:#ecf0f1;
}
I'm using a css3 spinner from http://cssload.net/ I want to know how the scale it up or down using px em or % by changing the height and width on #floatingBarsG. If I set the size 10px higher and 10px wider the icon goes out of shape. Any suggestions ?
Here is a working js fiddle example http://jsfiddle.net/PWLzb/8/
This is the html
<div id="floatingBarsG" style="">
<div id="rotateG_01" class="blockG"></div>
<div id="rotateG_02" class="blockG"></div>
<div id="rotateG_03" class="blockG"></div>
<div id="rotateG_04" class="blockG"></div>
<div id="rotateG_05" class="blockG"></div>
<div id="rotateG_06" class="blockG"></div>
<div id="rotateG_07" class="blockG"></div>
<div id="rotateG_08" class="blockG"></div>
</div>
and css
#floatingBarsG {
position:relative;
width:62px;
height:77px
}
.blockG {
position:absolute;
background-color:#FFFFFF;
width:10px;
height:24px;
-webkit-border-radius:8px 8px 0 0;
-webkit-transform:scale(0.4);
-webkit-animation-name:fadeG;
-webkit-animation-duration:0.5599999999999999s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:linear;
border-radius:8px 8px 0 0;
transform:scale(0.4);
animation-name:fadeG;
animation-duration:0.5599999999999999s;
animation-iteration-count:infinite;
animation-direction:linear;
}
#rotateG_01 {
left:0;
top:28px;
-webkit-animation-delay:0.20999999999999996s;
-webkit-transform:rotate(-90deg);
animation-delay:0.20999999999999996s;
transform:rotate(-90deg);
}
#rotateG_02 {
left:8px;
top:10px;
-webkit-animation-delay:0.27999999999999997s;
-webkit-transform:rotate(-45deg);
animation-delay:0.27999999999999997s;
transform:rotate(-45deg);
}
#rotateG_03 {
left:26px;
top:3px;
-webkit-animation-delay:0.35s;
-webkit-transform:rotate(0deg);
animation-delay:0.35s;
transform:rotate(0deg);
}
#rotateG_04 {
right:8px;
top:10px;
-webkit-animation-delay:0.41999999999999993s;
-webkit-transform:rotate(45deg);
animation-delay:0.41999999999999993s;
transform:rotate(45deg);
}
#rotateG_05 {
right:0;
top:28px;
-webkit-animation-delay:0.48999999999999994s;
-webkit-transform:rotate(90deg);
animation-delay:0.48999999999999994s;
transform:rotate(90deg);
}
#rotateG_06 {
right:8px;
bottom:7px;
-webkit-animation-delay:0.5599999999999999s;
-webkit-transform:rotate(135deg);
animation-delay:0.5599999999999999s;
transform:rotate(135deg);
}
#rotateG_07 {
bottom:0;
left:26px;
-webkit-animation-delay:0.63s;
-webkit-transform:rotate(180deg);
animation-delay:0.63s;
transform:rotate(180deg);
}
#rotateG_08 {
left:8px;
bottom:7px;
-webkit-animation-delay:0.7s;
-webkit-transform:rotate(-135deg);
animation-delay:0.7s;
transform:rotate(-135deg);
}
#-webkit-keyframes fadeG {
0% {
background-color:#000000
}
100% {
background-color:#FFFFFF
}
}
#keyframes fadeG {
0% {
background-color:#000000
}
100% {
background-color:#FFFFFF
}
}
This can be done very easily via CSS scale transforms:
#floatingBarsG {
-webkit-transform:scale(2);
-webkit-transform-origin:top left;
-moz-transform:scale(2);
-moz-transform-origin:top left;
-ms-transform:scale(2);
-ms-transform-origin:top left;
-o-transform:scale(2);
-o-transform-origin:top left;
transform:scale(2);
transform-origin:top left;
}
Demo.
Edit from 8 years after posting this answer: Nowadays, all of these prefixes are no longer necessary, so simply using the following would suffice:
#floatingBarsG {
transform:scale(2);
transform-origin:top left;
}
I have 2 buttons and the width is 50% each. (Fluid buttons)
If I want to make a 10px of space between the buttons (Fixed width space)
Is there any simple way to do ?
This is my code
<div class="btnWrap">
No
Yes
</div>
.btnWrap { text-align:center; overflow:hidden; margin:0 auto; }
.btnWrap .btnOrange { display:block; float:left; width:50%; height:36px; }
.btnWrap .btnGray { display:block; float:left; width:50%; height:36px; }
yes:
http://jsfiddle.net/fJ73C/
.btnWrap { text-align:center; overflow:hidden; margin:0 auto; }
.btnWrap .btnOrange { display:block; float:left; width:calc(50% - 5px); height:36px; background-color:orange; }
.btnWrap .btnGray { display:block; float:left; width:calc(50% - 5px); height:36px; background-color:gray; }
.btnWrap a:nth-of-type(odd)
{
margin-right: 5px;
}
.btnWrap a:nth-of-type(even)
{
margin-left: 5px;
}
You can set the button width to 50% minus 5 pixels (5 + 5 = 10) by using calc(50% - 5px)
and then set a margin of 5px on the right of the left button and 5px on the left of the right.
Im trying to give a div some small amount of margin-top. it works fine and does what I want in the design view but in live view or in a browser it shows nothing as if like that line of code does not exist.
Im new to stackflow so ill try and post the code im using.
<div class="overallWrap">
<div class="backgroundWrap">
<div class="topWrap">
<div class="dvd"></div>
</div>
<div class="titleWrap">
<div class="title"></div>
<div class="socialWrap">
<div class="facebook"></div>
<div class="twitter"></div>
<div class="link"></div>
</div>
</div>
<div class="midWrap">
<div class="tools"></div>
<div class="menuWrap">
<div class="ps"></div>
<div class="fl"></div>
<div class="dw"></div>
<div class="blender"></div>
</div>
</div>
<div class="bottomWrap">
<div class="logo"></div>
<div class="quote"></div>
</div>
</div>
and the css is:
* {
color:black;
}
body {
background-color:#000;
.overallWrap {
background-color:white;
width:920px;/*DO NOT CHANGE*/
height:1100px;/*DO NOT CHANGE*/
margin-left:215px;
margin-top:40px;
}
.backgroundWrap {
width:900px;/*DO NOT CHANGE*/
height:1060px;/*DO NOT CHANGE*/
background-image:url(dgltest.jpg);
background-repeat:no-repeat;
margin-top:12px;
margin-left:15px;
}
.dvd {
width:300px;/*DO NOT CHANGE*/
height:60px;/*DO NOT CHANGE*/
float:right;
margin-right:15px;
}
.topWrap {
width:900px;/*DO NOT CHANGE*/
height:65px;/*DO NOT CHANGE*/
}
.titleWrap {
width:900px;/*DO NOT CHANGE*/
height:265px;/*DO NOT CHANGE*/
}
.title {
width:780px;/*DO NOT CHANGE*/
height:265px;/*DO NOT CHANGE*/
float:left;
}
.socialWrap {
width:115px;
height:100px;
float:right;
margin-top:150px;
}
.leftWrap {
width:75px;/*DO NOT CHANGE*/
height:100px;/*DO NOT CHANGE*/
}
.facebook {
width:30px;/*DO NOT CHANGE*/
height:30px;/*DO NOT CHANGE*/
margin-top:70px;
margin-left:10px;
float:left;
}
.twitter {
width:30px;/*DO NOT CHANGE*/
height:30px;/*DO NOT CHANGE*/
float:right;
margin-top:70px;
margin-right:15px;
}
.link {
width:30px;/*DO NOT CHANGE*/
height:30px;/*DO NOT CHANGE*/
margin-top:70px;
margin-left:40px;
}
.midWrap {
width:900px;/*DO NOT CHANGE*/
height:410px;/*DO NOT CHANGE*/
}
.tools {
width:30px;/*DO NOT CHANGE*/
height:410px;/*DO NOT CHANGE*/
float:left;
margin-left:37px;
}
.menuWrap {
width:270px;/*DO NOT CHANGE*/
height:410px;/*DO NOT CHANGE*/
float:right;
}
.ps {
width:270px;/*DO NOT CHANGE*/
height:80px;/*DO NOT CHANGE*/
margin-top:10px;
}
.fl {
width:270px;/*DO NOT CHANGE*/
height:80px;/*DO NOT CHANGE*/
margin-top:30px;
}
.dw {
width:270px;/*DO NOT CHANGE*/
height:80px;/*DO NOT CHANGE*/
margin-top:30px;
}
.blender {
width:270px;/*DO NOT CHANGE*/
height:80px;/*DO NOT CHANGE*/
margin-top:20px;
}
.bottomWrap {
width:900px;/*DO NOT CHANGE*/
height:320px;/*DO NOT CHANGE*/
}
.logo {
width:200px;/*DO NOT CHANGE*/
height:240px;/*DO NOT CHANGE*/
margin-top:80px;
float:left;
}
.quote {
width:650px;/*DO NOT CHANGE*/
height:280px;/*DO NOT CHANGE*/
float:right;
}
The overallWrap is a div that is the total srceen size i want to display. The inside will be whit and the outside black so it will look like a big white rectangle in the middle of a black screen. Then ive made a smaller backgroundWrap div to fit inside the overallWrap with margin borders on the top of 12px and the left 10px. My problem is when I look at it in the browser or live view the code in the backgroundWrap for margin top does nothing so i cant see a 12px white strip if that makes sense. aarrgh its driving me made. Any help would be great thanks.
Evidently the box model in your design view is not collapsing margins. The proper behavior in margins is for them to collapse. Try using padding instead.
.backgroundWrap { padding-top: 12px; }
In short, when you set a margin-top: 40px around the wrapper and margin-top: 12px in the inner div the inner margins will collapse with the wrapper so you won't see a separation in between.
I downloaded JavaScript code from http://twitter.com to embedded a Twitter Widget in a block on the front page of this site: http://www.fareham.vm.bytemark.co.uk/.
The block renders fine in Google Chrome (10.0.648.133) and Opera (11.01), but in Internet Explorer (7.0.5730.13CO) and Firefox (3.6.15), the block is rendered incorrectly, obscuring the latest news block.
The CSS code is loaded from: http://widgets.twimg.com/j/2/widget.css:
.twtr-widget {
position:relative;
font-size:12px!important;
font-family:"lucida grande",lucida,tahoma,helvetica,arial,sans-serif!important;
zoom:1;
}
.twtr-fullscreen {
font-size:220%!important;
}
.twtr-fullscreen .twtr-new-results {
_display:none!important;
}
.twtr-inactive {
display:none;
}
.twtr-widget a img {
border:0!important;
}
.twtr-doc {
overflow:hidden;
width:100%;
text-align:left;
font-weight:normal;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.twtr-bd {
padding:0 1px;
}
.twtr-widget .twtr-tweet-wrap {
padding:6px 8px;
overflow:hidden;
zoom:1;
}
.twtr-fullscreen .twtr-tweet-wrap {
padding:20px;
}
.twtr-widget .twtr-tweet {
border-bottom:1px dotted #ddd;
overflow:hidden;
zoom:1;
}
.twtr-widget-profile img.twtr-profile-img {
display:block;
float:left;
width:31px;
height:31px;
border:0!important;
}
.twtr-widget h3,.twtr-widget h4,.twtr-widget p {
margin:0!important;
padding:0!important;
line-height:1.2!important;
width:auto!important;
}
.twtr-widget-profile h3,.twtr-widget-profile h4 {
margin:0 0 0 40px!important;
}
.twtr-widget h3 {
font-size:11px!important;
font-weight:normal!important;
}
.twtr-widget h4 {
font-size:16px!important;
}
.twtr-widget em,.twtr-widget .twtr-new-results {
font-size:9px;
font-style:normal;
display:block;
margin-top:2px;zoom:1;
}
.twtr-widget .twtr-new-results {
text-align:center;
padding:3px;
margin:0 auto -10px auto!important;
display:block;
position:relative;
bottom:5px;
line-height:.9;
}
.twtr-results-inner {
line-height:1;
font-size:100%;
padding:4px 0;
position:relative;
bottom:-2px;
width:40%;
margin:0 auto;
z-index:2;
text-align:center;
}
.twtr-results-hr {
width:100%;
position:relative;
z-index:1;
height:1px;
border-bottom:1px dotted #ddd;
bottom:7px;
background:none;
overflow:hidden;
}
.twtr-new-results span {
position:relative;
z-index:3;
top:-14px;
display:block;
font-size:9px!important;
}
.twtr-fullscreen .twtr-new-results span {
font-size:24px!important;
}
.twtr-hd {
padding:10px;
position:relative;
zoom:1;
overflow:hidden;
}
.twtr-fullscreen .twtr-hd {
height:0;
padding:0;
}
.twtr-timeline {
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
position:relative;
overflow:hidden;
z-index:2;
height:225px;
}
.twtr-scroll .twtr-timeline {
overflow-x:hidden;
overflow-y:auto;
}
.twtr-widget .twtr-tweet:last-child {
border-bottom-width:0;
}
.twtr-ft {
position:relative;
}
.twtr-ft div {
overflow:hidden;
padding:10px;zoom:1;
}
.twtr-ft span {
float:right;text-align:right;
}
.twtr-ft a {
float:left;display:block;
}
.twtr-ft a img {
position:relative;
top:2px;
}
.twtr-ft span a {
float:none;
}
.twtr-avatar {
width:40px;
height:40px;
float:left;
overflow:hidden;
display:block;
}
.twtr-fullscreen .twtr-avatar {
width:80px;
height:80px;
}
.twtr-img {
height:25px;
width:25px;
}
.twtr-img img {
width:30px;
height:30px;
}
.twtr-fullscreen .twtr-img img {
width:72px;
height:72px;
}
.twtr-fullscreen a.twtr-join-conv {
display:none;
}
.twtr-tweet-text {
margin-left:40px;
}
.twtr-fullscreen .twtr-tweet-text {
margin-left:90px;
}
.twtr-popular {
font-size:10px;
padding:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
display:inline-block;
margin-top:3px;
opacity:.8;
}
.twtr-doc a {
text-decoration:none!important;
}
.twtr-doc a:hover {
text-decoration:underline!important;
}
First of all your problem has nothing to do with positioning.
Your <h2> element which come just before the twitter feed...
<h2>Twitter Timeline</h2>
... is being affected by the following CSS rule: (demo.css, line 10)
.promo-center-2cols .block h2 {
float:left;
width:320px
}
Drop the float:left. The problem is that there is a div shortly after it... (class="twtr-doc")
<h2>Twitter Timeline</h2>
<div class="content">
<div id="twtr-widget-1" class="twtr-widget twtr-widget-profile">
<div class="twtr-doc" style="width:100%;">
... which is being targeted by the following rule: (widget.css line 12)
.twtr-doc {
overflow:hidden;
width:100%;text-align:left;
font-weight:normal;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
That float and overflow together are creating your problem. You'll have to change one of them, and since widget.css comes from widgets.twimg.com (Twitter) I assume you can't change it, so change the float value in demo.css.