Styling speech bubbles and dividing lists with CSS

Looking to create a speech popup with an internal menu that has items separated by borders. The challenge arises when there is an even number of items - how can the border extend inside the speech pointer?

After some consideration, also need to account for the possibility of scrolling the menu items within a fixed popup size. Ideally, the item border should follow the scrolling within the speech pointer as well (popup opening on the right instead of left in this case).

https://i.sstatic.net/BeMcP.png

Check out the codepen

or

The code snippet:

.bubble {
  position: relative;
  width: 100px;
  height: 240px;
  padding: 0px;
  background: #FFFFFF;
  -webkit-border-radius: 0px;
  -moz-border-radius: 0px;
  border-radius: 0px;
  border: #7F7F7F solid 1px;
}
.bubble:after {
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 15px 0 15px 15px;
  border-color: transparent #FFFFFF;
  display: block;
  width: 0;
  z-index: 1;
  right: -15px;
  top: 105px;
}
.bubble:before {
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 15px 0 15px 15px;
  border-color: transparent #7F7F7F;
  display: block;
  width: 0;
  z-index: 0;
  right: -16px;
  top: 105px;
}

.list {
  margin:0px;
  width: 100%;
  height: 100%;
  list-style: none;
  padding: 0;
}

.item {
  margin:0px;
  text-align: center;
  border-bottom: 1px solid black;
  width: 100%;
  height:59px;
  
}

.item:last-child {
  border-bottom:none;
}
<div class="bubble" style="border-color: rgb(127, 127, 127); width: 100px; height: 240px; top: 55px; border-radius: 0px; border-width: 1px; background-color: rgb(255, 255, 255);">
  <div class="pointer" style="content: '';position: absolute;border-style: solid;border-width: 15px 0 15px 15px;border-color: transparent #FFFFFF;display: block;width: 0;z-index: 1;right: -15px;top: 105px;">
  </div>
  <div class="pointerBorder" style="content: '';position: absolute;border-style: solid;border-width: 15px 0 15px 15px;border-color: transparent #7F7F7F;display: block;width: 0;z-index: 0;right: -16px;top: 105px;">
  </div>
  <ul class="list">
    <li class="item">1</li>
    <li class="item">2</li>
    <li class="item">3</li>
    <li class="item">4</li>
  </ul>
</div>

Answer №1

Initially, by utilizing the .pointer and .pointerBorder, you can omit the use of the :before and :after pseudo-elements on the .bubble to create the arrow.

Moreover, for consistent vertical alignment of the arrow within the .bubble, it is recommended to vertically align it as follows:

.pointerBorder,.pointer {
  margin: auto;
  top: 0;
  bottom: 0;
  height: 1px;
}

Additionally, removing the set height property from the .bubble is advisable since its height should be dictated by its content.

Upon implementing these modifications, a perfectly vertically aligned arrow will adorn your box.

Although extending the border is not feasible, creating an illusion that extends into the arrow is achievable. One way to achieve this effect is by adding a pseudo-element to the .pointer.

.pointer:after {
  content: '';
  position: absolute;
  width: 17px;
  height: 1px;
  background: #000;
  top: 0px;
  left: -17px;
  bottom: 0;
  margin: auto;
}

If the number of items is constant and even, there's no issue. However, for varying item quantities, distinguishing between odd and even numbers of items in the .bubble requires adding a dedicated class. This functionality can be implemented via server-side scripting or using JavaScript. (A CSS-only approach skips this section, but changes in the HTML would then be needed)

The comprehensive code stands as follows:

.bubble {
  position: relative;
  width: 100px;
  padding: 0px;
  background: #FFFFFF;
  -webkit-border-radius: 0px;
  -moz-border-radius: 0px;
  border-radius: 0px;
  border: #7F7F7F solid 1px;
}
.list {
  margin: 0px;
  width: 100%;
  height: 100%;
  list-style: none;
  padding: 0;
}
.item {
  margin: 0px;
  text-align: center;
  border-bottom: 1px solid black;
  width: 100%;
  height: 59px;
}
.item:last-child {
  border-bottom: none;
}
.odd_items .pointer:after {
  content: '';
  position: absolute;
  width: 17px;
  height: 1px;
  background: #000;
  top: 0px;
  left: -17px;
  bottom: 0;
  margin: auto;
}
.pointerBorder,
.pointer {
  margin: auto;
  top: 0;
  bottom: 0;
  width: 0;
  height: 1px;
  border-style: solid;
  border-width: 15px 0 15px 15px;
  position: absolute;
}
.pointer {
  border-color: transparent #FFFFFF;
  right: -15px;
  z-index: 1;
}
.pointerBorder {
  border-color: transparent #7F7F7F;
  right: -16px;
}
<div class="bubble odd_items">
  <div class="pointer">
  </div>
  <div class="pointerBorder">
  </div>
  <ul class="list">
    <li class="item">1</li>
    <li class="item">2</li>
    <li class="item">3</li>
    <li class="item">4</li>
  </ul>
</div>

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

"Tips for stopping users from using Ctrl+U to view page source in

