Utilize Bootstrap to incorporate a "Show More" and "Show Less

I need to create a paragraph that will display "Show more option" if the content exceeds 3 lines. When clicked, it will expand the paragraph and show a "Show less" option. Clicking on "Show less" will collapse the paragraph. This functionality must be implemented using only Bootstrap without any jQuery or JavaScript.

Answer №1

If you want to achieve the effect using javascript and jquery, you can follow these steps:

   

 $("document").ready(function(){
        // find elements
    var banner = $("#banner-message")
    var button = $("button")
    // when first load the window
    if($('.option').length>3){
    
    $('.option').each(function(index){
    var option=$(this);
    if(index>2){
    option.toggleClass('hidden');
    }
    })
    }
    
    // handle click and add class
    button.on("click", function(){
     if($('.option').length>3){
    
    $('.option').each(function(index){
    var option=$(this);
    if(index>2){
    option.toggleClass('hidden');
    }
    });
    }
    });
    });
body {
    background: #20262E;
    padding: 20px;
    font-family: Helvetica;
  }
  
  #banner-message {
    background: #fff;
    border-radius: 4px;
    padding: 20px;
    font-size: 25px;
    text-align: center;
    transition: all 0.2s;
    margin: 0 auto;
    width: 300px;
  }
  
  button {
    background: #0084ff;
    border: none;
    border-radius: 5px;
    padding: 8px 14px;
    font-size: 15px;
    color: #fff;
  }
  
  #banner-message.alt {
    background: #0084ff;
    color: #fff;
    margin-top: 40px;
    width: 200px;
  }
  
  #banner-message.alt button {
    background: #fff;
    color: #000;
  }
  
  .hidden {
    display: none;
  }

body {
    background: #20262E;
    padding: 20px;
    font-family: Helvetica;
  }
  
  #banner-message {
    background: #fff;
    border-radius: 4px;
    padding: 20px;
    font-size: 25px;
    text-align: center;
    transition: all 0.2s;
    margin: 0 auto;
    width: 300px;
  }
  
  button {
    background: #0084ff;
    border: none;
    border-radius: 5px;
    padding: 8px 14px;
    font-size: 15px;
    color: #fff;
  }
  
  #banner-message.alt {
    background: #0084ff;
    color: #fff;
    margin-top: 40px;
    width: 200px;
  }
  
  #banner-message.alt button {
    background: #fff;
    color: #000;
  }
  
  .hidden {
    display: none;
  }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <div id="banner-message">
        <div class='option'> option1</div>
         <div class='option'> option2</div>
          <div class='option'> option3</div>
           <div class='option'> option4</div>
      
        <button>Change color</button>
      </div>
</body>
</html>

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

Implementing a see-through layer using CSS

This part of my site features a background image. I am attempting to add a transparent overlay at the top of this section, as indicated by the red highlight. I want to achieve this effect using CSS without directly applying the overlay to the image. The re ...

Utilize CSS to generate overlapping blocks or align blocks next to each other within Drupal websites

As a newcomer to the website industry with only 2 months of experience, I am not certain if this task can be achieved using CSS. Despite searching on Google for a week, I have not been able to find the solution, so I decided to seek help here. My goal is ...

Challenges may arise when utilizing a variable query to showcase the outcomes within a div using ajax

Please assist me with this issue! How can I assign the value of a variable from a PHP file for comparison in my query? 2. The syntax is not correct. 3. Can I print data within the same div as "success" on my office's shed? ------ Contents of index.ht ...

The horizontal scroll feature is dysfunctional when attempting to allocate cell space based on a percentage

I want to display two sections of text that take up the full width of the screen and resize automatically when the screen size changes. Currently, I am using percentage widths to achieve this. However, when the text inside a section exceeds the available ...

Optimizing mobile page layouts with CSS

I'm putting in a lot of effort to ensure that my simple form page is optimized for mobile devices. Although the form is visible, I find myself having to zoom in quite a bit in order to read it. Here's an example: ...

What is the best way to achieve this particular look using CSS3?

