skip to Main Content

I’m trying to create a menu in my site, and I want to put the "quit" to the right, while the other links are in the left, however I simply can’t make it work

I’m trying to use class for the tag, inside a div, already tried creating a second div, however it makes the link go to the next line, and i don’t want that

the html file:

<div class="meio">
    <p class="paragraf">
        <a href="/php_01/">menu</a> 
        <a class="right" href="/PHP2024_01/">quit</a>
    </p>
</div> 

inside the css file:

.right {   
    text-align:right;
}

I have no idea what I did wrong, and I’ve spent almost 2 hours trying to solve it

2

Answers


  1. Parent elements take precedence over child elements, hence text-align doesn’t work on the a-element. You’d have to put the link in a separate paragraph and apply the text-align on the paragraph. However, you could use float:

    .right {   
      float:right;
    }
    

    This could mess up other parts of your code however, so use with ‘caution’.

    Login or Signup to reply.
  2. This is where display: flex comes in handy. Here’s a simple way to use it for this purpose:

    .paragraf {display: flex;}
    .right {margin-left: auto;}
    <div class="meio">
      <p class="paragraf">
        <a href="/php_01/">menu</a> 
        <a class="right" href="/PHP2024_01/">quit</a>
      </p>
    </div> 
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search