CSS:如何解决超链接对齐问题?

发布于 2025-01-05 10:32:51 字数 361 浏览 2 评论 0原文

我有两个链接:购物者和商店。这两个链接都有自己独立的左浮动和右浮动。 Store 链接应该位于右浮动中,但当向左浮动添加边框样式时,它会从其 div 中弹出。我怎样才能把它放回原位?请查看 http://jsfiddle.net/JuCKU/ 示例。

我完全忘记用新代码更新 jfiddle 。 http://jsfiddle.net/JuCKU/3/

firefox 存在对齐问题,而 google chrome 似乎存在对齐问题正确渲染布局。

I have two links: shopper and store. Both of these links are in there own separate left and right floats. The Store link is supposed to be in a right float, but it snaps out of its div when adding a border style to the left float. How do I get it back into place? Please have a look at http://jsfiddle.net/JuCKU/ for an example.

I completely forgot to update jfiddle with the new code. http://jsfiddle.net/JuCKU/3/

firefox is having the alignment issue while google chrome seems to render the layout correctly.

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

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

发布评论

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

评论(5

娇女薄笑 2025-01-12 10:32:51

将宽度从 50% 降低到 49%。由于有边框,它会占用空间,并且通过为每个 div 指定 50% 的宽度,总数有点太宽,并且第二个 div 会向下弹出一点。或者摆脱边界。

jsFiddle 示例

更改

#shopper, #store
{
    width: 50%;
    text-align: center;
}

为:

#shopper, #store
{
    width: 49%;
    text-align: center;
}

Drop the width from 50% to 49%. Since you have a border, it takes up space and by giving each div a width of 50%, the total is a bit too wide and the second div pop down a bit. Or get rid of the border.

jsFiddle Example

Change

#shopper, #store
{
    width: 50%;
    text-align: center;
}

To:

#shopper, #store
{
    width: 49%;
    text-align: center;
}
眼眸里的快感 2025-01-12 10:32:51

这是一个舍入问题。这不是四舍五入的问题,50%+50%+1px边框已经超过100%了。使宽度略小于 50% 是一个快速解决方案。

更改此:

#shopper, #store
{
    width: 50%;
    text-align: center;
}

为此:

#shopper, #store
{
    width: 49.9999%;
    text-align: center;
}

http://jsfiddle.net/JuCKU/4/

It's a rounding issue. It's not a rounding issue, 50% + 50% + 1px border is more than 100%. Making the width slightly less than 50% is a quick fix.

Change this:

#shopper, #store
{
    width: 50%;
    text-align: center;
}

for this:

#shopper, #store
{
    width: 49.9999%;
    text-align: center;
}

http://jsfiddle.net/JuCKU/4/

唔猫 2025-01-12 10:32:51

简单地在您的 shopper div 中给出 margin-right:-1px

#shopper
{
    float: left;
    border-right: 1px solid #ccc;
    margin-right:-1px;
}

检查这个 http://jsfiddle.net/JuCKU/6/

OR

您可以使用 css3 box-sizing 属性来实现此目的,但它直到 为止都有效IE8 &多于。

检查这个http://jsfiddle.net/JuCKU/7/

simple give margin-right:-1px in your shopper div

#shopper
{
    float: left;
    border-right: 1px solid #ccc;
    margin-right:-1px;
}

Check this http://jsfiddle.net/JuCKU/6/

OR

you can use css3 box-sizing property for this but it's work till IE8 & above.

Check this http://jsfiddle.net/JuCKU/7/

沦落红尘 2025-01-12 10:32:51

添加边框会将框的整体大小增加到 50%+1px,因此它们的总宽度大于 100%,并且必须给予一些东西。

您可以使用 CSS3 属性 box-sizing:border-box 将边框合并到总宽度的 50% 中,或者更具体地说,在 Firefox 中为 -moz-box-sizing,在 Firefox 中为 -webkit-box-sizing Chrome/Safari 以及 Opera 中简单的框大小调整。不幸的是 IE 还不支持这一点。

因此,将其添加到您的代码中。

#shopper, #store {
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
}

更多信息 - http://www.css3.info/preview/box-sizing/

正如其他人所提到的,跨所有浏览器的防弹解决方案是将框的宽度减少到略小于 50%。

Adding the border increases the overall size of the boxes to 50%+1px, so together their combined width is greater than 100% and something's gotta give.

You can use the CSS3 property box-sizing:border-box to incorporate the border into the total 50% width, or more specifically -moz-box-sizing in Firefox, -webkit-box-sizing in Chrome/Safari and simply box-sizing in Opera. Unfortunately IE doesn't yet support this.

So add this to your code.

#shopper, #store {
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
}

More info - http://www.css3.info/preview/box-sizing/

As mentioned by others the bulletproof solution across all browsers is to reduce the width of your boxes to fractionally less than 50%.

零度° 2025-01-12 10:32:51

给 div 一些宽度,

请参阅 http://jsfiddle.net/JuCKU/1/

Give the divs some widths

see http://jsfiddle.net/JuCKU/1/

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