Alignment of toggle icons in HTML accordions

I am trying to create an expandable list with toggle icons, and I want the icon to be centered in line in mobile view every time the text wraps. I have tried multiple methods that I found through my search but none of them seem to be working.

In Bootstrap:

.panel-default {
  border-color: #ddd;
}
.panel-default > .panel-heading {
  color: #333;
  background-color: #f5f5f5;
  border-color: #ddd;
}
.panel-default > .panel-heading + .panel-collapse > .panel-body {
  border-top-color: #ddd;
}

CSS:

.panel-heading {position: relative;}
.panel-heading [data-toggle="collapse"]:after {font-family:'FontAwesome'; content:"\f056"; float:right; color:#504371; font-size:18px;}
.panel-heading [data-toggle="collapse"].collapsed:after {content: "\f055";}
.panel-title a {display: block; padding: 10px 15px; margin: -10px -15px;}
.panel-title a:focus {text-decoration:none;}
.panel-body h3 {text-decoration:underline;}
.panel-options {position: absolute; right: 15px; top: 10px;}
h1.panel-title {font-size:18px;}

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="panel panel-default">
  <div class="panel-heading">
    <li>
      <a class="collapsed" data-toggle="collapse" href="#q1" aria-expanded="false">
        How can I get a coach ticket/invoice after booking a seat online?
      </a>
    </li>
  </div>
  <div id="q1" class="panel-collapse collapse" aria-expanded="false" style="height: 0px;">
    <div class="panel-body">
      <p>After buying online f you do not receive the email, you may login to membership =&gt; view booking history =&gt; select departure date, click invoice to print it out.</span> You are encouraged to print out the order summary to speed up check-in beside showing your ID. Please follow the instruction in the order summary especially about quoting the boarding code to check in into certain coach companies or waiting for the next email in the next working day to obtain an actual Ticket Number to check in into certain coach companies. </p>
    </div>
  </div>
</div>

Answer №1

To center align it, apply the following classes to the div:

<div class="col-lg-offset-5 col-md-offset-5 col-xs-offset-5">

By adding these classes, you should be able to achieve the desired result.

Answer №2

Using flex makes the process much simpler. Instead of using :after for .panel-heading, add an icon in a different way.

This method should work perfectly fine

CSS

.panel-heading li a{
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-heading li a i{
  margin-left: 10px;
}

HTML

    <div class="panel-heading">
        <li>
          <a class="collapsed" data-toggle="collapse" href="#q1" aria-expanded="false">
              How can I get a coach ticket/invoice after booking a seat online?
              <i class="fa fa-plus"></i>
            </a>   
        </li>
      </div>

Take a look at the Codepen example: https://codepen.io/zpokoin/pen/xWaMdQ

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

Customizing CSS for Various Browser Sizes

I have a query regarding window-dependent CSS. It seems to be a common issue, but I am facing some difficulties with it on Wordpress. I am currently using the script recommended by Nettuts. My goal is to apply different CSS styles based on the user's ...

Guide to generating an HTML table with database information employing jquery and ajax

I am faced with the challenge of creating a table using information retrieved from a database. Despite being able to view all the data through console.log, I am struggling to convert that into a table format. My latest version now displays at least one op ...

How can we ensure that specific criteria are displayed once a selection is made?

Users have multiple options to choose from. When a user selects one option, I want to display additional options that are dependent on the initial selection. For example, if the user can select between 1 or 2 gates, upon choosing a number I will show all t ...

Tips for loading Google fonts quickly using Font Face Observer

Upon reading an enlightening article on the optimal methods for serving web fonts, I was eager to employ the innovative javascript library known as Font Face Observer to asynchronously load Google fonts on my website. The documentation states that "fonts ...

Guide on how to log out in asp.net using an HTML button

I have designed a master page that features a "sign out" button. Can someone guide me on how to implement this button for logging out of the current session? Below is the code for the sign out button: <a href="#" class="btn btn-default btn-flat">Si ...

Several HTML dropdown menus that do not expand

On my website, I have several select elements but the first one related to math is giving me trouble. It doesn't expand properly - sometimes it works on the first click but stops working afterwards. I've tested this issue on both Google Chrome a ...

How to Implement Screenreader and Ontab Functionality for Hover Visibility Accessibility

Hello there! I am excited to share that I am currently in the process of creating my very first React app. The purpose of this project is to develop a writer's application that can be easily accessible to all users. As of now, I have successfully bui ...

Modify a singular aspect of shorthand background attribute

Imagine using the shorthand background property to define multiple properties. For example: .img { background: url('/Content/images/a.png') no-repeat scroll 100% 3px; } If you need to override just the background-position of the image, sh ...

What is the best way to create a trimmed edge around an input field?

I'm looking to design an input element that has a border which changes when the input is focused. Here's how I want the inputs to behave: Input without focus When the user focuses on the input or fills it out, I want the label to move up and t ...

Discover the obscure element

Note that the number of parent elements may vary. It could be just one or multiple. I'm experimenting with different methods to locate the outermost parent <div> element that contains a <div> element with the class rat along with a label. ...

Trouble getting CSS and Javascript to bind when dynamically appending HTML elements

Attempting to dynamically bind HTML from an Angular controller SkillsApp.controller('homeController', function ($scope, $http, $q, $timeout) { $scope.getAllCategories = function () { $http({ url: "/Categories/GetAllCategories", ...

utilize an additional style.css file for a particular section within the HTML document

Is it possible to use two different style.css files in the same HTML document, where a specific block will only get its styling rules from one of them? <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-widt ...

Is there a more efficient way to optimize my coding for this Cellular Automata project?

As a beginner in programming, I wanted to delve into the world of cellular automata and decided to create my own using JavaScript. The project involves a simple binary (black and white) 2D CA where each cell updates its color based on the colors of its 8 ...

The mp4 video on the website will only load if the Chrome developer tools are activated

Whenever I try to play the video set as the background of the div, it only starts playing if I refresh the page with Chrome dev tools open. HTML: <div id="videoDiv"> <div id="videoBlock"> <img src="" id="vidSub"> <video preload="prel ...

Utilizing a lone web element per row on a responsive webpage: A guide

click here for imageCurrently using the latest version of selenium web driver. Is there a method to utilize a single webelement (as a list webelement) in order to access row data on a responsive web page? For instance, consider the following CSS in the br ...

Internet Explorer experiencing issues with rendering WOFF fonts

My webpage utilizes the Avenir font, which displays correctly in Firefox, Opera, and Chrome. However, Internet Explorer 11 does not seem to render this font properly. I have included the following code to ensure compatibility with Internet Explorer: <s ...

Angular.js <div ng-include> not expanding to the full height of the viewport

My goal is to create a single-page app with a scrolling effect using Angular.Js. Each ng-include section within the <div class="viewport" ng-include="'views/file'" ng-controller="MainCtrl"></div> should fill the viewport entirely. How ...

Local HTML files are failing to link with CSS, whereas everything is functioning properly on Github Pages

Working on a beginner Web Development project, I encountered an issue with linking my CSS file to my portfolio. The page displays correctly on GitHub pages, but fails to load properly when accessed locally on any browser even after clearing the cache. He ...

What steps can I take to ensure the reset button in JavaScript functions properly?

Look at this code snippet: let animalSound = document.getElementById("animalSound"); Reset button functionality: let resetButton = document.querySelector("#reset"); When the reset button is clicked, my console displays null: resetButton.addEvent ...

Protected Bootstrap Environment

Bootstrap is an amazing tool, but it tends to enforce too many opinions. The selectors used in its rules are quite broad, such as input or label. Is there a method to isolate Bootstrap's CSS so that it only impacts elements within a container with a ...