Im trying to figure out how can i improve my work with sass using BEM. Should i change anything in my code below? I think It's really clean in HTML but in SASS it's hard to find out what is nested in what block. I have one .c-header class at the top and all items in one line using '&'. How can i fix it and make it better?
<header class="c-header">
<nav class="c-header__nav">
<div class="c-header__logo">
<a href="#">
<div class="c-header__circle">
<i class="c-header____leaf fab fa-envira"></i>
</div>
<h1 class="c-header____title">treehouse</h1>
</a>
</div>
<i class="c-header____burger fas fa-bars"></i>
<ul class="c-header__menu">
<li class="c-header__item">home</li>
<li class="c-header__item">about</li>
<li class="c-header__item">blog</li>
<li class="c-header__item">portfolio</li>
<li class="c-header__item">contact</li>
</ul>
</nav>
<div class="c-header__content">
<h1 class="c-header__caption">creative digital solutions</h1>
<p class="c-header__paragraph">Lorem ipsum dolor sit amet consectetur.</p>
<button class="c-header__button">view portfolio</button>
</div>
</header>``
It's one of the purposes of BEM: Make your CSS less dependent of your HTML structure.
That's why we don't have special classes for grand children element. In other words, that's why the .block__element__sub-element classes are forbidden.
According to the official documentation:
Besides the fact that the classes look much nicer, it makes the elements be dependent on the block only. So, you can easily move them across the block when providing changes to the interface. The changes of the block DOM structure would not need corresponding changes to the CSS code.
So yes, your HTML is pretty clean here. And I'm sure your CSS is clean too ;)
PS: some of the classes have too much background, like c-header____burger.
With BEM you should aim to create a cascading hierarchy, so that you can leverage SASS nesting and write your SCSS in components-like structure.
c-header
c-header__nav
c-header__nav__logo
c-header__nav__logo__circle
c-header__nav__logo__title
In that way your SASS should be:
.c-header {
width:100px;
&__nav {
width:101px;
&__logo {
width:102px;
&__circle { width:103px; }
&__title { width:104px; }
}
}
}
Please note that the proposed structure is quite a guess, since I don't have a clear overview of how you project looks but I hope it helps to clarify your doubts.
Related
I am beginning with AsciiDoctor and I want to output HTML. I've been trying to figure out how to create custom class in divisions, I searched google, manuals etc. and couldn't find a solution. What I want to do is simply write something like this:
Type the word [userinput]#asciidoc# into the search bar.
Which generates HTML
<span class="userinput">asciidoc</span>
but I want to have div tags instead of span. Is there any way to do it or should I just use something like
+++<div class="userinput">asciidoc</span>+++ ?
I think what you need is called "role" in Asciidoctor.
This example:
This is some text.
[.userinput]
Type the word asciidoc into the search bar.
This is some text.
Produces:
<div class="paragraph">
<p>This is some text.</p>
</div>
<div class="paragraph userinput">
<p>Type the word asciidoc into the search bar.</p>
</div>
<div class="paragraph">
<p>This is some text.</p>
</div>
You have now a css selector div.userinput for the concerned div.
See 13.5. Setting attributes on an element in the Asciidoctor User Manual (you can also search for "role").
You may want to use an open block for that purpose:
Type the following commands:
[.userinput]
--
command1
command1
--
Producing:
<div class="paragraph">
<p>Type the following commands:</p>
</div>
<div class="openblock userinput">
<div class="content">
<div class="paragraph">
<p>command1</p>
</div>
<div class="paragraph">
<p>command1</p>
</div>
</div>
</div>
The advantage is it can wrap any other block and is not limited to only one paragraph like the other answer.
For slightly different use cases, you may also consider defining a custom style.
I am using protractor to test my site. I countered a problem.
I have a ul, the number of li inside is dynamic,
<ul>
<li class='listing-item'>
<div class='prod-price'>$99</div>
</li>
<li class='listing-item price-onsale'>
<div class='prod-price'>$99</div>
<div class='prod-saving'>$10</div>
</li>
<li class='listing-item'>
<div class='prod-price'>$50</div>
</li>
...
</ul>
The 'prod-saving' div will only show up when 'price-onsale' class is present. I want to use protractor to test this logic, is there a way to do it? something like:
expect(elment(by.className('price-onsale').isPresent()).toBe(true).when('price-onsale).isPresent();
Your syntax will work almost word-for-word if you rearrange it a bit:
element(by.className('price-onsale')).isPresent().then(function(present) {
if(present) {
expect(element(by.className('prod-saving')).isPresent()).toBe(true);
}
});
It's a matter of testing the pre-condition first, and then testing the main condition based on the result of the first.
I am trying out Playframework with Polymer as a GUI tool. As a JSF developer, I am not really used to developing these ajax codes.
For now, I have this situation in my main.scala.html:
<core-scaffold>
<core-header-panel navigation flex mode="seamed">
<core-toolbar>Painel Administrativo</core-toolbar>
<nav>
<core-menu selected="0">
<paper-item noink>
<a href="#routes.ProjetoController.listar()">
<core-icon icon="settings"></core-icon> Projetos
</a>
</paper-item>
<paper-item noink>
<a href="#routes.TipoProjetoController.listar()">
<core-icon icon="settings"></core-icon>Tipos de Projetos
</a>
</paper-item>
</core-menu>
</nav>
</core-header-panel>
<div tool></div>
<div fit>#content</div>
</core-scaffold>
Question is: Is there a way of calling the routes I have into the paper-item elements and partially render it into #content ?? If so, how could I achieve this one page style behavior, without the page resfresh?
PS.: these are not static content.
ProjetoController.listar() should render projeto_listar.scala.html and TipoProjetoController.listar() should render tipoProjeto_listar.scala.html. Those are 2 different dynamic pages which implments main:
#()
#main("Page Title") {
}
Take a look at Page.JS, you can make all the routes in the single page format.
I am trying to get the error message off of a page from a site. The list contains several possible errors so i can't check by id; but I do know that the one with display:list-item is the one I want. This is my rule but doesn't seem to work, what is wrong with it? What I want returned is the error text in the element.
//*[#id='errors']/ul/li[contains(#style,'display:list-item')]
Example dom elements:
<div id="errors" class="some class" style="display: block;">
<div class="some other class"></div>
<div class="some other class 2">
<span class="displayError">Please correct the errors listed in red below:</span>
<ul>
<li style="display:none;" id="invalidId">Enter a valid id</li>
<li style="display:list-item;" id="genericError">Something bad happened</li>
<li style="display:none;" id="somethingBlah" ............ </li>
....
</ul>
</div>
The correct XPath should be:
//*[#id='errors']//ul/li[contains(#style,'display:list-item')]
After //*[#id='errors'] you need an extra /, because <ul> is not directly beneath it. Using // again scans all underlying elements for <ul>.
If you are capable to not use // it would be better and faster and less consuming.
It seems like {PreviousPost} and {NextPost} is not working on Tumblr for creating custom themes. Here's my code. Can someone point to my mistake...
<div>
{block:PreviousPost}<span>Previous Post</span>{/block:PreviousPost}
{block:NextPost}<span>Next Post</span>{/block:NextPost}
</div>
You need to wrap it in {block:PermalinkPagination}…{/block:PermalinkPagination} blocks, like this:
{block:PermalinkPagination}
{block:PreviousPost}
<a rel="prev" href="{PreviousPost}">{lang:Previous Post}</a>
{/block:PreviousPost}
{block:NextPost}
<a rel="next" href="{NextPost}">{lang:Next Post}<a/>
{/block:NextPost}
{/block:PermalinkPagination}