question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Let there be less divs

See original GitHub issue

Now that CSS grid is out and we’re finally able to implement sites semantically and lay out stuff nicely without enormous amounts of divs and hacks it would be very nice to see this principle followed in frameworks such as next.js. Unfortunately that’s not the case at the moment.

I’m currently following the tutorial and I already have…

<body>
  <div>
    <div id="__next">
      <div data-reactroot="" data-reactid="1" data-react-checksum="315191458">
        <!-- my content full of wrapper divs because of react.js -->
      </div>
      <div id="__next-error"><!-- guess this exists only in dev mode -->
    </div>
  </div>
  <div>
    <script>...</script>
    ...
  </div>
  <script>...</script>
</body>

Expected Behavior

I think only div we should have is the react root div.

Current Behavior

I see a few unnecessary looking divs.

Steps to Reproduce (for bugs)

  1. Follow the first tutorial until it works.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:28
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
timneutkenscommented, Feb 1, 2018

Fixed in canary. <> can’t be used yet because it requires the beta version of babel. Which we’ll integrate in next.js v6.

7reactions
jul-shcommented, Nov 11, 2017

would recommend a small edit to the workaround by @lancejpollard:

/* normalize divs surrounding the content*/
      body > div:first-child,
      #__next,
      #__next > div,
      #__next > div > div {
        height: 100%;
      }

This is to avoid the #__next-error div blowing up to 100% as well.

This is pretty darn hacky though. 😦 I would rlly appreciate it if the div inside of body could at least have a className, so I don’t have to try to target it using body > div:first-child which feels bad to do

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Less Divs
A blog about html, css, javascript, focusing on accessibility.
Read more >
Let there be less divs · Issue #2708 · vercel/next.js - GitHub
I think only div we should have is the react root div. Current Behavior. I see a few unnecessary looking divs. Steps to...
Read more >
Stop using so many divs! An intro to semantic HTML
My point in this thread was to let you know that there is a very real difference between arbitrary nonstandard elements, which have...
Read more >
CSS how to fill remaining space (1 div with smaller divs)
It may look good at 100% but when zooming, they will almost always give rounding errors. I would recommend using pixels or em's....
Read more >
Semantic HTML Guide – 10 Alternatives to Using divs
You can also use a footer element as a closing within a <section> element. Less common alternatives to div. There are also some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found