Autoformatting LESS code with vim - css

How to make vim format this LESS code properly? =G command gives horrific results.
Here is a sample:
// главный слайдер main slider
.herounit-row {
position: relative;
}
.hero-box {
position:absolute;
top:0;
width:100%;
.centered();
}
Here is how it looks after gg=G:
// главный слайдер main slider
.herounit-row {
position: relative;
}
.hero-box {
position:absolute;
top:0;
width:100%;
.centered();
}

If you want to use Vim's shipped filetypes, you can:
:set ft=scss
Afterwards gg=G should deliver the expected results.
EDIT: If it's working for all your use cases, you could also automate this via (I'm assuming the less file extension here):
autoread BufNewFile,BufRead *.less set filetype=scss

For me, this https://github.com/groenewege/vim-less worked nice.
But to be honest, I only see your padding line wrong, the rest seem ok.
This is your less code formated on my vim:
h1,h2,h3,h4,h5,h6 {
font-family: #main-font;
}
.browse-button {
.transition(0.4s all);
line-height: 2.3em;
padding: 0 13px 0 13px;
background: #additional-color;
font-size: 1em;
border:none;
color:#fff;
white-space: nowrap;
.border-radius(15px);
&:hover {
color:#dfdfdf;
background:lighten(#additional-color, 10%);
}
&:active {
box-shadow:inset 0px 1px 3px rgba(0, 0, 0, .5);
}
}

Related

How can i see or how do i know where to put the control according to the screen when using css?

I'm using netbeans 8.0.1 and i have a css file with this content:
/* null margins and padding to give good cross-browser baseline */
html,body,address,blockquote,div,
form,fieldset,caption,
h1,h2,h3,h4,h5,h6,
hr,ul,li,ol,ul,dd,dt,dl,
table,tr,td,th,p,img {
margin:0;
padding:0;
}
img,fieldset {
border:none;
}
hr {
display:none;
/*
HR in my code are for semantic breaks in topic/section, NOT
style/presenation, so hide them from screen.css users
*/
}
#media (max-width:600px) {
* {
-webkit-text-size-adjust:none;
-moz-text-size-adjust:none;
-ms-text-size-adjust:none;
}
}
body {
font:normal 85%/150% "segoe ui",helvetica,sans-serif;
}
.ss_scripted img {
display:none;
}
.ss_scripted .ss_show {
display:block;
}
#slideShow img {
margin:0 auto;
}
#slideCounter {
text-align:center;
padding:0.25em 1em;
font:bold 200%/120% consolas,courier,monospace;
color:#C00;
}
#slideControls {
width:512px;
padding:0.5em 0;
margin:0 auto;
}
#slideControls a {
float:left;
padding:0.25em 0.6em;
text-decoration:none;
color:#000;
background:#EEE;
border:2px solid #666;
-webkit-border-radius:1em;
-moz-border-radius:1em;
border-radius:1em;
-webkit-box-shadow:
inset 0 -0.5em 1em rgba(0,0,0,0.3),
0 0 1px #000;
-moz-box-shadow:
inset 0 -0.5em 1em rgba(0,0,0,0.3),
0 0 1px #000;
box-shadow:
inset 0 -0.5em 1em rgba(0,0,0,0.3),
0 0 1px #000;
}
#slideControls a:active,
#slideControls a:focus,
#slideControls a:hover {
background:#FFF;
}
#slideControls .next {
float:right;
}
How can i see in real time where it put and change the location of the controls and other stuff ?
I can change the values and run it every time to see but that's a lot of work.
For example in c# there is a designer. That's what i mean something like a designer.
You can use the Developer Tools on Chrome. Try with F12 or right click the element you want and chose "inspect element"
If I understood correctly, you can open the browser console by pressing F12.
You'll be able to spot a styles section under elements tab (inspector in FF), where you can change the CSS properties real time.
Following is a screenshot of chrome's console (It's somewhat similar is all major browses):
Right clicking and choosing inspect element will open the console in the above mentioned tab where you can play with the styles and corresponding changes real time

css and meteor 0.7.1 : property missing

