What is the best way to include two additional columns next to the sidebar?

I'm having trouble adding another two-column section next to the sidebar.

Is there anyone who can help me out?

<!-- -------------Navigation Bar------------- -->

<div class="sidebar">
  <a class="active" href="#home">Home</a>
  <a href="#services">Example 1</a>
  <a href="#portfolio">Example 2</a>
  <a href="#about">Example 3</a>
  <a href="#contact">Example 4</a>
</div>
<div class="col">
  <div class="content">
    <h2>Responsive Sidebar Example</h2>
    <p>This example uses media queries to switch the sidebar to a top navigation bar when the screen size is 700px or less.
    </p>
    <p>We have also included a media query for screens that are 400px or less, which will stack and center the navigation links vertically.</p>
    <h3>Try resizing the browser window to see the effect.</h3>
  </div>

</div>

Answer №1

Take a look at this for adjusting the width as needed

Set up 2 div elements and customize them to your liking, here is just a sample:

.section1{
    background-color:#00ffff;
    width:70%;
    float:left;
    height:100vh;
    border-right: 1vw solid #F5E5D6; 
    box-sizing: border-box;
    margin:0;
    padding:0;  
}
.section2{
    background-color:#f1c40f;
    width:30%;
    float:left;
    height:100vh;
    margin:0;
    padding:0;
  box-sizing: border-box;
}
<div class="sidebar">
  <a class="active" href="#home">Home</a>
  <a href="#services">Example 1</a>
  <a href="#portfolio">Example 2</a>
  <a href="#about">Example 3</a>
  <a href="#contact">Example 4</a>
</div>
<div class="col">
  <div class="content">
  <div class="section1">
    <h2>Editable Sidebar Example</h2>
    <p>This example applies media queries to change the sidebar into a top navigation bar when the screen size is 700px or smaller.
    </p>
    <p>Additionally, there's a media query for screens that are 400px or less, which will stack the navigation links vertically and center them.</p>

    </div>
    <div class="section2">
    Second display
</div>
  </div>

</div>

Answer №2

To accomplish this, encase your content in a container that mimics a row structure with its children aligned as columns. This can be achieved using either display: flex or display: grid, based on your preference.

.row {
  display: flex;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: 20%
}

.content {
  width: 60%
}
<div class="row">
  <div class="sidebar">
    <a class="active" href="#home">Home</a>
    <a href="#services">Example 1</a>
    <a href="#portfolio">Example 2</a>
    <a href="#about">Example 3</a>
    <a href="#contact">Example 4</a>
  </div>
  <div class="content">
    <h2>Responsive Sidebar Example</h2>
    <p>
      This example uses media queries to switch the sidebar to a top navigation bar when the screen size is 700px or less.
    </p>
    <p>
      Additionally, there's a media query for screens 400px or less, which vertically stacks and centers the navigation links.
    </p>
    <h3>Resize the browser window to observe the effect.</h3>
  </div>
  <div class="sidebar-2">
    Another container
  </div>
</div>

Answer №3

Something similar to this

