How can I use Bootstrap styles in a LESS file? - import

I am trying to import bootstrap.css into a .less file, so that I can conditionally apply Bootstrap styles with media-queries.
Here is my LESS code:
// Visual Studio is saying "Couldn't locate" the file for both, yet they are there:
#import url("bootstrap.min.css");
#import url("bootstrap-theme.min.css");
// ...can't find the source of the "#screen" at-rules:
#extra-small: ~"screen and (max-width: #screen-xs-max)";
#small: ~"screen and (min-width: #screen-sm-min) and (max-width: #screen-sm-max)";
#medium: ~"screen and (min-width: #screen-md-min) and (max-width: #screen-md-max)";
#large: ~"screen and (min-width: #screen-lg-min)";
footer {
text-align: center;
// ...doesn't like the comma "or" syntax here, so "or" is used instead:
#media #extra-small or #small {
#linkedin-flair {
.hide // compile error
}
#stackoverflow-flair {
.hide // compile error
}
}
#media #medium {
#linkedin-flair {
.col-sm-3 // compile error
}
#copyright-text {
.col-sm-6 // compile error
}
#stackoverflow-flair {
.col-sm-3 // compile error
}
}
#media #large {
#linkedin-flair {
.col-sm-4 // compile error
}
#copyright-text {
.col-sm-4 // compile error
}
#stackoverflow-flair {
.col-sm-4 // compile error
}
}
}
...the LESS is having trouble with the #import and #screen at-rules, and with referencing any Bootstrap classes such as .hide.
I am using Visual Studio 2013, Web Essentials 2013, and Bootstrap 3.

1) You should prefer to download Bootstrap's LESS files and import them with #import "bootstrap.less". If you can't follow #seven-phases-max 's links and use #import (less) bootstrap.min.css
2) "// ...can't find the source of the "#screen" at-rules:" these rules are not defined in Bootstrap's LESS files. The code from the docs illustrate the boundaries of the grid defined by Bootstrap. It will show you what happens if you change the variables mentioned.
For example take a look to grid.less which defines:
#media (min-width: #screen-sm) {
width: #container-sm;
}
Also read: http://blog.scur.pl/2012/06/variable-media-queries-less-css/ and LESS variables in #media queries i don't think you solution won't work cause:
#screen-lg: 992px;
#large: ~"screen and (min-width: #screen-lg)";
#media #large{ color: red; }
compiles to:
#media screen and (min-width: #screen-lg) {
color: red;
}
NB #screen-lg not set.
3) " .hide // compile error" there is no mixins called hide
You could use mixins from responsive-utilities.less (see also: http://getbootstrap.com/css/#responsive-utilities)
In your case you will get something like:
//example DO NOT compile to useful CSS
#import (reference) "bootstrap.less";
#linkedin-flair
{
&:extend(.hidden-xs);
&:extend(.hidden-sm);
}
4) " .col-sm-4 // compile error" .col-sm-4 is dynamical generate (grid.less) you can't use it as a mixin.
use:
#stackoverflow-flair {
.make-sm-column(4);
}

Related

How dynamically set scss variables $body-bg and $body-color for bootstrap-vue?

I need dark/white theme switcher in my bootstrap-vue project. I have a couple scss files:
dark.scss
$body-bg: #333;
$body-color: #eee;
#import 'node_modules/bootstrap/scss/bootstrap.scss';
#import 'node_modules/bootstrap-vue/src/index.scss';
white.scss
$body-bg: #fff;
$body-color: #000;
#import 'node_modules/bootstrap/scss/bootstrap.scss';
#import 'node_modules/bootstrap-vue/src/index.scss';
Also I have variable crTheme in data of app. Also app.vue has watcher:
watch: {
crTheme(val) {
if (val == 'dark') {
import('#/dark.scss')
} else {
import('#/white.scss')
}
}
}
It's working ok, but only 2 times: switch to dark, then to white, and after this switching not working. As I understood I need unload bootstrap.scss and bootstrap-vue/src/index.scss and load them again on each theme switching... But I dont know how resolve this issue

Make default Ionic alerts larger

I'm trying to make the default Ionic Alerts larger. I'm developing an app that needs to have easy touch points and the default alerts are too small for what I'm needing.
I've tried enlarging the font as well as expanding the width of the alerts but nothing seems to actually make the alerts larger.
Any easy/best ways to do this?
AlertController supports custom classes which could be placed in your component's scss file and there you can do necessary alterations.
For example in your component's ts file you can have this method that creates alert with reference to custom class "scaledAlert":
delete() {
let confirm = this.alertCtrl.create({
title: "Are You Sure?",
cssClass: "scaledAlert",
message: "this will remove image from your image gallery",
buttons: [
{
text: "Cancel",
handler: () => {
console.log("Canceled delete");
}
},
{
text: "Confirm",
handler: () => {
console.log("deleting...");
this.deleteImageFromGallery(this.image)
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
this.viewCtrl.dismiss();
}
}
]
});
confirm.present();
}
Now in the scss file you add class to style as you need to scale the controller, such class goes after your page or component:
home-page {
.item {
min-height: 2rem; /* <- this can be whatever you need */
}
ion-label {
margin: 0px 0px 0px 0;
}
.item-content {
padding-top: 0px;
padding-bottom: 0px;
margin-top: -12px;
margin-bottom: -12px;
height: 50px;
}
}
.scaledAlert {
transform: scale(1.5);
}
Here I used just naive "scale" function which may require you to add some cross browser compatible versions of it. But you should achieve what you want with it (it worked in my app without issues).
Alternatively you can override default styles using saas variables: https://ionicframework.com/docs/api/components/alert/AlertController/#sass-variables
You will have to alter them in theme\variables.scss" which is located in your project's folder
See more here: https://ionicframework.com/docs/theming/overriding-ionic-variables/
And third option is indeed to check elements' style via devtool and attempt to override those classes. But I don't like that way, feels a bit more hacky.
Some of the styles for alert are not getting updated if written in component SCSS file. The styles need to be written in the global scss file.

