Adjust the placement of the div dynamically in response to the positioning of another div tag

I have an icon that resembles a chat bubble. If the position of the icon is not fixed, how can I display the chat bubble relative to the icon and adjust its position dynamically based on the icon's location? See image here

#logowrap{
  padding: 8px;
  cursor: pointer;
  background-color: grey;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  text-align: center;
  font-family: "SF-Pro-Display-Regular,-apple-system,BlinkMacSystemFont,Helvetica Neue,Apple Color Emoji,sans-serif";
  position: absolute;
  right: 50%;
  top: 50%;
  animation: pulse 1.5s ease-in-out infinite both;
  border: 2px solid grey;  
}

.chat-container{
  position: absolute;
    bottom: 53%;
    right: 50%;
}

.chat-bubble-2{
  width: 170px;
  height: 56px;
  background-color: #6B8E23;
  text-align: center;
  padding: 0.2rem;
  line-height: 58px;
  color: #fff;
  border-radius: 27px;
  position: relative;
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
.chat-bubble-2::after{
  content: '';
  position: absolute;
  height: 24px;
  width: 26px;
  border-bottom: 2px solid #6B8E23;
  border-right: 2px solid #6B8E23;
  border-left: 0px solid #6B8E23;
  border-top: 0px solid #6B8E23;
  top: 100%;
  left: 74%;
  transform: rotate(45deg);
  margin-top: -22px;
  background: #6B8E23;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>
<body>
  
  
  <div id="logowrap"></div>
   <div class="chat-container" id="chatcontainer">
  <div class="chat-bubble-2" id="bubbleEndHere">I'm Still here!!</div>
  </div>
</body>
</html>

Currently, the position is fixed. How can I dynamically adjust the chat bubble's position if the icon changes without relying solely on media queries? Any alternative methods or suggestions would be greatly appreciated. Thank you for your help.

Answer №1

Move your #chatcontainer inside #logowrap, and then apply the style display:relative; to #logowrap.

#logowrap{
  padding: 8px;
  cursor: pointer;
  background-color: grey;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  text-align: center;
  font-family: "SF-Pro-Display-Regular,-apple-system,BlinkMacSystemFont,Helvetica Neue,Apple Color Emoji,sans-serif";
  position: relative;
  left: 50%;
  top: 500px;
  animation: pulse 1.5s ease-in-out infinite both;
  border: 2px solid grey;  
}

.chat-container{
  position: absolute;
    bottom: 90%;
    right: 40%;
}

.chat-bubble-2{
  width: 170px;
  height: 56px;
  background-color: #6B8E23;
  text-align: center;
  padding: 0.2rem;
  line-height: 58px;
  color: #fff;
  border-radius: 27px;
  position: relative;
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
.chat-bubble-2::after{
  content: '';
  position: absolute;
  height: 24px;
  width: 26px;
  borde
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>

<body>
  <div id="logowrap">
    <div class="chat-container" id="chatcontainer">
      <div class="chat-bubble-2" id="bubbleEndHere">I'm Still here!!</div>
    </div>
  </div>

</body>

</html>

combine into one.

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

Trouble with Mongoose adding items to an array

ReviewSchema with Mongoose: import mongoose from "mongoose"; const ReviewSchema = new mongoose.Schema({ likes: { type: Number, required: true, default: 0, }, reactedBy: [ { required: true, ...

What is the best way to retrieve AJAX data in Django views?

I am currently facing difficulties with retrieving data from an AJAX call in my Django views using the GET method. Unfortunately, I am encountering issues accessing the data within my views and the console.log statements are not showing any output. As a ne ...

Attempting to achieve the desired grid layout with Bootstrap 4

Need help achieving this Grid layout Hello, I am new to Bootstrap 4 and I am trying to achieve the layout shown in the image linked above. Here is what I have tried so far... <div class="container"> <div class="row"> <div class="col-md-4 ...

Disabling a button based on the state of a switch button using React and Material UI

For the task at hand, we need to ensure that the button is only activated when the switch button's state changes. This state is received as a prop and needs to be validated correctly within the handleChangeState function. const CustomSwitch = ({name, ...

Android Webview onLoad function provides incorrect height information

When I load a file:// URL into the webview, issues with height calculation arise. Instead of using WRAP_CONTENT, I calculate the height in javascript during the onPageFinished event in Android. However, about 2 out of 5 times, the javascript reports an inc ...

Unable to see the column filter in the data table

My datatable setup includes the column filter js on the page, everything is displaying and working smoothly without any errors in the console. However, after the smoothness loads, the inputs at the bottom are not visible. <body> <div id="stab ...

Tips for displaying JSON data in HTML without the use of placeholder DIV elements

Customer Scenario: A user wants to search through Wikipedia. The search results should be limited to 5 articles, and the user should be able to view the title and introduction of each article. Developer Scenario: User input is provided via an HTML input f ...

Creating a seamless user experience with Jquery validation, ajax, and php without the need for

I have been struggling with a problem solution for quite a few days now. I am trying to implement jQuery validation and AJAX calls without page refresh simultaneously. Interestingly, when I use either of them separately, the code works perfectly fine. Howe ...

Adding an overlay to a material UI table row: Step by step guide

My code is rendering a row in the following format: `<TableRow key={row.name} > <TableCell>{row.empId}</TableCell> <TableCell>{row.userId}</TableCell> <TableCell>{row.name}</TableCell> <TableCell>{r ...

is it possible to position datepicker's dropdown panel at the top in Vue.js?

Currently, I am developing a web page utilizing IView components by Vue.js. However, I am facing an issue where the dropdown menu of the datepicker component is not functioning properly when nested inside a card component. It appears that the dropdown pane ...

Deactivate the other RadioButtons within an Asp.net RadioButtonList when one of them is chosen

Is there a way to disable other asp.net radio buttons when one of them is selected? I have three radio buttons, and I want to disable the other two when one is selected. After doing some research, I managed to disable the other two when the third one is se ...

Tips for achieving full width with Bootstrap

Recently, I delved into the world of bootstrap and encountered some trouble setting my width to 100%. Despite trying to assign width:100%; in my container CSS, it didn't seem to work. The only workaround I found was using container-fluid no-padding in ...

Using loops to simulate the effects of :hover in Javascript for each child div element, as an

For a while now, I've been utilizing the code below (or something similar) to showcase information on specific posts: Html: <div class="main"> <div class="info"> <div>Words</div> <div>Words</div> < ...

Having trouble replacing using String.replace() in Javascript?

I am working on a project that involves parsing a website and retrieving information from a database. The code I have looks like this: var find = body.match(/\"text\":\"(.*?)\",\"date\"); After running the code, I get the fo ...

Typescript: The type 'X' does not correspond with the signature '(prevState: undefined): undefined' in any way

My React Native app, which is written in TypeScript, has been giving me a hard time with an error lately. The issue revolves around a Searchable List feature. This list starts off with an Array of values and gets updated when users type into a search bar. ...

Accessing Row Data from a Material Table using a Button Click, Not through Row Selection

My React component features a material table view, shown here: https://i.stack.imgur.com/OUVOD.png Whenever the delete icon is clicked in the table, I want to access the rowdata associated with that particular row. However, all I am able to retrieve is ...

Having trouble with the option:selected function in jQuery 1.9?

Here is a query that works perfectly with versions of jQuery prior to 1.9: $("select option:contains(fish)").attr('selected', true); Unfortunately, this query does not function at all with jQuery 1.9 and newer versions. Despite searching for ...

Enhance the structure of information retrieved from the API

Recently I sought advice on formatting API data and received some excellent responses. However, I encountered an error when the API lacked data for certain assets: https://i.stack.imgur.com/HgJDd.png Here is an example without the highlighted code: http ...

The automatic width feature in Firefox is malfunctioning and not behaving as expected

Here is my question: I have an image wrapped in a div (.indexWrap): <div id = "slider"> <div class="indexWrap"> <img class="indexImage" src=""> </div> ...

Logging client side errors to the server with AngularJS exclusively

Hey there, I'm a beginner in angularjs and I am trying to figure out how to create a client-side error/exception logger (.log/.js) file that sends data to the server using only angularjs. I prefer not to use jquery for this particular task. Any assis ...