The parent element is concealed when the content inside the expanding span grows

I created an HTML and CSS design with the following styles:

.sectionTitle {
  color: #fff;
  background-color: #e8eaed;
  padding: 0;
  height: auto;
}

.contentAlignment {
  margin-left: 10px;
  line-height: 23px;
  max-width: 100%;
  cursor: text;
  font-size: 15px;
}

.contentAlignment {
  font-size: 14px !important;
}

.contentAlignment {
  margin-left: 0;
}

The <span> element within the div using the class contentAlignment displays dynamic content that needs to be shown as provided by the user, even if it has a large font size which may overflow the parent div.

To address this issue, I attempted to adjust the CSS properties by changing the line-height:

.contentAlignment {
  line-height: 0;
  margin-left: 0;
}

However, removing the line-height property entirely from the global CSS file did not solve the problem, as it is used across all pages and altering it might affect other components. The challenge now lies in finding a suitable solution without compromising the existing layout.

Answer №1

Seems like the issue stems from setting line-height in pixels rather than relative to the font size. (Note: It's also recommended to use rem or em units for the font size, although that isn't directly related to this problem).

I've gone ahead and removed the CSS that was being overwritten anyway.

.sectionTitle {
  color: #fff;
  background-color: #e8eaed;
  padding: 0;
  height: auto;
}

.contentAlignment {
  line-height: 1.35;
  max-width: 100%;
  cursor: text;
  font-size: 14px;
  margin-left: 0;
}
<div class="sectionSpacing col-12">
  <!---->
  <div>
    <!---->
    <div class="sectionTitle d-flex justify-content-between align-items-center">
      <label class="formLabelStyles sectionheading">References</label>
    </div>

    <!---->
    <div>
      <!---->
      <div class="contentAlignment">
        <span style="font-size: 48px; background-color: rgb(255, 0, 0);">Middle Cerebral Artery</span>
      </div>
    </div>
  </div>
</div>

Answer №2

The issue at hand stems from the utilization of a fixed line height within your style sheet, causing an unintended enlargement of the font size while maintaining a line_height: 23px

To rectify this situation, simply eliminate the line-height declaration.

.sectionTitle {
  color: #fff;
  background-color: #e8eaed;
  padding: 0;
  height: auto;
}

.contentAlignment {
  margin-left: 10px;
  max-width: 100%;
  cursor: text;
  font-size: 15px;
}

.contentAlignment {
  font-size: 14px !important;
}

.contentAlignment {
  margin-left: 0;
}
<div class="sectionSpacing col-12">
  <!---->
  <div>
    <!---->
    <div class="sectionTitle d-flex justify-content-between align-items-center">
      <label class="formLabelStyles sectionheading">References</label>
    </div>

    <!---->
    <div>
      <!---->
      <div class="contentAlignment">
        <span style="font-size: 48px; background-color: rgb(255, 0, 0);">Middle Cerebral Artery</span>
      </div>
    </div>
  </div>
</div>

Answer №3

The issue arises from the discrepancy in line-height: 23px not aligning with the specified font-size (in this instance, 43px).

To remedy this, simply add line-height: normal to the .contentAlignment class. Unless another source specifies a more specific line-height, this should resolve the issue. Additionally, ensure that line-height: normal is placed after line-height: 23px in the CSS file as styles are processed from top to bottom. If your selector is more specific, it will take precedence.

You can observe in my example where I've included line-height: normal after line-height: 23px, effectively overriding the previous line-height. Remember, this principle also applies to stylesheets, so ensure that the stylesheet applying line-height: normal is read after the one implementing line-height: 23px (unless your selector is more specific).

.sectionTitle {
  color: #fff;
  background-color: #e8eaed;
  padding: 0;
  height: auto;
}


/*class from global css file */

.contentAlignment {
  /* doesn't work - it's being overridden */
  line-height: normal;
}

div.contentAlignment {
  /* works - more specificity than just .contentAlignment */
  line-height: normal;
}


.contentAlignment {
  margin-left: 10px;
  line-height: 23px;
  max-width: 100%;
  cursor: text;
  font-size: 15px;
  /* works - supersedes the line-height */
  line-height: normal;
}

.contentAlignment {
  /* works - overrides the line-height */
  line-height: normal;
}

/*these classes are modifications within the component itself */

.contentAlignment {
  font-size: 14px !important;
}

.contentAlignment {
  margin-left: 0;
}
<div class="sectionSpacing col-12">
  <!---->
  <div>
    <!---->
    <div class="sectionTitle d-flex justify-content-between align-items-center">
      <label class="formLabelStyles sectionheading">References</label>
    </div>

    <!---->
    <div>
      <!---->
      <div class="contentAlignment">
        <span style="font-size: 48px; background-color: rgb(255, 0, 0);">Middle Cerebral Artery</span>
      </div>
    </div>
  </div>
