【问题标题】:add a rounded border to content sticked to window (html & css)为粘贴到窗口的内容添加圆角边框(html & css)
【发布时间】:2013-02-18 09:21:44
【问题描述】:

我想设计一个网站,页面的角是圆角的(窗口所有角上都有黑色圆圈)。

为此,我将主体颜色设置为黑色,并在内容 div 中添加了一个圆角,这是其背景的一部分。

<body style="backgound: black">
  <div class="content" style="background: blue; border-radius: 8px;">
   ....
  </div>
</body>

之后我尝试过:

解决方案 1 无效

position: absolute;
height: 100%;

当内容高度大于窗口时不起作用,因为滚动时内容背景会隐藏。

解决方案 2 无效

position: fixed;
height: 100%;

当内容高度大于窗口时不起作用;不显示滚动条。

解决方案 3 无效

什么都没有。

当内容高度小于窗口时不起作用;底部为黑色。

丑陋的工作解决方案 1

添加4张带边框的图片,位置固定

任何人都知道该问题的干净解决方案吗?接受 css3。

谢谢

【问题讨论】:

  • 黑体bg是必须的??
  • 不,但这是我尝试在蓝色圆角上制作黑色背景的方式。

标签: html css


【解决方案1】:

我认为这应该会有所帮助:

.content
{
   position: absolute;
   height: 100%;
   width: 100%;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   background blue;
   border-radius: 8px;
}

编辑此解决方案将起作用:

.content
{
   float:left;
   min-height: 100%;
   height: auto;
   width: 100%;
   background: blue;
   border-radius: 8px;
}

working jsfiddle

另一个使用css3的例子calc()here

【讨论】:

  • 这是建议的“不工作解决方案1”,当内容高度大于窗口时不起作用,如帖子中所述
  • 不错的尝试!但这也不起作用。在滚动到底部之前,不会显示底部圆角边框。
  • 看最后一个例子。这是你想要的,但我会使用自定义 scrollbar
  • 哇!我不知道计算。但是它在任何移动浏览器中都不起作用:caniuse.com/calc 而且我需要在移动应用程序中使用 html。 +1,但如果有任何解决方案可以真正解决我的问题,请等待。
  • 对于移动版本使用 javascript :)
【解决方案2】:

你可以试试height:100%

body, html{height:100%}
.content{height:100%}

DEMO

【讨论】:

  • 这是建议的“不工作解决方案1”,当内容高度大于窗口时不起作用,如帖子中所述
【解决方案3】:

页眉使用两个嵌套的固定div,页脚也一样。

这适用于每个浏览器上的各种内容:

运行示例:http://jsfiddle.net/5kgN3/

HTML

<div id="headerOuter"><div id="headerInner"></div></div>
<div class="content">
    <br />test
    <br />test
    <!-- More tests here -->
    <br />test
    <br />test
</div>
<div id="footerOuter"><div id="footerInner"></div></div>

CSS

body, html {
    height: 100%;
    width: 100%;
}
.content {    
    min-height: 100%;
    height: auto;
    width: 100%;
    background: blue;
    padding-top: 20px;
    padding-bottom: 20px;
}

#headerOuter{
    background-color: black;
    height: 20px;
    width: 100%;
    position: fixed;
    top: 0;
}

#headerInner{
    border-radius: 20px 20px 0px 0px;
    background-color: blue;
    height: 20px;
    width: 100%;
    position: fixed;
    top: 0;    
}

#footerOuter{    
    background-color: black;
    height: 20px;
    width: 100%;
    position: fixed;
    bottom: 0;
}

#footerInner{
    border-radius: 0px 0px 20px 20px;
    background-color: blue;
    width: 100%;
    height: 20px;
    position: fixed;
    bottom: 0;
}

我使用了 20px 的边框半径,当将其调整为 8px 时,记得调整填充和高度。

【讨论】:

  • 也不工作。你可以看到,在角落里,文本被隐藏在页脚和标题内部,而不是当它们到达角落时。
  • 理论上,这个问题很好。我还在努力。实际上,使用 8px 圆形边框,问题不成问题:我希望您至少有 8px 的填充(在每一侧,横向也是如此),否则设计真的很糟糕......
  • 这是移动设备应用程序。没有使用填充物,设计精美。
猜你喜欢
  • 1970-01-01
  • 2011-04-01
  • 2017-12-30
  • 1970-01-01
  • 2010-09-24
  • 1970-01-01
  • 2016-10-13
  • 1970-01-01
  • 2018-04-22
相关资源
最近更新 更多