Positioning a group of hyperlinks to the right side

I'm encountering an issue aligning a list of links to the right side. The problem arises when the parent div width is increased beyond a certain point.

For instance, with width=700px, everything looks fine:

However, with width=800px, it appears like this:

HTML:

<div class='linksArea' style="width: 800px;">
    <div class="boxLeft"></div>

    <a href="google.com">Link1</a>
    <br>
    <a href="google.com">Link2</a>
    <br>
    <a href="google.com">Link3</a>
    <br>
    <a href="google.com">Link4</a>
    <br>
    <a href="google.com">Link5</a>
    <br>
    <a href="google.com">Link6</a>
</div>

CSS:

.boxLeft {
     display: inline-block;
     width: 200px;
     height: 200px;
     background-color: green;
     float:left;
}

.linksArea {
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
}

.linksArea a {
    display: block;
    background-color: #ccc;
    width: 20em;
    margin-bottom: 0.5em;
    padding-top: .6em;
    padding-bottom: .6em;
    float:right;
}

Any suggestions on how to resolve this issue?

Answer №1

To fix the positioning of your elements, simply include clear:right in your CSS for .linksArea a:

.linksArea a {
    display: block;
    background-color: #ccc;
    width: 20em;
    margin-bottom: 0.5em;
    padding-top: .6em;
    padding-bottom: .6em;
    clear:right;
    float:right;
}

Check out this jsFiddle example for reference.

By adding the clear property, you ensure that the element will be positioned below other right-floated elements and aligned to the right as intended.

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

Looking for assistance with extracting only numerical values from a webpage using Selenium in Python

Website Elements <td style="font-size:20px;font-family:LucidaGrande,tahoma,verdana,arial,sans-serif;padding:10px;background-color:#f2f2f2;border-left:1px solid #ccc;border-right:1px solid #ccc;border-top:1px solid #ccc;border-bottom:1px solid #ccc; ...

Mobile responsiveness issue with basic bootstrap navigation bar not collapsing

After trying everything possible, I am still unable to resolve my issue and it is leaving me puzzled. MY ISSUE Simplifying my page, I used the example from w3schools for a responsive navbar. When resizing the browser window, the navbar collapses correctl ...

Create a collapsible menu using only CSS that expands when the down arrow is clicked, specifically designed for

I am currently working on creating a mobile-friendly version of a menu. I have a list of items, and I want only the item with the class nav-current to be displayed initially. Using pseudo :after, I added an arrow after the link of that specific li element. ...

Are there any methods I can employ to maintain the traditional aesthetic while incorporating modern elements into web forms?

My current webforms application was built using visual basic, but now the user wants to migrate it to a new UI with Bootstrap and modern styling. The goal is to apply a side navigation bar and upper navigation bar while preserving the old pages and their o ...

Exploring the concept of nested views in AngularJS's UI Router with multiple views integration

I am facing an issue with configuring multiple views on one page, where one view is nested within another. My code in app.js does not seem to be working properly. Below are the details: This is my index.html file <body ng-app="configuratorApp" > ...

Ways to update the content within an IFRAME using server-side methods

I've searched through many posts, but I still haven't found a clear solution to my problem. Here's what's going on: I have a page with an IFRAME that is pulling content from a different domain. The style of the frame doesn't match ...

Tips for concealing lengthy text within a select box and automatically wrapping it when displayed as an option

Is there a way to conceal lengthy text within a select box and display it only when the option is selected? I want to hide long text in a select box options, but have some sort of signal to show that more text is available. Is there a javascript solution ...

Tips for ensuring the final row remains fixed at the bottom of the table while maintaining a minimal body height:

I'm currently working on designing an invoice table using HTML and CSS. I have dynamic rows that are added to the table, and I want the body of the table to have a minimum height to fit around 5-6 rows, after which it should extend based on the number ...

JavaScript code to generate diamond-shaped numbers

Greetings everyone! I am facing an issue with my code that is supposed to generate diamond-shaped numbers using javascript. The code involves two javascript functions triggered by a single onclick event, but unfortunately, one of the functions does not see ...

issues with adding class to div element

I have a div section that contains various movie items and overlay elements. <div class="overlay"> <a title="yes" href="#"><div class="yes"></div></a> <a title="no" href="#"><div class="no"></div>< ...

Parsing CSV files using AngularJS

I am currently developing a CSV file parser using node and Angular. When a user uploads a CSV file, it is processed on the server side with node and the csv-parse library. This results in an array of objects based on the input CSV file. On the Angular si ...

Has the new version of Bootstrap, Bootstrap 5, eliminated the spacing between rows

After switching to bootstrap 5, I couldn't help but notice the lack of spacing between rows. Is it necessary to use the spacing utility like mb-3 or mb-2 to add vertical spacing? I'm curious about the rationale behind this change. <script s ...

When Hovering, Pseudo-class Cannot be Applied

In my design, I have an image overlaid with a Play icon. The concept is that when the user hovers over the image, the brightness of the image decreases and the Play icon is replaced with a Magnifying Glass icon. However, there seems to be a problem. When ...

Adding a horizontal scrollbar to an iframe: A step-by-step guide

My issue involves embedding this iframe element <iframe src="https://opendsa-server.cs.vt.edu/OpenDSA/Books/Everything/html/Write.html#recurWriteStepsCON" scrolling="no" id='frameid1' width=100% height=330px></iframe& ...

Table with a set height containing four cells (without scroll bars) and text allocated to each cell

I am looking to create a table in HTML/CSS with 4 cells stacked on top of each other. I have a couple of questions: How can I set the width and height for each cell individually (with varying heights), while ensuring that there are no scroll bars if th ...

Tips for Building Common Controller Logic in CakePHP

I am in the process of developing a website where I have set up dynamic content for the footer, which is retrieved from a database. I am looking to create a single controller logic code that can be used across all pages on the site. Any suggestions or gu ...

Customize Next Js styling based on the user's browser requirements

There's a curious issue when viewing my website through Facebook or LinkedIn - the background color suddenly changes to a vibrant green, but only in those particular webviews. However, when I view it through other apps like Twitter or Instagram, the ...

Equally distribute grid column width inside container according to their content dimensions

I am facing a challenge with my side-by-side grid columns. I want the grid to always be the width of its container, ensuring that as much content from each column is visible as possible within that space. In my demo, the grid is currently set at 300px wid ...

Customize your CSS line height for the bottom of text only

Hey there, I'm pretty new to frontend development so please excuse me if this is a silly question :) I know that it's not usually done, but when you apply line-height to an element like an h1, it adds extra space both on the top and bottom of th ...

What is the process for adjusting the color of the underline in Material UI input fields

I am facing an issue with a Material UI Select component that is on a dark background. I want to change the text and line colors to white just for this particular component, while keeping the rest of the Select instances unchanged. Although I have managed ...