Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

`width: fit-content;` is a good tip. Still, it's annoying that the current behavior is the default.

I was not able to get the nth child variants to work:

    <main>
      <div>A</div>
      <div>B</div>
      <div>C</div>
      <div>D</div>
    </main>

    main {
      display: flex; flex-direction: row; justify-content: center;
    /*   width: fit-content; */
    }
    
    div {
      min-width: 400px; height: 300px; background-color: wheat; margin: 4px;
    }
    
    div:nth-child(1){
        margin-left: auto;
    }
    div:nth-last-child(1){
        margin-right: auto;
    }


Simply dont use justify-content in that case. https://codepen.io/inviz/pen/XWQxaOp


Hm, that works well enough as a replacement for `center`, but not any of the `space-*` variants. But "min-width: fit-content" works nicely for all the cases I tried.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: