Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
a Summer night - @163.58
Activity rating: Four Stars Posts & Arts: 57/1k.beats Random | Recent Posts | Guild Recents
News: :cry: Are u having fun? Guild Events: There are no events!

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  how to... make a sidebar!


« previous next »
Pages: [1] Print Embed
Author Topic: how to... make a sidebar!  (Read 923 times)
fairyrune
Sr. Member ⚓︎
****
View Profile WWWArt


we live to make the impossible possible!
⛺︎ My Room
iMood: fairyrune
Matrix: Chat!
RSS: RSS

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Dino FossilJoined 2025!
« on: an Autumn day » Embed

hello everyone! i'm adding a nav bar to my site, but i'm wondering what the best way to do this would be...

so i'm using a main page div, centered, to make all my elements stay in the middle (the flex boxes, headers,etc). what i did with my previous layout was i made a larger flex box with 3 divs inside. say my sidebar wants a div to be 200px wide, and my middle div with all my content wants to be 900px wide. i'd have a div on the opposite side to the sidebar that's also 200px, and center the flexbox i'm using - which makes the middle bit with all the content stay in the centre of the page even with a sidebar!

hope that makes sense. :ozwomp:

but is there a better way to do this? i want my content to remain exactly where it is, but with a navbar to the side of it, like this.

thanks in advance! i feel like there's something else i can do that would be simpler, but i'm not sure what! :drat:



* Screenshot 2025-11-04 111120.png (415.08 kB, 600x298 - viewed 69 times.)
Logged

☾ "you want to run - i'll run with you" ☼
https://files.catbox.moe/ivdca8.gifhttps://files.catbox.moe/qlgdtd.gifhttps://files.catbox.moe/ji1nvt.gifhttps://files.catbox.moe/9ypmrn.gifhttps://files.catbox.moe/3im96c.gif
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #1 on: an Autumn day » Embed

What you've described sounds like a perfect way to do what you're aiming for.

An alternative might be a grid layout: this would mean that you didn't need the empty "left-hand side" mirror of the sidebar. E.g. assuming you have a <div class="container"> containing a <main> and an <aside> you could do something like this:


Code
.container {
  display: grid;
  grid-template: "unused center sidebar" / 200px 400px 200px;
}

main {
  grid-area: center;
}

aside {
  grid-area: sidebar;
}

This creates an 800px-wide container, reserving 200px for each of two sidebars (called "unused" and "sidebar") and 400px for the "center" column... but then it only attaches things to the "center"  and "sidebar" columns.

I did you a CodePen if that helps explain it.

The end result is basically the same as what you're talking about, though, so just do what makes you most-comfortable!

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif

Artifact Swap: PolyamorousI met Dan Q on Melonland!Joined 2025!
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #2 on: an Autumn day » Embed

Oh, one more option for you if you either (a) don't care about responsive design or (b) are willing to write some media queries to handle mobiles: you could place the sidebar at an exact position using position: absolute.

E.g. with the same HTML, the CSS could be:


Code
.container {
  position: relative;
}

main {
  width: 400px;
}

aside {
  position: absolute;
  right: -200px;
  top: 0;
  width: 200px;
}

Here's how that works:

  • It sets position: relative on the container so that any inner position: absolute is relative to the container
  • Then it sets position: absolute on the sidebar element
  • Finally, it uses a negative-offset for of right: -200px, which is the width of the sidebar but negative (you can made it a larger negative value to move the sidebar "away" from the main content)

I did you another CodePen.

Just another option to consider!

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif

Artifact Swap: PolyamorousI met Dan Q on Melonland!Joined 2025!
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #3 on: an Autumn day » Embed

I gave my second suggestion a go with your website (screenshot attached). Here's how I did it:

I added <nav>this is your new nav!</nav> inside your <div class="flexbox">, right at the top.

Then I added this CSS:


Code
.flexbox {
  position: relative;
}

nav {
  position: absolute;
  top: 0;
  right: -225px;
  width: 200px;
  background: #fff7;
  border: 2px solid #19e119;
  min-height: 400px;
  font-size: 24px;
}



* deerlore-sidebar-nav-demo.jpg (159.76 kB, 1167x821 - viewed 56 times.)
Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif

Artifact Swap: PolyamorousI met Dan Q on Melonland!Joined 2025!
fairyrune
Sr. Member ⚓︎
****
View Profile WWWArt


we live to make the impossible possible!
⛺︎ My Room
iMood: fairyrune
Matrix: Chat!
RSS: RSS

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Dino FossilJoined 2025!
« Reply #4 on: an Autumn day » Embed



i guess i was doing something right then :ok: that's good to know! i'll have a test myself with these options and see how it goes. i learn this kind of coding piecemeal as and when i need it, so i thought i might have missed something about how to optimise this.

thank you so much for your time and suggestions!

Logged

☾ "you want to run - i'll run with you" ☼
https://files.catbox.moe/ivdca8.gifhttps://files.catbox.moe/qlgdtd.gifhttps://files.catbox.moe/ji1nvt.gifhttps://files.catbox.moe/9ypmrn.gifhttps://files.catbox.moe/3im96c.gif
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 MelonLand Editor Recent Edits Tenement Arcade Want to Login or Join ? Forum Art Hub Chat Webring Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Frutiger Aero Forum Onio Club m15o's Web Services 32Bit Cafe iMood Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers
Zap!
Minecraft: Online
Join: craft.melonking.net