Stylelint, have an empty line before non-nested rules and no empty line before nested rules?

Is there any way at all to accomplish this now?
I see rule-nested-empty-line-before has been removed for some reason, so is this config no longer possible?
I want this to throw errors...
#media (max-width: 300px) {
.foo {
display: block;
}
}
#media (max-width: 600px) {
.bar {
display: block;
}
}
There should be a space before #media since it's not nested, and no space before .foo since it's nested.
The rule-nested-empty-line-before and rule-non-nested-empty-line-before rules were combined together to form the new rule-empty-line-before rule in version 8.0.0. You can use this rule to control the empty lines before the .foo {} and .bar {} rules.
#media is an at-rule, so you should use the at-rule-empty-line-before rule to control the empty lines before it.
You can learn about how rules are named and how they work together in this section of the User Guide.
There should be a space before #media since it's not nested, and no space before .foo since it's nested.
With the above in mind, the configuration for that should be:
{
"rules": {
"at-rule-empty-line-before": ["always"],
"rule-empty-line-before": ["always", {
except: ["first-nested"]
}]
}
}
Alternatively, you can use stylelint-standard-config, which has sensible defaults for stylistic rules.

CSS3 animation every time class is applied (Firefox bug?)

There is some problem with CSS3 native animation I've bumped into with Firefox (tried in v17) while Chrome is ok.
The sample is also available on Codepen:
http://codepen.io/anon/pen/yxteC
The code is also duplicated below.
I apply some class to some element (tried to apply that with JS on hovering, but hovering by itself works absolutely the same way (:hover selector instead of .hover class)).
So, the problem is that in Firefox the animation triggers only once: the first time the class had been applied. Any next time it does not.
That works perfectly in Chrome. I did not test any other browsers though (IE still does not widely support that, and Opera... well, it does not bother me much for now).
One more detail: if not to hide/show internal element (display:none/block), then it works ok in Firefox (but that's obviously not a solution).
I would really ask not to add any comments related to general cleanliness and possible improvements of the code. That's just an example.
HTML:
<div>
<span>menu</span>
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
</ul>
</div>
CSS:
ul
{
display: none;
}
div.hover ul
{
display: block;
}
div li
{
position: relative;
top: -10px;
}
div.hover li
{
-webkit-animation: filterAppear 0.5s;
-moz-animation: filterAppear 0.5s;
top: 0;
opacity: 1;
-webkit-animation: filterItemAppear 0.1s;
-moz-animation: filterItemAppear 0.1s;
-webkit-animation-fill-mode: backwards;
-moz-animation-fill-mode: backwards;
}
div.hover li:nth-child(1)
{
-webkit-animation-delay: 0.15s;
-moz-animation-delay: 0.15s;
}
div.hover li:nth-child(2)
{
-webkit-animation-delay: 0.35s;
-moz-animation-delay: 0.35s;
}
div.hover li:nth-child(3)
{
-webkit-animation-delay: 0.55s;
-moz-animation-delay: 0.55s;
}
#-webkit-keyframes filterItemAppear
{
from { opacity:0; top:-25px; }
to { opacity:1; top:0; }
}
#-moz-keyframes filterItemAppear
{
from { opacity:0; top:-25px; }
to { opacity:1; top:0; }
}
I had similar problem and today I'll find the solution.
Firefox must notice the DOM manipulation somehow. So we must add .width() or setTimeout. Width solution is cleaner IMO.
Look at my edited CodePen for your example http://cdpn.io/yhbfB.
(More about it at http://css-tricks.com/restart-css-animation/)

mobile webapp CSS breaks on orientation change

The CSS for my webapp gets completely misaligned when the mobile device is rotated to landscape (target devices are iphone and android). I tried using the javascript solution explained here in order to get my app to switch between a portrait.css and a landscape.css file on orientation change, but that still didn't work. It even messed up the portrait.css once they were both posted to the live server (although it worked on my local machine).
The url for the app is http://mobile.geekstats.com/
Does anyone know how I can fix the landscape css? Thanks!
Use CSS Media Queries to update your design
iPhone doesn’t support orientation currently (Thx #vava), so use media queries for width below
Orientation queries:
http://www.w3.org/TR/css3-mediaqueries/#orientation
#media all and (orientation:portrait) {
h1 {
color: red;
}
}
#media all and (orientation:landscape) {
h1 {
color: blue;
}
}
Width queries:
/* Portrait */
#media only screen and (max-width: 320px) {
h1 {
color: red;
}
}
/* Landscape */
#media only screen and (min-width: 321px) {
h1 {
color: blue;
}
}
Check out http://lessframework.com for examples of width-based media query design.
There are many other media query options to target specific attributes of the viewing sesssion:
http://www.w3.org/TR/css3-mediaqueries/#contents