Ensure that two elements containing content of varying width are equal in width

I am facing a challenge with a container that contains two child elements (previous and next links). These links have labels of different lengths, but I need them both to have the same width on the page. Ideally, each link should be as wide as the widest element, without exceeding that width. The pagination container should adjust its width based on the text length of the links, rather than spanning the entire width of the page unnecessarily. Since the text of the links may change, setting a fixed width is not a viable solution.

Currently, I have this setup: http://jsbin.com/kukucusabecu/1/edit?html,css,output. However, my goal is to ensure that the "Next" link matches the width of the "Previous" link dynamically, avoiding fixed widths due to variable text content.

I have researched on Stack Overflow and came across a similar discussion here: Make Two Floated CSS Elements the Same Height. While informative, it focuses on equalizing heights rather than widths. Using a table for this purpose is not practical since the data does not fit within a table format.

Answer №1

If you're looking for a way to organize your links, consider using a CSS table layout where each link is treated as a cell with 50% width:

Check out this Demo Fiddle

.pagination {
    background: #ccc;
    display: table;
    font-size: 20px;
}
.pagination a {
    display: table-cell;
    width:50%;
    padding: 0.5em;
}
.pagination .prev {
    background: #ddd;
}
.pagination .next {
    background: #ccc;
}

It's important to note that CSS tables should not be confused with HTML tables - while HTML tables are best suited for organizing data content in a semantic way, CSS tables can be used purely for laying out elements in a tabulated format.

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

What is the best way to extend an image to fill the width of a webpage?

Can you advise me on how to expand the image to fit the width of my webpage? If possible, could you take a look at this website: Poklanjam The specific image I am referring to is the one of the city on the left-hand side. What additional CSS code should ...

Having two owl carousels on one page is causing some issues

Struggling to implement two owl carousels on my page. Gif: View Gif Here The first carousel (shown at the top in the gif) is functioning perfectly. However, the second one (beneath the first in the gif) is not behaving as expected. Instead of displaying ...

Transferring data between two HTML files through the POST method

Is there a way to pass two values (parameters) from one HTML page to another without displaying them in the URL, similar to using the POST method? How can I retrieve these values on the second HTML page using JavaScript, AJAX, or jQuery? For example: cli ...

Some websites are not displaying the CSS code for the inspector

In my experience, I have always relied on Firefox Inspector to troubleshoot CSS issues without any problems. However, when I attempted to analyze the CSS of a specific webpage (only encountering difficulties while logged in), I noticed that the inspector ...

Conversation panel text slipping out of <div>

I am currently working on creating a mock "chat" feature. The issue I am facing is that when I repeatedly click the "send" button, the text overflows from the div. Is there a way to prevent this by stopping the text near the border of the div or adding a s ...

By clicking on the image, you can expand it to a specific size, and clicking again will return it to its original size. This feature maintains the exact

There have been numerous inquiries regarding how to make an image larger on click, and then revert back to its original size upon clicking again. I've spent the past 10 hours experimenting with many solutions, but none of them achieve the desired out ...

Serve the mobile version to mobile visitors and the desktop version to all other visitors

Can someone please explain to me how I can display the Mobile Version of a website when visiting on my phone, and the Desktop Version when viewing on anything larger than 500px? I have separately created both a Mobile Website and a Desktop Website. Is it ...

Executing the Javascript function specified above upon the page being loaded

I'm fairly new to JavaScript, so please bear with me. I've got a JavaScript function on my page: <script type="text/javascript"> Sys.debug = true; var popup; Sys.require(Sys.components.popup, function () { popup = Sys.c ...

Having Trouble with Bootstrap 4: "Encountering Uncaught Error: Tooltip Transition in Progress"

I'm currently utilizing Bootstrap 4 on my website and incorporating the Tooltip feature. While my JavaScript appears to be correctly formatted, there are instances where I encounter errors in Console. My Javascript Setup | Bootstrap 4 <script src ...

Fixed Navigation Menu on Top with Specific Width Size

Currently diving into the world of CSS and eagerly following a tutorial on creating a responsive menu for my website. Managed to get it up and running, but hit a few roadblocks along the way: The navigation menu seems to shrink in both desktop and mobile v ...

A step-by-step guide on implementing an if-else statement to remove an item from Angular

I am currently working on implementing a feature that allows me to delete an item only if the quantity of that item is 0. If the quantity is not equal to 0, I need to prevent deletion and send an error message back to the front end. Below is my implementa ...

Expanding and hiding content using jQuery while also utilizing cookies for persistence

Hey there! I have a piece of code that I'm working on and could use some help. I'm trying to create a cookie that can remember the current state of a div even if the user reloads the page. Any assistance would be greatly appreciated! jQuery(fun ...

Troubleshooting issue: Bootstrap mixins not functioning properly due to LESS nesting

Recently I've been experimenting with Bootstrap and LESS, attempting the following: LESS: .class1 { .jumbotron; div { .container(); color: white; } } Here is the relevant part of the HTML code: <div class="class1"> <div> ...

struggling to access the value of a hidden field by using the parent class name

My coding experience so far looks like this- <tr class="chosen"> <td id="uniqueID">ABCDE5678</td> <input type="hidden" value="000005678" id="taxCode"> <td id="fullName">Z, Y</td> </tr> In this scenario, I need to ...

What is the correct way to include variables {{var}} within a {{#each}} loop?

I'm curious if there's a way to include double-stashed {{var}} embeds in my HTML code. Here is an example: I have the .hbs code below: {{#each tables.books.data}} <tr> <td>...</td> <td>...</td> </tr> {{/eac ...

Exploring the world of JSON on the internet

Hello there! I'm currently working on a project similar to . However, I am facing difficulties when integrating my code with a discord bot. I am questioning whether it is possible to host JSON data online directly with the code snippet below: documen ...

having trouble with changing the button's background color via toggle

I've been experimenting with toggling the background color of a button, similar to how changing the margin works. For some reason, the margin toggles correctly but the button's color doesn't. <script> let myBtn = document.querySele ...

How can I use AngularJS to show a JSON value in an HTML input without any modifications?

$scope.categories = [ { "advertiser_id": "2", "tier_id": 1, "tier_name": "1", "base_cpm_price": "", "retarget_cpm": "", "gender": "", "location": "", "ageblock1": "", "ageblock2": "", "ageblock3": ...

Resize the image to fit the dimensions of a div, but unfortunately, the overflow: hidden property is not effective in this

I'm looking to set up an image gallery using the Bootstrap grid layout. The gallery should span 100% width and consist of two grids in a row, each containing one picture. I want the height of the second picture to match that of the first, with croppin ...

Show the picture stored in the S3 cloud storage

I'm facing an issue with displaying images uploaded to S3. I've checked the permissions and can access the URL successfully to retrieve data. However, when I insert the URL into an image tag, it shows up as a broken link. Upon inspecting the net ...