Align an element in the middle next to its sibling element

Utilizing the pagination component in Bootstrap, the structure of the pagination itself is quite straightforward:

<ul class="pagination">
  <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
  <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
</ul>

However, I am looking to display additional metadata such as total pages and total records next to the pagination. I want this information to be aligned centrally with the pagination controls.

Unfortunately, adding the page information directly inside the ul element is not an option as it is generated by a third-party library.

I have attempted a solution showcased here: http://plnkr.co/edit/abVwf6rnluYKiOOzXNrt?p=preview

As demonstrated, achieving the desired alignment has proven challenging.

I have considered adjusting the padding or margin for the div.pageinfo, or manipulating the height and line-height. However, I am curious if there is a way to accomplish this without resorting to hardcoded values.

Answer №1

The Challenge

There are two primary obstacles to address:

  1. An issue preventing you from rearranging your blocks is the presence of a wrapping div with inline-styles like display: inline-block and Bootstrap classes such as pull-left, which are dictating how your elements are displayed.

  2. The issue of needing support for IE8, which will complicate efforts to provide the same user experience without compromising site performance.

Suggestion

Expecting websites to appear identical in IE8 compared to modern browsers is increasingly unrealistic today. The extent of adjustments required to achieve this is quite burdensome. Additionally, Bootstrap is phasing out IE8 support starting from Bootstrap 4. The only justifiable case would be if Google Analytics data revealed that a majority of your users still rely on IE8.

Hence, it's advisable to either (1) limit pagination items to fit a specific width and adjust the fixed width when new content is added, or (2) accept graceful degradation on IE8 to enhance the experience for the majority of users on up-to-date browsers.

Solution: Modern Browsers

To accomplish your goal easily, consider utilizing flexbox. I've simplified the code by removing unnecessary class names below (primarily functional in Chrome). For complete code with all prefixes, refer to the demo link provided.

Here's a snippet of the HTML and CSS:

Update: Solution for IE8 Compatibility

I've prepared a demo showcasing an alternative approach for IE8 compatibility using blocks. While avoiding hard-coding element sizes was requested, it may not be feasible due to legacy browser support constraints like IE8.

The key is understanding that older browsers lack the intelligence of modern ones. Another potential option involves dynamically determining element widths via JavaScript, but this method can be cumbersome and impact performance significantly.

Below is a snippet of the HTML and CSS for the IE8 solution:

Answer №2

If you're searching for something similar to the following:

/* Customize your styles here */

.mata-data {
    display: inline;
    position: absolute;
    margin-top: 27px;
    margin-left: 25px;
}
<!DOCTYPE html>
<html>

<head>
  <link data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52303d3d26212620332212617c617c67">[email protected]</a>" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body>

  <div class="text-center">
    <div>
      <div class="mata-data">Total:xxx 1/xx</div>
      <div class="container pull-left">
        <ul class="pagination">
          <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
          <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
        </ul>
      </div>
    </div>
  </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

Executing Python code through a website using PHP - is there a way to deactivate the button once it has been clicked?

Can you assist with the following issue? <?php if(isset($_POST['MEASURE'])) { shell_exec("sudo python /var/www/html/lab/mkdir.py"); } ?> Here is the HTML part: <form method="post" > <input type="submi ...

How can I fix the issue with border-radius not displaying correctly in tcpdf and how can I ensure the text is shown on

Currently, I am utilizing tcpdf to showcase a circle and text together in a PDF. Despite my attempts with the code below, the border-radius attribute is not functioning as expected: Upon implementation, I obtained the following result: The desired outcom ...

Is there a glitch in the Selenium Java CSS Selector functionality?

Everything seems to be working smoothly with that code! It successfully locates and clicks on my button within the span tag. driver.findElement(By.cssSelector("span[id$=somePagesCollection] a")).click(); However, after clicking the button, an input field ...

Bootstrap - Progress Bar Display

I have a mobile application that is built using Bootstrap 3. I am currently working on creating a responsive progress indicator for the app. This indicator will consist of three to five steps, each showing an icon, step name, and status. On mobile devices, ...

Is it possible to use v-if in conjunction with a style tag to specify a different source file? Alternatively, is there a more efficient method I

