CSS :before pseudo element is capable of displaying only one element, not both, on separate elements

I am currently working on integrating FA icons into WordPress sidebar widgets, and I have encountered some challenges with displaying the icons as intended. When targeting two separate items, only one of them displays the icon in the given code snippet.

Any advice or feedback would be greatly appreciated! Here is the CSS I am using:

    #recent-comments-2 li,
    .widget_recent_entries li {
      padding-left: 1.2em;
      margin-bottom: 7px;
    }
    .widget_recent_entries li:before {
      font-family: FontAwesome;
      content: "\f040";
      display: inline-block;
      width: 1.2em;
      margin-left: -1.2em;
    }
    #recent-comments-2 li:before {
      font-family: FontAwesome;
      content: "\f075";
      display: inline-block;
      width: 1.2em;
      margin-left: -1.2em;
    }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

<li id="recent-posts-2" class="widget-container widget_recent_entries">
  <h3 class="widget-title">Recent Posts</h3>
  <ul>
    <li>
      <a href="#">16OCT15</a>
    </li>
    <li>
      <a href="#">15OCT15</a>
    </li>
    <li>
      <a href="#">14OCT15</a>
    </li>
    <li>
      <a href="#">13OCT15</a>
    </li>
  </ul>
</li>

<li id="recent-comments-2" class="widget-container widget_recent_comments">
  <h3 class="widget-title">Recent Comments</h3>
  <ul id="recentcomments">
    <li class="recentcomments"><span class="comment-author-link">Bob</span> on <a href="#">16OCT15</a>
    </li>
    <li class="recentcomments"><span class="comment-author-link">Bill</span> on <a href="#">16OCT15</a>
    </li>
    <li class="recentcomments"><span class="comment-author-link">Bob</span> on <a href="#">15OCT15</a>
    </li>
    <li class="recentcomments"><span class="comment-author-link">Bill</span> on <a href="#">15OCT15</a>
    </li>
    <li class="recentcomments"><span class="comment-author-link">Bill</span> on <a href="#">Random Post</a>
    </li>
  </ul>
</li>

Answer №1

After some troubleshooting, I managed to get it to work by adding an extra CSS rule between the conflicting ones. Despite no apparent conflicts, making this adjustment resolved the issue. Here is how it was fixed:

#recent-comments-2 li,
.widget_recent_entries li  {
    padding-left: 1.2em;
    margin-bottom: 7px;
}

.widget_recent_entries li:before {
    font-family: FontAwesome;
    content: "\f040";
    display: inline-block;
    width: 1.2em;
    margin-left: -1.2em; 
}​

#footer {
    position: relative;
    margin-left: auto;
    margin-right: auto;
    height: auto;
    clear:both;
    text-align: center;
    background-color: #242424;
    padding-top: 5px;
    border-top: 1px solid rgba(0,0,0,.15);
    box-shadow: 0 0 7px #323232;
    margin-top: 35px;
    } 

#recent-comments-2 li:before {
    font-family: FontAwesome;
    content: "\f075";
    display: inline-block;
    width: 1.2em;
    margin-left: -1.2em;
}​

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

Image Animation Using a Rotational Control (HTML/JavaScript/...)

I am interested in achieving a specific effect with a series of images that transition from dark to light. My idea is to have a dial or slider underneath or over the frame so that when it is moved to the left, the black image is displayed, and when moved t ...

attribute alternativeType

<input type="text" name="date" value="" data-type="datetime" required="true" /> I'm looking for a different approach than using dojoType for a couple of reasons: The parseonload behavior causes the page to "jump" when loading (system-defaul ...

What are some ways to change the appearance of a component using its parent?

In order to make changes to the CSS properties of a Vue component from its parent, effectively overriding any existing styles within the component, I am seeking a solution. Initially, I assumed that styling a component like <my-component> directly f ...

Place numbers above the image in the top right corner or at the top of the image

I'm struggling to align an image with a number that updates on page load. I want the number to either be on top of the image or in the northeast corner (top right), but so far I can't get it to line up correctly. The best I've achieved is ha ...

Tips on aligning multiple elements vertically in a justified manner

