首页 \ 问答 \ 将水平CSS菜单居中(Center a horizontal CSS menu)

将水平CSS菜单居中(Center a horizontal CSS menu)

我有一个使用以下CSS的CSS菜单。

将整个菜单置于页面中心的最佳方法是什么?

我尝试在<nav> <div>外使用另一个<div>并设置边距,但它只是一直左对齐。

nav {
    margin: 0 auto; 
    text-align: center;
    border:1px solid black;
}

nav ul ul {
    display: none;
}

nav ul li:hover > ul {
    display: block;
}

nav ul {
    list-style: none;
}

nav ul li {
    float: left;
}

nav ul li:hover a {
    color: #000000;
}

nav ul li a {
    display: block; 
    padding: 10px 15px;
    color: #000000;
    text-decoration: none;
}       

nav ul ul {
    border-radius: 0px;
    padding: 0;
    position: absolute;
}

nav ul ul li {
    float: none; 
    border-top: 1px solid #000000;
    border-bottom: 1px solid #000000;
    position: relative;
}

nav ul ul li a {
    color: #000000;
}

nav ul ul li a:hover {
    color: #666666;
}

nav ul ul ul {
    position: absolute;
    top:0;
}

jsfiddle: http//jsfiddle.net/njuVm/


I have a CSS menu using the following CSS.

What is the best way to center the whole menu on the page?

I have tried using another <div> outside <nav> and setting margins but its just aligning left all the time.

nav {
    margin: 0 auto; 
    text-align: center;
    border:1px solid black;
}

nav ul ul {
    display: none;
}

nav ul li:hover > ul {
    display: block;
}

nav ul {
    list-style: none;
}

nav ul li {
    float: left;
}

nav ul li:hover a {
    color: #000000;
}

nav ul li a {
    display: block; 
    padding: 10px 15px;
    color: #000000;
    text-decoration: none;
}       

nav ul ul {
    border-radius: 0px;
    padding: 0;
    position: absolute;
}

nav ul ul li {
    float: none; 
    border-top: 1px solid #000000;
    border-bottom: 1px solid #000000;
    position: relative;
}

nav ul ul li a {
    color: #000000;
}

nav ul ul li a:hover {
    color: #666666;
}

nav ul ul ul {
    position: absolute;
    top:0;
}

jsfiddle : http://jsfiddle.net/njuVm/


原文:https://stackoverflow.com/questions/18839582
更新时间:2022-05-01 14:05

最满意答案

  1. 用SysInternals Process Explorer工具看看你的系统,看看这个CPU正在被使用的地方,它可能被分配到“中断”,在这种情况下,它是处理NIC中断的CPU。 如果是这种情况,请查看您的网卡驱动程序,并查看是否可以启用或调整中断合并,以便NIC为相同数量的数据报生成更少的中断。

  2. 查看是否可以卸载数据报校验和计算,如果它尚未卸载到NIC,则计算机上的CPU时间将被使用。 请注意,如果网卡无法跟上并且驱动程序不会抛出任何数据报(可参见本博客 ),则非分页池使用可能会存在潜在问题。

  3. 切换到使用GetQueuedCompletionStatusEx(),你说你正在使用“WSA重叠API”,希望你的意思是I / O完成端口方法。 如果是这样,那么GetQueuedCompletionStatusEx()将允许您使用较少的系统调用来读取更多的数据报。

  4. 切换到使用RIO API(请参阅此处了解Windows注册I / O网络扩展的介绍 )。 这继续了3的主题,并提供了更多的性能来获取数据报到您的代码。