I attempted the example provided below, but unfortunately, it did not function as expected. The reason behind my endeavor is that adding numerous modifiers (--tuned) to achieve the desired outcome seemed impractical. Therefore, I decided to try and link ...

What are the steps to implementing PNG masking using PixiJS?

I am currently working on incorporating a png sprite as a mask for another layer. I found a demo on the pixi.js official website and created this fiddle: https://jsfiddle.net/raphadko/ukc1rwrc/ The code snippet below is what I am using for the masking fu ...

Map on leaflet not showing up

I followed the tutorial at http://leafletjs.com/examples/quick-start/ as instructed. After downloading the css and js files to my local directory, I expected to see a map but all I get is a gray background. Can anyone advise me on what might be missing? T ...

Stylized widget for showcasing a list of cities for meetups

After extensive searching, I have yet to find a solution to stylize the "City List" widget for Meetup. The specific widget I am focusing on is the first one listed here. () Despite exploring various options such as the widget foundry and conducting onlin ...

What is the method for accessing HTML tag data within a script?

Looking for a way to extract a specific substring from a given string: var str = `<ul class="errorlist"><li>Enter a valid email address.</li></ul>`; Is there a method to extract the following substring? 'Enter a valid email ...

jQuery - class remains unchanged on second click event

Operations: Upon clicking on an element with the class thumb_like or thumb_unlike, a like will be added or removed for the image using a POST request. The element with the class thumb_count will increase or decrease based on user actions. For example, lik ...

Integrating HTML, JavaScript, PHP, and MySQL to enhance website functionality

Exploring the intricacies of HTML, JavaScript, PHP, and MySQL, I have been working on an order form to understand their interactions. View Order Form The aim of this table is to allow users to input a quantity for a product and have JavaScript automatica ...

I'm noticing that when I refresh the page, my inputs seem to disappear from the page, yet I can see that they are saved in the console's local

If anyone can help me with this issue I'm facing, I would greatly appreciate it. My aim is to retain values in the text box along with local storage even after refreshing the page. Here is an example of the code I am working with: Link to my web appl ...

Verify whether an accordion is in the open or closed position

I am trying to determine if an accordion item is currently open or closed in Framework7. Can anyone provide guidance on how this can be accomplished? To open an accordion item, I have been using the following code: myApp.accordionOpen(".accordion-item"); ...

Guide to utilizing a download link for file retrieval in Python

I'm currently working on creating a script that can automatically download specific files from webpages and save them to designated folders. For the most part, I've been successful in achieving this using Python, Selenium, and FirefoxPreferences ...

Rearranging div placement based on the width of the screen

I am currently working on building a responsive website and I need two divs to switch positions depending on the screen width, both on initial load and when resizing. Despite my efforts in researching and trying various options, I have not been successful ...

"Emulate the social sharing capabilities of CNET with interactive share

I remember a while ago, CNET had these amazing Social Share buttons that, when clicked, would reveal a "dropdown box" with the social network share dialog. Does anyone know how they achieved that? I've searched but couldn't find any information ...

Deciphering HTML encoding for text fields

As I transition from the Microsoft stack, specifically WPF, to HTML5, I apologize for any beginner-level questions. Today's topic is HTML encoding and decoding. Imagine an HTML5 application making AJAX calls to a C# backend using HTTP. The server al ...

Modify the color scheme of an HTML webpage

Looking to enhance my HTML page with a new feature. The page is responsive and currently using Bootstrap CSS and JS. My goal is to allow users to change the color of the page dynamically by selecting a background or text color. Check out this example link ...

Attempting to determine the smallest and largest dimensions of two values using CSS3

Trying to make sure the image on my phone adjusts its size based on orientation, I attempted using Ionic4. When in landscape mode, I want it to adapt according to height instead of width. Essentially, I need it to use the minimum size and also require the ...

What is the best way to modify a variable in a nested element using ng-click in the parent element?

Review this code snippet: <section class="page-section about-us" scroll-bookmark="about-us" ng-click="activeSection=true" ng-init="activeSection=false"> <div class="page-content sub-content active-section">{{activeSection}} < ...