Is there a way to prevent users from viewing the source code (HTML + JavaScript) of a page by disabling Ctrl+U in the browser? ...

Allow for separation amongst my cellular components

I have a table with multiple cells and I would like to add some spacing between each <td> element. You can find an example of my code on JSFIDDLE. .line { border-bottom:1px solid black; } .textRotation { -webkit-transform: rotate(-90deg); ...

Python: Change text within HTML content rather than the HTML tags

Looking for help with converting HTML code? <pre class="script">template("main/GlobalShared");</pre> <pre class="script"> var link = '/Draft/Tracker_1.1'; if (wiki.pageexists(link)) { &lt;div class="version"&gt; web ...

Can you guide me on switching between windows using the selenium IDE?

Instructions for handling popup windows in Selenium 2 (WebDriver) can be found at the following link: The instructions state that testing popup windows in Selenium 2 involves switching the driver to the popup window and then running the corresponding acti ...

Tips for positioning the bootstrap navbar correctly inside a container

I am having some trouble with my HTML page layout. I have a fixed Bootstrap navbar and a container with a width of 1000px. I'm trying to place the navbar inside the container, but it's not working as expected. The navbar is still taking up the fu ...

Discovering where to find Chrome for Android's font options

Currently, I am facing an issue with the fonts on my website. The fonts that I am using work perfectly with Chrome for Windows, but unfortunately do not display properly on Chrome for Android. I have a preference for using the Haettenschweiler and Impact ...

Tips for positioning large text next to an image

When creating a product detail page in HTML, I encountered an issue where adding large text to one div caused the entire page layout to shift. Does anyone know why this is happening? Could it be due to the size of the div not being defined? See the issue h ...

The jquery.blockUI plugin seems to be malfunctioning

Trying to disable a simple div: <div id="MyDiv"> </div> Here is the code I used: $('#MyDiv').blockUI({ message: '<h1>This has been blocked!</h1>', css: { border: '3px solid #a00' } }); Issue ...

Continue scrolling the HTML page before it reaches the end

https://i.sstatic.net/6iBof.png I am currently troubleshooting an issue with my chat thread. At the moment, the chat window automatically scrolls up when it reaches the bottom of the page to ensure it is always visible. However, there is a problem where ...

Aligning text vertically within a textbox using CSS

Currently tackling a textbox with a background and wondering if there's a way to vertically center the text inside it. Note: Text is perfectly centered in Firefox, but in IE it appears too high for some reason. Have tried adjusting line-height, paddi ...

Drawing with RGBA Colors on an HTML Canvas

While learning canvas, my main objective is to draw free-hand. Many online examples suggest calling stroke() within the onmousemove function. This approach works fine when using a color with 100% opacity in the strokeStyle. However, using rgba with an alph ...

Not able to drag or drop list items using Jquery Sortable in Django

I am having trouble with implementing a Jquery sortable drag and drop feature from one list to another in my code. The specific error message I am encountering is: Uncaught TypeError: $(...).sortable is not a function I would greatly appreciate any assis ...

Instructions for applying a CSS width to a specific column in an HTML table within an email template for Outlook

When trying to develop an email template for Outlook, I encountered an issue with adding width to the column in an HTML table. Despite setting the property, it did not reflect correctly in the email. Various attempts were made to address this problem. < ...

Show Api Image

Trying to display an image from an API call in PHP to an HTML img tag with the following code: <div class="col-md-3 col-lg-3 " align="center"><img alt="User Pic" <?php echo 'src="'. $data['response']['avatar'] . & ...

Displaying Data in Table Using Ajax Request

I'm working on a project that involves creating an HTML table from an ajax request pulling SharePoint list items. The screenshot provided demonstrates how it functions and what it displays after the button is clicked. However, I am looking for a way t ...

Trouble with Angular: mat-sidenav not responding to autosize or mode changes when resized

Currently, I am working on integrating the mat-sidenav into a project. Most of the functionality is working well, but there is one particular issue that arises. When running the app locally in a browser and resizing the window tab multiple times, it opens ...

What is the best way to position an image at the end of the initial sentence in a paragraph?

I have a basic HTML code that consists of an image within a paragraph element. <p> <img src="https://www.w3schools.com/css/pineapple.jpg" /> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus incidunt recusandae quae ...

PhantomJS in Python Selenium fails to retrieve source code after element click

View the code here import webdriver from selenium driver = webdriver.PhantomJS() driver.get("http://www.metasozluk.com/?r=girdi/goster&g=298794") driver.page_source # The result is a full HTML page. driver.find_element_by_css_selector(".entry-list-c ...

Is it possible to customize the appearance of individual sections in an HTML5 range slider by changing their

I'm looking to customize a stepped HTML5 range slider by changing the background color for each step, similar to the image provided. Is this customization achievable? ...

Submit HTML checkboxes that have not been selected

I have a set of checkboxes that come pre-checked by default. I anticipate that my users may uncheck some, but will probably leave most of them checked. Is there a way to configure the form so that it submits the unchecked checkboxes instead of the checked ...