Flex paragraph takes up more space on its right edge when it has multiple lines or longer words rather than one line

Viewed 436

The application I'm working with has a piece of HTML code styled using flex that is present in multiple places to visualize several pop-up messages. The messages have a closing icon in the upper right corner.

However, depending on the length of the message within the <p> element, the distance between the text and the closing icon changes. For instance, if the text has multiple lines or longer words, the <p> element takes up more space, the distance between the text and the closing icon increases, and I can't figure out why.

Short text example

Long text example

How do I ensure a uniform distance between them?

<div style="display:flex; align-content:stretch;" id="aProductDraftUpdating>
   <p style="margin: 0px; flex:1 1 auto">
      "Editing the product draft continues from the last altered step. 
       Editing the product draft continues from the last altered step."
   </p>
   <i class="icons iconClose" role="link" style="flex:1 1 auto;" onClick="methodThatRemovesTheMessage(aProductDraftUpdating)">
      ::before
   </i>
</div>
1 Answers

You could use position: absolute to place the close icon and add paddind to the right of the alert box. Here is an example:

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.alert {
  position: relative;
  background: #ffffb7;
  padding: 5px 50px 5px 10px;
  z-index: 1;
  margin-bottom: -10px;
  box-shadow: 0px 5px 5px 0px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
}

.alert i {
  position: absolute;
  right: 20px;
}

.container {
  width: 100%;
  height: 60px;
  background: #fff;
  box-shadow: 0px 5px 5px 0px rgba(0,0,0,0.25);
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">

<div class="alert">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam luctus dolor magna, a consequat enim fringilla vitae.</p>
  <i class="fas fa-times"></i>
</div>
<div class="container">
  
</div>

Related