简体   繁体   English

填充CSS菜单时遇到问题

[英]Having trouble with padding a CSS menu

I have been asked to "fix" a client's old website which was written in 2011, by a design team that was clearly struggling to understand the then-new HTML5+CSS. 我曾被设计团队要求“修复”客户在2011年编写的旧网站,当时该团队显然在努力理解当时的HTML5 + CSS。 There is a lot wrong with this code, and most of it I've been able to fix, stuff like using 这段代码有很多错误,其中大部分我已经可以解决,例如使用

<p>&nbsp;</p>

for line breaks. 换行。 I'm not even kidding. 我不是在开玩笑。

Anyway, one of the things I have been asked to do is extend the website's text container and menu, and stretch out the menu's actual text to fit the new width, which has gone fine. 无论如何,我被要求做的一件事情就是扩展网站的文本容器和菜单,并扩展菜单的实际文本以适应新的宽度,这已经很好了。 However, I'm having some trouble with padding out the menu text. 但是,我在填充菜单文本时遇到了一些麻烦。 I did a search through the forums for some advice, and tried out the style code suggested, but it seems to move the menu text out of the area of menu.jpg where it needs to be. 我在论坛上搜索了一些建议,并尝试了建议的样式代码,但似乎将菜单文本移出了menu.jpg所需的区域。

CSS (this is the client's, so yell at them) CSS(这是客户端的,所以大吼大叫)

#header_menu_container
/* This is verbatim from the code I am working with.  I seriously have NO IDEA why this selector even exists. */
{


}

#header_menu 
{
    margin: 0;
    display: inline-block;
    list-style: none;
    font-size: 15px;
}

/* header menu colour */
#header_menu li a {
color: #516a82;
}
/* menu hover colour */
#header_menu li a:hover{
color: #b55239;
text-decoration: none;
}

.no_submenu, .has_submenu
{
    display: block;
    float: left;
    position: relative;
}

.no_submenu a, .has_submenu span{
display: block;
font-size: 15px;
font-family: "Times New Roman", Times, serif;
color: #516a82;
text-decoration: none;
}

.no_submenu a:hover, .has_submenu span:hover{
color: #b55239;
}

.has_submenu span{
cursor: pointer;
_cursor: hand;
}

.is_submenu{
position: absolute;
left: -10px;
top: 32px;
background: #dfd7c5;
margin: 0;
padding: 0;
list-style: none;
z-index: 9999;
}

.is_submenu li a{
display: block;
text-align: left;
padding-left: 10px;
width: 122px;
padding-right: 10px;
font-size: 15px;
font-family: "Times New Roman", Times, serif;
color: #516a82;
text-decoration: none;
pading-top: 10px;
padding-bottom: 10px;
line-height: 18px;
}

.is_submenu li a:hover{
color: #b55239;
}

HTML (based on client's, with a bit of my modification) HTML(基于客户端,并做了一些修改)

<ul id="header_menu">
                    <li class="no_submenu" style="width: 63px;">
                        <b><a href="./index.html">Home</a></b>
                    </li>
                    <li class="has_submenu" id="who-we-are">
                        <b><span style="width: 103px;">Who We Are</span></b>
                        <ul class="is_submenu" style="display: none;">
                            <li>
                                <b><a href="./whoweare_janyce-lastman.html">Janyce Lastman</a></b>
                            </li>
                            <li>
                                <b><a href="./whoweare_ziny-kirshenbaum.html">Ziny Kirshenbaum</a></b>
                            </li>
                            <li>
                                <b><a href="./whoweare_tutors.html">Tutors</a></b>
                            </li>
                        </ul>
                    </li>

                    <li class="has_submenu" id="services"><span style="width: 73px;"><b>Services</b></span>
                        <ul class="is_submenu" style="display: none;">
                            <li>
                                <b><a href="./services_consultant-to-schools.html">Consultant To Schools</a></b>
                            </li>
                            <li>
                                <b><a href="./services_education-consulting-and-case-management.html">Education Consulting And Case Management</a></b>
                            </li>
                            <li>
                                <b><a href="./services_educational-assessments.html">Educational Assessments</a></b>
                            </li>
                            <li>
                                <b><a href="./services_school-placement-consultation.html">School Placement Consultation</a></b>
                            </li>
                            <li>
                                <b><a href="./services_seminars-and-workshops.html">Seminars And Workshops</a></b>
                            </li>
                            <li>
                                <b><a href="./services_test-tips-support.html">Test Tips Support</a></b>
                            </li>
                            <li>
                                <b><a href="./services_tutoring.html">Tutoring</a></b>
                            </li>
                        </ul>
                    </li>

                    <li class="has_submenu" id="media-and-press">
                        <span style="width: 113px;"><b>Media &amp; Press</b></span>
                            <ul class="is_submenu" style="display: none;">
                                <li>
                                    <b><a href="./media-and-press_in-the-press.html">In the Press</a></b>
                                </li>
                                <li>
                                    <b><a href="./media-and-press_book-reviews.html">Book Reviews</a></b>
                                </li>
                                <li>
                                    <b><a href="./media-and-press_selected-articles.html">Selected Articles</a></b>
                                </li>
                                <li>
                                    <b><a href="./media-and-press_interesting-links.html">Interesting Links</a></b>
                                </li>
                            </ul>
                    </li>
                    <li class="no_submenu" style="width: 53px;">
                        <a href="./faq.html"><b>FAQ</b></a>
                    </li>

                    <li class="has_submenu" id="testimonials"><span style="width: 103px;"><b>Testimonials</b></span>
                        <ul class="is_submenu" style="display: none;">
                            <li>
                                <b><a href="./testimonials_ttg-tutors.html">Testimonials for TTG Tutors</a></b>
                            </li>
                            <li>
                                <b><a href="./testimonials_janyce-lastman.html">Testimonials for Janyce Lastman</a></b>
                            </li> 
                        </ul>
                    </li>     

                    <li class="has_submenu" id="contact-us">
                    <span style="width: 70px;"><b>Contact</b></span>
                        <ul class="is_submenu" style="display: none;">
                            <li>
                                <b><a href="./contactus_contact-info.html">Contact Info</a></b>
                            </li>
                            <li>
                                <b><a href="./contactus_employment-opportunities.html">Employment Opportunities</a></b>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>

There's a display call inside a class selector, which is likely part of the issue, but my gut feeling tells me that this needs someone with more expertise to dissect everything wrong with it. 在类选择器中有一个显示调用,这很可能是问题的一部分,但是我的直觉告诉我,这需要一个具有更多专业知识的人来剖析其所有错误。

It's one thing to figure out what's wrong with your own code, and another to try and analyze what's wrong with someone else's. 找出您自己的代码有什么问题是一回事,而试图分析别人的代码有何问题则是另一回事。 Any advice would be greatly appreciated :) 任何建议将不胜感激 :)

So looking back over the code again, I think I've figured out the problem. 因此,再次查看代码,我想我已经解决了问题。

Instead of putting padding in the CSS, the original authors put a numerical width in a style tag in the HTML for every single menu , eg 原始作者没有在CSS中添加填充,而是在每个菜单的HTML样式标签中添加了数字宽度,例如

<span style="width: 73px;"><b>Services</b></span>

Idiots. 白痴。

I'm going to try and write something similar into the stylesheet properly. 我将尝试将类似的内容正确地写入样式表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM