Guide to aligning an icon and p tag on one line using materializecss

I am currently working with materialize css and material icons. I am attempting to display an icon next to a set of numbers, but I am unsure how to achieve this. Below is the code snippet in question:

<i class="material-icons">person</i>
<p>123123</p>

Any assistance would be greatly appreciated!

Answer №1

Swap out your snippet with this new one:

<div><i class="fas fa-user">user</i>987654</div>

Answer №2

If you want to follow the materialize approach, simply include a class of left to the icon:

<i class="material-icons left">person</i>
<p>123123</p>

The button documentation provides some insight on how to align text and icons side by side within the framework.

<a class="waves-effect waves-light btn"><i class="material-icons left">cloud</i>button</a>

The explanation given by @927tanmay is technically accurate - the left class essentially applies float:left to the element. It's unnecessary to write additional inline CSS since the left class is included in the documentation for use with icons.

For more information, refer to the helpers section.

Answer №3

To align your icon to the left, simply add the style property "float: left" to the icon tag. You can use the following code as a reference:

  <i class="material-icons" style="float:left">person</i>
  <p>123123</p>

Answer №4

I was a bit confused by your message, but I believe you're looking to align numbers and icons next to each other. To achieve this, you can place them within a div tag and style it like so:

<div style="display:flex;">
   <i class="material-icons">person</i>
   <p>123123</p>
</div>

Sometimes browsers automatically apply styles to <p> tags, such as margins, so if needed, you can set margin:0 for the <p> element.

Alternatively, you can achieve the same result by setting the display property of both the <p> and <i> elements to "inline-block".

Answer №5

The Importance of the Display Property

The display property plays a crucial role in determining the layout of elements on a webpage.

Block vs Inline Elements

Block elements, like the classic div, automatically take up the full width and start on a new line. On the other hand, inline elements, such as span, do not break onto a new line.

<div>Div's display defaults to block</div>
<div>Div's display defaults to block</div>

<span>span's display defaults to inline</span>
<span>span's display defaults to inline</span>

This simple distinction allows for clear vertical or horizontal layout choices.

Advanced Layout Techniques

In response to the need for more sophisticated layouts, CSS now offers powerful tools like Flexbox and CSS Grid. These tools provide more flexibility and control over element positioning than traditional methods like float.

Flexbox operates on a single axis for laying out elements, while CSS Grid allows for true 2D grid-based layouts. It is highly recommended for readers to dive deeper into these advanced techniques.

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

A fresh javascript HTML element does not adhere to the css guidelines

