在 IE7 中使用 ASP.Net、CSS、VS 2008 的奇怪定位行为

发布于 2024-07-08 04:39:01 字数 800 浏览 4 评论 0原文

我正在 ASP.Net/C# 中开发一个网页,该网页对文本框(实际上是多个文本框)使用绝对定位。 它工作得很好,直到我添加了更多文本框。 也就是说,现有的文本框仍然定位正确,但新的文本框却没有正确定位,尽管我像其他文本框一样在 CSS 中为它们创建了新样式。 下面是一个示例:

.pieceBox {
    position: absolute;
    top: 425px;
    left: 133px;
    background-color: White;
    color: Black;
    width: 132px;
    font-weight: bold;
    text-align: center;     
} 

同一 CSS 文件中的相同样式(当然名称不同)在该文件的上方和下方都可以正常工作。 我已经检查、双重检查、三次检查 CssClass 属性中的样式名称,它是正确的。 然而,无论我做什么,包括给它一个新名称、复制旧条目、重命名等,这三个新文本框都会将自己定位在页面顶部,而其他文本框则显示在正确的绝对位置。 我查看了 aspx 源页面,并确保它们不在其他 DIV 中,等等。我对它束手无策。 我现在确实想出了一个解决方法,但这不是我想要的方式(涉及以编程方式在 Asp:Literal 中创建一些 HTML。)

我检查了生成的源(通过 IE 的 viewsource)并且该类在生成的 HTML。

如果这很重要,还有一件事; 该网站项目最初是在 VS 2005 中创建的,并转换为 VS 2008 格式。 并不是说这很重要,但我想我会提到它。

还有其他人经历过这种行为吗?

I am working on a webpage in ASP.Net/C# that uses absolute positioning for a textbox, for several in fact. It was working just fine, until I added some more text boxes. That is, the existing text boxes still positioned correctly, but the new ones did not, despite the fact that I created new styles in the CSS for them just like the others. An exampe is below:

.pieceBox {
    position: absolute;
    top: 425px;
    left: 133px;
    background-color: White;
    color: Black;
    width: 132px;
    font-weight: bold;
    text-align: center;     
} 

Identical styles in the same CSS file (with different names of course) both above and below this one work fine. I have checked, double-checked, and triple-checked the name of the style in the CssClass attribute of the and it is correct. However, no matter what I do, including giving it a new name, copying the old entries, and renaming them, etc., these three new text boxes position themselves at the top of the page, whereas the others show in their correct absolute positions. I looked at the aspx source page and made sure they are not in some other DIV, etc. I am at my wits end with it. I did come up with a workaround for now, but it is not how I want to leave it (involves programmatically creating some HTML inside an Asp:Literal.)

I checked the resulting source (via IE's viewsource) and the class is set correctly in the resulting HTML.

One more thing in case this matters; this website project was originally created in VS 2005 and converted to VS 2008 format. Not that it should matter, but thought I would mention it.

Has anyone else experienced this type of behavior?

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

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

发布评论

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

评论(2

土豪我们做朋友吧 2024-07-15 04:39:02

如果您的绝对定位元素的父级是绝对定位或相对定位,则它们将相对于其容器而不是整个页面定位自己。

换句话说,您的元素可能会从不同的原点定位自己。

If you have absolutely positioned elements that have a parent that is either absolutely or relatively positioned, they will position themselves relative to their container instead of the whole page.

In other words, your elements might be positioning themselves from different origin points.

拧巴小姐 2024-07-15 04:39:02

如果没有提供实际代码,则很难解释这样的问题,但我的第一个猜测是,您遇到的新控件问题与旧控件不使用相同的父容器。

您是否检查过适用于正常工作的文本框的父容器的 CSS 规则? 它们通常应设置为“position:relative;” 如果您想让您的子控件根据它们对齐。

还要确保不会由于控件重叠而发生布局问题,即两个文本框可能具有相似或接近的位置,然后一个文本框会覆盖另一个文本框。

无论如何,如果您想要正确且直接地解决您的问题,我建议您发布部分代码。

It is difficult to explain problems like this if no actual code is provided, but my first guess would be that you're having problem with new controls that are not using the same parent containers as the old ones.

Have you checked the css rules that apply for parent containers of properly working text boxes? They usually should be set to "position: relative;" if you want to have your child controls aligned according to them.

Also make sure that the layout problem isn't occurring due to overlapping of the controls i.e. two text boxes might have similar or near positions and then one comes over another.

In any case, if you want proper and straight solution to your problem, i would suggest that you post part of your code.

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