Creating a layout similar to Facebook can be achieved by utilizing HTML and CSS, specifically using flexbox to structure

I am looking to create a website layout similar to Facebook, with the following features:

  1. A fixed or sticky header and no footer
  2. 3 div elements, where div1:div2:div3 = 1:2:1
  3. 3 scroll bars to control each div... Scroll-1 and scroll-3 will be inside div-1 and div-3 respectively to control their content. Scroll-bar-2 will be on the right side of the main body to control the content of div-2.
  4. A fully fixed page without any extra scroll bars, testing by adding lorem1000 in each div

I would appreciate your assistance in creating this layout. Thank you in advance.

Here is the HTML code that I have written:

<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/style.css">
    <title>test</title>
</head>

<body>
    <nav>
        <h1>This is nav</h1>
    </nav>
    <div class="row">
        <div class="col-3">lorem1000</div>
        <div class="col-5">lorem1000</div>
        <div class="col-3">lorem1000</div>
    </div>
</body>
</html>

I would really appreciate your help in achieving this layout goal. Thank you in advance. https://i.sstatic.net/Ufvrd.png

Answer №1

After reviewing the photo of your idea and examining your html

Implementing css grid

By using css grid, you can simplify the code by applying styles only to the parent element :)

In this scenario, use the class names you previously defined (.col-3, .col-5)


I have used these classes to distribute the width equally into sections (fr). The sidebars account for 3 fractions of the screen space each, while the mainDiv takes up 5 fractions... making the mainDiv wider than the sidebars.

This layout is responsive, allowing you to adjust the values of fr as needed (ensuring the first and last values are the same, with the middle value larger than the sidebars).

  display: grid;
  grid-template-columns: 3fr 5fr 3fr;

body {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.5rem;
}

.row {
  gap: 0.5rem;
  display: grid;
  grid-template-columns: 3fr 5fr 3fr;
}

nav,
.row>div {
  border-radius: 0.3em;
  border: 1px solid rgb(0, 51, 255);
}

.col-3 {
  overflow: scroll;
}
<!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">
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <nav>
    <h1>This is nav</h1>
  </nav>
  <div class="row">
    <div class="col-3">sideBar</div>
    <div class="col-5">mainContent</div>
    <div class="col-3">sideBar</div>
  </div>
</body>

</html>

Answer №2

Utilizing grid, I positioned the container with a relative setting, which serves as the container for the left, middle, and right divs. The left and right divs have a specific height and are set to sticky position to maintain their place.

* {
    margin: 0;
    padding: 0;
}

nav {
    width: 100%;
    background-color: black;
    color: white;
    position: fixed;
    z-index: 10;
}

nav ul {
   display: flex; 
}

main {
    position: relative;
    top: 5.4rem;
}

main .container {
    display: grid;
    grid-template-columns: 18vw auto 20vw;
    column-gap: 2rem;
    position: relative;
}

main .container .left {
    height: 88.5vh;
    position: sticky;
    top: 5.4rem;
    overflow-y: auto;
}

main .container .right {
    height: 88.5vh;
    position: sticky;
    top: 5.4rem;
    overflow-y: auto;
}

This block represents my HTML structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>socialmedia</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <nav>
        <ul>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
        </ul>
    </nav>
    <main>
        <div class="container">
            <div class="left">
                <h1>Left</h1>
                <!-- Left content here -->
            </div>
            <div class="middle">
                <h1>
                    <!-- Middle content goes here -->
                </h1>
            </div>
            <div class="right">
                <h1>Right</h1>
                <!-- Right content here -->
            </div>
        </div>
    </main>
</body>
</html>

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

Transitioning Between Div Elements Using Jquery