While attempting to dynamically add rows to a table using Javascript and jQuery, I encountered an issue. Here is my code: <script> $(document).ready(function(){ for (i=0; i<myvar.length; i++){ $("#items").after('<tr class="item- ...

Template Binding Issue in Angular Not Resolving

After implementing the directive below... app.directive('layoutPreview', function () { return { restrict : 'E', transclude : false, scope: { layout: '@', previewid : '=' }, contro ...

Finding your site's First Contentful Paint (FCP) can be done by analyzing the

After doing some research on Google insights, I came across information about FCP. However, I'm still unsure about how to determine my site's FCP and other relevant metrics. If anyone could provide me with more information or share detailed link ...

Customizing CSS according to specific URLs

I have two different domains - one ending with .nl and the other ending with .be. For instance, domain.nl and domain.be. Both domains share a similar overall style, but I want certain elements to have distinct styling depending on whether it is the .nl o ...

Using the table component object in Angular, you can easily set focus to an input field contained within a <td> element of a table

Currently, I am working on a table that dynamically populates data. Within this table, there are multiple input tags and I am looking to enhance user experience by enabling the focus to shift to the next input in the following td tag when the right arrow k ...

How to dynamically disable a dropdown based on the selection of another dropdown using AngularJS

This project has been more challenging than I anticipated. I thought it would be a simple task to accomplish. Currently, I am developing a basic form with an input text field and two dropdown boxes. These dropdown boxes represent different types of contra ...

Difficulty displaying SVG in Opera browser when using the Raphael JS library

Currently, I am experimenting with Raphael JS to create visually appealing SVG graphics on a webpage. You can view my progress at . Most browsers display the graphics properly except for Opera 11. In Opera, the graphics fail to render when clicking on any ...

Guide to Repairing Uncaught TypeError: players.setAttribute is not a recognized method?

I'm a beginner and encountered an error saying Uncaught TypeError: players.setAttribute is not a function when submitting an action. How can I solve this issue? Please share your insights. ''' //selecting all necessary elements const s ...

Trouble with z-index when attempting to stack forms on top of one another

Currently, I am working on creating a login page and signup page for my program. The goal is to stack them on top of each other with only one being displayed at a time. However, I am facing an issue where they are not stacking properly. I attempted using t ...

Achieving full width for the elements in a row with Flexbox: A step-by-step guide

I am dealing with a flexbox grid that contains random width images: https://i.stack.imgur.com/pfPeU.jpg I want to stretch the elements in each row to full width to eliminate any white space - Is there a way to achieve this using CSS? justify-content do ...

What is the method for activating the on collapse event with a bootstrap navbar?

I am encountering a common issue with collapsing the navbar on smaller screens and triggering an event when the collapse button icon is clicked. Despite my efforts to find a solution, I have been unsuccessful in using the following JavaScript code: $(&apos ...

The benefits of utilizing "native tags" instead of foreignObject in an SVG

As the creator of the stackoverflow-readme-profile project, I dedicated extensive time and effort to crafting a personalized Stackoverflow profile in the form of an SVG image. Utilizing "native svg tags," I meticulously constructed elements such as: < ...

Using JQuery to automatically scroll and anchor to the bottom of a dynamically populated div, but only if the user doesn't

I am attempting to achieve the functionality of automatically scrolling to the bottom of a div with the ID #chat-feed. The overflow for this div is set to auto, and I want it to remain at the bottom unless a user manually scrolls up. If they do scroll up, ...

Tag - A guide on setting the required attribute for a tag

Currently, I am utilizing Jquery Tag it in order to manage tags and save the values in a database. My challenge lies in using jQuery to make the myTags field required, ensuring that at least one tag is added before proceeding with the save operation. This ...

What steps can be taken to identify the referrer of external links when the target attribute is set to "_blank"?

Can't seem to capture the Referrer with PHP: $_SERVER['HTTP_REFERER']; Whenever visitors land on mywebsite.com from external-web-site.com via a link with target="_blank", for example: ... <a href="http://mywebsite.com" target ...

query in PHP to display specific data

Seeking guidance for developing a document tracking system using PHP. Struggling with defining the correct title for my project and unable to generate relevant keywords for search queries. The main issue pertains to determining how the system can validat ...

Attempting to relocate various containers

My task involves handling a group of randomly placed boxes on a webpage, each painted in random colors. I am currently attempting to enable their movement from one location to another. Despite being a seemingly simple task, my lack of familiarity with mous ...

Troubleshooting z-index problem with background image and parent tag of image

I seem to be facing an issue with the z-index property. Here is the code snippet in question: <div id="sidebarCont"> <div id="avatarCont" class="mask"> <img id="" class="" src="img.jpg" alt=""/> </div> And here is the correspo ...

Aligment issues in columns on Bootstrap 5

I currently have a layout using Bootstrap 5 with multiple rows and columns. My goal is to have the columns aligned within each row, but I am experiencing issues where some borders are not lining up correctly with the columns. .VI-border { border-t ...

Combining Jquery scripts for seamless integration

I am facing an issue while trying to execute two different jQuery scripts simultaneously - one named balancedgallery and the other museum. Individually, each script works perfectly fine. However, when running them together, the balancedgallery script seems ...