Is there a way to move my class="active" all the way to the far right, and the logo to the far left in both pictures?

I am struggling with adjusting the placement of my logo and dropdown icon in a responsive navbar. How can I move my class="active" to the extreme right and the logo to the extreme left, as shown in both images?

On a max-width of 700px, I want the layout to resemble image 2, with the logo on the extreme left and the dropdown on the extreme right.

Similarly, in image 1, I need the class="active" to be on the extreme right and the logo on the extreme left.

I am new to HTML and CSS and restricted from using JavaScript or Bootstrap for this project.

*{
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
}

.navbar{
    background-color: #6D6A6A;
    display: flex;
}

.navbar a{
    color: white;
    text-align: center;
    font-weight: bold;
    text-decoration: none;
    text-transform: uppercase;
    padding: 14px 28px;
}

.navbar a:hover{
    background-color: white;
    color: black;
}

.content p{
    text-align: justify;
    margin: 10px;
    padding: 10px;
}

#toggle{
    display: none;
}

.togglearea{
    background-color: #6D6A6A;
    border-bottom: 2px solid white;
    color: white;
    padding: 10px;
    display: flex;
    justify-content: flex-end;
}

.togglearea label{
    background-color: white;
    height: 45px;
    width: 50px;
    color: black;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.togglearea label span{
    background-color: black;
    height: 4px;
    width: 70%;
    margin: 2px 0px;
}

.togglearea{
    display: none;
}

@media screen and (max-width: 700px)
{
    .navbar{
        flex-direction: column;
        display: none;
    }
#toggle:checked + .navbar{
        display: flex;
    }
.togglearea{
        display: flex;
    }
    .navbar .logo{
        display: none;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Responsive Menu</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <div class="togglearea">
        <img class="togglelogo" src="https://images.freeimages.com/images/large-previews/7e9/ladybird-1367182.jpg" alt="cdac logo" height="150px" width="250px">
        <label for="toggle">
            <span></span>
            <span></span>
            <span></span>
        </label>
    </div>

    <input type="checkbox" id="toggle" class="check">

    <div class="navbar">
        <img class="logo" src="https://images.freeimages.com/images/large-previews/7e9/ladybird-1367182.jpg" alt="cdac logo" height="150px" width="250px">
        <a class="active" href="#">About Us</a>
        <a class="active" href="#">Logout</a>
    </div>

    <div class="content">
        <p>
            [Insert Your Text Here]
        </p>
    </div>
</body>
</html>

https://i.sstatic.net/XHhJZ.png

https://i.sstatic.net/ouILU.png

Answer №1

According to your explanation, I have resolved your issues.

I placed your a.active within a container named .containerActive.

Below is how the class is defined:

.containerActive{
  display: flex;
  align-items: center;
  margin-left:auto;
}
@media screen and (max-width: 700px)
{
   .containerActive{
      flex-direction: column;
      margin-left:0;
   }
}

This application is for the links.

For the image, I simply added this line:

.togglelogo{
    margin-right:auto;
  }

To ensure it stays on the right when the screen width is under 700px.

*{
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
}

.navbar{
    background-color: #6D6A6A;
    display: flex;
}

.navbar a{
    color: white;
    text-align: center;
    font-weight: bold;
    text-decoration: none;
    text-transform: uppercase;
    padding: 14px 28px;
}

.navbar a:hover{
    background-color: white;
    color: black;
}

.content p{
    text-align: justify;
    margin: 10px;
    padding: 10px;
}

#toggle{
    display: none;
}

.togglearea{
    background-color: #6D6A6A;
    border-bottom: 2px solid white;
    color: white;
    padding: 10px;
    display: flex;
    justify-content: flex-end;
}

.togglearea label{
    background-color: white;
    height: 45px;
    width: 50px;
    color: black;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.togglearea label span{
    background-color: black;
    height: 4px;
    width: 70%;
    margin: 2px 0px;
}

.togglearea{
    display: none;
}

.containerActive{
  display: flex;
  align-items: center;
  margin-left:auto;
}
@media screen and (max-width: 700px)
{
   .navbar{
        flex-direction: column;
        display: none;
    }
  #toggle:checked + .navbar{
        display: flex;
    }
  .togglearea{
        display: flex;
  }
  .togglelogo{
    margin-right:auto;
  }
  .navbar .logo{
      display: none;
  }
  .containerActive{
    flex-direction: column;
    margin-left:0;
  }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Responsive Menu</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <div class="togglearea">
        <img class="togglelogo" src="https://images.freeimages.com/images/large-previews/7e9/ladybird-1367182.jpg" alt="cdac logo" height="150px" width="250px">
        <label for="toggle">
            <span></span>
            <span></span>
            <span></span>
        </label>
    </div>

    <input type="checkbox" id="toggle" class="check">

    <div class="navbar">
        <img class="logo" src="https://images.freeimages.com/images/large-previews/7e9/ladybird-1367182.jpg" alt="cdac logo" height="150px" width="250px">
        <div class="containerActive">
          <a class="active" href="#">About Us</a>
          <a class="active" href="#">Logout</a>
        </div>
    </div>

    <div class="content">
        <p>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequatur sunt corporis, ex alias nobis dicta laborum aperiam deserunt dolore doloremque? Vero reprehenderit, distinctio necessitatibus eius deleniti saepe accusantium nesciunt. Ipsum, amet, earum sit veritatis saepe veniam non fuga illo nobis quos voluptatibus nesciunt eveniet eius eum a ducimus sapiente rem quidem perspiciatis facilis odit eos architecto dolorem quis porro. Voluptas a perferendis quod facilis excepturi, dolore ab, perspiciatis vel, quidem ad tenetur aspernatur pariatur minima deserunt consequatur sit culpa quos earum ipsum possimus eum vero! Quae, iusto, rerum? Maxime inventore porro facere distinctio totam, a quis ipsum doloremque pariatur quibusdam sint, magnam quo, odio non dolorem temporibus in veniam expedita. Nisi nobis labore illo rem maiores a dicta dolor magni ducimus, nulla et quas iure in rerum quam aut culpa quod, accusantium qui ipsum, numquam saepe. Et sit modi maiores, eligendi. Architecto mollitia praesentium, quaerat omnis nulla voluptates dignissimos sapiente natus quos incidunt saepe eligendi, sunt suscipit minus quasi culpa asperiores perspiciatis quis possimus, voluptatem quisquam cum. Minima ipsa obcaecati odit debitis laudantium ut possimus, quam accusantium eum reiciendis! Numquam, repellendus, accusantium. Ab corporis, esse quidem nobis alias omnis accusantium laborum ducimus mollitia vitae provident quia magni velit, quos aliquam?
        </p>
    </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

Is it possible to maintain a fixed footer while utilizing async/ajax functions?

Looking for a reliable solution to have a fixed footer that adjusts based on the page content? I've tested multiple samples, but they all fall short when it comes to incorporating AJAX elements. Is there a fixed footer out there that truly works seaml ...

utilize the flex index.html layout

Upon reviewing the template, I noticed that there is code implemented to check if the client has the necessary version. This code performs certain actions based on whether or not the required version is available. Additionally, there seems to be an <obj ...

What is the best way to select and style individual HTML elements using CSS?

Having trouble editing a Validations Form in Ionic 4 with CSS. It seems that only the form elements are targeted after clicking on the form group. Attached below are the form states before and after click. I'm unable to style the form elements before ...

The alignment of circles and balls is steady, with no bouncing in sight

How can I place a large circle in the center of the screen and four smaller circles on the right side? The small circles should have bouncing balls inside, each with only one ball instead of multiple. An alert should be triggered by the main big circle but ...

"Design the website with a WYSIWYG editor while preventing users from disrupting the page's

I am considering using an HTML WYSIWYG editor like CKEditor, but I am concerned about the possibility of users submitting HTML code that could alter the layout of the page when rendered. Here is a comparison between two posts: <p><b>This is m ...

What is the best way to retrieve the value from local storage?

const value = document.getElementById("demo").getAttribute('value'); if(typeof(Storage)!=="undefined") { alert(value); localStorage.setItem("GetData", value); alert(localStorage.getItem("GetData")); } function loading() { alert("coming" ...

Publicly accessible Google Drive

I am currently working with Google Drive Picker and encountering an issue where the URL generated after selecting an item from Google Drive is only accessible to the owner, making it not public. I am seeking a way to make this URL publicly accessible. To ...

Escape sequences do not seem to be functioning properly when using innerHTML

I am facing an issue where a string containing HTML escape characters (such as < and >) needs to be rendered inside a div using innerHTML. The intention is for the escaped characters to appear as text rather than as actual HTML, but they still render ...

Can anyone provide guidance on displaying a JS alert every time a tab in the slider is opened?

Utilizing the liquidslider script on my website, I have created a slider with the following HTML code: <div class="liquid-slider" id="slider-id"> <div> <h2 class="title">Slide 1</h2> // Content goes here ...

Display a unique button and apply a strike-through effect specifically for that individual list item

I've encountered an issue with my code that is causing problems specifically with nested LI elements under the targeted li element: $('#comment-section .comment-box a#un-do').hide(); $('#comment-section ul li[data-is-archived="true"]& ...

Inequality in spacing between Bootstrap columns

I am currently working on a website where the home page has columns with icons and text. The issue arises on mobile devices as the columns stack unevenly due to varying text lengths, resulting in inconsistent vertical spacing. Is there a way to ensure cons ...

Swap out the image backdrop by utilizing the forward and backward buttons

I am currently working on developing a Character Selection feature for Airconsole. I had the idea of implementing this using a Jquery method similar to a Gallery. In order to achieve this, I require a previous button, a next button, and the character disp ...

Enhance the appearance of the standard black rectangle displaying the messages "No video source" or "No video permissions"

Is there a way to change the styling of the video element that appears as a black rectangle with a strikethrough play button when the user is prompted for permission on Safari? Does it have a specific ID, class, or tag that can be targeted? I'm curre ...

`<li>` - a list element aligned on the same line as the text before it

I am currently working on customizing an HTML logfile that allows specific items (like exceptions) to be collapsed. To achieve this, I have utilized an unordered list with several li elements. However, I am facing an issue where the first li element is not ...

Achieving a multiline ellipsis (clamp) across various levels of HTML tags, compatible with popular browsers like IE and Firefox

After conducting extensive research, I finally discovered a reliable method for implementing multiple Line Ellipsis (using JS, as plain CSS is not effective). Despite exploring 100 different Google results and Q/As, this is currently the only solution that ...

The collapse feature of the navbar-toggle is not showing up

My navbar is experiencing issues with the navbar-toggle collapse class. When I reduce the size of the page, the button meant to appear does not show up, even though other collapsing elements are working properly. <nav class="navbar navbar-inverse navba ...

Tips for Displaying JSON Data on an HTML Page

How can I display JSON data in an HTML web page and group names from the JSON Data only? Here is the URL for the data: http://www.celeritas-solutions.com/pah_brd_v1/productivo/getGroups.php?organizationCode=att&userId1 I have searched online and fo ...

The PHP mail() function seems to be having trouble delivering emails to Hotmail users, although it works fine with all

Utilizing the php mail() function on my dedicated server via a php script, I am able to send emails to all recipients except for those using Hotmail accounts. Below is the code snippet for the mail() function: $hyperlink = 'http://test.guru99.com/&ap ...

Implementing dynamic CSS class addition on CodeIgniter web pages

Exploring the templating mechanism I use in my CodeIgniter application: public function index($page = 'login') { $this->load->view('admin/header',array('page'=>$page)); $this->load->view(&a ...

Displaying React components using Bootstrap in the navigation bar

I'm feeling a little stuck here. I'm currently working with React Bootstrap and the Navigation component. One of the routes in my application is the dashboard, which is only accessible after logging in. When a user navigates to the dashboard, I ...