Animate the entire paragraph with CSS hover effect

I'm seeking ideas on how to achieve a specific effect without the need to wrap individual lines in inner elements like span or a.

Check out this example

<div class="m-linkitem">
    <h1>Hover Below</h1>
    <a href="#">Lorem ipsum dolor </a><br/>
    <a href="#">Lorem ipsum</a><br />
    <a href="#">Lorem ipsum</a><br />
</div>


    body {
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
        font-family: 'Open Sans', sans-serif;
        background: linear-gradient(180deg, #111, #00393c);
        background-size: 400% 400%;
        animation: backgroundGradient 30s ease infinite;
    }

    h1, h2, h3, h4 {
        font-family: 'Roboto', sans-serif;
        font-weight: 900;
        color: #fff;
    }

    p {
        font-size: 18px;
        font-size: 1.8rem;
        line-height: 26px;
    }

    .m-linkitem {
        position: absolute;
        top: 50%;
        left: 50%;
        -webkit-transform: translate(-51%, -50%);
        -moz-transform: translate(-51%, -50%);
        -ms-transform: translate(-51%, -50%);
        -o-transform: translate(-51%, -50%);
        transform: translate(-51%, -50%);
        max-width: 500px;
        width: 100%;
        transform-origin: center;
        animation: loadBounce 0.5s ease-in-out forwards;
    }

        .m-linkitem a {
            transition: all 0.25s linear;
            display: inline;
            font-size: 22px;
            font-size: 2.2rem;
            line-height: 45px;
            color: #fff;
            text-decoration: none;
            text-transform: uppercase;
            font-weight: 600;
            padding-bottom: 5px;
            background: linear-gradient(to right, rgba(0, 209, 177, 1) 0%, rgba(39, 143, 198, 1) 98%);
            background-size: 0px 2px;
            background-repeat: no-repeat;
            background-position: left 85%;
            text-shadow: 0;
        }

            .m-linkitem:hover a{
                background-size: 100% 1px;
                text-shadow: 0 2.5px 4px rgba(0, 0, 0, 0.5);
            }

This will be implemented for responsive design so number of words per line would be changing on resize and point break changes. Anyone can think of CSS way of underlining all lines simultaneously, like in the codepen example?

Thank you.

P.S. This is what animation would look like when applied to entire paragraph. Not what I'm looking for:

View another example here

Answer №1

To start, make sure to include class="m-linkitem" on each line of your HTML code. By using the text-decoration property, you can easily add underlines to your text without worrying about how it will look on different devices:

.m-linkitem{
    text-decoration: underline;
}

By applying the m-linkitem class, you can quickly highlight an entire paragraph simply by hovering over any part of it. The text-decoration feature automatically adjusts to changes in text size, eliminating the need for specifying a specific length.

Answer №2

It seems that the goal you are aiming for is a bit unclear to me personally.

My understanding is that you want to achieve the same visual effect as the codepen example you shared, but without the need to separate each line into different elements.

Instead of asking "how do you...", perhaps the question should be "can you do...".

You may have to consider using Javascript or a similar solution...

Although the following example adds an underline to each line of text, it's a bit hacky and might not be suitable for the responsive design you have in mind:

Answer №3

My HTML & CSS skills are at a beginner level, but I believe creating a class should do the trick for adding underlining as shown in the example. The effect will then be applied to everything within that class.

classname{
    text-decoration: underline;
}

If you're looking for a more fancy effect, simply paste the code into the class.

Best regards.

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

Unable to close modal after receiving ajax response

Utilizing mdbootstrap for my current project has been a great experience. One area that I am struggling with is implementing an AJAX call upon checking a checkbox, where I expect a response from PHP indicating success (1) or failure (0). However, despite d ...

Dynamic navigation menu shifting when bolded

Looking at my menu, you'll notice the following layout: If one clicks on Recruitment in the menu, it correctly bolds the text as intended. However, an issue arises where the entire menu unexpectedly shifts 1 or 2px to the left. The menu is implemente ...

Tips for preventing redundant function calls to a prop within a ReactJS component

I am currently facing an issue where I am repeatedly calling the same function within a component to retrieve a specific prop inside the render function. Is there a way to optimize this and avoid calling the function multiple times for each required prop ...

Error: AJAX encountered a 'parsererror' due to inability to convert text to application/json format

While attempting to send a JSON using a basic AJAX client and utilizing PHP as a restful server, an error occurred when trying to parse the JSON data. ERROR: "parsererror", "No conversion from text to application/json" The code for my client is display ...

Customizing your buttons in Wordpress with extra CSS styles upon clicking

I am in the process of developing a Wordpress website and I require a button for switching between mobile and desktop versions manually. Within my .css file, I have included: @media (pointer:coarse) {} This adds modifications for the mobile version ...

pop-up window that shows chosen choices using javascript or ajax

I have a specific HTML code that allows users to select multiple options. I would like these selected options to be displayed in a popup or a div in real-time as the user makes their selections. I have attempted using a selectbox with checkboxes, but extra ...

Can the default jQuery mobile ajax loader be triggered automatically when making a $.post() call?

Similar Question: Displaying Spinner on jQuery Mobile Ajax Call Is there a way to automatically trigger the default jquery-mobile ajax loader when using $.post()? For example, can I set up a global configuration for this behavior? I came across this ...

What method can I use to adjust the font style when it overlays an image?

Sorry if this is a bit unclear, but I'm trying to figure out how to change only a section of my font when it overlaps with an image while scrolling. If you visit this example website, you'll see what I'm referring to: For a visual represen ...

Using the "this" keyword is required for an Angular Service-created function

Although this question leans more towards JavaScript than Angular, I encountered an issue while creating a service. The function call looked like this: // controller injects activityApi , then service function call is made var activities = activityApi.get ...

Having difficulty accessing a public array item within chained AXIO transactions in VUE

I am currently facing an issue with a chained AXIOS call that is triggered from an array. The challenge I am encountering is ensuring that the second call completes before the first one initiates another API request, which seems to be working fine so far. ...

The ability to choose only one option in a checkbox within a grid view column

In my grid view, I have a checkbox in the last column. I am trying to ensure that only one row can be selected at a time. <tr *ngFor="let permit of PermitDetails" (click)="GoByClick(permit)"> <td style="text-align: center">{{permit.TVA_BAT ...

Ways to detect scrolling activity on the v-data-table module?

Are you looking for a way to detect scrolling events on the v-data-table component in Vuetify framework? I am referring to the scenario where the table has a fixed height, causing the table body to scroll. <v-data-table fixed-header :height=400 : ...

Firefox compatibility issue with Angular JS for downloading excel files

I've encountered an issue with my AngularJS code for downloading an Excel file. While it works smoothly in Chrome and Internet Explorer, it fails to function in Firefox. The server response isn't presenting any problems. Here's the code snip ...

Adding a dynamic key-value pair object to an array using the JS push method

In my programming challenge, I am dealing with an array of objects that have dynamic keys and values. The structure is a bit complicated, but here's a simplified version: let products_row = [ { id: 1, category_id: 11, options: { &a ...

The loop in MVC is not functioning properly when dealing with various MapRoutes

I am new to MVC and have a good understanding of C#. While experimenting with MVC in Visual Studio, I encountered an issue that is puzzling me. I am struggling to identify the cause of this error. My goal is to print a variable n number of times. It works ...

View is unable to trigger the success attribute

Currently, I am delving deep into Backbone JS and facing an issue where the 'success' function in 'EditUser' is not being triggered. I would greatly appreciate it if someone could guide me on what changes I need to make in the code? B ...

What is the best way to change an object into a string in node.js?

Recently, I've delved into the world of node js and I'm eager to create a basic coap client and server using this technology. Successfully, I managed to set up a server hosting a text file, but now I aim to access it from the client. var coap = ...

Effective methods to prevent the `translate` transform from triggering an element to be perceived as position relative?

I am encountering an issue with an absolutely positioned div that is nested within a statically-positioned parent container. I noticed that when I apply the transform: translateY(-50%) property to the container, the child element behaves as if it were bein ...

Adjusting the box sizing of a contentEditable DIV to conceal the first and last characters

I am having trouble with a ContentEditable div that requires the hiding of characters, specifically the first and last character. I need to overlay a layer on top of the "#" character to make it appear as if the character and the border line beneath it are ...

Navigation Menu Dropdown Present on the Right Side and Arranged in a Horizontal Stack

I'm having trouble with a dropdown menu in my navigation bar. I followed the example on W3Schools but when I hover, the menu appears horizontally instead of vertically and to the far right of the page. I've searched for solutions but can't s ...