CSS 布局与边框的问题

发布于 2024-12-01 21:44:04 字数 399 浏览 5 评论 0原文

我目前正在为客户 http://minta.jvsoftware.com/ 在以下网站工作,但我我正在尝试使主容器 div 的顶部和底部边框看起来像这样 http://awesomescreenshot.com/0f8jdwn71 基本上使边框向左延伸到屏幕末端(不要介意红色,这应该是相同的颜色作为我现在的边界)。

我一直在尝试提出一个解决方案,但到目前为止我失败了,如果仅用 css 实现它变得太困难,我愿意尝试 JS/jQuery 解决方案。

谁能帮助我吗?提前致谢!

I'm currently working in the following site for a client http://minta.jvsoftware.com/ but I'm trying to make the top and bottom borders of the main container div to look like this http://awesomescreenshot.com/0f8jdwn71 basically make the borders span to the left up to the end of the screen (don't mind the red color this is supposed to be the same color as the border I have now).

I've been trying to come up with a solution but so far I have failed, I'm willing to try a JS/jQuery solution if implementing it with just css becomes too hard.

Can anyone help me? Thanks in advance!

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

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

发布评论

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

评论(3

帅气称霸 2024-12-08 21:44:04

您可以通过带有负边距的纯 CSS 来实现此目的。

首先,您必须更新 .container 的 CSS,如下所示:

.container {
  clear: both;
  font-family: "Times New Roman",Times,serif;
  margin: 124px auto 36px;
  padding: 0;
  width: 940px;
}

现在将主 div 的内容包装到另一个 div 中并应用一些 css,如下所示:

<div id="main" class="container clearfix" role="main">
    <div style="border: 1px solid red; margin-left: -2000px; padding: 8px 8px 8px 2000px;">
        <div class="content"> ... </div>
        <div class="featured-image"> ... </div>
        <div style="clear:both;"></div>
    </div>
</div>

这里有一个屏幕截图可以帮助您弄清楚:
在此处输入图像描述

You can achieve this by pure CSS with negative margins.

First you have to update the CSS for .container as follows:

.container {
  clear: both;
  font-family: "Times New Roman",Times,serif;
  margin: 124px auto 36px;
  padding: 0;
  width: 940px;
}

Now wrap the content of the main div into another div and apply some css like this:

<div id="main" class="container clearfix" role="main">
    <div style="border: 1px solid red; margin-left: -2000px; padding: 8px 8px 8px 2000px;">
        <div class="content"> ... </div>
        <div class="featured-image"> ... </div>
        <div style="clear:both;"></div>
    </div>
</div>

Here a screenshot to help you figure it out:
enter image description here

谈情不如逗狗 2024-12-08 21:44:04

为了实现你想要的布局,我认为你必须在容器div旁边放置一个,让它们向左浮动,并给这个div的顶部和底部边框加上红色

To achieve the layout you want, i think you have to put a at the left beside the container div and make them float left and give this div the border at the top and the bottom with the red color

如何视而不见 2024-12-08 21:44:04

为什么不使用“位置:绝对”?在这种情况下,我想这是完美的解决方案。

<style>
.topborder,
.bottomborder {
  position:absolute;
  left:-100px;
  width:150px;
  height:3px;
  background:#ff0000;
  z-index:999;
}

.topborder {
  top:-3px;
}

.bottomborder {
  bottom:-3px;
}

#main {
  position:relative;
}
</style>

<div id="main" class="container clearfix" role="main">
  <div class="topborder"></div><div class="bottomborder"></div>

  your content

</div>

Why you don't use "position:absolute"? In this case it's perfect solution I guess.

<style>
.topborder,
.bottomborder {
  position:absolute;
  left:-100px;
  width:150px;
  height:3px;
  background:#ff0000;
  z-index:999;
}

.topborder {
  top:-3px;
}

.bottomborder {
  bottom:-3px;
}

#main {
  position:relative;
}
</style>

<div id="main" class="container clearfix" role="main">
  <div class="topborder"></div><div class="bottomborder"></div>

  your content

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