How should I go about optimizing CSS code? There's various CSS3 lines, like -moz- and -webkit-, border-top-left-radius, etc.. I believe bigger CSS files increase page load time significantly.
And another question: I've written quite some code, however some of it is left unused. I have over 2000 lines of CSS code, and I bet around 200-300 lines could be removed, perhaps even more. Is it worth revising all the code? It would take quite some time...
GZip the files before uploading them on server
It will reduce the files size significantly
Edit: Effect of GZipping -
By gzipping the .css file on Bargaineering, its size dropped from 28.2K to 7.3K, a 74.1% savings.
always remove the last semicolon:
body { background: black; color: white; }
to
body { background: black; color: white }
combine multiple properties:
.class { margin-top: 10px; margin-right : 20px; margin-bottom: 30px; margin-left: 40px; }
to
.class { margin: 10px 20px 30px 40px; }
use simple colors (instead of `#FFFFFF, #AABBCC, #FF0000 put #FFF, #ABC, #F00)
the most important thing: minify your code before uploading on the server. It will remove whitespaces and comments and significantly reduce your code and file size.
The smaller the file, the quicker it will download and the faster users can render the styles. There are various minifying scripts, I'd check out the YUI Compressor: http://refresh-sf.com/yui/
Related
Is there some way in IntelliJ to define a shortcut key to auto-indent key - value pairs?
Instead of this:
form {
position: relative;
display: table-cell;
vertical-align: middle;
outline: 0;
border-radius: 4px;
}
I very much prefer this:
form {
position: relative;
display: table-cell;
vertical-align: middle;
outline: 0;
border-radius: 4px;
}
Note:
I'm quite peculiar about the formatting of my personal code (hobby project) and spend a good amount making it as readable as possible. I'm also a bit concerned someone may one day screw it up through a linter and auto-formatting during git commit.
If you have an alternate way of achieving this, I'd like to hear.
I apply the same formatting in JSX key-value pairs.
If not, I may have to write something myself.
I have a solution for you. For example if you are using .css file you should go:
setting -> Code style -> Style Sheet and choose Align valued option. (for you formatting it is Align value: On Values)
After applying your changes you could format your code with default format short cut: Command +alt + L for Mac and for widows ctrl + alt + l
I hope it is useful :)
Styled components claim to cover all of css but I've run into this simple but significant issue. I need to enlarge my line-height but in a relative way, otherwise the line gets cut (it's height is smalled than the letters).
When I try to use rem or % as unit, I get an error saying a number type is expected instead of a string.
line-height: 100% means 100% of the font size for that element, not 100% of its height. In fact, the line height is always relative to the font size, not the height, unless its value uses a unit of absolute length (px, pt, etc). another option which you can try is using table-cell
#wrapper{
height: 40px;
width:200px;
display: table-cell;
vertical-align: middle;
text-align: center;
background: red;
}
I have long Msg and they are the same except the last part. As you can see below - i can't tell the difference: - they are actually different.
I've open up the debugger with chrome and i saw this:
But this doesn't work on page reload as you might expect. It reverts back to 30 ch.
Question:
Where are this styles kept? So that by modifying them i always have this debugger-sidebar at 70 ch.
Or is there a better way to do this?
Node: It would be even better if i can make it resizable instead of fixed at 70 ch. But this is enough for now.
You are not alone, there is a Github issue for this.
As #Simon H pointed out this is not fixed yet . But until then - to have a resizable debugger-sidebar you can do this:
Go into:
elm-stuff/packages/elm-lang/VirtualDom/Debug.elm
Do a search for the class: .debugger-sidebar
and then add:
.debugger-sidebar {
display: block;
float: left;
width: 30ch;
height: 100%;
color: white;
background-color: rgb(61, 61, 61);
/* add this 2 lines */
overflow-x: auto;
resize: horizontal;
}
It works on save with elm-live also. But if you delete the elm-stuff folder for some reason it will get back to normal - because elm-stuff is build on the fly.
I've taken this from #rtfeldman pull-request here
Hope that helps:)
EDIT:
There has been some improvements recently (model stays open during updates.. awesome !!:D ) and stuff was moved around. If you want this:
My gif recorder only does 600px - can't record the hole thing. To change the styles:
step 1. go to:
elm-stuff/packages/elm-lang/virtual-dom/ < your version number ex 2.0.4 > /src/VirtualDom/Debug.elm - and open up Debug.elm
step 2.
Find styles function, and inside, locate:
#debugger {
width: 100%
height: 100%;
font-family: monospace;
display: flex; -- add display flex here.
}
step 3. find:
.debugger-sidebar {
display: block;
float: left;
width: 30ch;
height: 100%;
color: white;
background-color: rgb(61, 61, 61);
width: 30%; -- add this 3 lines - maybe you want more width then 30%.
overflow-x: auto;
resize: horizontal;
}
Don't delete elm-stuff folder - if you do all this steps need to be done again.
For webpack users.
And also make sure you restart webpack build after doing this - because webpack-dev-server is working form the unchanged elm-stuff folder in memory - and will not pick up this change without a restart.
I need to make my Previous and Next buttons smaller.
Im using the dataTables plugin alongside bootstrap so the tables are already styled.
Here you can see the involved files .css and .js
I've tried twicking them a bit but I can't make it work for me, I can't fing the buttons-related data.
Thanks in advance, any direction you may point would be helpful.
You can select those two links by class
.previous, .next {
// CSS here
}
Here's a live version to play with.
Answering to an old question.
You are probably looking for this. I found it somewhere on Datatable's official site not sure where. But for me the below solution worked:
.dataTables_paginate>span>a {
margin-bottom: 0px !important;
padding: 1px 5px !important;
}
.dataTables_paginate>a {
margin-bottom: 0px !important;
padding: 1px 5px !important;
}
Hope it helps someone like me.
I am new to bootstrap, and I added bootstrap 3 into my project and it shrunk all the font sizes, I never had any font size specified in these classes. I thought bootstrap 3 had the default size to 14.. is there something else I need to do?
Thanks
It appears to be happening, at least as of version 3.3.6, due to this block on line 1097:
html {
font-size: 10px;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
You can restore your font-size by adding this to your stylesheet:
html
{
font-size: 100%;
}
You can customize/override anything - if, for example, you load YOUR css file AFTER the bootstrap file, then your settings will override it. Whatever you can dream:
p {
font-size 18px;
}
and so on...
I strongly recommend digging into the source code: https://github.com/twbs/bootstrap/blob/master/dist/css/bootstrap.css
html {
font-size: 62.5%;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.428571429;
color: #333333;
background-color: #ffffff;
}
UPDATE: TO clarify, "No" you shouldn't have to do anything else. It sounds like there is another problem. The linked source code has changed since the original answer date... as of Feb 2015, it looks like this:
html {
font-size: 10px;
}
body {
font-size: 14px;
}
Assuming we've set our project up correctly, (bower install bootstrap is pretty easy)... attempting to echo text outside of the body should result in 10px text, inside body should be 14px.
If you don't see 14 point text inside the body, then something else might be stepping on it. I'd next inspect in in Chrome (for example) to confirm where the font-size was coming from.
I'd like to add that I think it's helpful to understand how these values we see in this /dist/css file are derived from less variables... the defaults should work out of the box, but you have easy control over everything, including the body text size: see http://getbootstrap.com/css/#less-variables.