Giter Club home page Giter Club logo

chevron's Introduction

The Chevron

Instructions from Lars

I made this a few days ago, when you click the chevron > the block beneath it becomes visible and when you click it again it toggles back to hidden.

It’s pure CSS, no JavaScript at all. Can you tell me how I did it? Or make one yourself.

The simplest form is between 10 and 20 lines of CSS. If it gets much more than that ask me and explain your process.

chevron

Round 1

  1. The <input type="checkbox"> is the right way to go. When a checkbox input is 'checked' it triggers a pseudo selector called :checked You can listen to :checked in order to hide or show elements.

  2. Then there’s another thing, a label is connected by id to an input. That means that if you click the label, the input toggles.

In this case you can hide the actual input, because you don’t need it for this. In the label text you can put the chevron > see more.

  1. Finally, the order of elements matters because in CSS there are sibling selectors, + selects the next sibling, ~ selects all following siblings. But you can’t select a previous sibling or a parent. So the label, input and the element that you want to hide/show need to be adjacent siblings, in a certain order.

Final Comments

Q: For the owners boxes (the ones with the names), you're not using display: flex, right? Considering the display: none?

A: For the gray boxes with the owners I use display: grid; in a separate nested div

<div class="unit-new-form">
    <div class="toggle-more">
        <input type="checkbox" name="view-more-ownership" id="view-more-ownership" class="view-more">
        <label for="view-more-ownership">...</label>
        <div class="additional-fields">
            <div class="owner-container">...</div>
        </div>
    </div>
</div>
er {
    max-width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-auto-rows: 100px;
    grid-gap: 10px;
}

Q: In your real project, did you draw the chevron using CSS?

A: In my real project I used a Font Awesome chevron https://fontawesome.com/icons/chevron-right?style=solid.

I normally wouldn’t draw a lot with CSS, I’d use an SVG in that case (you can also manipulate those with CSS/JavaScript).

If you do want to draw with CSS then you can find a few basic shapes here, but they’re always a bit hacky https://css-tricks.com/the-shapes-of-css/

Q: Any details that caught your attention while looking at my code? Naming? Use of selectors?

A: Your code is fine, it’s quite an improvement in terms of structure in comparison to what you showed me earlier. I don’t really have any remarks in this, the only thing I noticed is that you used -webkit-transform: rotate(90deg); instead of just transform: rotate(90deg);

Resources

Can I have an onclick effect in CSS?

Child and Sibling Selectors

How do you order your CSS properties

chevron's People

Contributors

mirhamasala avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.