positioned division towards a subset

Is there a way to align a div with a span? For instance:

<div style="some magic">foo bar<div> 
<p>this is a random text with <span class="stressed">stressed phrase</span> in it</p>

The desired output would look like this:

                              foo bar
this is a random text with stressed phrase in it

Here, the content of the div is centered to the text in the span.

Answer №1

Demo: http://jsfiddle.net/rJXE3/3/

HTML

<p>This text contains a <span class="stressed"><span class="somemagic">highlighted</span>stressed phrase</span> within it.</p>

CSS

.somemagic {
    display: inline-block;
    position: absolute;
    width: 100%;
    height: 100%;
    text-align: center;
    bottom: 100%;
    white-space: nowrap;
    margin-left: -25px;       // Adjust this if stressed text size varies
}
.stressed {
    position: relative;
}

To prevent overlapping, ensure to add margin to your "p" element or include an additional line break.

UPDATE 2

Demo: http://jsfiddle.net/rJXE3/4/

Another CSS configuration option has been discovered that eliminates the need for JavaScript.

.somemagic {
    display: inline-block;
    position: absolute;
    width: 300%;
    height: 100%;
    text-align: center;
    bottom: 100%;
    white-space: nowrap;
    left: -100%;
}
.stressed {
    position: relative;
}

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

creating an identical copy of a dynamic element's size

I am currently working on a project using react js where I need to incorporate multiple images. My goal is to have standard background divs / rectangles that match the exact size of each image, allowing for animations to be performed on top of them. The sn ...

Generating a QR code with a web link in Node.js

Currently, I am immersed in a project that requires me to generate a QR code with specific information using NodeJS. To kick things off, I've set up a canvas in HTML and transferred it to NodeJS. <canvas id="canvas" width="300" height="300">& ...

What is the best way to manage font size on an HTML webpage?

In a scenario where I specify font-size = 25px along with a specific font-family, my intention is to display a character that is exactly 25px on the HTML page. However, the rendered character's size may be slightly different, such as 27px or another v ...

Aligning the tooltip element vertically

I've created a unique flexbox calendar layout with CSS tooltips that appear on hover. One challenge I'm facing is vertically aligning these tooltips with the corresponding calendar dates effectively. Although I prefer to achieve this alignment u ...

Tips for maintaining proper alignment of the element within the given space and organizing it vertically with appropriate spacing

I am trying to align the elements so that they take up the available space and stay vertically arranged in the same order, but I'm having trouble achieving this. Is there a way to accomplish this? Here is my code: .parent { border: 1px solid red; ...

Struggling to make HTML5 geolocation coordinates function properly

I've attempted to work with examples in this code snippet, but I'm struggling to make the html5 geolocation coordinates function properly. Everything works fine when I hardcode the coordinates. var infowindow; var map; function initialize() ...

Is there a way for my website visitors to seamlessly download the font I use if it's not already installed on their devices?

I've chosen the unique font ff-clifford-eighteen-web-pro-1 for my website. I'm looking to ensure that all text is consistently displayed in this font, even for users who may not have it downloaded on their device. Is there a way to make this hap ...

Steps for serving audio files in a Spring Boot application

Can someone advise on the best location to place my audio folder in order to reference it as src="audio/audio_name" within an HTML audio tag? I attempted placing it in the resources folder, but when using src="http://localhost:9191/resource ...

Is it possible to change the background as I move the sun across the screen?

Recently, I developed a page that allows users to drag an image of the sun in an arc. The sun transitions from a bright sun to a darker version and eventually into a moon as it moves along the arc. Now, my goal is to have the background image also transiti ...

Difficulty using Container, Row, and Col components in React-Bootstrap

Currently, I am diving into the world of React and React-Bootstrap to expand my skill set. My focus is on utilizing the React-Bootstrap grid layout effectively. However, I suspect that I might be doing something wrong in my implementation. It seems like t ...

Center Checkboxes in Bootstrap 4 Form Input

I am working with a Bootstrap Form that contains checkboxes. One specific scenario involves a large number of options to choose from. Currently, these options are displayed in a single long list, which can make it difficult for users to read and select the ...

IE9 Z-index Issue

Currently, I am facing an issue with two images not displaying correctly on a website that I am working on. The problem seems to be specific to IE 9, as other browsers are working fine. The trouble arises when I try to create a slideshow with a shadow back ...

The pagination feature for Swiper is experiencing issues across both desktop and mobile platforms

I am having an issue with the pagination display in the text. I would like it to appear below the text as a standalone item for better visibility. Another problem arises when viewing the page on mobile devices - the hamburger menu displays behind the slid ...

Press here to unveil and modify using the Redactor JS WYSIWYG HTML editor

I am working on a project where I have three separate divs that are set to be editable using the attribute contenteditable="true". Additionally, I have configured the redactor wysiwyg toolbar to remain fixed on the page. Here is the structure in HTML: &l ...

Dropdown search menus are failing to appear in the correct location

I have 4 dependent search dropdown menus side by side. There are two issues I am facing: Whenever I type in any of the drop-down menus, the MySQL-connected lists appear but not directly beneath the actual 'input-type-search-box'. Additional ...

What steps can you take to convert your current menu into a responsive design?

I am currently developing a website using PHP, HTML, and CSS. The site is not responsive, and I want to make the menu responsive. My global navigation and admin interface are not adapting properly as they are designed using tables. Is there a method I can ...

`A problem with HTML element display in Internet Explorer versions 8 and 9 involving <p> and <h2> tags`

While working on my website, I encountered an issue with the way text is being rendered in <p> and <h2>. The footer of my site has three columns, but for some reason the middle column is displaying its <p> text within the <h2> text ...

The outcome when submitting an HTML survey

I have a curiosity about what really happens when you click the submit button on an HTML survey like the one displayed below: <INPUT TYPE="radio" NAME="bev" VALUE="no" CHECKED>No beverage<BR> <INPUT TYPE="radio" NAME="bev" VALUE="tea">Te ...

Which web browsers are compatible with the input attribute "multiple"?

I am currently incorporating this particular plugin, and its file input does not support multiple file selection. To address this issue, I have added the 'multiple' attribute. However, I am curious if there are any browsers or other platforms (su ...

Bootstrap dropdown menu is functional only on the active page in a dynamic navigation system

During my journey of learning PHP, SQL, and other web development skills, I built a website. Now, I am working on enhancing the original page by incorporating a bootstrap navbar. However, I encountered an issue where the dropdown box only appears for pages ...