Seeking assistance with creating a CSS3 layout similar to the one shown in the image below: CSS3 layout Currently, I have managed to center a square on the screen using the following HTML and CSS: HTML: <div id="divBorder"> </div> CSS: #d ...

Is there a way to utilize HTML and CSS to position checkboxes in front of text questions?

I need help with organizing checkboxes and labels in my webform. Currently, the checkboxes are appearing after the label text, causing them to be misaligned. How can I ensure that the checkboxes appear before the corresponding text? <label for="needs ...

Injecting external HTML into a Razor view with Html.Raw is causing the page's HTML to display incorrectly

I have a separate external HTML file, which serves as the body of an email. This HTML file contains all necessary tags and elements for a complete HTML structure. I am trying to display this email content inside a Bootstrap modal. <div class="moda ...

What causes the <td> element to extend beyond the boundaries of the <table>?

I need to add next and previous buttons to a <td> that has an asp:DropDownList. However, when I do this, the <td> ends up overflowing the width of the table. Here is the edited code snippet with the entire table included: <table class=" ...

Font Awesome icons displayed using the <i class="icon-ok"></i> markup are not styled correctly and do not respond to events in Chrome

I implemented Font-Awesome, an iconic font designed for use with Twitter Bootstrap. Here is the markup: <i class="icon-remove reset-preference-button"></i> And here is the CSS: .reset-preference-button { cursor: pointer; } For JavaScript f ...

Creating an infinite loop of SVG rectangles pulled from a database

As I extract svg rectangles from a database using Python, I find myself hardcoding the process in order to change the colors of each rectangle in my CSS style sheet. With potential scalability issues in mind - if there were 100 rectangles - I am wondering ...

Jquery Flip! plugin causing problems with Ajax functionality

I'm currently experimenting with the FLIP! plugin and attempting to load its content using ajax. However, I've encountered a glitch along the way. It just doesn't seem to be functioning properly. While I can observe the post event taking pl ...

Changing the positions of objects on a resized HTML Canvas

I am currently developing a tool that allows users to draw bounding boxes on images using the Canvas and Angular. Everything was working smoothly until I encountered an issue with zooming in on the canvas causing complications when trying to draw bounding ...

What is the best way to combine a top <div> with a bottom <div> in an image without creating unsightly white gaps?

I need help overlapping two divs on top of an image in HTML. The first div should cover part of the top area of the image, while the second div should cover part of the bottom area of the image. These divs should be displayed over the image without leaving ...

In Angular, you can add a unique design to an HTMLElement by applying a

I'm currently facing an issue with Typescript where I am attempting to apply a style on a HTMLElement. Below is the code snippet: styleChoice(element:HTMLElement){ console.log(element); element.style.background="rgba(228, 48, 48, 0.2)&qu ...

Arrangements of lines in website design for various screen resolutions

I am having an issue with the layout I'm working on - specifically, there is a visible outline of the div boxes at certain resolutions or when zooming in. This is what it should look like: However, this is how it appears at some resolutions or when ...

Decapitalizing URL string in jQuery GET request

Check out my code below: $.get('top secret url and stuff',function(data){ console.log($("[style='color:white']", data.results_html)[0].innerHTML); window.html = document.createElement('d ...

Ways to modify the color of table fonts and contents using inline CSS

I would like some help changing the color of the alphabet in my table. Here is the current format: <table border="1" background="images/haya1.jpg" cellpadding="5" cellspacing="10" width="30%" align="center" bordercolor="brown" bgcolor="red"> & ...

Convert text into a clickable link

Creating a form with numerous text fields, some of which require numerical input. The main goal is to have users enter a tracking number, order number, or any other type of number that, when submitted, will open a new URL in a separate window with the spec ...

Is it possible to trigger a JavaScript function without altering its existing value?

I am looking for a way to repeatedly call a JavaScript function without altering its previous values. The challenge I am facing is with an icon JSON object that contains 15 different icons. I am using a switch statement to execute the corresponding functio ...