Choosing a sibling element before another using CSS

Is there a way to make both of my icons display some text when hovered over? I managed to make it work, but the leftmost icon doesn't trigger the span element when hovered. The text needs to appear on the left side of the Yelp icon for design reasons. You can find the code below or check out the Codepen link: https://codepen.io/ChumperDumper/pen/MWgoEpL

I attempted to wrap the text that should be faded in with the icon, but Font Awesome behaves strangely when attempting this.

.fa-yelp {
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  -webkit-transition: all 0.5s ease;
  color: red;
  margin: 1rem 2.5rem 1rem 0;
}

.fa-yelp:hover {
  transform: rotate(-20deg);
}

.fa-yelp:hover~.text-bubble-yelp {
  opacity: 1;
  transition: opacity 0.5s ease-in;
}

.fa-twitter {
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  -webkit-transition: all 0.5s ease;
  color: #1DA1F2;
  margin: 1rem 0 1rem 2.5rem;
}

.fa-twitter:hover {
  transform: rotate(20deg);
}

.fa-twitter:hover~.text-bubble-twitter {
  opacity: 1;
  transition: opacity 0.5s ease-in;
}

.text-bubble {
  opacity: 0;
  transition: opacity 0.5s ease-out;
  position: static;
  vertical-align: 25px;
  font-weight: bold;
  font-size: 1.5rem;
  margin: 0 2rem
}
<meta charset="utf-8">
<title>Website</title>
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<link rel="stylesheet" href="css/styles.css">
</head>

<body>

  <!-- Welcom Section -->

  <section id="welcome">
    <span class="text-bubble text-bubble-yelp">Review us on Yelp!</span>
    <span class="logo fab fa-yelp fa-3x"></span>
    <span class="logo fab fa-twitter fa-3x"></span>
    <span class="text-bubble text-bubble-twitter">Follow us on Twitter!</span>
  </section>

The expectation was for it to select the sibling element, but it appears that it won't pick a sibling element that precedes itself. :/

Answer №1

Try this solution, it should work for you - here

.fa-yelp {
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  -webkit-transition: all 0.5s ease;
  color: red;
  margin: 1rem 2.5rem 1rem 0;
}

.fa-yelp:hover {
  transform: rotate(-20deg);
}

.fa-yelp:hover~.text-bubble-yelp {
  opacity: 1;
  transition: opacity 0.5s ease-in;
}

.fa-twitter {
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  -webkit-transition: all 0.5s ease;
  color: #1DA1F2;
  margin: 1rem 0 1rem 2.5rem;
}

.fa-twitter:hover {
  transform: rotate(20deg);
}

.fa-twitter:hover~.text-bubble-twitter {
  opacity: 1;
  transition: opacity 0.5s ease-in;
}

.text-bubble {
  opacity: 0;
  transition: opacity 0.5s ease-out;
  position: static;
  vertical-align: 25px;
  font-weight: bold;
  font-size: 1.5rem;
  margin: 0 2rem
}

.text-bubble-yelp {
  float: left;
  position: relative;
  top: 25px;
}
<head>
  <meta charset="utf-8">
  <title>Website</title>
  <script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
  <link rel="stylesheet" href="css/styles.css">
</head>

<body>

  <!-- Welcom Section -->

  <section id="welcome">
    <span class="logo fab fa-yelp fa-3x"></span>
    <span class="text-bubble text-bubble-yelp">Review us on Yelp!</span>
    <span class="logo fab fa-twitter fa-3x"></span>
    <span class="text-bubble text-bubble-twitter">Follow us on Twitter!</span>
  </section>

This may not be the perfect fix, but it could help resolve your issue.

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

What steps should I take to confirm the text exists within a particular <DIV> element using Selenium WebDriver (java) and Chrome?

Background: My current setup involves using Selenium WebDriver with Java and utilizing Google Chrome as the browser. I have a question regarding locating specific text on a webpage. What if there are multiple instances of the same text that I am looking f ...

Issue with the text wrapping of Angular mat-list-option items

When the text of my checkboxes is too long, it doesn't wrap properly. Please see the image below for reference: Click here to view Checkbox image and check the red box Here is my HTML code: <mat-selection-list #rolesSelection ...

Deactivating Cluetip tool tips and adjusting the height limit in JQuery

How can I momentarily turn off the hints? I have seen references to being able to do so on the website and in this forum, but I am having trouble locating the command to disable them. I just need to temporarily deactivate them and then enable them again. ...

Trouble with card alignment in Bootstrap

