如何使菜单在更改浏览器或缩放比例时固定且不移动

发布于 2024-11-25 06:05:38 字数 3174 浏览 4 评论 0原文

问:

我有一个导航菜单,我注意到每次更改浏览器缩放时。它的位置发生了变化。如何使菜单固定在其位置。

.css:

ul#topnav
{
    margin-left:0;

    margin-bottom:50px;
    margin-top:5px;
    padding: 0;
    float: right;
    width: 800px;
    list-style: none;
    position: relative; /*--Set relative positioning on the unordered list itself - not on the list item--*/
    font-size: 1.2em;
    background:#CC6A11; /*url(topnav_stretch.gif) repeat-x;*/
}
ul#topnav li
{
    float: right;
    margin: 0;
    padding: 0;
    border-right: 1px solid #555; /*--Divider for each parent level links--*/
}
ul#topnav li a
{
    padding: 10px 15px;
    display: block;
    color: #f0f0f0;
    text-decoration: none;
}
ul#topnav li:hover
{
    background: #1376c9 url(../images/topnav_active.gif) repeat-x;
}

ul#topnav li span
{
    float: right;
    padding: 10px 0;
    position: absolute;
    left: 0;
    top: 35px;
    display: none; /*--Hide by default--*/
    width: 800px;
    background: #1376c9;
    color: #fff; /*--Bottom right rounded corner--*/
    -moz-border-radius-bottomright: 5px;
    -khtml-border-radius-bottomright: 5px;
    -webkit-border-bottom-right-radius: 5px; /*--Bottom left rounded corner--*/
    -moz-border-radius-bottomleft: 5px;
    -khtml-border-radius-bottomleft: 5px;
    -webkit-border-bottom-left-radius: 5px;
}
ul#topnav li:hover span
{
    display: block;
}
/*--Show subnav on hover--*/
ul#topnav li span a
{
    display: inline;
}
/*--Since we declared a link style on the parent list link, we will correct it back to its original state--*/
ul#topnav li span a:hover
{
    text-decoration: underline;
}

.aspx

<div style="  margin-right:20%" >
            <ul id="topnav">
                <li><a href="frm_AssistantCV.aspx">الرئيسية</a></li>
                <li><a href="#">النشاط التعليمي</a> <span><a href="frm_TeachingLoad.aspx">العبأ التدريسي</a>
                    | <a href="frm_EducationalActivities.aspx">الأنشطة التعليمية</a> | <a href="frm_EducationalActivitiesDirectly.aspx">
                        الأنشطة التعليمية المباشرة</a> </span></li>
                <li><a href="#">النشاط العلمي</a> <span><a href="frm_ScientificActivity.aspx">النشاط
                    العلمي 1</a> | <a href="frm_ScientificActivity2.aspx">النشاط العلمي 2</a> | <a href="frm_ScientificActivity3.aspx">
                        النشاط العلمي 3</a> </span></li>
                <li><a href="frm_ManagementActivity.aspx">النشاط الاداري</a></li>
                <li><a href="frm_StudentActivities.aspx">االاشتراك في أنشطة طلابية</a></li>
                <li><a href="frm_Evaluation.aspx">التقييم العام</a></li>
                <li><a href="LoginPage.aspx">خروج</a></li>
            </ul>
        </div>

我使用这个 菜单

Q:

I have a navigation menu ,i notice that every time i change the browser zoom. its position changed.how to make the menu fixed in its place.

the .css:

ul#topnav
{
    margin-left:0;

    margin-bottom:50px;
    margin-top:5px;
    padding: 0;
    float: right;
    width: 800px;
    list-style: none;
    position: relative; /*--Set relative positioning on the unordered list itself - not on the list item--*/
    font-size: 1.2em;
    background:#CC6A11; /*url(topnav_stretch.gif) repeat-x;*/
}
ul#topnav li
{
    float: right;
    margin: 0;
    padding: 0;
    border-right: 1px solid #555; /*--Divider for each parent level links--*/
}
ul#topnav li a
{
    padding: 10px 15px;
    display: block;
    color: #f0f0f0;
    text-decoration: none;
}
ul#topnav li:hover
{
    background: #1376c9 url(../images/topnav_active.gif) repeat-x;
}

