What causes a neighboring div to change width when a multi-line span is present?

Here is my React code:

<InfoWrapper>
  <InfoCircle>
    <span>i</span>
  </InfoCircle>
  <span className="info-label">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    elit.
  </span>
</InfoWrapper>

This displays correctly as shown below:

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

The information circle is sized at 28x28.

However, when I add more text causing the span to expand across multiple lines, the size of the info circle changes to 16.5x28:

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

I have not set any shrinking rule on InfoWrapper, and have specified align-items: flex-start to prevent vertical stretching of items.

Below is a snippet containing the complete code:

span {
  font-size: 0.875rem;
}


.info-wrapper {
  align-items: center;
  display: flex;
  flex-flow: row nowrap;
  margin-top: 1.25rem;
}

.info-circle {
  align-items: center;
  background-color: #f5f7ff;
  border-radius: 0.875rem;
  display: flex;
  flex-flow: row nowrap;
  height: 1.75rem;
  justify-content: center;
  width: 1.75rem;
}

.info-label {
  font-size: 0.9375rem;
  margin-left: 0.5rem;
}
<div class="info-wrapper">
  <div class="info-circle">
    <span>i</span>
  </div>
  <span class="info-label">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </span>
</div>

Answer №1

It is not possible to specify the width of a span element because by default, spans have the attribute display: inline;. To apply a width to the span, you can change its display property to either display: block; or display: inline-block; as width only applies to block-level elements.

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

When hovering over a select option, a description and clickable link will be displayed

I need to display a description with a clickable link when hovering over any option in the select tag. <div class="col-lg-4"> <div class="form-group"> <label class="form-label">Goal</label> <select name="semiTaskType ...

The default value is not displayed in the Angular dropdown menu

When using regular html select menus, if you create an option element with selected and disabled attributes and provide text for that option, the text will be displayed by default in the select menu. Below is a basic example of HTML code: <select name= ...

`Certain browsers are experiencing issues with text overlay functionality.`

I have managed to successfully create the necessary code to incorporate an image with a child element containing text overlaying the image. However, this functionality does not appear to be working on Internet Explorer (IE), and I am struggling to find a C ...

Varying levels of scaling on iPhone and iPad

I am currently working on a website project for my friend's brother and everything is running smoothly (for the most part). The layout of the site is designed with a centered container, leaving approximately 15-20% space from the left side. However, ...

What is the best way to incorporate classes into <li> elements within WordPress?

I'm currently in the process of building my WordPress theme from scratch, but I've run into a roadblock when it comes to adding custom classes to the < li > tags alongside those that are automatically generated by WordPress. Below is the co ...

A guide to accessing and managing events for the child inside a div element using extjs4

How can I dynamically switch between the divs with classes "icon-right" and "icon-left" when clicked? Here is an example of the HTML and ExtJS code involved: Html code: <div class="msg"> <div> <div cla ...

Guide to expanding the sidebar width

As I delve into the world of CSS, I find myself puzzled by the issue of expanding the sidebar to ensure that the "Gestion des utilisateurs" section appears on a single line. https://i.stack.imgur.com/xzFEA.png To provide context, I have included an illus ...

The design does not have the capability to scroll

I am currently working on developing an application using Vaadin and Spring Boot. I have successfully set the background of my app by utilizing the following CSS code within the styles.scss file (inside myTheme as specified by Vaadin): .backgroundImage{ ...

Utilizing grease/tampermonkey (or any other browser extension) to filter out specific characters within webpage elements

Forgive me if my language is not accurate, as I am still learning about programming. The forum that I visit has cluttered the page with unnecessary and glitchy images and text for a promotion. This has made the forum difficult to navigate. I was successful ...

Tips for resolving alignment issues in a chat box:

I am currently working on adjusting the alignment of my chat box app. I have placed 3 div elements with the class .bubble inside a div with the class .chatlines, but they appear to be clustered together instead of aligned properly. It's challenging to ...

Sticky Position Not Functioning Properly in Flexbox Layout

I've attempted to use align-self: flex-start, but it had no effect. The main flex container is on the right side of my page (flex-direction: column) and I want one block of flex columns to stick once I scroll down to them. I enclosed a container aroun ...

The state variable undergoes changes upon being accessed within the useEffect() function

After creating a new variable named 'name' and initializing it with useState to Math.Random(), I printed the variable in two locations - once in the body of the component, and once in the useEffect of the component. However, I noticed that the va ...

Incorporating data from an api call to establish the starting state of a react component

I have been delving into the world of React and TypeScript while working on a fun project - a word guessing game inspired by Hangman. In this game, players have 5 chances to guess the correct word, which is retrieved from an API call. I populate an array w ...

How can I trigger a function or automate code execution in Angular?

I have some code within a function that is crucial for initializing other variables. The issue I am facing is that this function does not execute unless it is called through another tag in the HTML. Is there a method to automatically initialize this func ...

Error: Attempting to access a property named '_updatedFibers' on an undefined object is not possible due to a TypeError

I encountered the following error: Uncaught TypeError: Cannot read properties of undefined (reading '_updatedFibers') at requestUpdateLane (react-dom.development.js:25411:23) at updateContainer (react-dom.development.js:28810:14) at ReactDOMHydra ...

ReactJs Error: Unable to access property value because it is undefined (trying to read '0')

I am currently attempting to retrieve and display the key-value pairs in payload from my JSON data. If the key exists in the array countTargetOptions, I want to show it in a component. However, I am encountering an error message stating Uncaught TypeError ...

Try using inline styling to configure the opening direction of the Select tag in a React application

I have scoured the internet searching for a solution to this issue, and the only advice I seem to find with the most upvotes on every website is either: menuContainerStyle={{top: 'auto', bottom: '100%'}} as an inline solution or som ...

Using javascript to quickly change the background to a transparent color

I am in the process of designing a header for my website and I would like to make the background transparent automatically when the page loads using JavaScript. So far, I have attempted several methods but none seem to be working as desired. The CSS styles ...

Allow-Origin-Control, handler.php for emails, and form validation script

I encountered a strange bug recently. There's been some issues with the HTML5 template I downloaded, specifically related to the contact form and MailHandler.php file. Despite having both files in the same directory, when inspecting element in Chrome, ...

What is the best way to target a specific element in the DOM when using a function to trigger an action?

I am facing a challenge with a functional component where I want to trigger an action using onClick to update the store in Redux for a like button. I need the onClick function to access the DOM element's store properties in order to make the necessary ...