What steps can I take to ensure that the elements are in the same row instead of being displayed in three separate rows?

(I'm a beginner in web development and need some help) Is there a way to align elements into the same row instead of stacking them up in separate rows? I'm working on creating a header bar similar to the one on the Naive UI Documentation Website. My tech stack includes Vue.js 3 with composition API, TypeScript, Naive UI Component Library, and Tailwind CSS.

TopViewGuide.vue

<script setup lang="ts">
import {RouterLink, RouterView, useRouter} from 'vue-router'
import {
  NAvatar, NButton, NConfigProvider, NDialogProvider, NDropdown,
  NGradientText,
  NLayout, NLayoutHeader, NLoadingBarProvider, NMenu, NMessageProvider, NSpace
} from 'naive-ui'
import type { DropdownOption } from 'naive-ui'
import TopViewGuide from "@/views/Guides/TopViewGuide.vue";
const $router = useRouter();
import {h, ref} from 'vue'
import type {Component} from "vue";
import { NIcon } from 'naive-ui'
import type { MenuOption } from 'naive-ui'

function renderIcon (icon: Component) {
  return () => h(NIcon, null, { default: () => h(icon) })
}

const menuOptions: MenuOption[] = [
  {
    label: 'Home',
    key: 'home'
  },
  {
    label: 'Tools',
    key: 'tools'
  },
  {
    label: 'Schedules',
    key: 'schedules'
  },
  {
    label: 'Tasks',
    key: 'tasks'
  }
]

const activeKey = ref(), isLoggedIn = false;
const dropdownOptions: DropdownOption[] = [
  { label: "Account", key: "auth.principal" },
  { label: "Sign out", key: "auth.sign-out" },
];
function dropdownHandler(key: string) {
  $router.push({ name: key });
}
</script>

<template>
  <div class="flex items-center justify-between px-8 w-full">
    <div class="flex items-center cursor-pointer">
      <img src="@/assets/images/TaskJournal%20Icon.svg" width="40" height="40" />
      <NGradientText>TaskJournal</NGradientText>
    </div>
    <div class="flex-grow">
      <NMenu v-model:value="activeKey" mode="horizontal" :options="menuOptions"/>
    </div>
    <div v-if="!isLoggedIn" class="flex gap-3">
      <NButton type="primary">Get Started</NButton>
    </div>
    <div v-else class="flex gap-3">
      <NDropdown placement="bottom-end" show-arrow :options="dropdownOptions" @select="dropdownHandler">
        <NAvatar/>
      </NDropdown>
    </div>
  </div>
</template>

<style scoped>

</style>

LandingPage.vue

<script setup lang="ts">
import {RouterLink, RouterView, useRouter} from 'vue-router'
import {
  NAvatar, NButton, NConfigProvider, NDialogProvider, NDropdown,
  NGradientText,
  NLayout, NLayoutHeader, NLoadingBarProvider, NMenu, NMessageProvider, NSpace
} from 'naive-ui'
import type { DropdownOption } from 'naive-ui'
import TopViewGuide from "@/views/Guides/TopViewGuide.vue";
const $router = useRouter();
import {h, ref} from 'vue'
import type {Component} from "vue";
import { NIcon } from 'naive-ui'
import type { MenuOption } from 'naive-ui'
</script>

<template>
  <NDialogProvider>
    <NConfigProvider>
      <NMessageProvider>
        <NLoadingBarProvider>
          <NLayoutHeader bordered class="h-16 flex">
            <TopViewGuide/>
          </NLayoutHeader>
          <div class="w-full relative">
            <NLayout>
              <NGradientText>
                sadsada
              </NGradientText>
            </NLayout>
          </div>
        </NLoadingBarProvider>
      </NMessageProvider>
    </NConfigProvider>
  </NDialogProvider>
</template>

<style scoped>

</style>

In my App.vue file, the <RouterView> component is the only element within the <template>.

I've attempted using flex containers for each element but it hasn't worked as expected. View image here for reference. Feeling quite confused at this point and could use some guidance.

Answer №1

Is this the desired outcome?


<template>
  <div class="flex items-center justify-between px-8 w-full">
    <div class="items-center cursor-pointer">
      <img src="@/assets/images/TaskJournal%20Icon.svg" width="40" height="40" />
      <NGradientText>TaskJournal</NGradientText>
    </div>
    <div class="">
      <NMenu v-model:value="activeKey" mode="horizontal" :options="menuOptions"/>
    </div>
    <div v-if="!isLoggedIn" class="gap-3">
      <NButton type="primary">Get Started</NButton>
    </div>
    <div v-else class="gap-3">
      <NDropdown placement="bottom-end" show-arrow :options="dropdownOptions" @select="dropdownHandler">
        <NAvatar/>
      </NDropdown>
    </div>
  </div>
</template>

A flex container can contain divs (or display: block tags) in a single row.

Refer to https://www.w3schools.com/css/css3_flexbox.asp

Answer №2

Another option is to utilize the "Float" element. The float property in CSS is used to position and format content, allowing elements to float alongside each other rather than stacking on top of each other.

.mybox div {
   float:right;
}

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

detect the dismissal event in the modal controller from the main component

Within my MainPage, I invoke the create function in the ModalController, which displays the ModalPage. Upon clicking cancel, the dismiss function is called and we are returned to the MainPage. The process functions as expected. @Component({ selector: &a ...

What is the best way to alter the background of a div when hovering over an image?

I am looking to achieve a unique effect with my thumbnail image and background. Currently, I have the thumbnail image inside a div with another image serving as the background to frame it. My goal is to change the position of the background image from bott ...

The reactivity of Vuex store properties is lost when they are newly created

Currently, I am utilizing Vue.js and Quasar, along with a Vuex store. Although the properties that were initially present during the initialization of the store are reactive, none of the newly created properties on an object of the store seem to be reacti ...

Neglect to notify about the input text's value

Having trouble retrieving the text from a simple <input id="editfileFormTitleinput" type="text>. Despite my efforts, I am unable to alert the content within the input field. This is the code snippet I've attempted: $('#editfileFormTitleinp ...

Error message: Invariant Violation: Portal.render() being caused by semantic-ui-react Basic Modal

As part of enhancing an existing React component, I attempted to include a basic modal (link to documentation). Everything was working well without the modal, but once I added it in following the semantic-ui-react guidelines, I encountered a runtime error ...

Animating the Click Event to Change Grid Layout in React

Can a grid layout change be animated on click in React? For instance, consider the following component: import { Box, Button, styled, useMediaQuery } from "@mui/material"; import Row1 from "./Row1"; import React from "react"; ...

Having trouble with integrating jsPlumb with Nuxtjs and encountering the error "document is not defined"?

I've seen some similar questions, but none of the solutions have worked for me so here's my issue. I'm attempting to integrate jsPlumb into my Nuxt.js/Vue.js application. Here are the steps I've taken: npm i jsplumb --save Create a ne ...

What is the best way to click on a particular button without activating every button on the page?

Struggling to create buttons labeled Add and Remove, as all the other buttons get triggered when I click on one. Here's the code snippet in question: function MyFruits() { const fruitsArray = [ 'banana', 'banana', & ...

Steps for dynamically loading the correct pane without having to refresh the header, footer, or left navigation

Looking to create a web application using HTML, Bootstrap, and jQuery that includes a header, footer, left navigation, and right pane. The content of the right pane will be loaded from a separate HTML page based on what is clicked in the left navigation. ...

How to display an unordered list horizontally in HTML

I'm working on a screen that has filters displayed vertically, but I want to align them horizontally and have the filter options arranged in two columns. I've tried using CSS properties like spacing, clear, and display block, but the checkboxes/l ...

Why isn't useEffect recognizing the variable change?

Within my project, I am working with three key files: Date Component Preview Page (used to display the date component) useDateController (hook responsible for managing all things date related) In each of these files, I have included the following code sn ...

Switching the input to LTR changes the overall direction to LTR while maintaining the RTL placeholder

The text input is currently set to be RTL, including both the placeholder and the actual input. The settings for this were done elsewhere. My question is how can I modify it so that only the input changes to LTR, while the placeholder remains RTL. For exa ...

Creating a Vertical Navbar Dropdown in Bootstrap 3.0 Without Appending to the Last List Item Only

Currently, I'm in the process of creating a panel layout that features an elegant vertical navbar. Although everything seems to be aligned correctly and I've managed to implement a dropdown menu in a vertical layout, it keeps appending to the las ...

Is there a way to access the badge hidden behind the collapsible menu in bootstrap 4?

After moving from bootstrap 3 to bootstrap 4, my items no longer align properly. I've scoured the entire Internet for a solution, but I've run out of options (and patience.. haha) This is how it currently looks: I want the badge to be positione ...

Submitting a form using an anchor tag in Angular 8: A step-by-step guide

I have a question about how to submit form data using hidden input fields when a user clicks on an <a> tag. <form action="/submit/form/link"> <input type="hidden" [attr.value]="orderNumber.id" /> <input type="hidden" [attr.value]= ...

The vuetify-loader fails to automatically initiate my variables during bootstrapping

After setting up my project with vue-cli and installing vuetify through vue-cli, I decided to create a directory named sass within the src folder, containing a variables.scss file. According to the documentation (https://vuetifyjs.com/en/features/sass-var ...

Using CSS GRID for creating layouts with customized grid-template-areas that include empty cells and automatic placement

Struggling with implementing the css grid layout module to showcase a 12-column, 3-row grid. The initial row should only contain two elements, positioned on each side of the grid with empty cells in between using ten periods. Subsequent rows should autom ...

Flashing Effect of Angular Ui-Bootstrap Collapse During Page Initialization

Below is the code snippet I've implemented to use the ui-bootstrap collapse directive in my Angular application. HTML: <div ng-controller="frequencyCtrl" style="margin-top:10px"> <button class="btn btn-default" ng-click="isCollapsed = ...

Specialized spinning tool not in sight

Having an angular 11 application with a spinner that should be visible during data loading from the backend. However, when the fa-icon is pressed by the user, it becomes invisible while waiting for the server response. The issue arises when the spinner its ...

A function injected into a constructor of a class causes an undefined error

As I delve into learning about utilizing typescript for constructing API's, I have encountered a couple of challenges at the moment. Initially, I have developed a fairly straightforward PostController Class that has the ability to accept a use-case wh ...