Tips for inserting an icon alongside a list item in HTML

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

Can you help me with adding an icon to a list item using Font Awesome or any other method? I want the icon to appear on the right side of the text. I have four sections of text that I want to convert into expandable dropdowns. I tried adding an arrow pointing down (

<i class="fa-light fa-arrow-down"></i>
) from Font Awesome, but it doesn't seem to be showing up.

.container-fluid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30vw;
  background-image: url(pictures/output-onlinepngtools.png);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  word-break: keep-all;
  border: 2px solid rgb(68, 115, 216);
  padding-left: 20px;
  padding-right: 100px;
}

.container-fluid h1 {
  margin: 0;
  line-height: calc(30vw / 3);
}

.sec2drop li {
  list-style: none;
  border-top: 1px solid rgb(161, 159, 159);
  line-height: 50px;
}
<div class="container-fluid">
  <div class="sec3">
    <ul class="sec2drop">
      <li>
        <i class="fa-light fa-arrow-down"></i> Prepare for a language exam
      </li>
      <li>Hungarian for kids</li>
      <li>Take on a challenge</li>
      <li>Translation services</li>
    </ul>
  </div>
</div>

Answer №1

Please make sure to double-check the file path for your font-awesome css and the font-faces linked in the css file. Once you have done that, simply copy and paste the following code:

<div class="container-fluid">
    <div class="sec3">
      <ul class="sec2drop">
        <li>
           Get ready for a language exam <i class="fa fa-caret-down"></i>
        </li>
        <li>Hungarian lessons for children</li>
        <li>Embrace a new challenge</li>
        <li>Professional translation services</li>
      </ul>
    </div>
  </div>

Answer №2

To enhance accessibility and improve the structure of your code, it is recommended to refrain from using icon fonts and instead utilize native HTML elements styled with CSS for a cleaner approach:

ol,
ul,
li {
  /* Eliminating default list markers: */
  list-style-type: none;
}
<div class="container-fluid">
  <div class="sec3">
    <ul class="sec2drop">
      <li>
        <details>
          <summary>Prepare for a language exam</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
      <li>
        <details>
          <summary>Hungarian for kids</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
      <li>
        <details>
          <summary>Take on a challenge</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
      <li>
        <details>
          <summary>Translation services</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
    </ul>
  </div>
</div>

View JS Fiddle demo.

You can further customize the styling as needed:

ol,
ul,
li {
  /* Removing default list styles: */
  list-style-type: none;
}


/* Adding borders to non-first-child <li> elements
   on their block-axis start edge: */

li:not(:first-child) {
  border-block-start: 1px solid #ccc;
}

details ::marker {
  /* Clearing default content from ::marker pseudo-elements: */
  content: '';
}

summary {
  /* Using cursor for interactive hint: */
  cursor: pointer;
  /* Flex layout for gap between <summary> text and ::before pseudo-element: */
  display: flex;
  gap: 0.25em;
}

details summary::before {
  /* Using downward-pointing triangle as content: */
  content: '\25BE';
  background-color: transparent;
}

details[open] summary::before {
  /* Switching to upward-pointing triangle as content
     when parent <details> is open: */
  content: '\25B4';
}
<div class="container-fluid">
  <div class="sec3">
    <ul class="sec2drop">
      <li>
        <details>
          <summary>Prepare for a language exam</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
      <li>
        <details>
          <summary>Hungarian for kids</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
      <li>
        <details>
          <summary>Take on a challenge</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
      <li>
        <details>
          <summary>Translation services</summary>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Similique, necessitatibus voluptas nisi sequi perferendis distinctio maiores magnam eos odit assumenda id minima fugiat cum explicabo adipisci vero culpa eligendi hic!</p>
        </details>
      </li>
    </ul>
  </div>
</div>

Check out JS Fiddle demo.

For more detailed information, refer to the following resources:

Additional Reading:

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

"Ensure only one checkbox is selected at a time by unchecking the previous

Hi, I'm facing two issues with the code below. The first problem is that when I select checkbox number 3, it automatically selects number 2 as well. I only want this to happen if I manually check it (similar to checkbox number 2). The second issue i ...

Tips on merging HTML node lists from various `getElement`s

Is there a way to combine HTML elements and extract values using array methods? I am struggling to merge them as a nodeList. I tried using get elements and array.unshift to consolidate elements into one variable. var elemsLabel = document.querySelecto ...

What is the best way to pass a CSS root constant to a separate CSS file?

