Is there a way to shift this structure to the right without relying on the float property?

Here's the HTML and CSS I have -

.font-size-add-class {
background-color: #2f2f2f;
color: #f9f7f1;
}

.font-sizes {
  text-align: right;
  display: table;
  margin-top: 15px;
  cursor: pointer;
}
.font-sizes > .small {
  font-size: 12px;
}
.font-sizes > .medium {
  font-size: 14px;
}
.font-sizes > .large {
  font-size: 18px;
}
.font-sizes > div {
  display: table-cell;
  padding: 0 10px;
  font-weight: bold;
  border-top: 1px solid #2f2f2f;
  border-bottom: 1px solid #2f2f2f;
  border-right: 1px solid #2f2f2f;
}
.font-sizes > div:first-child {
  border-left: 1px solid #2f2f2f;
}
<div class="font-sizes">
    <div class="small">a</div><!--
 --><div class="medium font-size-add-class">a</div><!--
 --><div class="large">a</div>
</div>

If I avoid using table on the parent and table-cell on the child, the div blocks will have different sizes due to varying font sizes. Additionally, the fonts won't be horizontally aligned.

I'm looking to replicate the current structure exactly as it looks now but move it to the right side of the page. Any suggestions on how I can achieve this?

Answer №1

Instead of using text-align, consider utilizing the following:

margin-left: auto;
margin-right: 0;

.font-size-add-class {
background-color: #2f2f2f;
color: #f9f7f1;
}

.font-sizes {
  /*text-align: right;*/
  display: table;
  margin-top: 15px;
  cursor: pointer;
  margin-left: auto; /* align table to the right */
  margin-right: 0;
}
.font-sizes > .small {
  font-size: 12px;
}
.font-sizes > .medium {
  font-size: 14px;
}
.font-sizes > .large {
  font-size: 18px;
}
.font-sizes > div {
  display: table-cell;
  padding: 0 10px;
  font-weight: bold;
  border-top: 1px solid #2f2f2f;
  border-bottom: 1px solid #2f2f2f;
  border-right: 1px solid #2f2f2f;
}
.font-sizes > div:first-child {
  border-left: 1px solid #2f2f2f;
}
<div class="font-sizes">
    <div class="small">a</div><!--
 --><div class="medium font-size-add-class">a</div><!--
 --><div class="large">a</div>
</div>

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

Stop the automatic hiding of the sticky header when reaching the bottom of the page

I have implemented the position: sticky property for my website's header. However, I am facing an issue where the header becomes hidden when I scroll halfway down the page (bottom on mobile devices). Can anyone suggest a solution to fix this problem? ...

The vertical-align property fails to properly align the list-style-image with the text

My HTML list is structured like this: <ul id="remove"> <li id="rm_txt_1" onClick="remove_1();">Remove </li> </ul> <ul id="move"> <li id="mv_txt_1" onClick="position();">Move Down</li> </ul> It is styled u ...

Imitate adjustment of orientation without the need to resize the browser window

Is there a way to simulate page portrait orientation on a PC browser without resizing the window? In my HTML code, I have a <div> element that displays content dynamically based on screen orientation. Is it possible to use JavaScript to trick this & ...

Placing a div directly beneath an anchor tag

I'm trying to create a dropdown menu that appears directly under the URL that triggers it. I have successfully made the menu appear, but I am struggling with positioning it correctly. Here is my HTML code: <div id="container"> Content here ...

Displaying information collected from a submission form

I am in the process of designing a cheerful birthday card and I need to transfer data from a form to the birthday card page. How can I take information from the first div (which contains the form) and display that data in the second div? <!DOCTYPE ...

What is the most reliable method for displaying an SVG shape in any color across various web browsers?

Is there a way to render a 2D SVG shape, which is flat and 100% black, in any color across various browsers? ...

Place the div absolutely on top of the Flash content

Can a <div /> be absolutely positioned over a Flash banner without including wmode="transparent" in the banner? I am trying to display a lightbox above my ads, but I cannot make changes to the banners since they are provided by a third party. Edit: ...

Elevated Floating Button

I am attempting to create a vertical floating button for my website, but the text is displaying outside of the box. CSS #feedback { height: 104px; width: 104px; position: fixed; top: 40%; z-index: 999; transform: rotate(-90deg); -webki ...

2-panel accordion interface

Hello there, I've encountered a problem that seems to be related to CSS. Here is the project I'm currently working on: My main focus is on the News accordion menu. The goal is to display a small image (50x50 with padding) next to a large headlin ...

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 ...

Preventing the collapse of the right column in a 2-column layout with Bootstrap 3

I've recently begun exploring Bootstrap and am attempting to achieve the following: (Left column - larger) Heading Heading 2 Heading Image Heading Image Heading Address (Right column - smaller) Heading Paragraph List items My issue ...

Refresh the current page with jQuery Mobile when it is clicked

I have a multi page template in jQuery Mobile. How can I refresh the current page when clicking on a hyperlink or button? I am using JQM version 1.4.5 Despite trying the code suggested in how to refresh(reload) page when click button in jQuery Mobile, it ...

Find the div element that wraps around the currently selected radio button

Take a look at this code snippet: <div class="paymentOption"> <input type="radio" name="paymentOption" value="1" /> <span class="marginLeft10">1-time payment using a different credit card</span> </div> Is it feasible ...

Issue with Photoswipe pswp class Not Getting Properly Cleared Upon Closing Image

My website has a Photoswipe image gallery from . The issue I'm facing is that the CSS class does not reset or clear after closing the gallery for the second time. For example, when a user opens item 1, the images are loaded into the picture div via A ...

Adjust the CSS extension within the about:config settings of Firefox

I've been using the Zotero extension and I want to adjust how TinyMCE handles paragraph spacing. I'm looking to customize the CSS in extensions.zotero.note.css by adding specific CSS rules. The reason I want to make these changes is because I fe ...

Step-by-step guide on utilizing jQuery to fade out all elements except the one that is selected

There are multiple li elements created in this way: echo '<ul>'; foreach ($test as $value){ echo '<li class="li_class">.$value['name'].</li>'; } echo '</ul>'; This code will generate the fol ...

The function document.getElementById is unable to select multiple elements simultaneously

I've been tackling a loading issue. I have a visible div, #loading, and multiple hidden divs, #message. I also have a JavaScript function. function loading() { setTimeout(function() { document.getElementById("loading").style.display = " ...

After converting my HTML elements to JSX in Next.js, I am experiencing issues with my CSS files not being applied

Hey there, I'm currently working on a website using Next.js. I've converted the HTML elements of a page to JSX elements but for some reason, the CSS of the template isn't showing up. I've double-checked all the paths and even updated th ...

Enhance the visual appeal of your checkboxes in React Fluent UI by customizing the color of the checked mark and

I have a React application using Fluent UI. Currently, the <Checkbox/> component is displaying with its default colors and behavior like this: I want to customize the color of the checked mark and label (Green for checked mark and brown for label). ...

What is causing my animation to jump when using the Web Animation API reverse() function?

I've come across various sources stating that when you call reverse() while an animation is playing, it should have the same effect as setting playbackRate to -1. However, in my case, using reverse() makes my animation behave erratically and jump arou ...