• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CSS - Need box to stick to the left side of the page

Community Beginner ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

I'm in Squarespace trying to create a sidebar using their plugin. PROBLEM - my sidebar (the reddish/brownish block on the left) is floating on the left side of the page. I want it to be attached to the left side of the page. What property or style do I need to use to get it to stick to the left side of the page?

This is how it looks now sidebar.jpg

Views

4.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2019 Jan 01, 2019

Copy link to clipboard

Copied

LATEST

What you're looking for is keeping the HTML structure out of the site flow (usually) and then using the CSS position property, setting it to fixed. That will allow you to use the properties top/bottom/left/right and adjust how many pixels away from those edges you want your content. Finally, if it should be on top of other content, you can use the z-index property, setting it to a higher value than the content below it to assure it visually appears on top.

For example, to stick it 50px below the top and 0px from the left edge, you can do this:

HTML:

<div class="your-class-name">

   ...content...

</div>

CSS:

.your-class-name {

   position: fixed;

   top: 50px;

   left: 0;

   z-index: 100;

}

The bar will now stick to the left side of the screen and will not scroll with the page.

Edit:

If you do want it to scroll with the page, simply change the CSS above from postiion: fixed; to position: absolute; .. And make sure your HTML is directly inside the container you want to position it with. For the browser window, just make sure it's at the <body> level.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines