BEM - How to add a condition to a modifier? - bem

I have positioning modifiers for my project's images. One of them is .image_stuck_left.
In the layout there is an image that should stick to the left only on wide screens.
How should I add this condition to the existing modifier?
Is image_stuck_left_viewport_wide a good name?

Independent blocks should not know about positioning. Consider using mixes instead.
For you case it'd be something like this. Let's have a block called some-section where images should stuck to the left. In this case you may mix universal image block with an element of some-section: <img class="image some-section__image"> and apply styles about positioning to .some-section__image.
As for wide viewport just use media queries for .some-section__image. No need for additional classes in this case.
PS: image_stuck_left_viewport_wide is not a valid naming according to https://en.bem.info/methodology/naming-convention/

Why would an image stick to left only on widescreen?
This doesn't seems to be a responsibility for the image only, but a responsibility for the layout, certainly its parent block.
Considering the following HTML:
<div class="page">
<img class="image image--stuck-to-left-on-wide-screen" />
<div class"page__content">
<p>...</p>
<p>...</p>
</div>
</div>
I would create what I call a nest, it just an element made to welcome a child block. A nest is a great way to decide the size and position of a child block.
So I would write:
<div class="page">
<div class"page__image">
<img class="image" />
</div>
<div class"page__content">
<p>...</p>
<p>...</p>
</div>
</div>
So now, the element page__image could define all the logic we need for the position. For example "stuck to the left on wide screen":
#media (min-width: 1200px) {
.page__image {
position: absolute;
left: 0;
}
}
I'm not a fan of BEM mixes. The concept is really near of what I call "nest", but:
A nest is not a new concept, it's just a normal element
A mix breaks the isolation between two components.

Related

Cannot get radio buttons to align with text correctly in pdf

I have an html fragment that looks like this:
<style>
.r {
display: flex;
}
.d-flex {
display: flex;
align-items: center;
}
</style>
<div class="r">
<input type="radio" disabled="disabled" value="1">
<div class="d-flex">
<span class="answernumber">1) </span>
<div class="answer"><p>One</p></div>
</div>
</div>
When I render this in a browser the radio button, the "1)" and the "One" are all aligned nicely. But when I render this html in a pdf the radio button is not aligned with the text. I have tried multiple alternative style definitions for the classes r, d-flex, answernumber and answer and also for the input[type="radio"] and every time it looks good in a browser, the result is no good in the pdf.
Interestingly, check boxes work just fine. Is there a way to get the html to render in the pdf aligned? Or is this something that needs to be fixed inside iText?
The html inside the div.answer may be much more complex and I have no control over it as it is delivered to me by an external system, so I am limited as to what I can do with the html. What I am in control over, is the style definitions and any configurations to be done to iText (perhaps some ConverterProperties).

SCSS bootstrap btn-group Media Query multiple pages

I am working on an application in Ruby. It has 8 pages and on each one of the pages the general layout is bootstrap's .container . row .col-sm-6 .col-sm-6 layout. I have a btn-group in the 2nd col-sm-6 layout that looks great on lg, xl and s devices.
When the screen falls between 992px-768px the button group breaks in an unpleasant fashion
It adjust well when the columns shift one on top of the other on small screens 544px-768px and Breaks bad again on xs devices < 544px
.
I have found a nice solution where I make the btn-group vertical on xs screens by duplicating the code adding the btn-group-vertical to duplicated code and hiding this code until it detects an xs screen (then it hides the horizontal btn-group). However, this is a lot of duplicate code that I have to replicated on 8 pages and still doesn't solve for medium screens.
I thought about keeping my code cleaner by adding scss like this:
.myClass {
#media (max-width: 760px) {
&:extend(.btn-group-vertical all);
}
#media (min-width: 761px) {
&:extend(.btn-group all);
}
}
That I found on stack overflow question 31893581. It doesn't work even with the manipulations that I thought would work. I could follow the solution stated in that same post but I am uncertain how sanitary that would be etc.
If somebody has any advice for me on how to solve for a class that pulls in bootstrap classes at specific browser widths or a completely different solution to my problem, I am all ears.
Thanks in advance.
I can think of a number of ways to do this, here are two methods that are easy to picture:
https://codepen.io/panchroma/pen/XgojBL
Add a clearfix div at the point where you want the buttons to break, then use media queries to hide or show this div.
Another method instead of using a clearfix would be to target .btn-group in your CSS, and using media queries set a max-width at viewports 768 - 992 px.
Good luck!
HTML
<div class="container">
<div class="row">
<div class="col-sm-6">first col</div>
<div class="col-sm-6">
<div class="btn-group">
<button type="button" class="btn btn-primary">btn-1</button>
<button type="button" class="btn btn-primary">btn-2</button>
<div class="cf"></div>
<button type="button" class="btn btn-primary">btn-3</button>
<button type="button" class="btn btn-primary">btn-4</button>
</div>
</div>
</div>
</div>
CSS
.btn-group .cf{
display:none;
}
#media (min-width: 768px) and (max-width: 992px) {
.btn-group .cf{
display:block;
}
}

