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

Is it mandatory to include a DOCTYPE/DTD in XHTML5?

Currently in the process of developing a new language that converts to XML, I am facing the limitation of not being able to support DOCTYPE/DTD. Would it be possible for me to utilize XHTML5 without needing to declare , or will I have no choice but to in ...

What is the method for altering font color in HTML?

Here is the section of my code that I am struggling with: <p style="font-family:'impact', color:red"> something </p> The issue I am facing is that I am unable to use both the color and the font propert ...

Ways to apply Angular ng-options outside of a select element besides traditional use?

According to the official documentation, ng-options can be used on any element, not limited to just the select tag. This flexibility allows for enhanced customization of the selection UI, such as displaying thumbnail images or additional information beyond ...

Save the entire compiler output as a text or CSV file by using the "strict":true compiler option in TypeScript

The tsconfig.json file in my Visual Studio project includes the following settings: { "CompileOnSave":false, "CompilerOptions":{ "strict": true, "skipLibCheck":true }, "angularCompilerOptions":{ "fullT ...

The correct terminology for divs, spans, paragraphs, images, anchor tags, table rows, table data, unordered lists, list

Just wondering, I've noticed that every time I come across a page element '<###>[content]<###>' and want to learn how to manipulate it, I usually search for something like "how to do x with div" or "how to get y from div". I know ...

Is it possible to integrate Firebase Storage into a TypeScript/HTML/CSS project without the use of Angular or React?

For my project, I am aiming to create a login and register page using TypeScript. Currently, my code is functioning well even without a database. However, I would like to implement Firebase for storing user credentials so that the login process becomes mor ...

Create a custom data type that consists of a specific set of keys from an object

Is there a way to create a type in TypeScript that includes only a subset of keys from an object? Consider the example object below: const something = { cannary: "yellow", coyote: "brown", fox: "red", roses: "white", tulipan: "purple", palmera: ...

Guide to setting up a Cordova and TypeScript project using the command line interface

For my mobile application development, I rely on Cordova and execute cordova create MyApp in the command-line to initiate a new project. I am familiar with JavaScript but now require TypeScript for my project. Please assist me in setting up a Cordova pro ...

If the URL matches a specific path, then append a parameter

I've created a script that adds a parameter to a URL based on specific subfolders. For example, if the URL contains /de, it will add ?_sft_language=german. However, I'm encountering an issue where the code is running multiple times instead of jus ...

Sending information to the styles feature in Angular 2

Is there a way to transfer data from an Angular tag to the styles in the @Component? Take a look at my component: import { Component, Input } from '@angular/core'; @Component({ selector: 'icon', template: `<svg class="icon"> ...

Issue: Cannot assign type 'Promise<PostInfo>[]' to type 'PostInfo[]' while updating state

At the moment, I am facing an issue with my function that fetches an API and updates state. Specifically, I encounter an error when attempting to assign a Promise to the state. type DataState = { postList: Array<PostInfo>: }; const [state, setSt ...

css element remains stationary and in view

Issue at hand: I have created a logo file named .art-obj1631017189 and I am looking to fix its position. It appears to work fine, but when scrolling down and it encounters the content section, my object falls behind the content (item-layout). I desire to ...

What is the best way to make my button sticky across different screen sizes on my webpage?

I'm having trouble figuring out how to make my purple button sticky and responsive on the right side of the screen as I scroll down. Can someone help me with this? This is the snippet of my HTML code: <Col className="colPre"> ...

Partially Assessed Ajax Response

I am struggling with my ajax response as it seems to evaluate only some of the html, but not all of it. For instance, I have this code that replaces a div with the response from the request: eval(document.getElementById("test").innerHTML-xmlhttp.response ...

Struggling with creating text that adapts to various screen sizes when displayed

As someone who is new to HTML/CSS, I recently developed my first website using the Cargo platform. Within a section on my site featuring various videos, I encountered difficulty in properly positioning the titles over them while ensuring they remain respo ...

Use Ramda to convert an array of objects into nested objects

As a beginner, please forgive me for asking what may be considered a naive question. I currently have an array of objects const arr = [{id: 1, name: 'Pete'}, {id: 5, name: 'John'}, {id: 3, name: 'Peter'}] and I am looking to ...

Challenges with HTML and Session Handling

It's not functioning properly! <?php session_start(); ?> <p class="username"><?php echo $_SESSION['name']; ?></p> ...

Ensure that the dropdown menu remains visible even after the mouse no longer hovers over it

Looking to create a main menu with dropdown items that appear when the user hovers over them? You may have noticed that typically, the dropdown disappears once the hover event is lost. But what if you want the menu to stay visible and only disappear upon c ...

Efficiently organizing dates in the Vuetify date range picker

I am working with a vuetify date range picker component and have the following code: <v-menu ref="effectiveDateMenu" v-model="effectiveDateMenu" :close-on-content-cl ...

What is the best way to ensure that the child flex box matches the height of the parent flex box by 100%?

As a beginner, I'm venturing into creating an experimental site for myself. However, I am facing an issue where the .menu-container does not seem to stretch 100% the height of the .container. You can view the code on jsfiddle: https://jsfiddle.net/y1 ...