Now I'm using LESS to customize Bootstrap to my own website.
I have a problem with LESS's mixins.
For example, the following LESS code:
.Article {
margin-left: 5px;
.Small {
color: #111;
}
}
.Small {
font-size: 5px;
}
.MyArticle {
.Article;
.Address {
.Small;
}
}
is compiled to the following CSS:
.Article {
margin-left: 5px;
}
.Article .Small {
color: #111;
}
.Small {
font-size: 5px;
}
.MyArticle {
margin-left: 5px;
}
.MyArticle .Small {
color: #111;
}
.MyArticle .Address {
color: #111;
}
However, in addition to the above generated CSS, I want to make ".MyArticle .Address" small:
.MyArticle .Address {
font-size: 5px;
}
What is the best way?
EDITED:
In the above example of LESS code, the .Article and .Small are the library's class, and I don't want to modify them.
The Problem is Scoping
In your original layout, by including .Article at the same level as .Address is defined, then it is using the .Small from the .Article as the only mixin, because it is the "local" .Small in the .Address context. To avoid this, the .Article must be isolated to its own block. But then you lose the color being picked up from it's .Small, so it must be explicitly included back into .Address through a namespaced call. The code ends up like this:
LESS
.Article {
margin-left: 5px;
.Small {
color: #111;
}
}
.Small {
font-size: 5px;
}
.MyArticle {
.Address {
.Small;
.Article > .Small;
}
& {.Article;}
}
CSS Output
.Article {
margin-left: 5px;
}
.Article .Small {
color: #111;
}
.Small {
font-size: 5px;
}
.MyArticle {
margin-left: 5px;
}
.MyArticle .Address {
font-size: 5px;
color: #111;
}
.MyArticle .Small {
color: #111;
}
Not really sure, but possibly this code:
.Article {
margin-left: 5px;
.Small {
color: #111;
}
}
.Small {
font-size: 5px;
}
.MyArticle {
.Article;
.Address {
.Small;
font-size: 5px;
}
}
Try extend:
.Article {
margin-left: 5px;
.Small {
color: #111;
}
}
.Small {
font-size: 5px;
}
.MyArticle {
.Article;
.Address {
&:extend(.Small);
}
}
This compiles to:
.Article {
margin-left: 5px;
}
.Article .Small {
color: #111;
}
.Small,
.MyArticle .Address { //<-- this
font-size: 5px;
}
.MyArticle {
margin-left: 5px;
}
.MyArticle .Small {
color: #111;
}
Related
I have a Jekyll blog with GitHub pages and have an issue where images embedded in blog posts don't have any padding, meaning the text is too close to the image:
I'd like to specify the padding in the style.scss file so it's applied to all images in blog posts in the future. Where should I add a padding argument? Thank you!
---
---
//
// IMPORTS
//
#import "reset";
#import "variables";
// Syntax highlighting #import is at the bottom of this file
/**************/
/* BASE RULES */
/**************/
html {
font-size: 100%;
}
body {
background: $white;
font: 16px/1.4 $helvetica;
color: $darkGray;
}
.container {
margin: 0 auto;
max-width: 740px;
padding: 0 10px;
width: 100%;
}
h1, h2, h3, h4, h5, h6 {
font-family: $helveticaNeue;
color: $darkerGray;
font-weight: bold;
line-height: 1.7;
margin: 1em 0 15px;
padding: 0;
#include mobile {
line-height: 1.4;
}
}
h1 {
font-size: 30px;
a {
color: inherit;
}
}
h2 {
font-size: 24px;
}
h3 {
font-size: 20px;
}
h4 {
font-size: 18px;
color: $gray;
}
p {
margin: 15px 0;
text-align: justify;
}
a {
color: $blue;
text-decoration: none;
cursor: pointer;
&:hover, &:active {
color: $blue;
}
}
ul, ol {
margin: 15px 0;
padding-left: 30px;
}
ul {
list-style-type: disc;
}
ol {
list-style-type: decimal;
}
ol ul, ul ol, ul ul, ol ol {
margin: 0;
}
ul ul, ol ul {
list-style-type: circle;
}
em, i {
font-style: italic;
}
strong, b {
font-weight: bold;
}
img {
max-width: 100%;
}
// Fixes images in popup boxes from Google Translate
.gmnoprint img {
max-width: none;
}
.date {
font-style: italic;
color: $gray;
}
// Specify the color of the selection
::-moz-selection {
color: $black;
background: $lightGray;
}
::selection {
color: $black;
background: $lightGray;
}
// Nicolas Gallagher's micro clearfix hack
// http://nicolasgallagher.com/micro-clearfix-hack/
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
/*********************/
/* LAYOUT / SECTIONS */
/*********************/
//
// .masthead
//
.wrapper-masthead {
margin-bottom: 50px;
}
.masthead {
padding: 20px 0;
border-bottom: 1px solid $lightGray;
#include mobile {
text-align: center;
}
}
.site-avatar {
float: left;
width: 70px;
height: 70px;
margin-right: 15px;
#include mobile {
float: none;
display: block;
margin: 0 auto;
}
img {
border-radius: 5px;
}
}
.site-info {
float: left;
#include mobile {
float: none;
display: block;
margin: 0 auto;
}
}
.site-name {
margin: 0;
color: $darkGray;
cursor: pointer;
font-family: $helveticaNeue;
font-weight: 300;
font-size: 28px;
letter-spacing: 1px;
}
.site-description {
margin: -5px 0 0 0;
color: $gray;
font-size: 16px;
#include mobile {
margin: 3px 0;
}
}
nav {
float: right;
margin-top: 23px; // #TODO: Vertically middle align
font-family: $helveticaNeue;
font-size: 18px;
#include mobile {
float: none;
margin-top: 9px;
display: block;
font-size: 16px;
}
a {
margin-left: 20px;
color: $darkGray;
text-align: right;
font-weight: 300;
letter-spacing: 1px;
#include mobile {
margin: 0 10px;
color: $blue;
}
}
}
//
// .main
//
.posts > .post {
padding-bottom: 2em;
border-bottom: 1px solid $lightGray;
}
.posts > .post:last-child {
padding-bottom: 1em;
border-bottom: none;
}
.post {
blockquote {
margin: 1.8em .8em;
border-left: 2px solid $gray;
padding: 0.1em 1em;
color: $gray;
font-size: 22px;
font-style: italic;
}
.comments {
margin-top: 10px;
}
.read-more {
text-transform: uppercase;
font-size: 15px;
}
}
.wrapper-footer {
margin-top: 50px;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
background-color: $lightGray;
}
footer {
padding: 20px 0;
text-align: center;
}
// Settled on moving the import of syntax highlighting to the bottom of the CSS
// ... Otherwise it really bloats up the top of the CSS file and makes it difficult to find the start
#import "highlights";
#import "svg-icons";
I would modify your img tag in your style.scss...
change this...
img {
max-width: 100%;
}
to this...
img {
max-width: 100%;
padding: 5px;
}
if the image has it's own DIV use this...
.imageDiv img {
padding: 5px;
}
So I'm trying to follow this tutorial here.
I had a bit of an issues with the .scss file so I'm just sticking to .css because its a lot easier for me to follow. Video number 32 (section 4), minute 3:21, is where I start to get lost.
I try and convert the syntax so it can all work on .css and without using anything complicated. Here is the udemy teachers code so far:
#import 'variables';
.navbar {
padding: 20px;
margin-bottom: 40px;
.bwm-search {
height: 50px;
width: 300px;
}
.navbar-brand {
margin-right: 30px;
font-size: 30px;
letter-spacing: 1px;
color: $main-color;
font-weight: 500;
}
.nav-item {
font-size: 14px;
}
.btn-bwm-search {
border-color: $main-color;
color: $main-color;
&:hover, &:focus, &:active {
background-color: transparent;
border-color: $main-color !important;
color: $main-color !important;
box-shadow: none;
}
}
.dropdown-item {
font-size: 14px;
&:active, &:focus {
background-color: $main-color;
}
}
}
Here is what I'm trying out:
#import '../variables';
.navbar
{
padding: 20px;
margin-bottom: 40px;
bwm-search
{
height: 50px;
width: 300px;
}
.navbar-brand
{
margin-right: 30px;
font-size: 30px;
letter-spacing: 1px;
color: red;
font-weight: 500;
}
.nav-item
{
font-size: 14px;
}
.btn-bwm-search
{
border-color: red;
color: red;
:hover red:focus, red:active
{
background-color: transparent;
border-color: main-color !important;
color: main-color !important;
box-shadow: none;
}
}
}
Like I said, I'm getting a lot of syntax issues.
I knew how to fix most of them and did but some are still present.
Main-color isn't as clear when it comes to fixing, and it appears as though I'm having some errors with the identifiers.
Pic of problems
Your CSS is invalid; if you are not working with any pre-processor it should be like this:
.navbar {
padding: 20px;
margin-bottom: 40px;
}
.navbar bwm-search {
height: 50px;
width: 300px;
}
.navbar .navbar-brand {
margin-right: 30px;
font-size: 30px;
letter-spacing: 1px;
color: red;
font-weight: 500;
}
.navbar .nav-item {
font-size: 14px;
}
.navbar .btn-bwm-search {
border-color: red;
color: red;
}
.navbar .btn-bwm-search:hover red:focus,
red:active {
background-color: transparent;
border-color: main-color !important;
color: main-color !important;
box-shadow: none;
}
}
}
I'm following Ruby On Rails Tutorial by Michael Hartl and I think there is something wrong with my styles.
First, I get this instead of this
As you see, there is smth wrong with title style and debug box style
Then, in signup page I get this instead of this
My style file (custom.css.scss):
#import "bootstrap";
/* variables */
$paddingTopBody: 60px;
$marginBottomH1: 10px;
$grayMediumLight: #eaeaea;
#mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: $paddingTopBody;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: $marginBottomH1;
}
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $grayLight;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: white;
text-transform: uppercase;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
line-height: 1;
&:hover {
color: white;
text-decoration: none;
}
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid $grayMediumLight;
color: $grayLight;
a {
color: $gray;
&:hover {
color: $grayDarker;
}
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 10px;
}
}
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
#include box_sizing;
}
/* sidebar */
aside {
section.user_info {
margin-top: 20px;
}
section {
padding: 10px 0;
margin-top: 20px;
&:first-child {
border: 0;
padding-top: 0;
}
span {
display: block;
margin-bottom: 3px;
line-height: 1;
}
h1 {
font-size: 1.4em;
text-align: left;
letter-spacing: -1px;
margin-bottom: 3px;
margin-top: 0px;
}
}
}
.gravatar {
float: left;
margin-right: 10px;
}
.gravatar_edit {
margin-top: 15px;
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
#include box_sizing;
}
input {
height: auto !important;
}
#error_explanation {
color: #f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}
.field_with_errors {
#extend .control-group;
#extend .error;
}
}
Any ideas where the error could be?
I don't know about Michael's book, but as your screenshot, you might be omitted 'css reset'
edit: I find out sample app's github from that book, you can compare style file directly.
Finally I've found the error. I forgot } after footer so everything after footer was under its tag. Thanks #Leqna for answer
I have a little LESS code:
.text-wraper {
width: 50%;
height:200px;
h2 {
margin: 10px 15px;
padding: 0px;
}
}
.sucess-wraper-header {
width: 100%;
background-color: #f2f2f2;
&,
.text-wraper,
h2 {
margin: 10px 15px;
padding: 0px;
span {
color: red;
}
}
}
Please note that there is a little duplication i.e.
h2 {
margin: 10px 15px;
padding: 0px;
}
we can putt outside the wrappers. But we have different styling for the h2. Can we remove this duplication in LESS?
Thanks
You can mixin these properties:
.heading() {
margin: 10px 15px;
padding: 0px;
}
.text-wraper {
width: 50%;
height:200px;
h2 {
.heading();
}
}
.sucess-wraper-header {
width: 100%;
background-color: #f2f2f2;
&,
.text-wraper,
h2 {
.heading();
span {
color: red;
}
}
}
I have the following CSS:
ul.arbo {
margin-top: 0.5em;
}
ul.arbo li {color
padding-bottom: 0.333em;
}
ul.arbo li:last-child {
color: #333;
}
I can implement the simple CSS using Less. But how do I implement the li:last-child?
Try:
ul.arbo {
margin-top: 0.5em;
li {
color: #444;
padding-bottom: 0.333em;
&:last-child {
color: #333;
}
}
}