CSS-powered animation of a div's movement

Is there a way to make the "icon" div move dynamically when the text is long?

Does anyone have any suggestions on how to achieve this?

I appreciate any help or advice.

.tit {
  display: table;
}

.icon {
  border-top: 5px solid currentcolor;
border-right: 5px solid currentcolor;
min-width: 42px;
float: left;
height: 22px;
margin-top: -23px;
margin-left: 25px;
}
<div class="tit">Titleeeeeeeeeeeeeeeee</div>
<div class="icon"></div>

Answer №1

A container designed using flexbox.

.container {
  display: flex;
}

.icon {
  border-top: 5px solid currentcolor;
  border-right: 5px solid currentcolor;
  min-width: 42px;
  height: 22px;
  margin-left: -40px;
}
<div class="container">
  <div class="title">Titleeeeeeeeeeeeeeeee</div>
  <div class="icon"></div>
</div>

Answer №2

enclose the div with class "tit" inside a div with class "icon"

<div class="icon">
  <div class="tit">Titleeeeeeeeeee</div>
</div>

example on jsfiddle

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

Did my code effectively block an XSS attack?

Recently, I was informed that my website has vulnerabilities to XSS attacks. In an effort to improve security, I have implemented the htmlspecialchars method as a preventive measure. Here is the function I created: function _e($string){ return htmlsp ...

When utilizing SVG 'use' icons with external references, Chrome may fail to display icons when viewing an HTML file locally

I'm currently experimenting with using SVG icons, following the guide found at https://css-tricks.com/svg-use-with-external-reference-take-2/ Here's how it appears: <!-- EXTERNAL reference --> <svg> <use xlink:href="sprite.svg# ...

Steps for creating a SlideMenu:

"The function defined below is meant to create a slideMenu on the left side of the index page. However, it seems like I have overlooked something as the slide Menu doesn't work." <!DOCTYPE html> <html> <head> <title>Respon ...

Ways to address the issue of "$ is not a function"

Whenever I attempt to upload an image, this error message pops up: $ is not a function The source of the error can be found here: $(document).height(); ...

Using makeStyles() in MUI for conditional rendering

Trying to dynamically change the value of backgroundColor under the property "& + $track" using props.disabled but it seems that MUI does not recognize it. Why could that be? const useStyles = makeStyles((theme) => ({ root: { overflow: "vis ...

Tips for eliminating the gap between Bootstrap 4 columns

Is there a way to eliminate the spacing between Bootstrap columns? I have three columns set up using Bootstrap but no matter what I do, I can't seem to get rid of the space between them. <!doctype html> <html lang="en> <head> ...

The CSS3 selector matching a value starting with "[attribute^=value]" does not match a value that has spaces after the quotation marks

When using the div[class^="test"] selector, keep in mind that it will not select an element with a class attribute like class=" test-something" (This selector was generated on the backend.) Using the div[class^=" test"] is not a valid choice. ...

When a specific JavaScript function is triggered, the value of an HTML control will reset to its original default value

I have a form with a specific requirement. I need to allow users to input data in a text field and press enter, which should dynamically create new controls like another text field, a dropdown menu, and another text field using jQuery. While the functional ...

The card has adhered itself to the uppermost part of the Bootstrap 4 webpage

I attempted to center the container on the page, but it appears to be stuck at the top instead. I have come across a related question, but the solutions provided did not work for me. I even tried copying some code snippets, but in my Firefox browser, the ...

When utilizing scoped slots in BootstrapVue, you may encounter an error stating "Property or method 'data' is not defined."

Greetings! I am currently in the process of learning how to utilize BootstrapVue, and I decided to reference an example from the official BootstrapVue documentation. <template> <div> <b-table :fields="fields" :items="items" foot-clone ...

Ways to eliminate the excess margin of ng-container from the webpage

When controlling two mat tabs with a statement, I encountered an interesting issue. Both mat-tab elements contain a card-list and are controlled with a statement in ng-container. Strangely, on the first tab, the card has a slight margin from the top when I ...

Could there be a tag present in the DOM that is not visible on the page?

During my browsing session, I encountered a scenario in which I located an "anchor" tag within the DOM using xpath. However, the corresponding element was mysteriously missing from the page. To add to the confusion, when I tested the tag, the click() ope ...

Can you provide me with a variable that will give me the total size of the scrollbar?

How can I determine the maximum number of pixels scrolled on a webpage? I attempted using window.pageXOffset, but it only gives the current scrolled amount. I require the total size at all times. ...

Guide to dynamically modify the font family value of the entered text

I have a simple question regarding customizing font styles. I have an input text field and a drop-down list with various font family options. My goal is to display the text entered in the input field in the selected font style from the dropdown list. Can ...

Converting a serialized PHP array using JavaScript

I am working with a PHP array: <?php information = array ( 'name' => 'John', 'surname' => 'Doe' ); ?> After serializing this array in PHP, I have inserted it into an input's ...

JavaScript not functioning consistently on various browsers

When using http.responseText, it seems to not work properly in Chrome. Is there a way to modify this line so that it does? ...

Troubles with Angular elements not aligning correctly when using the "display: block" property

When using an angular element for a directive with "display: block", it may not automatically take up 100% of the width of the parent container. In order to ensure that it does, the width must be explicitly set to "100%" in the CSS. Despite setting "width: ...

Unable to dispatch the form on a connected page using jQuery Mobile

I have encountered an issue while trying to submit a form using jQuery Mobile. The problem arises when the form is placed on a linked page, as it fails to submit properly. To illustrate, if my home page is mysite.com/page.html, placing the form code on tha ...

How to have Div occupy 100% of its grandparent container?

Here's what I'm trying to figure out: I have a div with a max width of 960px. The child div inside the parent div is set to 100%, but that means it only goes up to 960px. Is there a way to make the child div stretch to 100% of the user's ...

Toggle the current list item in Jquery to expand to 100% width, while simultaneously shifting any adjacent items on the left and right downwards if present

I am working with a list (ul) that contains multiple items displayed in a tiled format. Each item has a brief introduction and can expand to show more information when clicked on. What I would like to achieve is for the expanded item to take up the entire ...