我正在開發一個ASP.NET的web應用程序,我正在使用菜單控件來創建一個導航欄。但是,我面臨一個在水平線中顯示菜單項的問題。目前,菜單項像列表一樣垂直顯示。
我想為我的菜單實現以下布局:
narudbe | Artikli | Prijevoznici | ku PCI | izvje Taji
以下是我的代碼:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="LandingPage.aspx.vb" Inherits="Mi?kovi?_OMIS_projekt.LandingPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.navbar {
background-color: #333;
overflow: hidden;
display: flex;
justify-content: center; /* Align items horizontally */
}
.navbar a {
float: none; /* Remove float property */
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
.logo {
text-align: center;
padding: 20px 0;
}
.logo img {
width: 800px; /* Adjust the width as per your logo's dimensions */
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="navbar">
<asp:Menu ID="MyMenu" runat="server">
<Items>
<asp:MenuItem Text="Narud?be" Value="~/Stranice/Narudzbe.aspx"></asp:MenuItem>
<asp:MenuItem Text="Artikli" Value="~/Stranice/Artikli.aspx"></asp:MenuItem>
<asp:MenuItem Text="Prijevoznici" Value="~/Stranice/Prijevoznici.aspx"></asp:MenuItem>
<asp:MenuItem Text="Kupci" Value="~/Stranice/Kupci.aspx"></asp:MenuItem>
<asp:MenuItem Text="Izvje?taji" Value="~/Stranice/Izvjestaji.aspx"></asp:MenuItem>
</Items>
</asp:Menu>
</div>
<div class="logo">
<img src="Images/logo.png" alt="OMIS Logo" />
</div>
</form>
</body>
</html>
我嘗試過修改CSS屬性,比如display: flex和float: none,但是菜單項仍然顯示在垂直列表中。我如何修改我的CSS或ASP.NET代碼來實現菜單項的水平布局?
下面也是VB中的代碼隱藏。網絡:
Public Class LandingPage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyMenu.Items(0).NavigateUrl = "~/Stranice/Narudzbe.aspx"
MyMenu.Items(1).NavigateUrl = "~/Stranice/Artikli.aspx"
MyMenu.Items(2).NavigateUrl = "~/Stranice/Prijevoznici.aspx"
MyMenu.Items(3).NavigateUrl = "~/Stranice/Kupci.aspx"
MyMenu.Items(4).NavigateUrl = "~/Stranice/Izvjestaji.aspx"
End Sub
Protected Sub MyMenu_MenuItemClick(sender As Object, e As MenuEventArgs) Handles MyMenu.MenuItemClick
' Get the selected item's URL
Dim selectedItemUrl As String = MyMenu.SelectedItem.Value
' Redirect to the selected page
Response.Redirect(selectedItemUrl)
End Sub
End Class
嘗試以下菜單設置:
如果您在屬性表中設置了以上內容,那么您的菜單將變成這樣:
<asp:Menu ID="MyMenu" runat="server"
Orientation="Horizontal" RenderingMode="Table">
<Items>
結果是這樣的:
上一篇如何增加選擇的高度?
下一篇vue 路由拋出異常