Unusual alterations to HTML and CSS to meet specific needs

Struggling with bringing my website ideas to life! My header contains a navigation bar, followed by a centered chat box within a fixed <section>. Want the left and right side of the chat box to be content areas that scroll in sync while the chat box stays fixed.

Attempts at creating a content wrapper with padding and margins failed as content kept going over. Also struggled to position the left and right sections correctly.

Here is some of my HTML and CSS:

body {
    background-color: #2A0944;
    font-family: 'Roboto';
}

* {
    margin: 0;
    padding: 0;
}
i {
    margin-right: 10px;
}



.chat-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    width: 40%;
    left: 30%;
    top: 80px;
}
<header>
    <div id="navbar-animmenu">
        <ul class="show-dropdown main-navbar">
            <div class="hori-selector"><div class="left"></div><div class="right"></div></div>
            <li>
                <a href="#"><i class="fas fa-wrench"></i>&nbsp;Demo</a>
            </li>
            <li class="active">
                <a href="#"><i class="fas fa-robot"></i>&nbsp;ChatBot</a>
            </li>
            <li>
                <a href="#"><i class="fas fa-map-pin"></i>&nbsp;About</a>
            </li>
            <li>
                <a href="#"><i class="fas fa-users"></i>&nbsp;Team</a>
            </li>
        </ul>
    </div>
</header>

<body>
   
    <section class="chat-section">


        <div class="mode-selector">
            <button class="mode-button" id="normal-mode">Normal Mode</button>
            <button class="mode-button" id="material-mode">Material Mode</button>
        </div>
    
        <div class="chatbox">

          <div class="messages-container"></div>
          
          <div>
          <div class="send-section">
            <button class="clear-chat"><i class="fas fa-poo"></i></button>
            <input type="text" class="message-input" placeholder="Talk with ChatBot ..."/>
            <button class="send-button">Send</button>
            </div>
            </div>
        </div>
      </section>

    <script src="main.js"></script>
</body>

Having no issues with CSS for items in the navigation bar and chatbox, but struggling most with adding left and right sections. Do I need to modify the current chatbox? How can I ensure scrolling keeps content below a certain line? Any advice appreciated!

Mentioned above the struggles with using a content wrapper unsuccessfully.

Answer №1

Below is a simple solution using a 3-column flexbox layout. The middle column contains a "chatbox" that has the following CSS:

width: 150px;
position: sticky;
top: 0;
height: calc(100vh - 20px);
  • The width property sets the width of the column.
  • The position: sticky and top: 0 properties keep the element fixed at the top as you scroll.
  • The height: calc (100vh - 20px) ensures that the element's height matches the window height, accounting for padding.

body{margin:0; padding:0;}
#wrapper{
display: flex;
background: purple;
color: white;
min-height: 100vh;
}

.side{
padding: 10px;
}

#chatbox{
width: 150px;
background: #CCC;
color: black;
padding: 10px;
position: sticky;
top: 0;
height: calc(100vh - 20px);
}
<main id="wrapper">
<div class="side">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas...</p>
...additional content here...
</div>
<div>
<div id="chatbox">
This is the chatbox
</div>
</div>
<div class="side">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
...more content here...
</div>
</main>

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

How can I update two divs simultaneously with just one ajax call?

Is there a way to update 2 divs using only one ajax request? The code for updating through ajax is in ajax-update.php. <?php include("config.inc.php"); include("user.inc.php"); $id = $_GET['id']; $item = New item($id); $result = $item->it ...

If a quote character is detected in a string, color the line red

My goal is to highlight each line from a string in red if it contains the ">" character. I am applying this logic to a database query result, and while it's successful, I'm encountering an issue where an HTML line break is inserted after each "qu ...

Show different values in Array arranged in Table format with the help of Ajax code

