i started using LESS to have a simple tool for creating .css files.
My question is, what is the most common way to handle such css class-construct:
<div id="wrapper">
<div id="left">
<h2>Left</h2>
</div>
<div id="right">
<h2>Right</h2>
</div>
</div>
The boxes #left and #right have exactly the same stylesheet, the h2 in each box should be different.
I would have solved it with this code:
#wrapper {
#left, #right {
width:50%;
float:left;
}
#left h2 {
color:black;
}
#right h2 {
color:red;
}
}
or you can solve it like this:
.left_right {
width:50%;
float:left;
}
#wrapper {
#left {
.left_right;
h2 {
color:black;
}
}
#right {
.left_right
h2 {
color:red;
}
}
}
What is the 'right' way or is it just a personal choice...
P.S: And is there any way to get highlighting in CODA for .less files?
Thanks
Personal preference for sure. The first example, for me, is easier to read and should result in less CSS, which is the purpose of LESS after all!
As for syntax highlighting in CODA, I don't use it myself, or have access to a Mac right now, but a quick Google search turned up a few results.
Instructions for one way can be found here: http://christophercasper.com/2010/09/less-syntax-highlighting-in-coda/
I also found a that there was a plugin for CODA, but it's now been turned into it's own app. Not sure how useful it is, but you can find it here: http://incident57.com/less/
Related
Background:
Im working on a framework that has browser classes applied to the HTML element.
Im trying to apply a cross browser fix (for safari5) whenever I extend to a mixin.
Example Markup:
<html class="safari5">
<div class="child"></div>
</html>
LESS:
.mixin{
content:"cool style mixin that breaks on safari";
}
.safari5{
.fix{content:"hacks safari5's bullshit and semi-fixes cool style mixin"!important;}
}
.child{
&:extend(.mixin);
&:extend(.fix);
}
/*
Expected CSS Output:
.mixin,
.child {
content: "cool style that breaks on safari";
}
.safari5 .fix,
.safari5 .child{
content:"hacks safari5's bullshit and semi-fixes cool style mixin"!important;
}
*/
Thanks!
See extend all. E.g.:
.mixin {
1: 1;
}
.safari5 {
.fix {2: 2}
}
.child {
&:extend(.mixin, .fix all);
}
I'm trying to hide a video while it's loading (e.g. the black window with just a loading spinner). The only class I've found that sort of made sense is the .vjs-has-started one but the loading screen still shows with the following CSS. I also didn't see anything in the javascript api that meets this need (sorry if I missed something).
.video-js {
display: none;
visibility: hidden;
}
.video-js.vjs-has-started {
display: block;
visibility: visible;
}
I've also tried adding .vjs-playing into the mix both in place of an in conjunction with .vjs-has-started. Any thoughts on getting this to work or a answer about why it won't currently would help. If I need to I can work on adding this to video.js if it's not already there but I first wanted to get your definitive answer on the current state of video.js for this functionality.
I added the vjs-waiting class to be able to accomplish this now vjs-waiting can be used in css to show and hide the content see the pull-request for more details.
Example:
.vjs-waiting {
visibility: hidden;
background: transparent;
}
.vjs-loading-spinner {
display: none !important;
}
Reference - https://github.com/videojs/video.js/pull/1351
You could use the vjs-waiting
.vjs-waiting {visibility: hidden;}
Hey I have been struggling with this too, Docs are not intuitive at all!
Im implementing Video JS in React Hooks, so I solved with loadingSpinner set to false;
useEffect(() => {
let player = videojs('my-player',{
autoplay: 'muted',
sources: [
{
src: videoUrl, // m3u8 format
type: "application/x-mpegURL"
}
],
controlBar: false,
loadingSpinner: false
});
player.play()
return () => {
player.dispose()
}
}, [])
Hope it helps! =)
Although LESS is a Preprocessor, how can I do this
#ltr: ltr;
#rtl: rtl;
#dir: #rtl;
.SetTypeFaceVariables when (#dir = #ltr) {
#headType: 'Segoe UI_';
}
.SetTypeFaceVariables when (#dir = #rtl) {
#headType: Tahoma;
}
.SetTypeFaceVariables(); // Error is here, we cannot call Mixins here like this
h1{
font-family: #headType;
}
How can I define #headType variable in different direction?
Thanks to #seven-phases-max you can find the Demo on Codepen
As it's already mentioned in comments your example compiles fine with Less version 1.5.0 and higher. Most likely your IDE ships with some outdated version of the Less compiler (1.4.2? 1.3.3?). Never mind, you need just a tiny fix to make the code to be compatible with ancient Less versions (down to 1.3.2):
#ltr: ltr;
#rtl: rtl;
#dir: #ltr;
// the magic is in parens:
.SetTypeFaceVariables() when (#dir = #ltr) {
#headType: 'Segoe UI_';
}
.SetTypeFaceVariables() when (#dir = #rtl) {
#headType: Tahoma;
}
.SetTypeFaceVariables();
h1 {
font-family: #headType;
}
I would like to target specific elements within a class using less.
In this case, I would like to target elements of class button, but within that I would like to target an anchor tag a.
Currently I have:
.button {
/* lots of bits and pieces go here, hence
the need to keep it at a class level
*/
/* further down, but still in .button */
/* Attempt 1 - fails: compiled = a .button (note the space)
a& {
height:20px;
}
/* Attempt 2 - fails: compiled = .buttona
&a {
height:20px;
}
}
I basically want it to compile to:
a.button
This is so I can create elements such as:
<a class="button">
<button class="button">
But slightly alter it when its an anchor. I don't want to throw in the it's a bug in less! card too early, but if I use &.another-class it works as expected (compiled: .button.another-class, but not when targeting elements
You're using an old version of less. The code below generates the correct CSS using less 1.3.3
.button {
a& {
height:20px;
}
}
generates:
a.button {
height: 20px;
}
#Allen Bargi answer is correct, yet only for this specific scenario. I am a little confuse about what you want to achive.
As #Allen Bargi pointed out, this will target "a" lements with a "button" class and generates a
.button {
a& {
height:20px;
}
}
It generates:
a.button {
height: 20px;
}
Meanwhile, this below will target "a" elements contained whitin an element with a "button" class. which seems to me was your original objective.
.button {
a {
height:20px;
}
}
It generates:
.button a {
height:20px;
}
Both solutions migt work fine in this case because you are using the same "button" class for both the parent and the child elements, but they are not targeting the same elements.
I hope this helps.
Let's say that I have a style defined using Less:
ul.unstyled,
ol.unstyled {
margin-left: 0;
list-style: none;
}
Later on, I want to re-use the unstyled class:
.my-list {
.unstyled;
}
This doesn't work, however, and I can't figure out the magic to make it work. Any thoughts?
You can't re-use arbitrary class definitions, only mixins (those starting with a dot). In this case you'll need to duplicate it.
Try this:
.unstyled {
margin-left: 0;
list-style: none;
}
.my-list {
.unstyled;
}
You won't be able to nest .unstyled if it's defined as ul.unstled and ol.unstyled.
Since you can't reuse .unstyled when it's a nested style and you probably don't want to edit the Bootstrap source code, I'd suggest you just assign both classnames to your list:
<ul class="unstyled my-list" />