.wrapper {
    display: grid;
    grid-template-columns: 1fr 2fr;
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="stylesheet" href="styles.css" />
        <title>My Document</title>
    </head>
    <body>
        <div class="wrapper">
            <div class="left-sidebar">
                <a class="active" href="#home">Home</a>
                <a href="#services">Service 1</a>
                <a href="#projects">Project 1</a>
                <a href="#about">About Us</a>
                <a href="#contact">Contact Us</a>
            </div>
            <div class="main-content">
                <h2>Responsive Sidebar Demo</h2>
                <p>This demo utilizes CSS Grid for a responsive layout where the sidebar transforms into a top navigation menu when the screen size is small.</p>
                <p>There are also media queries for screens smaller than 400px, which will stack the navigation items vertically in the center of the page.</p>
            </div>
        </div>
    </body>
</html>

Answer №4

I have introduced a new DIV element, so please review it and gather some insights. I have made edits relevant to your code.

 @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');

*{
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
}

.container{
    max-width: 1400px;
    margin: auto;
}
.header{                /* Header */
    padding: 10px 20px;
    background-image: linear-gradient(rgba(0,0,0,0.75), rgba(0,0,0,0.75)),url(/assets/top.jpg);
    background-size: cover;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    
}
   
.fa{                     /* icon color */
    color: white;
}
.comLink:hover{          /* icon hover */
    color: #ccc;
}

input{                  /* Search input*/
    margin-top: 8px;
    padding:6px ;
    border: 1px solid #ccc;
    width: 70%;
    border-radius: 4px;
}
.btn{                   /* Search Button */
    padding: 7.5px;
    background:#f44336 ;
    border: none;
    cursor: pointer;
    border-radius: 4px;
}
.btn:hover{                /* Button hover */
    background: #FF7F50;
}
.links a{
    padding-left: 19px;
}

.logo{                      /* Logo */
    font-family: 'Roboto', sans-serif;
   padding: 40px 0px;
   font-size: 30px;
   text-decoration: none;
   color: white;
   letter-spacing: 8px;
}
span{
    color: #f44336;
}

a{
    text-decoration: none;
}

.myDIV{         /* here is my changes */
  display:flex;
}

li{
    list-style: none;
}
   
.sidebar {
  display:flex; /* here is the changes */
  flex-direction:column; /* here is the changes */
  margin: 0;
  padding: 0;
  width: 200px;
  background-color: #f1f1f1;
  height: 100%;
  overflow: auto;
  position: relative;
}

.sidebar a {
    font-family: 'Lato', sans-serif;
  display: block;
  color: black;
  padding: 16px;
  text-decoration: none;
}
 
.sidebar a.active {
  background-color: #f44336;
  color: white;
}

.sidebar a:hover:not(.active) {
  background-color: #555;
  color: white;
}

/* Content */


@media screen and (max-width: 768px) {
  
.myDIV{      /* here is my changes */
  display:flex;
  flex-direction:column;
}

.sidebar{   /* here is my changes */
    display: flex;
    flex-direction: row;
    width: -webkit-fill-available;
}
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
  }
  .sidebar a {
      float: left;
    }
  div.content {
      margin-left: 0;
    }

  .logo{
      font-size: 25px;
  }
}

@media screen and (max-width: 500px) {
  .sidebar a {
    text-align: center;
    float: none;
  }
  .logo{
      font-size: 25px;
      letter-spacing: normal;
  }
}