today i've updated my app from meteor 0.7.0.1 to 0.7.1.1 and, i have a crash of my app because of my app.css file.
Here is the part that fail :
#media screen (min-width: 1200px) {
#BtnCollapseStatusFilterBar { /* IT'S HERE JUST BEFORE THE EMBRACE */
display: block;
}
}
And the message is :
=> Errors prevented startup:
App 21289 stdout:
App 21289 stdout: While building the application:
App 21289 stdout: app.css: property missing ':' near line 10:31
App 21289 stdout:
App 21289 stdout: => Your application has errors. Waiting for file change.
I don't really understand the problem because i'm not a CSS master.
Any idea ?
Here is the full CSS
#-webkit-viewport{width:device-width}
#-moz-viewport{width:device-width}
#-ms-viewport{width:device-width}
#-o-viewport{width:device-width}
#viewport{width:device-width}
#grid-float-breakpoint: #screen-desktop;
#media (min-width: 1200px) {
#BtnCollapseStatusFilterBar {
display: block;
}
#navbar-status-filterbar-collapse.collapse {
display: none !important;
}
}
/* CSS declarations go here */
#nprogress .bar {
z-index: 2000; /*bs3 navbar is on 1030*/
background: #A300FF;
}
body {
background-image: url(subtlenet2.png);
background-attachment: repeat;
/*line-height: 19px;*/
padding-top: 50px;
}
.blockAd {
padding-left: 10px;
min-height: 275px; /* don't work, only if inside style attribute directly in html */
border: none; /*1px solid grey;*/
border-radius: 10px 0 10px 0;
margin-bottom: 20px;
margin-right: 6px;
width:208px;
background: rgba(256, 256, 256, .7);
}
/* new ad */
.blockAd.newAd {
border-top: solid turquoise;
}
/* no more new */
.blockAd.viewedAd {
border-top: solid mediumseagreen;
}
/* detail open */
.blockAd.openedAd {
border-top: solid aquamarine;
}
/* no more interesting */
.blockAd.removedAd {
border-top: solid orange;
}
/* went to product */
.blockAd.visitedAd {
border-top: solid skyblue;
}
/* owner contacted */
.blockAd.starAd {
border-top: solid orangered;
}
.blockAd .btn-toolbar {
padding-top:5px;
}
.blockAnnonce .infos {
height: 110px;
margin-bottom: 3px;
}
.blockAd .infosHead {
color:black;
}
.blockAd .centerContentImage {
float:right;
width:100%;
padding-right:5px;
display:table-cell;
vertical-align:middle;
text-align:center;
margin-left:auto;
margin-right:auto;
}
.blockAd .centerContentImage img {
max-height: 110px;
max-width:140px;
}
.blockAd .centerContentImage button.OpenDetailAd {
height:105px;
margin-left:3px;
}
/* background of geo zone */
.navbar-collapse.navbar-location-collapse {
max-height: inherit;
}
/* title and buttons up / down non clickable */
.navbar-location-collapse ul {
margin-top: 50px;
}
/*
a.BtnConfiguration span {
width: 44px;
height: 34px;
}*/
Seems like version 0.7.1 throws errors where the syntax of your CSS is incorrect rather just ignoring the relevant rule, as was previously the case. There was probably always a problem there, it just wasn't raised before 0.7.1.
I'd put your entire CSS file in CSS Lint and see what it comes up with - it's possible that there's a problem on a different line to the one that Meteor is suggesting, or at least a problem somewhere.
UPDATE
Looking at the full code, you have at least one LESS variable in your file (#grid-float-breakpoint). I don't use LESS, but as far as I'm aware you need to give LESS files a .less filename extension to tell Meteor to compile them to CSS, otherwise the rules will fail. Try changing the filename from app.css to app.less and see if that works. Obviously, you need to have the LESS package added too, so meteor add less if you haven't done so already.
I had the same problem few hours back. I just missed some property value like this
padding-left:""
I forgot to give a value and after I gave it worked fine. Check for the same in your CSS.
I think in your app something in 10th line you forgot to give a value for the property like above.

CSS Won't work Unless Rule Set is Repeated

I have two classes, left and right, that float and clear things left and right (real crazy stuff).
But here's the problem.
.dashWrap h3 {
background-color: #666;
border: 2px solid #000;
/*border-radius: 0.5em 0.5em 0 0;*/
text-indent: 0.5em;
}
.dashWrap .dashContent {
/* max-height: 5em;*/
min-height:5em;
overflow-x: hidden;
overflow-y: auto;
border: 2px solid #000;
border-top-color: transparent;
}​
.right //If I delete or comment this out, left no longer is applied to anything.
{
clear:right;
float:right;
width:35%;
}
.left
{
float:left;
clear:left;
}
.right //If I delete or comment out this, right no longer is applied to anything.
{
clear:right;
float:right;
width:35%;
}
That's the exact section I have in the file I am editing. the only difference in the actual source file when I load the website is that after the closing curly for .dashContent, there is this :
​
What could be causing this?
You have some invisible or corrupted characters in you file, so the first rule after the .dashContent will be broken and is ignored by the browser.
Try to delete everything between the rules to get rid of the invisible characters, and if that fails you can try copying the rules into a new file. If all else fails, you may have to retype part of the file.

CSS - Extending class properties

I'm pretty new to CSS and have been finding my way around so far.
I am creating these button like links with shadows and stuff. Now there are several such buttons required on the site - everything about the buttons is same - except few properties change like width and font size.
Now instead of copying the same code - over and over for each button - is there a way of extending the button and adding just the properties that change.
Example of two buttons - css
.ask-button-display {
background: #8BAF3B;
border-radius: 4px;
display: block;
letter-spacing: 0.5px;
position: relative;
border-color: #293829;
border-width: 2px 1px;
border-style: solid;
text-align:center;
color: #FFF;
width:350px;
font-size: 20px;
font-weight: bold;
padding:10px;
}
.ask-button-submit {
background: #8BAF3B;
border-radius: 4px;
display: block;
letter-spacing: 0.5px;
position: relative;
border-color: #293829;
border-width: 2px 1px;
border-style: solid;
text-align:center;
color: #FFF;
font-weight: bold;
width:75px;
font-size: 12px;
padding: 1px;
}
And this is how I'm currently using it in my html
Ask a Question Submit
So I'm wondering if there is a cleaner way to do this - like
.button {
/* PUT ALL THE COMMON PROPERTIES HERE */
}
AND THEN SOMEHOW EXTEND IT LIKE
.button #display {
/* THE DIFFERENT PROPERTIES OF Display BUTTON */
}
.button #ask {
/* THE DIFFERENT PROPERTIES OF Ask BUTTON */
}
But I'm not sure how to do this.
Thanks for your inputs
You can add multiple classes to one element, so have one .button class which covers everything, then a .button-submit class, which adds things in.
For example:
.button {
padding: 10px;
margin: 10px;
background-color: red;
}
.button-submit {
background-color: green;
}​
See a live jsFiddle here
In your case, the following should work:
.button {
background: #8BAF3B;
border-radius: 4px;
display: block;
letter-spacing: 0.5px;
position: relative;
border-color: #293829;
border-width: 2px 1px;
border-style: solid;
text-align:center;
color: #FFF;
width:350px;
font-size: 20px;
font-weight: bold;
padding:10px;
}
.button-submit {
width:75px;
font-size: 12px;
padding: 1px;
}​
See a live jsFiddle here
You might want to try this:
.button {
padding: 10px;
margin: 10px;
background-color: red;
}
.button.submit {
background-color: green;
}
.button.submit:hover {
background-color: #ffff00;
}
This way you avoid repeating the word and will able to use the classes in the elements like this:
Ask a Question
Submit
See the example in JSFiddle (http://goo.gl/6HwroM)
Rather than repeat the common "Add a button class to the element" answer I'm going to show you something new in the weird and whacky world of new age CSS, or better known as SCSS!
This reuse of code in stylesheets can be achieved with something called a 'Mixin'. What this allows us to do is reuse certain styles by using the '#include' attribute.
Let me give you an example.
#mixin button($button-color) {
background: #fff;
margin: 10px;
color: $color;
}
and then whenever we have a button we say
#unique-button {
#include button(#333);
...(additional styles)
}
Read more here: http://sass-lang.com/tutorial.html.
Spread the word!!!
You can do this since you can apply more than one class to an element. Create your master class and and other smaller classes and then just apply them as needed. For example:
Ask a Question Submit
This would apply the button and submit classes you would create while allowing you to also apply those classes separately.
Modify your code example along the lines of:
.master_button {
/* PUT ALL THE COMMON PROPERTIES HERE */
}
AND THEN SOMEHOW EXTEND IT LIKE
.button_display {
/* THE DIFFERENT PROPERTIES OF Display BUTTON */
}
.button_ask {
/* THE DIFFERENT PROPERTIES OF Ask BUTTON */
}
And apply like:
Ask a Question
Submit
.ask-button-display,
.ask-button-submit {
/* COMMON RULES */
}
.ask-button-display {
}
.ask-button-submit {
}
You may want to look into Sass. With Sass you can basically create variables in your css file and then re-use them over and over. http://sass-lang.com/
The following example was taken from Sass official website:
$blue: #3bbfce;
$margin: 16px;
.content-navigation {
border-color: $blue;
color:
darken($blue, 9%);
}
.border {
padding: $margin / 2;
margin: $margin / 2;
border-color: $blue;
}
Add a button class to both links for the common parts
.button {
background: #8BAF3B;
border-radius: 4px;
display: block;
letter-spacing: 0.5px;
position: relative;
border-color: #293829;
border-width: 2px 1px;
border-style: solid;
text-align:center;
color: #FFF;
}
Keep in your other classes the rules that aren't common.
And your HTML will be
Ask a Question
Submit
Without changing/ adding new classes you can add styles to all elements with a class name starting with "ask-button"... (whatever the elements with the class are; button, anchor, div etc.) let's say your buttons are divs then:
div[class^="ask-button"] {
// common css properties
}
You can also list all classes that will have common properties like this:
.ask-button-display,
.ask-button-submit {
// common css properties here
}
And then you add the separate styling for each button:
.ask-button-display{
// properties only for this button
}
.ask-button-submit {
// properties only for this button
}

How can I insert text before an item with CSS?

I'm sorry, I'm a complete newbie to CSS and I'm trying to create a custom display for an xml file with CSS.
My question is: how can I display a certain text before a certain element, e. g. "Project:" before each element?
I tried like that with ":before" but that does not seem to do the trick
ThinkingRock
{
background-color: #ffffff;
width: 100%;
}
project
{
:before{content:"Projekt:";};
display: block;
margin-bottom: 30pt;
margin-left: 0;
}
description
{
color: #FF0000;
font-size: 20pt;
}
notes
{
color: #0000FF;
font-size: 20pt;
}
id, created, parent, topic, context, state, done, priority, modified, purpose, success, brainstorming, processed
{
display: block;
color: #000000;
margin-left: 20pt;
}
The xml file use is this one: http://www.trgtd.com.au/index.php?option=com_docman&task=doc_download&gid=16&Itemid=71
I've only added the first line <?xml-stylesheet type="text/css" href="thinkingrock.css"?>
:before is a pseudo-selector itself, so it needs its own style block, like below:
project:before {
content:"Projekt:";
}
project {
display: block;
margin-bottom: 30pt;
margin-left: 0;
}
fiddle: http://jsfiddle.net/wNEt3/
fiddle using your xml and css: http://jsfiddle.net/pRwMT/1/
Btw, http://htmldog.com/ is a great place to go for HTML & CSS tutorials, and they kindly point out W3schools inconsistencies, if you've visited there first :D
use z-index , z-index Only Work with position: fixed,relative,absolute:
project:before {
width:100%;
height:100%;
position:absolute;
content:"";
z-index:-2;
}
project {
position:relative;
display: block;
z-index:30;
}
or:
project:before {
width:100%;
height:100%;
position:relative;
content:"";
z-index:-2;
}
project {
display: block;
z-index:30;
}
documention : https://www.w3schools.com/cssref/pr_pos_z-index.asp

Resources