</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

Discover the visibility of an element through monitoring DOM manipulation with Selenium

Is it possible to monitor a webpage for events such as when an element becomes visible? Can this be achieved using Selenium? For instance, if I set a timeframe to watch a webpage from startTime to endTime, various page events could be recorded, including ...

What is the CSS technique for displaying text overflow after displaying only two lines within a div?

Currently working on a webpage design where I am looking to display text overflow using ellipsis within a div. However, my requirement is to display two lines of data in the div before handling the text overflow. I prefer not setting a fixed height for t ...

When submitting a form with the jQueryForm plugin, take action on the form by selecting it with `$(this)`

I have a situation where I have multiple forms on one page and am utilizing the jQuery Form plugin to manage them without having to reload the entire page. The issue arises when I need some sort of visual feedback to indicate whether the form submission wa ...

Troubleshooting a display issue with Chrome's User Agent - Possible CSS solution?

After recently installing a WordPress theme, I am encountering an issue with a Facebook conversion box not displaying when accessing my site through Chrome. Interestingly, this problem does not occur when using Firefox. Upon inspecting the element in Chro ...

Activate the WebDAV feature within the .htaccess file

Can WebDAV be activated through an .htaccess file? I'm experiencing issues with Plesk not recognizing my modified config files that have WebDAV enabled. Is it feasible to enable WebDAV without using an .htaccess file? ...

Can you customize the background color for the entire section where the first child appears in a nested collapsible list with CSS?

In my current setup, I have a nested list within a larger container box. Each ul element has a border-top style applied, while each li element has a border-bottom and padding. The HTML code looks like this: <div class="menu"> <ul ...

Personalize a bootstrap theme specifically for the mobile interface

My current template, based on Bootstrap, displays a text along with a button and an image. Using a checkbox, you can choose whether the image appears to the right or left of the text. One issue I'm facing is that in the mobile view, the text and butt ...

Angular element fails to display properly

I'm currently working on developing a website using Angular and creating a header component. To generate the necessary files, I used the command ng g c commons/header which creates the HTML, SCSS, TS, and .spec.ts files. I then made modifications to t ...

The item on my list is barely visible, as the height of the list column is adjusted upon loading the page

In my footer, I have a list of links. When I click on the last item labeled "See more links," jQuery's slideToggle() function replaces the list with new members. However, this action causes the bottom of my footer to shift slightly up and then back d ...

Tips for creating a layout with two responsive columns side by side: one with text and the other with an image, using Bootstrap 4

How can I create two responsive columns in Bootstrap 4, one with text and the other with an image, similar to the layout shown in the image below? <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" int ...

Automating the process of populating preferredCountries from intl-tel-input with database output

I am looking to dynamically populate the preferredCountries:["xx","yy","zz"] array with a function that retrieves the most frequently used country codes from a MySQL database, listing them in descending order of usage and including those with a count of at ...

How do you locate elements using text in Selenium with special characters like &#65279?

As a newcomer to test automation, I'm looking for a way to click on a link with only partial text available. I am aware of the find_element_by_partial_link_text method, but there seems to be random words in the code that include &#65279;. This pre ...

Set the background of the vue widget to be completely see-through

I have a project where I am creating a widget using Vuetify, and embedding it into another website in the following way: <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="component-styl ...

Whenever I insert an http link for FontAwesome, the icons work perfectly fine. However, when I try to host it locally,

After providing the CDN link: <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet"> The icons are displaying correctly and everything is working fine. You can view the code on ...

Utilizing Bootstrap for Efficient Image Alignment

I'm encountering an issue with my code and I am unsure of how to fix it. The current state of my code is different from the desired outcome https://i.sstatic.net/Ti1kK.jpg As you can see, the image above does not match the appearance of the image I ...

Using Laravel to seamlessly integrate Bootstrap modals into a table structure

I am working on a Laravel datatable with the following setup: <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd ...

Excessive content and the upper limit of height

I'm in the process of creating a scrolling table with a maximum height, and here's what I've done so far: <table> <tbody style="height: 300px; overflow:auto;"> //php for loop to populate table with <tr>s/<td>s </t ...

Incorporating JavaScript unit tests into an established website

I am facing a challenge with testing my JavaScript functions in the context of a specific webpage. These functions are tightly integrated with the UI elements on the page, so I need to be able to unit-test the entire webpage and not just the functions them ...

AJAX fails to retrieve a result

I've been attempting to grasp the concept of using ajax, but unfortunately I have not been able to receive any response. Here is the HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta ...