12

How to implement an immediate parent selector in SASS, SCSS?

 2 years ago
source link: https://www.codesd.com/item/how-to-implement-an-immediate-parent-selector-in-sass-scss.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to implement an immediate parent selector in SASS, SCSS?

advertisements

I have HTML layout as below:

<div class="card">
    <div class="section">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
</div>

Compiled CSS should look like:

.card{
}

.card .section .item{
}

.card .section .item+.item{
}

What I'm writing in SCSS:

.card{

    .section{

        .item{

            &+&{
            }
        }
    }
}

Can we have something like & + &, which is not working, I do not want to write,

.card{

    .section{

        .item{
        }
        .item+.item{
        }
    }
}


& is the parent selector, you can't use two & because then you'd be out of the scope. In that case, just go up one block.

#main {
  color: black;
  a {
    font-weight: bold;
    &:hover { color: red; } /* Look at notes below */
  }
}

Compiles to

#main {
  color: black; }
  #main a {
    font-weight: bold; }
    #main a:hover { /* parent selector is replaced :D  */
      color: red; }

If you used two & adjacently you would be in the parent of the parent, which wouldn't make sense since you can just write your sass or scss one code block higher in the hierarchy.

DOCUMENTATION: Referencing Parent Selectors: &

Related Articles

How difficult is it to overprint selectors in SASS / SCSS?

I have a .scss file that, among other things contains this: nav { font-size: 0; ul { margin: $padding/3; } li { z-index: 10; position: relative; display: inline-block; font-size: $fontSize; /** * If we want separated, Uncomment! margin: $padding/3; @

How to implement a gradient color selector in a code?

I'm wanting to program something like Photoshop's gradient color picker. I've been googling but can't find anything. Do you guys know how to do it?It's a bit out of date (and .NET if that's your choice of framework), but in the past I've implemented

How to implement Insert, Update and Delete in a parent class that works for all database models using sqlite-net?

I'm using a SQLite database in a Windows 8 Store Application. Furthermore I use the SQLite wrapper sqlite-net to do operations on the database. I will explain this in detail so that you understand my situation. There are Model classes that contain th

Faking the: has () & ldquo; parent selector & rdquo; using only CSS

It's long been hailed as the answer to many selector problems, even disputed by some as entirely unnecessary, but the Selectors Level 4 pseudo-class :has(), better known as the parent selector, is the only one from Level 4 that will not be implemente

Symfony2 - How to implement nested records and recursive functions in Entity Field or Twig Layout?

I have a serious doubt about doing a combo box with nested records from an entity in Symfony2. I have read about nested tree extension for Doctrine 2 in http://gediminasm.org/article/tree-nestedset-behavior-extension-for-doctrine-2, it appears to be

How to Implement a Default Upload to uiscrollview

How to implement lazy loading to uiscroll view I am taking 15 images from the web service and add it to UIscrollview I want to lad the scroll view with temporary image and when the image is ready it can add the image to uiscrollview -(void)loadthscro

How to Implement Static CGRect and CGFloat

I'm looking on the net but I can not find a clear answer ..          In your opinion what is the best way to make these functions static? CGRect ScreenRect = [[UIScreen mainScreen] bounds]; CGFloat screenwidth = screenRect.size.width; CGFloat screenH

How to Implement Line Numbering in h: dataTable

I have this JSF table with pagination. <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3

How to implement code for signal loss or site?

In my app I am using webservices. I have implemented the Network Reachability using Reachability class. But that checks only when i start my application. Note that, while downloading the data if loss of signal or site down occurs, I want to show the

How to skip running a parent method to run the grandparents method?

Possible Duplicate: How do I get a PHP class constructor to call its parent's parent's constructor I know this sounds strange, but I am trying to get around a bug. How can I call a grandparent method? <?php class Person { function speak(){ echo 'pers

How to get the nearest parent node given a text node in jQuery?

Assuming I have a selector for a text node in jQuery, how can I get the parent node? $('selector_for_your_textnode').parent() for a jQuery object, or $('selector_for_your_textnode').parent()[0] for a regular DOM object. You might also use .closest('e

What is the difference between .closest () and .parents ('selector')?

What's the difference between these? Is one more efficient than the other? I'm a little bit confused to why they both exist. Say I have this markup: <table> <tr> <td>...</td> <td><span class='toggle'>Toggle</span>

How to Implement OnFragmentInteractionListener

I have a wizard generated app with navigation drawer in android studio 0.8.2 I have created a fragment and added it with newInstance() and I get this error: com.domain.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.ClassCastException: com.do

How to implement Touch Up Inside in touchBegan, touchEnded

I'm wondering if someone knows how to implement the "touch up inside" response when a user pushes down then lifts their finger in the touchesBegan, touchesEnded methods. I know this can be done with UITapGestureRecognizer, but actually I'm tryin

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK