DEV Community

Cover image for Daily Code 69 | CSS Position (🟥 HTML & 🟦 CSS Course 11)
Gregor Schafroth
Gregor Schafroth

Posted on

1

Daily Code 69 | CSS Position (🟥 HTML & 🟦 CSS Course 11)

It’s HTML & CSS course day 11! Now about 80% through this course already: https://www.youtube.com/watch?v=G3e-cpL7ofc

Today we look at CSS position, apparently the last major thing to learn here.

My Code

Below is some practice code fot this. What’s interesting for position: fixed; is that I can use both left: 0; and right: 0; (or any other value) to just stretch the content.

Also interesting to know is that the best way to avoid the header blocking content below is to just add padding-top to the boddy.

<body style="
  padding-top: 50px;
">

  <div style="
    background-color: black;
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    ">header</div>
  <div style="
    background-color: lightblue;
    height: 200px;
    width: 200px;
    position: static;
    ">div 1</div>
  <div style="
    background-color: lightpink;
    height: 200px;
    width: 200px;
    ">div 2</div>
Enter fullscreen mode Exit fullscreen mode

The same thing applies to sidebars. So for YouTube that means the CSS might have something like this

body {
  margin: 0;
  padding-top: 80px;
  padding-left: 80px;
}
Enter fullscreen mode Exit fullscreen mode

So that’s it. At this point I’m not posting the whole YouTube code anymore, as it gets too complex for you to follow. If you want that follow the linked course above instead 🙂

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

Top comments (0)

Sentry image

Make it make sense

Only the context you need to fix your broken code with Sentry.

Start debugging →

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay