Present the "Read more" button aligned with v-html content

I have some HTML content that I want to display using the v-html directive. The text is quite lengthy, so I am looking to add a clickable Read more link that appears on the same line as the text.

The code structure would look like this:

<div v-html="some-variable-containing-html"></div>
<a @click="makeMoreTextVisible()">Read more</a>

Typically, I would use display:inline to ensure the Read more link aligns with the end of the HTML text, but it doesn't seem to work in this case.

Has anyone encountered this issue before?

Answer №1

The default setting for the div is display:block, which causes the element to start on its own line, pushing the Read more text to the next line.

If you switch the div to a span, it will be set to display:inline by default. This assumes that there are no elements in the HTML variable that would force elements onto a new line like the original div.

Check out demo 1 here

In cases where your HTML variable contains elements styled with display:block (such as div or p), you can add a class to the HTML container that makes its last child element use display:inline:

<template>
  <div>
    <div class="container" v-html="myHtml"></div>
    <a @click="makeMoreTextVisible()">Read more</a>
  </div>
</template>

<style>
.container {
  display: inline;
}
.container :nth-last-child(1) {
  display: inline;
}
</style>

See demo 2 for reference

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

How can you display an image with text on hover in a simple way?

Is there a way to display an image (a company logo sized at 150 x 100 px) when a user hovers over the company name? The image should appear on the right side of the name. I am uncertain whether this can be achieved with CSS3 alone or if I would need to us ...

Issue with checkbox v-model not syncing with asynchronous data retrieval

I'm currently working on a component that fetches data from a database at the beginning. The goal is to check if the input value is true or false. However, I'm facing an issue where it's not checking when the value is true. I have tried usin ...

Incorporating Vue.js components into PHP applications

I am currently working on a project using PHP in conjunction with Vue.js and vue-router. In my PHP form handler, I have implemented functionality to send emails. What I am trying to achieve is redirecting the user to a specific component within my Vue ap ...

TypeScript is unable to recognize files with the extension *.vue

Can someone assist me with an issue I'm facing in Vue where it's not detecting my Single File Components? Error message: ERROR in ./src/App.vue (./node_modules/ts-loader!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/Ap ...

How to transform a JQuery button into a dropdown menu

For inspiration, consider this JQuery UI Button example: http://jqueryui.com/demos/button/#splitbutton Now, how can you create a dropdown menu when the small button is clicked? My main concern is the way .button() alters the button's actual appearanc ...

What is the best way to add a directional hover effect to a filter?

I am attempting to implement a sliding hover filter effect on an image. The original filter I have is set to grayscale(1). What I want to achieve is for the filter to transition directionally instead of having a slider overlay effect, in order to change i ...

Javascript and CSS combo for creating a stylish fade effect

Hey everyone, I have a design challenge where I need to change the color of a picture inside a box when the user hovers over it. I have four boxes like this and my goal is to make everything else fade out when a user hovers over a specific box. Anyone kn ...

Having trouble with basic HTML/CSS functionality not functioning properly

It appears that the stylesheet is correctly linked, but it seems like there might be an issue with the HTML/CSS code. I haven't worked on HTML/CSS in a while, so I could be missing something obvious. Can you help figure out what's wrong? ...

What is the best way to remove an event binding before navigating to a different page in NUXTjs?

I wrote this code all on one page and it works perfectly. However, I am unsure how to unbind this event when transitioning to another page. private mounted () { if (process.browser) { const banner:any = document.querySelector('.banner ...

How can I make my div change color when the check-box is selected?

I have a dynamic table in my web application that is populated with data from a database. Each row in the table represents multiple time slots for a specific date. I am working on a feature where the background color of a time block can be changed if a che ...

Conceal all alphabetical characters exclusively within paragraph content

I have a lengthy, dynamically generated paragraph containing both alphabetic and numeric characters. Query: How can I filter out all alphabetic characters from the paragraph and only display the numeric ones? For instance: <div class="mytexts"> So ...

Is there a way to center the pagination at the bottom of the screen?

I want to position my pagination at the bottom-center of the page using Angular Material's mat-paginator component. Currently, this is what it looks like: 1: https://i.sstatic.net/21mUj.png 2: https://i.sstatic.net/kfXH6.png The issue I'm fac ...

React App build isn't displaying all elements on the webpage

My experience with create react app has been interesting lately. When I run npm run dev, everything in my application looks great: https://i.sstatic.net/lVf7x.png The button texts are coming from an API call, and all seems to be in order. But when I tr ...

Issue with sticky navbar in parallax design

I have been working on a website where all pages feature a header and a navbar located just below it. As the user scrolls down the page, I want the navbar to stick to the top of the screen once it reaches that position. However, on one specific page, I am ...

Move a div by dragging and dropping it without creating duplicates

I'm in need of some assistance. It seems like a simple task, but I'm having trouble finding a solution. I've managed to create draggable elements that work smoothly without any issues. The drag and drop functionality is working perfectly. ...

What is the best way to create a responsive mobile menu?

I recently used W3Schools as a reference to create a sidenav overlay menu https://www.w3schools.com/howto/howto_js_sidenav.asp with an accordion feature https://www.w3schools.com/howto/howto_js_accordion.asp. Despite my efforts, I'm struggling to make ...

align items center with respect to my central element

Describing my issue might be a bit complex, but I'll give it a shot. I'm working on a website and have 3 div elements in the header for my navigation bar (burger menu / logo / social networks). I've used flex display with justify-content: be ...

Firebase integration for vusjs dropzone image uploads encountering issue with storage functionality

Struggling to implement image uploads in a VueJS app following this guide. However, I keep encountering the error: TypeError: _config_firebaseInit__WEBPACK_IMPORTED_MODULE_2__.default.storage is not a function Below is my firebase initialization file: ...

Methods for refreshing a child component when new elements are added to a data array

One of my vue.js child components contains a data array named messages. I am looking for a way to refresh the DOM when new elements are inserted into the array. Below is a simplified version of the code snippet: <template> <q-item v-for="(msg, ...

A plugin for TypeScript that highlights nearly every line in Vue files as errors with underscores

Recently, I decided to work on a project using Vue with TypeScript. After creating the project with vue-cli and enabling TypeScript and eslint standard, everything seemed fine initially. However, when working in VS code, I noticed that the ts-plugin was fl ...