如何在HTML和CSS中完成粘性边框?

时间:2014-11-08 00:11:35

标签: html css

我想在HTML和CSS中完成这项工作。我需要将边框包裹在div上,而不是作为一个盒子。下面的框和过去的客户框也是如此。

这是我正在尝试的代码。我可以给它一个边框,但是它会以盒子的形式出现,而不是只包含内容。

<div style="border: 1px solid black">
        <div class="clients" style="text-align: center;">Past clients</div>
        <div class="bigbox">
            <img src="1.jpg" alt="">
            <img src="1.jpg" alt="">
            <img src="1.jpg" alt="">
            <img src="1.jpg" alt="">
        </div>
    </div>

3 个答案:

答案 0 :(得分:2)

这是个主意。进行调整。想法是将边框覆盖到空白空间。玩弄它。 @编辑: http://jsfiddle.net/ByShine/3Q4qv/4/

HTML

<div class="contents">
    <div class="clients" style="text-align: center;"><span class="text">Past clients</span></div>
<div class="wrapper">
  <div class="container">
    <div class="1">B.B King</div>
    <div class="2">Tower of Power</div>
    <div class="3">Ready For The World</div>
    <div class="4">KC And the sunshine Band</div>
  </div>
</div>
</div>

CSS

.wrapper {
    overflow: hidden;
    border:dashed;
    display:table;
    border-collapse:separate;
    border-spacing:15px;
}
.container {
    display:table-row;
}
.container > div {
display:table-cell;
border:solid;
    height:2em;
    min-width:2em;
    width: 200px;
}
.contents { 
    width: 100%;
}
.clients {
    position: relative;
    top: 1px;
    display: block;
    width: 100px;
    margin: 0 auto;
}
.text {
    border: dashed;
    margin-left: 2px;
    margin-right: 2px;
    border-bottom: solid white;
}

答案 1 :(得分:2)

我认为这可能是您所需要的:http://jsfiddle.net/hc40c963/1/

修改:误解了您的问题。请参阅 Aaron 的回答。我将把这个答案留给今后的读者。

HTML:

<div class="dots">
  <div class="clients" style="text-align: center;">
      <div class="left"></div><div class="middle">
      Past clients</div><div class="right"></div></div>
    <div class="bigbox">
        <div>
            <img src="1.jpg" alt="">
            <span>Client 1</span>
        </div>
        <div>
            <img src="2.jpg" alt="">
            <span>Client 2</span>
        </div>
        <div>
            <img src="3.jpg" alt="">
            <span>Client 3</span>
        </div>
        <div>
            <img src="4.jpg" alt="">
            <span>Client 4</span>
        </div>
    </div>
</div>

CSS:

* {
    box-sizing: border-box;
}

.dots {
    border: 1px dashed black;
    padding: 1px;
}
.clients { 
    display: table;
    width: 100%;
    margin-bottom: -1px;
}
.clients .left {
    margin-top: 10px;
    border-right: 1px solid black;
    width: 33%;
    height: 20px;
    float: left;
}
.clients .middle {
    border-top: 1px solid black;
    border-radius: 4px;
    width: 33%;
    height: 24px;
    margin-top: 7px;
    float: left;
}
.clients .right {
    margin-top: 10px;
    border-left: 1px solid black;
    width: 33%;
    height: 20px;
    float: left;
}
.bigbox {
    min-height: 200px;
    border: 1px solid black;
    border-radius: 8px;
    width: 100%;
}
.bigbox > div

 {
    vertical-align: top;
    box-sizing: border-box;
    display: inline-block;
    width: 24%;
    margin: 0;
    padding: 0;
}

.bigbox > div img {
    display: block;
    margin: auto;
    margin-top: 10px;
    -ms-transform: rotate(-30deg); /* IE 9 */
    -webkit-transform: rotate(-30deg); /* Chrome, Safari, Opera */
    transform: rotate(-30deg);
}

.bigbox > div span {
    display: block;
    margin-top: 10px;
    text-align: center;
}

此外,当您提出问题时,请尝试更加具体,并向您展示您自己尝试自己做的事情。

答案 2 :(得分:2)

其他答案都很好。你必须使用多个div来获得你想要的效果。

这是一个处理CSS中不规则形状的页面:http://css-tricks.com/examples/ShapesOfCSS/

http://jsfiddle.net/r0m32vpu/1/

HTML:

<div id="main">
<div id="top-left"></div>    
<div id="top-middle"></div>
<div id="top-right"></div>
<div id="bottom"></div>
</div>

CSS:

#top-middle {
    float: left;
    display: block;
    height: 20px;
    width: 150px;
    background-color: red;
    border: 2px solid black;
    border-bottom: none;
}
#top-right {
    display: block;
    float: left;
    height: 20px;
    width: 173px;
    border-bottom: 2px solid black;
}
#top-left {
    display: block;
    float: left;
    height: 20px;
    width: 173px;
    border-bottom: 2px solid black;
}
#bottom {
    display: block;
    float: left;
    height: 110px;
    width: 496px;
    background-color: red;
    border: 2px solid black;
    border-top: none;
}
#main {
    width: 500px;    
}