Ensuring multi-line text is properly aligned with Font Awesome icons

I'm facing a challenge with aligning an icon with text to its right in a multi-lined content. Currently, the setup looks like this:

<p style="text-align: left;">
    <i class="fa fa-example-icon" style="margin-right: 20px;"></i> 
    Text that is multi-lined.
</p>

On the first line, everything seems aligned perfectly:

|icon| Text that is multi-lined.

However, as soon as the text wraps onto the next line, the alignment gets disrupted:

|icon| Text that is multi-lined and now
it actually comes to the next line.

My goal is to achieve the following consistent alignment for all lines:

 |icon| Text that is multi-lined and now
        it actually comes to the next line.

What would be the most effective approach to maintain seamless alignment across multiple lines of text? I have some temporary solutions, but I aim to implement a proper solution.

Answer №1

Here is one way to achieve it:

.container{
  width: 200px;  
}
.container, .content{
  overflow: hidden;  
}
.content{
  margin: 0;
}
.fa-custom-icon{
 float: left;
  display: block;
}
<div class="container" style="text-align: center;">
    <i class="fa fa-custom-icon" style="margin-right: 30px;">Icon</i> 
    <p class="content">Text that spans multiple lines. This is an example of multi-line text Text that spans multiple lines. This is an example of multi-line text Text that spans multiple lines. This is an example of multi-line text Text that spans multiple lines. This is an example of multi-line text</p>
</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

The click event in an Angular 6 loop is not being activated

When the Test is clicked, the function should be invoked. However, nothing happens when I click on it. Here is the HTML component code: <div class="row m-0 justify-content-between" *ngFor="let i of k[currentk]?.details | keys"> <div (click ...

In Javascript, use the replace() function to target and replace text that is not contained

Seeking help with highlighting search strings in an autocomplete form. In my current approach, I aim to encapsulate the search term within specific tags for emphasis. However, complications arise when the pattern resides within HTML tags. var searchPatter ...

What is the best way to align the 5th and 6th list items to the left using CSS?

I am experimenting with Bootstrap to create a customized navbar. I am encountering difficulties in aligning the login and logout buttons to the right. Is there a way to achieve this? I have included my HTML and CSS code below: HTML code: <body> &l ...

Cannot locate the Django bootstrap files

Although I have set up Django with bootstrap by following tutorials, I am facing an issue where Django is unable to locate the static files even when I am replicating the steps shown in the tutorials. The structure of my Project is as follows: webshop ...

Stop chrome from cropping background images on body while using background-position

The body tag of my website has a background image of a paper airplane. However, I'm facing an issue where the very tip of the image is being cut off in Chrome. Interestingly, resizing the browser window causes the full image to reappear. This proble ...

CSS Color-Range Conditional Styling

I am interested in creating a simple chart using divs and spans, with the goal of implementing conditional formatting on each column based on its value to determine height. I have been struggling with figuring out how to make it work similar to Excel' ...

The table is not properly displaying within the parent scrolled div due to issues with the fixed positioning

Apologies for any language barrier. I am encountering an issue with a PHP page that includes a table meant to be displayed as position:fixed; however, it consistently appears above the scrollbars and does not stay within the parent div. View screenshot he ...

AngularJS: Default value causes dropdown menu text to not display

I am facing an issue with my select menu. <select id="dd" ng-show='data != null' ng-model='search'></select> Initially, I set the filter to display only USA by default. $scope.search = 'United States of America' ...

Calculating available balance by subtracting the entered amount from the existing balance in Python Django

In the user profile model within my Django project, there are fields for available balance and current balance. I am looking to deduct an input amount from the current balance in order to display the updated available balance on the user's web page. ...

Exploring the depths of Javascript scope with the Polymer starter-kit 2

When working on my-app.html ... <paper-icon-button icon="my-icons:menu" onclick="this.$._joesDrawerToggle()"></paper-icon-button> ... <script> Polymer({ is: 'my-app', ... _showPage404: function() { thi ...

Optimizing the use of .less files in an expansive angularjs application

Currently, I am in the process of developing a large-scale application using AngularJS as a Single Page App. All the html files have been organized under the Views folder as shown here. Views Sample sample.html sampleheader.html ...

Responsive Audio Tag with Bootstrap 5

<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link href="https: ...

Set the background image width to 75% of the screen size

I want to use this image https://i.sstatic.net/gt30c.jpg as a background for a section on my page. My preference is to have the white part cover only 75% of the screen, stopping before reaching the content in the left grid. Is it possible to achieve this ...

Generate a dynamic form that automatically populates different input fields based on JSON data

I am trying to dynamically auto populate a form with various input types such as select boxes and text areas. I have successfully implemented this for input boxes, see example below: function autofill(){ var data = [{visible_retail: "0", brand: ...

"Incorporate Bootstrap drop-down and button together for a stylish group feature

I am looking to format the code below to resemble the layout shown in the image using Bootstrap 3.3. When there isn't enough space to show all elements in a single line, I want them to stack vertically so that each element utilizes the entire width of ...

What could be the reason for a missing button in the Bootstrap navbar on smaller devices?

I'm new to Bootstrap and noticed on smaller devices, there is no visible button to tap for displaying the menu items. However, tapping on the upper right-hand side does reveal them. What could I be missing here? index.html <!DOCTYPE html& ...

Altering the dimensions of radio button options

Is it possible to change the size of a radio button using CSS in all browsers? I'm struggling to find a solution and don't want to waste my time if it's not achievable. I haven't explored CSS3 for HTML5 yet. Hmm... ...

What are some ways to restrict the number of words per line?

I'm currently developing an online store using NextJS and Material UI. The issue I encountered is related to the long product names that are causing my Card component to stretch. As shown in this image: https://i.sstatic.net/07qNm.png If you obse ...

Check if the page is active using is_page() function

I'm trying to apply styling to the active link using the is_page() function. It seems to work for the first navigation item, but once I click on the "om" link, it receives styling while the "hem" link retains its styling. Additionally, when clicking o ...

Identify the position of a mouse click event when dots overlap

Experience this live demo on CodePen by visiting it here. 1) When you click on the grid, a first red point will be added. 2) Click on the grid again to add a second red point. 3) By clicking back on the first red point, you may notice that the coordinat ...