Adjusting a side navigation bar

header {font-weight: bold; font-size: 50px;}
article {font-size: 30px;}
p {font-size: 20px;}

#nav-bar {position: fixed;
min-width: 290px;
top: 0px;
left: 0px;
width: 300px;
height: 100%;
border-right: solid;
    border-right-color: currentcolor;
border-color: rgba(0, 22, 22, 0.4);
}
<main id ="main-doc"> 
  <section class="main-section" id = "introductions">
    <header id ="introductions"> Introductions </header>
    <article> This is words and stuff</article>
    <p> This is the P1 text</p>
    <p> This is the P2 text</p>
    <li>This is the 1st list<li>
    <code>This is code one</code>
  </section>
  
  <section class="main-section" id ="article1">
    <header id ="article1">Article1</header>
    <article> This is the first article's text</article>
    <p>This is the P3 text</p>
    <p>This is the P4 text</p>
    <li>This is the 2nd list</li>
    <code>This is code two</code>
  </section>
  <section class = "main-section" id = "article2">
    <header id = "article2"> Article2</header>
    <article>This is the seconds article</article>
    <p>This is the P5 text</p>
    <p>This is the P6 text</p>
    <li>This is the 3rd list</li>
    <code>This is code three</code>
  </section>
  <section class = "main-section" id = "article3">
    <header id = "article3">Article3</header>
    <article>This is the third article text</article>
    <p>This is P7 text</p>
    <p>This is the P8 text</p>
    <li>This is the 4th list</li>
    <code>This is code 4</code>
  </section>
  <section class = "main-section" id = "article4">
    <header id = "article4">Article4</header>
    <article>This is the fourth article tect</article>
    <p>This is the P9 text</p>
    <p>This is the P10 text</p>
    <li>This is the 5th list</li>
    <code>This is code 5</code>
  </section>
  <nav id ="nav-bar">
    <a href="#introductions" id="introductions">Introductions</a>
    <a href= "#article1" id="article1">Article1</a>
    <a href="#article2" id="article2">Article2</a>
    <a href="#article3" id="article3">Article3</a>
    <a href="#article4" id ="article4">Article4</a>
  </nav>
    

Hello! I am currently tackling a Free Code Camp project and require some assistance with repositioning the main page relative to the side navigation bar. My goal is to prevent overlap between the main content and the sidebar by adjusting their positioning. Additionally, I need assistance in aligning the list elements of the navigation bar vertically instead of horizontally. Any guidance or suggestions would be greatly appreciated.

I will share the link to the page for reference.

Answer №1

When it comes to content placement, Flexbox is the way to go.

#container{
display:flex;
justify-content:flex-start;
}

#nav-bar{
display:flex;
flex-direction:column;
margin-right:10vw;
}
<div id='container'>
   <nav id ="nav-bar">
    <a href="#introductions" id="introductions">Introductions</a>
    <a href= "#article1" id="article1">Article1</a>
    <a href="#article2" id="article2">Article2</a>
    <a href="#article3" id="article3">Article3</a>
    <a href="#article4" id ="article4">Article4</a>
  </nav>
  <main id ="main-doc"> 
  <section class="main-section" id = "introductions">
    <header id ="introductions"> Introductions </header>
    <article> This is words and stuff</article>
    <p> This is the P1 text</p>
    <p> This is the P2 text</p>
    <li>This is the 1st list<li>
    <code>This is code one</code>
  </section>
  
  <section class="main-section" id ="article1">
    <header id ="article1">Article1</header>
    <article> This is the first article's text</article>
    <p>This is the P3 text</p>
    <p>This is the P4 text</p>
    <li>This is the 2nd list</li>
    <code>This is code two</code>
  </section>
  <section class = "main-section" id = "article2">
    <header id = "article2"> Article2</header>
    <article>This is the seconds article</article>
    <p>This is the P5 text</p>
    <p>This is the P6 text</p>
    <li>This is the 3rd list</li>
    <code>This is code three</code>
  </section>
  <section class = "main-section" id = "article3">
    <header id = "article3">Article3</header>
    <article>This is the third article text</article>
    <p>This is P7 text</p>
    <p>This is the P8 text</p>
    <li>This is the 4th list</li>
    <code>This is code 4</code>
  </section>
  <section class = "main-section" id = "article4">
    <header id = "article4">Article4</header>
    <article>This is the fourth article tect</article>
    <p>This is the P9 text</p>
    <p>This is the P10 text</p>
    <li>This is the 5th list</li>
    <code>This is code 5</code>
  </section>
  </main>
  </div>

Answer №2

Utilizing flex-box is a great solution for this.

#main-doc {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 80%;
    margin-left: 20%;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using .animate() to set the position, it takes precedence over manually assigning

I'm facing an issue with constantly scrolling objects on the screen, each assigned a number. When you press one of their numbers, it should move far left off the screen and then scroll back on. However, when I try to reassign the position of the eleme ...

Having difficulty converting the navbar into a horizontal layout