Using a background image with an 'H' tag

I followed the answers to try to achieve a similar look to be found here www.thexxcorporation.com
The first header is using a shortcode (its a Wordpress site).
My problem is that the shortcodes don't reflect their actual styling setting, therefore, I'm trying to reproduce the look, but with my own sizes, images etc.
I've tried this:
h1:after
{
background:url(image path);/* apply your image here */
background-repeat:repeat-x;
content:" ";
position:absolute;
width:999em;
height:25px;
margin:10px 0 0 5px;
}
This, almost works, but has a problem. The style relates to headers that are with a content div. My other hears fit within the div fine (100% of the width of the div).
The above code results in the background image overflowing outside the content div it sits within.
So, how do I constrain it to the width of the div it sits within?
My page code looks like this:
<div id="main-content" class="clearfix">
<header id="page-heading">
<div class="boxed">
<h1>Test</h1>
</div><!-- /boxed -->
</header><!-- /page-heading -->
<div id="home-content" class="clearfix boxed container">
<article id="post" class="clearfix">
<div class="entry clearfix fitvids">
<h1>Test page for H1</h1>
</div><!-- .entry .clearfix -->
</article><!-- #post -->
<aside id="sidebar">
</aside><!-- /sidebar --></div><!-- #home-content -->
<div class="clear"></div>
The containing divs are set with position:relative.
If I add position:relative to the h1:after - the background image disappears.
slightly baffled.
Cheers,
Mike
the div it sits within should in relative position. add this style to the div
position:relative;
and the h1::after should have 100 percent width - don't use em. change the width to
width:100%;
hope this helps
cheers

Is it possible to calculate padding based on another element's height with SASS?

I am confused as to what to use for this. Is it possible to use SASS to calculate the padding for an element based on another's height?
for example:
<div class="element-1">
<h2>Some Title</h2>
</div>
<div class="element-2">
<h2>Element Contents</h2>
</div>
Styles for the elements (varying according to screen size):
.element-1{
height:200px;
#extend .pos-fixed;
width:$site-width;
}
.element-2{
width:$site-width;
padding-top:calc(element-height(.element-1)+20px);
}
Compass enables me to do a similar thing with image-height and image-width, but how can apply this with padding-top:element-height(.element-1)+20px;?
Is this possible?

EmberJs: nested views

I have this view which can rotate a div element. Something like
<div class="rotatable">
<div class="front">
{{outlet front}}
</div>
<div class="back">
{{outlet back}}
<div>
</div>
Now I have this index template which contains two of these rotatable elements. Each rotatable elements has a different front and back. So it could look like this
<div id="index">
{{#rotatable}}
{{outlet front App.FrontView1}}
{{outlet back App.BackView1}}
{{/rotatable}}
{{#rotatable}}
<div>This should show up inside {{outlet front}}</div>
{{outlet back App.BackView2}}
{{/rotatable}}
</div>
This doesn't work of course, but how should this be done ?
Cheers
I guess this question was a little bit unclear. Anyway, the answer is given in this post
EmberJs: how to use connectOutlet

Resources