In my Angular test project, I'm experimenting with using the same colors repeatedly. To achieve this, I created a constants.css file where I defined all my root constants, which currently consist of colors. However, I've hit a roadblock when atte ...

Having trouble with refreshing the div content when using jQuery's $.ajax() function

My goal is to refresh a div that has the id #todos after saving data in the database. I attempted to use .load() within $.ajax() $('.todo--checkbox').change(function () { let value = $(this).data('value'); $.ajax({ url: ...

Connecting CSS styles and images to my EJS templates on a distant Express server using Node.js (Ubuntu 18.04)

I have been hunting for a solution here extensively, but every attempt has failed. So, here's the issue I'm facing: I have created a basic Express server locally to display a static page until I finish full integration. The structure of my site ...

Tips for maintaining the alignment of four buttons in a single row as the size of the screen changes

I'm creating a simple browser game as part of my web development learning process. I have a set of divs that represent a warrior, and at the head of the "div table" I have a group of 4 buttons arranged horizontally. However, when the screen size is re ...

Arranging components in a horizontal layout on Jquery mobile

I'm completely new to Jquery mobile and I'm having trouble getting these elements aligned. Here's my code, but I need the two icons to line up horizontally with the caption "Heading". <h3>Heading</h3> <img src="../re ...

Unlimited scrolling gallery with multiple rows

I am looking for a way to create a multi-row infinite loop scrolling gallery using html, css, and javascript. Can anyone help me with this? ...

Why do my tablet media queries take precedence over mobile view media queries?

I've noticed that when I view my website on mobile devices, the tablet media queries always seem to override my mobile media queries. Can anyone explain why this is happening? Here is how I have set it up: /* X-Small devices (portrait phones, less t ...

Transform your standard HTML buttons into a collective of radio buttons

Looking for a way to make some ordinary buttons function as radio buttons without adding another library to the project. Any suggestions on how this can be achieved using just HTML and JavaScript/jQuery? Appreciate any help, thank you. ...

Utilize a specific component to enclose particular words within a contenteditable div in an Angular project

I have a task at hand where I need to manipulate text input from a contenteditable division, use regex to identify specific words, and then wrap those words within an angular component. Although I have managed to successfully replace the text with the com ...

Bootstrap 4 and Angular 7 application experiencing issues with toggle button functionality in the navigation bar

I am currently working with Angular7 and Bootstrap4. I am attempting to integrate a navbar into my application, but I am facing an issue where the toggle button does not work when the navbar is collapsed. It is important for me to mention that I do not wa ...

A guide to connecting keyboard events to div elements within a React application

Currently working on a basic react project to gain some practical experience with the library. I aim to develop a simple user interface with blank spaces to be filled in by typing via keyboard input. Here's a glimpse of my progress so far: function ...

How can I show hidden column names in the Sencha Touch 2 date picker component with CSS?

I am currently utilizing a date and time picker that has the ability to display ['month', 'day', 'year','hour','minute','ampm']. You can find the source code here. Although everything is function ...

Guide to activating form elements using a JQuery function

I need help setting up a form with 11 rows and 11 columns. By default, the form fields should be disabled, but when I click on an "EDIT" button, they should become enabled. Any assistance would be greatly appreciated. Thank you in advance. Here is my edit ...

Eliminating data from selection options on a HTML menu list

Currently, I am facing an issue while attempting to incorporate a menu bar into my HTML page. After adding the icons, they are displaying with both underlines and dots at the back. I have tried using text-decoration=none; to remove the underline, but unf ...

Angular: merging object values into a single string by looping over them

i am dealing with the following data : "commercialRanges": [ { "rangeId": "700", "rangeName": "POSTPAID" }, { "rangeId": "500", "rangeName": "PREPAID" }, ] In my view, I am aiming to display the ...

Prevent using href for opening the browser when clicked

In the control, there is an href link that triggers a javascript function and passes a variable to it: <a href="<%#XPath("link").ToString()%>" onclick="return getLink(this)">Link</a> I'm looking for a way to prevent the browser fro ...

Tips for setting up the image as the header background in HTML5 and CSS3

I am currently designing a website. I'm wondering if there is a way to create a div with a curved bottom using HTML5, CSS3 and JavaScript. It should resemble the design of the curved header bottom ...

CSS Navigation Bar Fails to Function Properly on Mobile Devices

Check out the plunkr I have created by visiting: http://plnkr.co/edit/gqtFoQ4x2ONnn1BfRmI9?p=preview The menu on this plunkr functions correctly on a desktop or laptop, but it doesn't display properly on a mobile device. I suspect that the issue may ...