The use of absolute positioning in Chrome may encounter issues when it is nested within a relative span element

I am encountering an issue specifically with the Chrome Browser. In my HTML code, I have several span tags, some of which have the position: relative CSS property as they contain a div with position: absolute. The goal is for the div to be positioned at the bottom-left of the span element.

Everything works correctly, except when the span starts on a new line, there is a positioning problem with the div.arrow (refer to the images and code provided). (Alternatively, see it in action on JSFiddle)

.selected {
  position: relative;
  border-bottom: 2px solid red;
  padding-bottom: 2px;
}

.arrow {
  position:absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 0 solid transparent;
  border-right: 4px solid transparent;
  border-bottom-width: 4px;
  border-bottom-style: solid;
  border-bottom-color: red;
}
<span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> ... 

To replicate the issue, try resizing your window to match the image provided: https://i.sstatic.net/Occke.png

The expected outcome should resemble this: https://i.sstatic.net/Bf8CU.png

If you have any solutions or suggestions to resolve this issue, please share. Thank you!

Answer №1

Instead of using position:absolute, consider implementing a background to address the issue, eliminating the need for additional elements or pseudo elements. Keep in mind that nesting a div inside a span is not valid.

.selected {
  padding-bottom: 4px;
  background:
    /* The arrow*/
    linear-gradient(to bottom left,transparent 49.5%,red 50%) bottom 2px left 0/4px 4px,
    /* The line*/
    linear-gradient(red,red) bottom/100% 2px,
    /* Backgroudn color */
    lightblue;
  background-repeat:no-repeat;
}
<span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span class="selected">foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span> <span>foobar</span>

Answer №2

To apply the desired styling, include display: inline-block; in your CSS rule for the .selected class.

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 on arranging check-boxes horizontally in this code repository

We are working with an autogen form in PHP, and the way the checkboxes are currently displayed is demonstrated in the following code: case FIELD_CHECK_BOX: $fieldHtml = printCheckbox($mode, $field->getId().'[]', $field->get ...

Setting the Disabled and Checked attributes on HTML Elements based on certain conditions

Within an asp GridView template field, there is a button and a checkbox. The goal is to set the disabled property of the button and the checked property of the checkbox based on the Data Field Expiration conditionally. If the Expiration equals Permanent, t ...

Yet another IE8 CSS dropdown in shambles

This particular PyroCMS site is quite dynamic, which is why using jsfiddle for posting doesn't work as smoothly. The menu seems to be functioning properly in all major current browsers and their versions, except for IE7, which is not supported. Howeve ...

The UI-SELECT feature in angular-js does not seem to be displaying

I've added the necessary ui-select js and css files to my page : <link href="assets/plugins/ui-select/select.min.css" rel="stylesheet" type="text/css" <script src="assets/plugins/ui-select/select.min.js" tyle="text/javascript" </script> ...

Enhance your picture links with a:hover box-shadow styling

I've been struggling to add a box shadow on hover to a Facebook icon image. I assumed it would be straightforward, but as always, I was wrong. I'm working with a child theme in WordPress because I recently started, thinking it would be an easy wa ...

When the direction is set to rtl, special characters that are supposed to be at the

When using the direction property for a label with windows style directory paths containing backslashes, I encountered an issue. The purpose of using direction:rtl; was to display the end part (file names) of the path. However, I found that I am getting th ...

What is the best way to align a form in the center of a page both horizontally and vertically

Currently, this is the HTML code I am working with: <body> <form id="form_login"> <p> <input type="text" id="username" placeholder="username" /> </p> ...

Best practices for embedding Internal CSS and rectifying missing classes in mobile view for email templates on Gmail

I am currently facing an issue with my email template. While it works perfectly fine in Outlook web and the Outlook app, Gmail web and Gmail's internal CSS strip away certain classes automatically. In an attempt to hide the pre-header on mobile devic ...

Effort to update Div element with Ajax fails to function

Looking for some assistance here. I'm attempting to update a database's entries using Ajax after submitting a form. The entries are displayed within a div. I've tried the following code to refresh only that specific div, but it doesn't ...

modify style when not valid and is touched

When I try to modify the style of an i tag based on the touched and invalid state of another field, only the input tag's style changes and not the i tag. Here's the CSS code I'm using: input.ng-touched.ng-invalid { border-color: red; } ...

In Internet Explorer 9, the cursor unexpectedly moves up above the element

Within my MVC3 application, I have implemented a feature to change the cursor when hovering over an element. Below is the JavaScript code that accomplishes this: $('#print').hover(function () { var cursorUrl = 'url(@Url.Content("~/Cont ...

Creating a new page break in an Excel cell produced through HTML

Currently, I am facing an issue while attempting to create an excel file using PHP with HTML and responding with an excel Content-type. Everything seems to be working smoothly except the preservation of new lines within a cell. Various methods like &#1 ...

Failure of Highchart's resizing mechanism when hidden

Check out this AngularJS demo app featuring Highcharts: http://jsfiddle.net/dennismadsen/dpw8b8vv/1/ <div ng-app="myapp"> <div ng-controller="myctrl"> <button ng-click="hideView()">1. Hide</button> <button ng ...

Angular dropdown menu not being populated

I need assistance in creating a menu that allows me to modify the "cell" attribute of an individual. The cells are specified as follows: Cells: [ { name: 'NE', id: 1 }, { name: 'NW', id: 2 }, { name: 'SE', id: 3 }, { name: & ...

What is the best method to position a submit button to the right of a cluster of radio buttons when utilizing Twitter Bootstrap?

I am trying to align a group of radio buttons and a submit button side by side using Twitter Bootstrap. I want the radio buttons on the left and the submit button aligned proportionately on the right. What is the correct method to achieve this layout? Des ...

My JavaScript/jQuery code isn't functioning properly - is there a restriction on the number of api calls that can be made on

Below is the code I have implemented from jquery ui tabs: <script> $(function(){ // Tabs $('#tabs1').tabs(); $('#tabs2').tabs(); $('#tabs3').tabs(); //hover states on the sta ...

What steps can be taken to ensure a function operates even when the mouse is stationary?

$(document).ready(function() { var score = 0; $("body").mousemove(function() { score++; $("#result").val(score); console.log(score); }); }); As I move my mouse, the score keeps increasing. But, I'm wonde ...

Can you explain the intended function of .reference in the CSS code provided?

Currently delving into some sample HTML from codrops. I came across the following CSS styling. After scouring the web, it seems others have used span.reference, but I can't seem to grasp the purpose of .reference. Any insights would be much appreciat ...

Obtain all elements of the body except for the div element through a Selenium python query

I need help fetching all body elements in a query without including div elements. Below is the code I have so far: body = driver.find_element(By.TAG_NAME, 'body') elements = body.find_elements(By.TAG_NAME, '*') However, this code retr ...

Guidelines for dynamically displaying <router-link> or <a> in Vue based on whether the link is internal or external

<template> <component :is="type === 'internal' ? 'router-link' : 'a'" :to="type === 'internal' ? link : null" :href="type !== 'internal' ? link : null" > <slot /> < ...