I've been experimenting with creating a grid layout using cards and utilizing ng-repeat for generating the cards. Unfortunately, I'm running into an issue where there is no spacing between each card, as depicted in the image. https://i.stack.img ...

What is the simplest method for fetching and parsing JSON data with jQuery and JavaScript?

I'm having trouble making this code snippet work. I can't seem to figure it out. The objective is to retrieve and parse a JSON object in the simplest and easiest way possible. Here's the code snippet. <!DOCTYPE html> <html> &l ...

Ensure that buttons appear neat and organized when viewed on mobile devices

As a CSS beginner utilizing the Bootstrap framework, I have encountered an issue with my button layout on mobile devices. I have successfully created a set of buttons that display correctly on both desktop and mobile views. In the desktop view, you can se ...

What is the best way to style only textboxes with CSS without affecting other input types such as checkboxes?

If attribute selectors were universally supported by all browsers, we could effortlessly implement the following styling: input[type='text'] { font:bold 0.8em 'courier new',courier,monospace; } input[type='radio'] { margin:0 ...

Displaying a div on click is simple with CSS and JQuery, but what if you want it to stay visible even after a second click? By utilizing classes within <li> tags instead of buttons

My current code involves clicking on a menu, which should reveal a list where each item has a corresponding section that slides down and slides back up when clicked. However, only the sliding down functionality is working at the moment. I'm new to jQu ...

Display a modal when clicking on a bootstrap glyph icon

I tried following a tutorial on how to create a Bootstrap modal at https://www.w3schools.com/bootstrap/bootstrap_modal.asp However, I would like to use a glyph icon in the code snippet like this: <span class="glyphicon glyphicon-pencil" class="btn btn ...

The Bootstrap Dynamic Navbar is not adjusting for mobile devices because of the addition of a logo

Struggling to incorporate a logo into the navbar of my website. It looks good on larger screens, but causes the navbar to break on smaller screens. View without the logo: Click Here View with the logo and resizing issues: Click Here I think I can make th ...

What is the proper way to include a parameter in an ASP onclick function within a table row?

Below is a table row declared within a listview: <tr onclick="<%= _jsPostBackCall %>;" /> When calling a postback method on the backend, I need to retrieve the tr index: public void RaisePostBackEvent(string eventArgument) { ...

Creating a Seamless Bond Between JavaScript and HTML

I've been struggling to find a helpful and straightforward solution to a simple problem. On my web page, I have five image placeholders that should be filled with one of nine random pictures. To achieve this, I wrote a JavaScript code that generates r ...

What is the best jQuery library to add to my website?

I have included several jQuery scripts on my website for various functionalities such as sticky header, anchors, and animations. I am wondering if it is necessary to include all of them or if I can just include one or two? Here are the jQuery scripts I ha ...

How can I ensure that a div is positioned over another div with the same coordinates across all screen sizes?

[http://jsfiddle.net/w7r3gveg/]1 I am looking to position 4 Facebook logos in the center bottom of my background image. The background is represented by the 'bg' div, while the Facebook logo is in the 'facebook' div. Currently, I can ...

CSS not being properly rendered on newly inserted row within table via jQuery

I'm currently working on a table that allows users to select rows, and I've implemented some CSS to highlight the selected row. The issue arises when new rows are added to the table as they do not get highlighted when selected. HTML Portion: &l ...

Creating a line with CSS is a straightforward process that involves using properties

I am trying to achieve a yellow line effect similar to the image shown using CSS. I have managed to create line holes so far, but I'm struggling with creating vertical straight lines. Here is an example of my current code: https://i.sstatic.net/MqRUE ...

I have the ability to shift text 50 pixels to the left

My navigation bar is currently aligned to the left, but I'm looking to move the text 50px from the left. Is there a way to achieve this? .navigation { width: 100%; height:35px; background-color: #f1b500; /*f2c255*/ margin-top: 4.4em; } .navig ...

Adjusting the input label to be aligned inside the input box and positioned to the right side

I am currently working on aligning my input label inside the input box and positioning it to float right. The input boxes I am using have been extended from b4. Currently, this is how it appears (see arrow for desired alignment): https://i.stack.imgur.co ...

Implementing CSS to effectively scale images within a fixed box size

I am attempting to create a collection of images with rounded borders that will expand on hover, while staying within a specified box size. I want the effect to give the illusion that the image is only zooming inside the box and not physically enlarging on ...

Ensure that the div element spans the entire width of the screen

Having issues working with the div tag and encountering this problem: The left side doesn't extend as far as the right side, despite testing in multiple browsers. Here is the HTML code being used: <!DOCTYPE html> <html lang="en"> <h ...