I am stuck with the following HTML code: <section> <div id="first"> ---content </div> <div id="second"> ---content </div> </section> When the page loads, the second div and its contents are not visible (I'm uns ...

Make sure that the equal sign is never utilized at the beginning of a form input field

Seeking a method to prevent the use of the "=" character in any input field within a form. <form> <input name="email" type="email" placeholder="Email" required=""> <input name="last name" type="text" placeholder="Last Name"> ...

Surprising pause in the menu transition animation

Currently, I am in the process of developing a menu that seems to have some flaws. One issue is that it appears a bit choppy, but the more concerning problem is the half-second delay after clicking an item before it animates. The concept behind this menu ...

Is there a way to apply dual linear-gradients to both the left and right borders simultaneously?

I want to design a yellow div with wide left and right borders that gradually fade to white towards the edges to create a transparent effect. Although I have successfully created the div, I am struggling to achieve the desired gradient: .fade { margi ...

the combination of class and type functions as a jquery selector

<button class="actionButton default" type="submit"> Save</button> Can you select this button by both its class and type using a jQuery selector? I attempted the following, but it did not work: var saveBttn = $('.actionButton.default [ty ...

Make menu links stretch to match parent's width

Trying to set the dropdown submenu links in my navigation bar to match the width of their parent <li>, but it's proving to be more challenging than I expected. Below is the code: HTML: <div id="navbar" class="navbar"> <nav id="site ...

How can I send an HTML document from a WebApi 2 action using the IHttpActionResult interface?

When it comes to building an html document and returning it in a web api, many resources recommend using HttpResponseMessage. However, I am eager to achieve this using IHttpActionResult instead. Here is my current approach: [ResponseType(typeof(HttpRe ...

Drop-down Navigation in HTML and CSS is a popular way to create

My navigation menu is functioning well and has an appealing design. The HTML structure for the menu is as follows: <div id="menubar"> <div id="welcome"> <h1><a href="#">Cedars Hair <span>Academy</span></ ...

Is there a way to showcase SVG and PNG images retrieved from a database simultaneously?

I've encountered an issue with displaying images from the database. While png images are showing up correctly, the svg images don't seem to display at all. public ActionResult GetImage() { // some code here return new FileContentResult(im ...

Floating with Flex in Bootstrap 4: A seamless way to achieve

Is there a way to achieve this floating layout using Bootstrap 4 flex Grid? I've attempted to use the flex order function but encountered some issues. Have a look at my result: <div class="row align-items-start"> <div class="col-sm- ...

Access the Android mobile application by using a JavaScript click event

I have been attempting to launch an installed android mobile application from an html page in the Chrome browser using a javascript or jQuery click function. While an anchor tag tap works perfectly and opens the installed app, I have encountered issues wh ...

Having trouble getting a background image with tint to display properly in Bootstrap

I applied a sleek black transparent gradient to my body background picture, but as soon as I integrated bootstrap into the HTML code, the effect ceased to function. body { background: linear-gradient( rgba(0, 0, 0, 0.5), rgba ...

The horizontal alignment of a jQuery div is off-center

There is a div element with a width: 50% and some text inside. Using jQuery, I am calculating the widths of both. Then, I attempted to horizontally center the text within the div using this jQuery code: var wrapperWidth = $("#wrapper").width(); var textW ...

Statement featuring session parameter for querying

Is it appropriate to include session variables in a SQL query? The following is an example of a query I am working with: $sql="SELECT teacher.f_name,attendance.student_id,attendance.SNO ,attendance.s_section,attendance.DateTime FROM teach,subject,teacher ...

Utilizing background images in CSS to enhance bootstrap icons

Here is the HTML code snippet I'm working with: <a class="iconContainer" href="#"> <span class="containerIcon chevron-right"/> Test </a> And this is the corresponding CSS code: .chevron-right::befor ...

Trigger Audio Playback in Javascript

Currently working on a webpage with an embedded audio file using the HTML audio tag. The viewer controls the audio playback, but I'm looking to add a button (either in HTML or Javascript) that, when clicked, will start playing the audio from a specifi ...

Adjust the backdrop for the currently chosen tab

For some reason, my code isn't working even though I thought I did everything correctly. My goal is to change the background color for the selected tab. This is what I have tried so far: <script> $('#navigation li').click(function() { ...

Automatically refreshing the canvas whenever the value of an HTML element is modified in Javascript

Below is the javascript code that is relevant <script> $.fn.ready(function() { var source = $('#source').val(); Meme('url1', 'canvas','',''); $('#top-line, #bottom-li ...

Ways to navigate to a tabbed section that is currently inactive

One of my challenges involves managing a tabbed form with multiple tabs: <ul class="tab-links"> <li class="active"><a href="#tab1">Pending</a></li> <li><a href="#tab2">All</a></li> ...

Creating specific CSS classes for individual slides in a basic slider framework

So, I have a rather simple slider that is created using only CSS. Each slide has unique labels for navigation buttons. The main question here is: how can I dynamically add or remove classes to specific items on the slide only when that particular slide is ...