I'm struggling to figure out how to display the navbar horizontally across the page instead of vertically. I've experimented with different solutions, but it seems like the issue lies within the ul class. Unfortunately, I haven't been able t ...

What is the best way to resize an image to perfectly fit inside a div in a responsive design?

Currently implementing a fluid layout design using Twitter's Bootstrap. Below is an excerpt from my code: <div class="hero-unit" style="background-image:url('images/ball on sand.JPG'); background-size:100%;"> <h1>Pelican Volle ...

Desktop froze up as modal failed to respond

I recently updated my modal to only work on screens smaller than tablets, which was successful. However, I now need it to also work on desktop size. After trying to change d-none to d-block, it still didn't work. Any suggestions? <div class="col ...

Animating the scale of an element while also adjusting its border-radius using CSS

I'm currently working on an animation that involves scaling a box with a rounded border of 8px. The issue I'm facing is that the rounded angle looks strange when the box is expanded, and I'm trying to avoid changing the width in the keyframe ...

Display PHP Array data in a table on a webpage

I need help arranging the results from a MYSQL database into an HTML table. Right now, each item is displayed in one column per row. Here is my current code: <?php $catagory=$_GET["q"]; $con = mysql_connect("localhost","cl49-XXX","XXX"); if (!$con) ...

What is the process for inserting a scroll bar within a div element?

   I have recently created a webpage using some divs, along with a bit of CSS and JavaScript. I am struggling to figure out how to add a scrollbar to one of my divs. The code is not overly complex, as it includes both CSS and JavaScript. <html> & ...

What is the best technique to incorporate dark/light mode in Bootstrap 5?

Is it best to introduce themes such as dark and light themes in Bootstrap 5 using CSS/SCSS, JavaScript, or a combination of both? Should we create a separate CSS file like dark.css to overwrite classes? Or should we use JavaScript to switch classes like ...

Can SCSS be compiled into CSS specifically tailored for external use on a website or internal use on a specific page?

Typically, I construct websites using Next.js along with external CSS files for compiling from SCSS to CSS, or static/CMS based sites/modules/plugins with Gulp handling the compiling process. However, this approach leads to all CSS being included on every ...

Encountering an issue with the message "chartobject-1.render() Error >> Unable to locate the container DOM element." within a JavaScript function

I have encountered an issue while working with Fusion Charts in my HTML page using JavaScript. When attempting to display two charts simultaneously, I receive an error message that says: "fusioncharts.js:71 Uncaught RuntimeException: #03091456 chartobjec ...

Insert title into PDF document

I am currently working on a react application that generates PDF documents easily. The libraries I have utilized are: jspdf html2canvas Below is the code snippet that demonstrates my approach: index.js: <div className="App"> < ...

Is it possible to extract pages from a PDF document and showcase them?

I have a vision to create a seamless magazine reading experience on a platform, and I want the process of uploading magazines to be quick and smooth. My idea is to utilize PDF files for this purpose. I am wondering if it's achievable to develop a mod ...

Tips for adjusting the font size of the xdsoft calendar datetimepicker

Looking to enhance the appearance of my jQuery calendar within my HTML template with the help of this resource. I've identified that adjusting the font-size is crucial for increasing the size of the calendar. <script> $(function () { $(&qu ...

The current limitation of the Dev.to API restricts the display of only the most recent

For the past 3 years, I've integrated Dev.to's public API into my portfolio to display all of my articles. However, after transitioning my entire portfolio to ReactJS and SaSS from native HTML, CSS, and JS, it now only shows my latest 30 articles ...

The close button within a Bootstrap modal window is experiencing a malfunction

My small JavaScript script is supposed to change the button text from "Subscribe" to "Close" after someone signs up for a newsletter. However, the functionality does not work as expected and the modal box closes instead. Check out an example page here. T ...

The Role of Filling in a Process

I am looking to create a rectangle that fills up gradually every day, increasing by 1% each time. This is the basic concept. My main struggle is figuring out how to fill it up. I need the rectangle to increase by 1% of its width each day. So essentially, ...

Unexpected appearance of DOM elements

I've come across an unusual bug in a web application I've been developing that is reproducible in Chrome and Safari, but not in Firefox. To witness the bug, go to www.lastcalc.com and type a single uppercase letter. The letter will be immediatel ...

Tips for preserving session on an Atheros board with C programming to access a website

Currently, I am utilizing the Atheros development board with LSDK-9.2.0_U10.5.13 stack and mips-linux-2.6.31 Linux version. On the board, I have c file, html, js, and css files, without utilizing the cgi library or any scripting language like php. My curr ...

I'm looking for a way to retrieve an object from a select element using AngularJS. Can

I am working with a select HTML element that looks like this: <select required="" ng-model="studentGroup"> <option value="" selected="">--select group--</option> <option value="1">java 15-1</option> <option value="2">ja ...

Disarray in form saving process across multiple models

I am facing difficulties in displaying the page due to issues with models. I am a beginner in Django and despite trying various solutions, I am unable to resolve the problem. Here is a brief overview: I have created two forms based on interrelated models a ...