Check out the code I have attempted below: <script type="text/javascript"> $('#doctorselected').on('change', function(e){ console.log(e); var doctorid = e.target.value; var url = '{{URL::to('getdoc ...

Struggles with ajax and JavaScript arise when attempting to tally up grades

Currently, I am facing an issue with my JavaScript. The problem arises when trying to calculate marks for each correctly chosen answer based on information from the database. If an incorrect answer is selected, the marks are set to '0', otherwise ...

What is the best way to add child elements to existing elements?

When it comes to creating elements with jQuery, most of us are familiar with the standard method: jQuery('<div/>', { id: 'foo', href: 'http://google.com', }).appendTo('#mySelector'); However, there ar ...

Using Jquery to loop through various select options within a designated container div

I am seeking a way to loop through multiple select options within a specific div using the jQuery each function. If any field is left empty during this iteration, I would like the loop to break and set the reqCourseFlag variable to 0. The current implement ...

Creating a tool to display mouse coordinates as a pointer on an HTML5 canvas

I'm struggling with mouse coordinates while working on canvas in HTML5. My approach involves using JavaScript for drawing on the canvas. Below is my current code to track the mouse pointer within the canvas: $('#canvasID').mousedown(functi ...

The E.js Template encountered an error with an unexpected token "else"

I am in the process of creating a website quickly using e.js & Express. However, I am encountering some problems when trying to use an if-else statement within e.js tags. The if statement works fine, but as soon as I add an else statement, things start t ...

How can I protect a text or script file from being accessed or downloaded by entering its URL directly into the browser address bar?

While working on my JSP file, I have incorporated some Java-script code but to safeguard it from being visible to clients, I decided to store it in a separate codescript.js file and load it using ajax like so: $.ajax({ cache: true, dataType: "script ...

Is there a method to exclude children objects from spring animations during application?

Is it possible to create a fading in and out effect for a div (for example, to cycle through different backgrounds) while keeping its children (such as text) visible at full opacity at all times? {transitions((style, <animated.div class={ bg[i] + ...

Show input field depending on chosen option

I'm looking to create a dynamic form where specific input fields are displayed based on the selection made in another field. For example, if "gender: male" is selected, the input field for "blue" should appear, and if "gender: female" is selected, the ...

Changing the color of a progress bar in Bootstrap based on a specific percentage level

var elem = document.getElementById("progress-bar"); var progress = 75; elem.style.width = 80 + '%'; if (progress > 80) { elem.style.background = "red"; } #myProgress { height: 5px; } #progress-bar { w ...

When scrolling, the selected text does not maintain its correct position

I'm looking to enable my users to search by selecting text. Once they select text, a new button will appear on the right side of the selected text giving them the option to search or not. However, when the user scrolls to the bottom of the page, the p ...

An angular component that is functioning properly when connected to a live server, however, it is experiencing issues when trying to run `

I tried integrating versitka into my Angular component by placing the version HTML file and all necessary assets in the appropriate directories. However, when I run ng serve, only the HTML file seems to be working, while the CSS and images fail to load. I ...

Displaying an HTML button above JavaScript code

Hello, I am currently working on a project that involves displaying the Earth and I am in need of assistance with positioning some buttons on the screen. Currently, I am facing an issue where the buttons appear either above or below the JavaScript code. I ...

Exploring the ways to retrieve the returned Dynamic scope in AngularJS

There's a specific need I have - I require a single AngularJS function that can dynamically return the scope variable based on an input parameter. When it comes to controller functions, I've come across examples of how to achieve this dynamic sco ...

The background image fails to display

Having some trouble with setting an image as the background using CSS. When I directly input the image URL, it shows up fine with this code: background: url('images/image1.jpg); However, I would prefer to use this CSS code instead: .masthead { m ...

What is the best way to utilize the features of component A within component B when they exist as separate entities

Component A has all the necessary functionalities, and I want to use it in Component B. The code for ComponentA.ts is extensive, but it's not written in a service. How can I utilize the logic from Component A without using a service, considering both ...

"Customizing the Material-ui TextField DOM Element: A Step-by-Step

After trying the code below, I was expecting to see a yellowish "Hi," but instead received [object Object]. Is there a way to correct this issue? Possibly utilizing InputProps would help, but I haven't been able to locate a comprehensive tutorial on ...

Learning the ins and outs of HTML5 and CSS3

Does anyone have recommendations for high-quality HTML5 and CSS3 tutorials? ...