CSS:需要一个元素与其相邻元素垂直缩放

发布于 2024-10-11 02:05:55 字数 359 浏览 3 评论 0原文

alt text

也许最好用图像来说明。

  1. 主要内容填充元素 (d) 左侧的高区域 (b) 需要与该内容元素 (d) 一起缩放,但仍需要其顶部的左上角部分 (a)。
  2. 还需要有一些元素覆盖两列的底部,如 (c、e) 所示。
  3. 整个区域的宽度不能超过 640px。
  4. 文档流程中将有多个这些部分,因此它们不能绝对定位或其他什么。
  5. 左列 (a,b,c) 是固定宽度,帽片 (a,c,e) 是固定高度。右列可以是固定宽度的,如果这样可以让事情变得更简单的话。

我该怎么做?

alt text

Best illustrated with an image, perhaps.

  1. The tall area (b) to the left of the main content-filled element (d) needs to scale along with that content element (d), but still needs that top-left corner piece (a) at its top.
  2. There also needs to be elements capping off the bottom of both columns as indicated (c, e).
  3. The entire area cannot exceed 640px in width.
  4. There will be more than one of these sections within the flow of the document, so they can't be absolutely positioned or whatever.
  5. The left column (a,b,c) is a fixed width, and the cap pieces (a,c,e) are fixed heights. The right column can be fixed width, if that makes things simpler.

How do I do this?

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

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

发布评论

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

评论(2

空城仅有旧梦在 2024-10-18 02:05:55

沿着这些思路的东西可能会实现你想要的;它对各个部分(a、c、e)使用绝对定位,但在可以重复的非绝对定位的 div 内。

“b”部分是使用“.main”div 创建的,因为它将随“.rightColumn”的内容展开。我认为因为其中没有内容,所以您需要用颜色或图像填充它,因此将“b”部分的任何图像等放入“.main”div 的样式中。

HTML

<div class="main">

    <div class="leftColumnTopCap"></div>

    <div class="rightColumn">

        <p>Your content here...</p>

    </div>

    <div class="leftColumnBottomCap"><div>
    <div class="rightColumnBottomCap"></div>

</div>

CSS

.main {
    /* Any 'b' piece styling goes in here. */
    display: block;
    float: left;
    width: 640px;
    margin: 0;
    padding: 0 0 100px 0; /* Change 100px to whatever the height of your bottom caps are. */
    position: relative; /* We can use relative positioning here. */
}

.rightColumn {
    display: block;
    float: right;
    width: 540px; /* Change to whatever width piece '640px - width of a' is. */
    margin: 0;
    padding: 0;
}

.leftColumnTopCap {
    position: absolute; /* The absolute position here relates to the 'main' div. */
    top: 0;
    left: 0;
    width: 100px; /* Change to whatever width piece 'a' is. */
    height: 100px; /* Change to whatever height piece 'a' is. */
}

.leftColumnBottomCap {
    position: absolute; /* The absolute position here relates to the 'main' div. */
    bottom: 0;
    left: 0;
    width: 100px; /* Change to whatever width piece 'c' is. */
    height: 100px; /* Change to whatever height piece 'c' is. */
}

.rightColumnBottomCap {
    position: absolute; /* The absolute position here relates to the 'main' div. */
    bottom: 0;
    right: 0;
    width: 540px; /* Change to whatever width piece '640px - width of a' is. */
    height: 540px; /* Change to whatever height piece '640px - width of a' is. */
}

希望有帮助。

Something along these lines might achieve what you want; it uses absolute positioning for the various pieces (a, c, e) but within a non-absolutely positioned div which you can repeat.

The 'b' section is created using the '.main' div since it'll expand with the content of '.rightColumn'. I assumed as there was no content in there you'd be filling it with a colour or image, so put any image etc. for the 'b' piece in the styling for the '.main' div.

HTML

<div class="main">

    <div class="leftColumnTopCap"></div>

    <div class="rightColumn">

        <p>Your content here...</p>

    </div>

    <div class="leftColumnBottomCap"><div>
    <div class="rightColumnBottomCap"></div>

</div>

CSS

.main {
    /* Any 'b' piece styling goes in here. */
    display: block;
    float: left;
    width: 640px;
    margin: 0;
    padding: 0 0 100px 0; /* Change 100px to whatever the height of your bottom caps are. */
    position: relative; /* We can use relative positioning here. */
}

.rightColumn {
    display: block;
    float: right;
    width: 540px; /* Change to whatever width piece '640px - width of a' is. */
    margin: 0;
    padding: 0;
}

.leftColumnTopCap {
    position: absolute; /* The absolute position here relates to the 'main' div. */
    top: 0;
    left: 0;
    width: 100px; /* Change to whatever width piece 'a' is. */
    height: 100px; /* Change to whatever height piece 'a' is. */
}

.leftColumnBottomCap {
    position: absolute; /* The absolute position here relates to the 'main' div. */
    bottom: 0;
    left: 0;
    width: 100px; /* Change to whatever width piece 'c' is. */
    height: 100px; /* Change to whatever height piece 'c' is. */
}

.rightColumnBottomCap {
    position: absolute; /* The absolute position here relates to the 'main' div. */
    bottom: 0;
    right: 0;
    width: 540px; /* Change to whatever width piece '640px - width of a' is. */
    height: 540px; /* Change to whatever height piece '640px - width of a' is. */
}

Hope that helps.

甜心 2024-10-18 02:05:55

有时,表格是完成工作的最可行的想法。我认为这种情况存在被批评的风险,因为“表格不应该用于设计/布局”。

其他解决方案将需要(如果针对多个浏览器)大量 javascript 或 CSS3

Sometimes tables area the most feasible idea to get the job done. I would consider this such a situation, risking being bashed since "tables should not be used for design/layout".

Other solutions would require (if targeted across multiple browsers) a lot of javascript or the CSS3 flexible box layout module.

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