已更新以反映问题更新:

  1. 发起多次读取以开始获得良好的待处理读取积压。 因此,例如,有100个挂起的读取,然后开始发布新的(如果您使用“跳过完成端口”处理,但想法是建立积压,则稍微复杂一点。

  2. 从GQCSEx中检索多个完成,或者没有意义使用它。

  3. 当您获得“内联”完成时避免递归,宁愿循环。 否则,你正在咀嚼堆栈。


  1. Take a look at your system with the SysInternals Process Explorer tool and see where this CPU is being used, it may well be allocated to "Interrupts" in which case it's the CPU which deals with the NIC interrupts. If this is the case then look at your NIC driver and see if you can enable or adjust interrupt coalescing so that the NIC generates fewer interrupts for the same number of datagrams.

  2. See if you can offload datagram checksum calculation if it's not already offloaded to the NIC then CPU time on your computer will be being used. Note that there may be potential issues with non-paged pool usage if the NIC can't keep up and the driver doesn't ever throw any datagrams away (see this blog posting of mine).

  3. Switch to using GetQueuedCompletionStatusEx(), you say you're using the "WSA overlapped API" hopefully you mean the I/O Completion Port method. If so then GetQueuedCompletionStatusEx() will allow you to read more datagrams with fewer system calls.

  4. Switch to using the RIO API (see here for an introduction to the Windows Registered I/O Network Extensions). This continues the theme of 3 and provides more performance for getting the datagrams into your code.

Updated to reflect question update:

  1. Issue multiple reads to start with to get a good backlog of pending reads. So, for example, have 100 pending reads and then start issuing new ones (a little more complex if you are using "skip completion port" processing but the idea is to build up a backlog.

  2. Retrieve multiple completions from GQCSEx or there's no point in using it.

  3. Avoid recursion when you get "inline" completions, prefer to loop. Otherwise you're chewing stack away.

相关问答

更多
  • 您的网络堆栈将定期发送IGMP消息。 您的网络上的交换机可能使用IGMP监听来确定您的计算机需要哪些(如果有)多播消息。 (这是为了避免由于他们没有请求的流量而在主机上施加过多的负载。) 当您的笔记本电脑休眠时,它将停止发送定期消息,确认其对某些多播流量的兴趣。 您的交换机会注意到这一点并停止将流量发送到您的笔记本电脑 我想你需要发现你的笔记本电脑何时从休眠状态恢复并重新添加成员资格到多播组。 我过去通过使用控制代码SIO_ADDRESS_LIST_CHANGE调用WSAIoctl来完成此操作(以及启用/禁 ...
  • 用SysInternals Process Explorer工具看看你的系统,看看这个CPU正在被使用的地方,它可能被分配到“中断”,在这种情况下,它是处理NIC中断的CPU。 如果是这种情况,请查看您的网卡驱动程序,并查看是否可以启用或调整中断合并,以便NIC为相同数量的数据报生成更少的中断。 查看是否可以卸载数据报校验和计算,如果它尚未卸载到NIC,则计算机上的CPU时间将被使用。 请注意,如果网卡无法跟上并且驱动程序不会抛出任何数据报(可参见本博客 ),则非分页池使用可能会存在潜在问题。 切换到使用G ...
  • 发往以239和224开头的IP的数据包是组播数据包 。 这是一种处理一组计算机的流量而不将其广播到整个网络的方法。 它被各种合法协议使用。 224.0.0.252是由链路本地名称解析协议使用的地址。 239.255.255.250是简单服务发现协议使用的地址。 224.0.0.1是您的路由器使用的所有主机地址 ,以查看您的网络上的谁愿意参与多播对话。 发给18.243.255.255的广播看起来像广播,这也被许多合法的协议如Bonjour所使用。 正如Luka所建议的那样,像Wireshark这样的好的协议 ...
  • 所以这似乎是解决方案(在我上面的注释中)。 如果从上面使用我的示例,您希望它看起来像: stream { server { listen 11016 udp; proxy_pass juniper_close_stream_backend; proxy_responses: 0; } } 这告诉nginx不要期待一个响应,它不应该需要来自UDP。 我不知道为什么他们的例子在讨论DNS时没有显示这一点,而DNS可以完全由UDP驱动 ...
  • 你可以看看flush()函数 “刷新PHP的写入缓冲区以及PHP正在使用的任何后端(CGI,Web服务器等)。这会尝试将当前输出一直推送到浏览器,但需要注意几点。” 您可能还需要调用ob_flush; 因此,如果您将以下内容放在战略位置,它应该有效: echo "something"; flush(); ob_flush(); 您可以使用set_time_limit(0)让PHP运行无限。 请参阅PHP手册 。 所以把这一行放在php文件的顶部。 如果60秒后出现问题,请查看default_socket_ ...
  • 这可能是WireShark获得一个数据包,并且我的应用程序没有? 是。 特别是,每个套接字都有其自己的固定大小的传入数据缓冲区,并且如果在内核尝试将新传入数据包添加到该缓冲区时,缓冲区没有足够的可用空间来容纳该数据包,则数据包将不会被添加到缓冲区,因此从该套接字读取传入数据的应用程序将不会收到它。 鉴于此,WireShark的缓冲区完全有可能接受传入的数据包,但您自己的应用程序的缓冲区却没有。 Is this possible that WireShark get a packet and that my ...
  • 我是否必须手动分段要发送的数据? 是的你是。 您应该对它们进行分段,以便每个段都适合以太网数据包(1536字节 - ethernet + ip + udp标头),这有点不方便,但是所有段都可以作为asio :: buffer中向量的向量传递给async_write ()。 如果是这种情况,我该如何处理图像丢包? 就像我怎样才能分辨出我的图像结尾是什么? 我是否必须使用与其对应的图像行标记每个数据包? 您必须对每个数据包进行编号,数据包#就足够了,但是您的错误处理可能最终会使您的传输速度慢于tcp。 boos ...
  • 好吧,sendto允许您指定要发送的数据量,而usleep可用于控制发送内容的频率,因此在它们之间您可以控制速率。 例如,如果你调用sendto发送1kb的块,并在sendto()调用之间暂停(usleep)1/10秒,你将以每秒10kb的速率发送。 Well, sendto lets you specify the amount of data you want to send, and usleep can be used to control how often you send something, ...
  • 如果您通过UDP发送许多单独的数据报,肯定会导致大量硬件中断和大量CPU使用。 如果您的数据报相对较小,10 Gb肯定在“大量CPU”范围内。 每个CPU都有自己的硬件中断。 您可以在性能选项卡上看到负载在核心上的分布情况 - 红线是内核CPU时间,其中包括硬件中断和操作系统的其他低级套接字处理。 If you have many individual datagrams being sent over UDP, it's certainly going to cause a lot of hardware ...
  • 是的,您可以在Windows机器上轻松创建> 30,000个插槽,但您可能需要调整MAXUSERPORT (请参见此处 )。 使用I / O完成端口或异步I / O,然后您不必担心“轮询”和可扩展性“正常”。 主要的资源问题是非页面缓冲池,但这在Vista或更高版本(见此处 )上已成为一个问题,下一个问题是I / O锁定页面限制,如果您发布非常大的缓冲区可能会出现问题对于你的读取,但鉴于这是UDP我假设你将有'合理'大小的数据报,因此锁定的页面限制不太可能是一个问题。 我在这里写了一些关于可伸缩性问题的博客 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)