ul#topnav li span
{
    float: right;
    padding: 10px 0;
    position: absolute;
    left: 0;
    top: 35px;
    display: none; /*--Hide by default--*/
    width: 800px;
    background: #1376c9;
    color: #fff; /*--Bottom right rounded corner--*/
    -moz-border-radius-bottomright: 5px;
    -khtml-border-radius-bottomright: 5px;
    -webkit-border-bottom-right-radius: 5px; /*--Bottom left rounded corner--*/
    -moz-border-radius-bottomleft: 5px;
    -khtml-border-radius-bottomleft: 5px;
    -webkit-border-bottom-left-radius: 5px;
}
ul#topnav li:hover span
{
    display: block;
}
/*--Show subnav on hover--*/
ul#topnav li span a
{
    display: inline;
}
/*--Since we declared a link style on the parent list link, we will correct it back to its original state--*/
ul#topnav li span a:hover
{
    text-decoration: underline;
}

.aspx

<div style="  margin-right:20%" >
            <ul id="topnav">
                <li><a href="frm_AssistantCV.aspx">الرئيسية</a></li>
                <li><a href="#">النشاط التعليمي</a> <span><a href="frm_TeachingLoad.aspx">العبأ التدريسي</a>
                    | <a href="frm_EducationalActivities.aspx">الأنشطة التعليمية</a> | <a href="frm_EducationalActivitiesDirectly.aspx">
                        الأنشطة التعليمية المباشرة</a> </span></li>
                <li><a href="#">النشاط العلمي</a> <span><a href="frm_ScientificActivity.aspx">النشاط
                    العلمي 1</a> | <a href="frm_ScientificActivity2.aspx">النشاط العلمي 2</a> | <a href="frm_ScientificActivity3.aspx">
                        النشاط العلمي 3</a> </span></li>
                <li><a href="frm_ManagementActivity.aspx">النشاط الاداري</a></li>
                <li><a href="frm_StudentActivities.aspx">االاشتراك في أنشطة طلابية</a></li>
                <li><a href="frm_Evaluation.aspx">التقييم العام</a></li>
                <li><a href="LoginPage.aspx">خروج</a></li>
            </ul>
        </div>

I use this menu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

新雨望断虹 2024-12-02 06:05:38

您只需做两件事,就能解决您的问题!

1) 删除 div 的右边距。

Previous :<div style="  margin-right:20%" >

Modified: <div>

2)更新你的topnav css如下:

ul#topnav {
    background: none repeat scroll 0 0 #CC6A11;
    float: right;
    font-size: 1.2em;
    list-style: none outside none;
    margin-bottom: 50px;
    margin-top: 15px;
    padding: 0;
    position: relative;
    text-align: left;
}

希望这能解决你的问题!!!!

You just have to do two things, and it will solve your question !

1) Remove margin right from div.

Previous :<div style="  margin-right:20%" >

Modified: <div>

2) Update your topnav css as below :

ul#topnav {
    background: none repeat scroll 0 0 #CC6A11;
    float: right;
    font-size: 1.2em;
    list-style: none outside none;
    margin-bottom: 50px;
    margin-top: 15px;
    padding: 0;
    position: relative;
    text-align: left;
}

Hope this will solve your problem!!!!!

雨后咖啡店 2024-12-02 06:05:38

它会缩放,但你可以通过替换:

<div style="  margin-right:20%; width:100%" >

来使其保持不变

<div style="position:absolute; top: 0px; left: 20px;" >

It is going to zoom but you can make it stick by replacing:

<div style="  margin-right:20%; width:100%" >

with

<div style="position:absolute; top: 0px; left: 20px;" >
俏︾媚 2024-12-02 06:05:38

确保 HTML 文件中包含元视口标签应该会有所帮助,并且
在菜单的 CSS 中将“position”属性设置为“fixed”将使其粘性/浮动。

Ensuring that you have your meta viewport tag in your HTML files should help, and
setting the 'position' attribute to 'fixed' in your menu's CSS will make it sticky/float.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文