I'm struggling to articulate what I need, but I'll give it a shot. I want to vertically align three different elements, each wrapped in their own divs. This is my current code: .service_info { margin-top: 45px; clear: both; ...

Utilizing a mySQL database to insert HTML content into a div: a step-by-step guide

Presently, this jQuery snippet is being utilized to insert HTML content from another file into a div: $("#list li a").click(function(){ var id = this.id; $('#content').fadeOut('fast', function(){ $.ajax({url:"./html/" + id + ".html ...

Improving the way text entered in an input box is displayed using HTML table cells

Seeking advice on how to display the last two input boxes in a dynamic HTML table so that users can easily view the data they have entered. The issue arises when the length of the data in these columns is large, making it difficult for users to see all the ...

What are the steps to ensure the effective functioning of my checkbox filter?

Currently, my product list is dynamically created using jQuery. I now need to implement filtering based on attributes such as color, size, and price. I found some code that filters the list items by their classes, which worked perfectly for someone else. ...

a container holding two floating divs

I have been attempting to create two divs positioned side by side, with one containing content and the other acting as a sidebar. Both of these divs are contained within another larger container div. Despite my efforts, I have not been successful in achiev ...

How can I use absolute positioning and scrolling with an Iframe?

One of the key elements of this website is the implementation of iframes, with only one displayed at a time. However, my current issue revolves around the inability to scroll within these iframes due to their absolute positioning. I have attempted variou ...

Ways to emphasize the current tab on the site's navigation bar?

Here's my question: I have a menu with different items, and I want to make sure that the active tab is highlighted when users switch to another page. I noticed that Stack Overflow uses the following CSS: .nav { float: left; font-size: 1 ...

Is there a way to ensure that the vertical scrollbar remains visible within the viewport even when the horizontal content is overflowing?

On my webpage, I have multiple lists with separate headers at the top. The number of lists is dynamic and can overflow horizontally. When scrolling horizontally (X-scrolling), the entire page moves. However, when scrolling vertically within the lists, I wa ...

Issues with implementing a Bootstrap dropdown list in a Django HTML template

I'm having trouble implementing Bootstrap in my Django project's shared HTML file. The dropdown list isn't functioning properly despite trying various approaches, including using CDN and local Bootstrap files. When I click on the dropdown li ...

Cease the automatic redirection of the contact form

Hey there, I'm currently working with this contact form: HTML <form action="mail.php" method="POST"> <p>Team Name</p> <input type="text" name="name"> <p>Your Email</p> <input type="text" name="email"> <p& ...

Issue arising with hover animation on a stable colored background

I recently created my own website and utilized this codepen https://codepen.io/nikolamitic/pen/vpNoNq to incorporate an animation effect on my name. While it works well overall, I encountered an issue when trying to decrease the line-height of my elements ...

Achieve horizontal wrapping of div elements

Currently, I am developing a blog where search results for articles will be displayed within divs. The design of the website is completely horizontal, meaning that articles scroll horizontally. Creating a single line of divs is straightforward, but it&apo ...

A method for evaluating the condition of a <td> value in a table based on its corresponding table header

I am looking to modify the th and td values in my HTML code. Specifically, I want to align numbers to the right (except for s.no) and text to the left. <button type="submit" class="btn btn-raised btn-primary mr-5" (click)="productPrintSection(&apos ...

Tips for activating animated text upon hovering over a text or image:

My brand name is: Code The navigation bar displays as follows: Code Home | Service | Product | Contact I would like to change the appearance of my brand name from Code to { Code } when users hover over it. Additionally, I wish to style the brackets { ...

Effortlessly add the input form using the selectpicker feature

Is it possible to automatically input values using selectpicker and calculate a form without having to manually click on the input field first? The JavaScript for calculating is working, but I need the Input Price to have a value automatically when selecti ...

Can AJAX Delete requests be executed without using jQuery?

Is it possible to use AJAX delete request without using jQuery? My JSON object at localhost:8000 appears like this: { "Students":[{"Name":"Kaushal","Roll_No":30,"Percentage":94.5}, {"Name":"Rohit","Roll_No":31,"Percentage":93.5}, {"Name":"Kumar ...