.section1{
    background-color:#00ffff;
    width:70%;
    float:left;
    height:100vh;
    border-right: 1vw solid #F5E5D6; 
    box-sizing: border-box;
    margin:0;
    padding:0;  
}
.section2{
    background-color:#f1c40f;
    width:28%;
    float:left;
    height:100vh;
    margin:0;
    padding:0;
  box-sizing: border-box;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <title>Hi There! Aziz</title>


    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="container">

        <!-- -------------Header/Banner------------- -->

        <div class="header">
            <a href="#" class="logo">ABDUL <span>AZIZ</span></a>
            <div class="links">
                <a href="#"><i class="comLink fa fa-facebook-square fa-2x"></i></a>
                <a href="#"><i class="comLink fa fa-github-square fa-2x"></i></a>
                <a href="#"><i class="comLink fa fa-linkedin-square fa-2x"></i></a>
                <a href="#"><i class="comLink fa fa-behance-square fa-2x"></i></a>
                <form action="#">
                    <input type="text" placeholder="Search...">
                    <button class="btn" type="submit"><i class="fa fa-search"></i></button>
                </form>
            </div>

        </div>


        <!-- -------------Navigation Bar------------- -->
    <div class ="myDIV">              <!-- here is the DIV I added-->
        <div class="sidebar">
            <a class="active" href="#home">Home</a>
            <a href="#services">Example 1</a>
            <a href="#portfolio">Example 2</a>
            <a href="#about">Example 3</a>
            <a href="#contact">Example 4</a>
        </div>
        
        <div class="col">
            <div class="content">
                <div class="section1">
                    <h2>Responsive Sidebar Example</h2>
                    <p>This example use media queries to transform the sidebar to a top navigation bar when the screen
                        size
                        is
                        700px or less.
                    </p>
                    <p>We have also added a media query for screens that are 400px or less, which will vertically stack
                        and
                        center the navigation links.</p>

                </div>
                
                <div class="section2">
                    2nd screen
                </div>
                
            </div>
        </div>                
     </div>
   </div>
</body>

</html>

I have indicated "here is my changes" like that to identify my modifications

Please see the updated answer

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

Subtract and include characters in a string

Can you help me swap out \n for a new line? Below is the content retrieved from the database: <!DOCTYPE html>\n<html>\n<body>\n<div>\n<label class=\"s20 c03\">Label</label>\n< ...

Database insertion failed due to a data error

I'm struggling to insert data into a MySQL database using PHP based on a condition check, but the process is not functioning as expected. The initial condition is working correctly, but the second condition fails to insert data into the database; ins ...

What is the best way to use CSS to hyphenate a capitalized word?

I have a single word that needs to be hyphenated, but the lang=en hyphenate: auto property does not work on capitalized words. To address this, I utilized the slice function in JavaScript to split the word in half so that the second half, which requires h ...

The moving div suddenly halts before continuing its journey

Two overlapping divs create an interesting sliding effect. A gray div slides in from the top over a black div. Hovering your mouse over the black div causes the gray one to slide out of view. If you hover over the gray div, it also slides out but pauses ...

Unable to display PHP response in a div using AJAX - issue persisting

Hey there! I'm currently working on a project where I want the form submission to load a response into a div without refreshing the page. I've looked at various examples of ajax forms with PHP online, but haven't been able to solve my issue ...

Selection of text within a block resembling a bar of buttons

design.css body { background-color: #666666; margin-left:500px; margin-right:500px; margin-top:10px; margin-bottom:20px; font-family:Verdana, Geneva, Tahoma, sans-serif; font-size:12px; color:white; } div.header { bac ...

Extracting information from HTML and transferring it to Javascript using jQuery

My goal is to utilize jsGrid for showcasing database data without repeating code extensively. I aim to generate separate grids for each <div> with a specific id while passing on relevant values accordingly. To clarify my objective, here's a sni ...

Child element does not follow z-index rules

I have a website Suoi Hong Resort However, the menu block displays behind the logo. The navigation class has a position of absolute and a z-index of 3. The logo has a position of absolute and a z-index of 2. The menu block has a z-index of 10. Despite th ...

What is the best way to integrate multiple HTML static pages within an ASP.NET MVC project while utilizing the Layout page?

I am currently working on an MVC project that requires me to include 40 static pages. I would like these pages to utilize the Layout page. What would be the most efficient method to achieve this? I have searched for answers to this question before ...

I am encountering issues with an HTML table that is in need of fixing, and I must find a solution without relying on

Can someone help me troubleshoot the structure of this table in the given image? It seems like my rowspan and colspan attributes are not working as expected. I've only used CSS to specify the width and height of the cells. https://i.sstatic.net/VtHbH ...

When a base html tag is dynamically added, the browser mistakenly loads assets twice

When managing relative paths on a website, I utilize the <base> tag within the <head> section of each page. Although all resources loaded via relative-like paths in the documents are displayed correctly, my observations show that browsers such ...

Creating an If statement to evaluate the state of a parameter

In my simple Graphics User Interface, when the user clicks on "move", a yellow rectangle div moves across the screen. Now, I am trying to implement an event based on the position of the rectangle on the page. For example, if the div is at 400px (right), t ...

Folded Corner Div using only CSS

I've been tirelessly experimenting with countless online methods, but I can't seem to make anything work. There's a div that needs to be flexible in width and height, positioned on a tile-able background image with a 1px border. The challe ...

Tips for creating unique Styles for H1, H2, and H3 with MaterialCSS by utilizing createTheme

In my application built with NextJS and styled with MaterialCSS, I have created two themes: a dark theme and a light theme using the following code: import { createTheme } from '@mui/material/styles'; export const darkTheme = createTheme({ pal ...

What is the best way to create a collage of images with a random and unique arrangement?

Recently, I stumbled upon a website and was intrigued by the unique effect of images randomly appearing on the screen. I'm curious about how this effect can be achieved. Is it possible to use CSS Grid to divide the screen and designate some grid ite ...

How many logical lines of code are in the Ubuntu operating system?

As I develop my web application, it is crucial for me to track the lines of code written in languages such as php, css, html, and JavaScript specific to the /var/www directory. However, when using the command line code counter tool, I find myself tempted ...

problems with an extra administrator account access

Is it possible to have a single login form that can cater to both users and admins? I currently have a user login system in place but would like to add an admin login as well. How can I implement this without creating separate logins? if(isset($_POST[&ap ...

When attempting to send data using jQuery to PHP, an issue arises where PHP is unable to receive the information, resulting in an undefined variable

Has anyone successfully sent data from an HTML select to a PHP file using jQuery? I've tried multiple solutions suggested here, but none seem to be working for me. Below is the code I'm using: <select id="city" name="city" > <optgro ...

A common occurrence is for jQuery/Javascript Ajax POST to generate 6 identical posts when used within a .each loop, happening approximately 20

Context: Building a jQuery mobile phonegap application with multipage-ajaxload and sisyphus enabled form that utilizes an AJAX POST loop to interact with a GUI database. The process involves posting 171 section entries, along with one summary entry to a se ...

SQL query for finding the number of shared nodes between two given nodes

How can we determine the common nodes between two specific nodes in SQL, using the following example: Count the occurrences of <li> tags between <h2 id="vgn">VGN A </h2> and <h2 id="vgn">VGN </h2>, as well as the total number ...