2017-01-07 696 views
0

我试图复制这个模拟了设计。css在边框底部有空隙的方形边框

设计:

Mock up design

电流:

current progress

有没有一种方法,以确保 “本店所有” 忽略溢出:隐藏,但之前和服从后溢出:隐藏?

或者是否有另一种方法可以尝试实现?

的Html

<div id="outer"> 
    <div id="opaq"> 
    <div id="inner"> 
    <h1>Performance Parts</h1> 
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi efficitur in arcu at placerat. Aenean sed lorem tincidunt, maximus purus eget, ornare metus. Nam interdum lobortis imperdiet. Nunc gravida urna urna. Vestibulum vitae lectus leo. Etiam fermentum nunc vel nulla tincidunt, sit amet molestie lectus pulvinar.</p> 
    <div id="shop">Shop all</div> 
    </div> 
    </div> 
</div> 

的CSS

#outer{ 
    max-width:500px; 
    text-align:center; 
    background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7"); 

} 
#opaq{ 
    background-color: rgba(48, 44, 44, 0.7); 
    padding:5px; 
} 
#inner{ 
    border:1px solid red; 
    margin:10px; 
    color:white; 
    border-bottom:none; 
    overflow:hidden; 
} 

#shop{ 
    position:relative; 
    top:8px; 
    display: inline-block; 
} 
#shop:after{ 
    content: ""; 
    position: absolute; 
    border-bottom: 1px solid white; 
    top: 9px; 
    width: 600px; 
    left: 100%; 
    margin-left: 15px; 
} 
#shop:before{ 
    content: ""; 
    position: absolute; 
    border-bottom: 1px solid white; 
    top: 9px; 
    width: 600px; 
    right: 100%; 
    margin-right: 15px; 
} 
+0

http://codepen.io/anon/pen/oBXPPE 它不会让我发布两个以上的链接。这是当前进展的一个代码。 – comato

回答

4

* { 
 
    margin: 0; 
 
    padding: 0; 
 
    font-family: sans-serif; 
 
} 
 
.wrapper { 
 
    background-image: linear-gradient(rgba(0, 0, 0, .3), rgba(0, 0, 0, .3)), url(http://beerhold.it/400/300); 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    width: 400px; 
 
    height: 200px; 
 
    box-sizing: border-box; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
} 
 
fieldset { 
 
    width: 90%; 
 
    height: 90%; 
 
    margin-top: .7em; 
 
    transform: rotate3d(0, 0, 1, 180deg); 
 
    border: 3px solid rgba(255, 255, 255, .4); 
 
} 
 
legend { 
 
    font-size: 1.4em; 
 
    font-weight: 700; 
 
} 
 
legend span, 
 
fieldset .text { 
 
    display: block; 
 
    transform: rotate3d(0, 0, 1, 180deg); 
 
    color: white; 
 
    text-shadow: 0 0 4px black; 
 
    padding: 0 1em; 
 
} 
 
legend span { 
 
    color: yellow; 
 
} 
 
fieldset .text { 
 
    height: 100%; 
 
} 
 
fieldset .text h1 { 
 
    padding: .3em 0; 
 
    text-align: center; 
 
} 
 
fieldset .text p { 
 
    line-height: 1; 
 
}
<div class="wrapper"> 
 
    <fieldset> 
 
    <legend align="center"><span>SHOP ALL</span> 
 
    </legend> 
 
    <div class="text"> 
 
     <h1>Lorem ipsum</h1> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a justo nisl. Phasellus consequat tincidunt elit, sed interdum nibh blandit ut. Nunc augue erat, rutrum ac vehicula nec, pulvinar in eros. 
 
     </p> 
 
    </div> 
 
    </fieldset> 
 
</div>

+0

这是完美的。我刚想出了一个解决方案,但它不像这样干净。我不知道fieldset属性,但看起来正是我所需要的。 – comato

+0

@comato fieldset是用于形式:) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset请注意当你使用一个把戏:) –

+0

@GCyrillus是的,我注意到。这种方法是否存在潜在的问题? – comato

0

您可以尝试阴性切缘和一些弯曲画侧边框,它会保持一个连贯的HTML标题在代码中排在第一位:

div { 
 
    margin:2em; 
 
    display:flex; 
 
    flex-flow:column; 
 
    text-align:center; 
 
    border:solid; 
 
    border-bottom-color:transparent; 
 
    background:rgba(0,0,0,0.2); 
 
    box-shadow: 0 0 0 2em rgba(0,0,0,0.2); 
 
    } 
 
div h2 { 
 
    order:1; 
 
    display:flex; 
 
    margin:0 0 -0.6em 0; 
 
    font-variant:small-caps; 
 
    } 
 
h2:before, 
 
h2:after { 
 
    content:''; 
 
    flex:1; 
 
    border-bottom:solid; 
 
    margin:auto 1em auto -3px ; 
 
    } 
 
    h2:after { 
 
    margin: auto -3px auto 1em; 
 
    } 
 
    p {padding:0.25em 0.5em;} 
 
    html {background:url(http://lorempixel.com/800/600/city/6); 
 
    background-size:cover; 
 
    color:white; 
 
    text-shadow:0 0 1px black; 
 
    }
<div> 
 
    <h1>HTML Ipsum Presents</h1> 
 
    <h2>shop all</h2> 
 
    <p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris 
 
    placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis 
 
    tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p> 
 
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. 
 
    Mauris placerat eleifend leo.</p> 
 
</div>

+0

”连贯的HTML,标题在代码中排在第一位“ 它总是会在差距而不是标题中出现”全部购买“,所以先决条件并不重要。 – comato

+0

@comato,好吧,看起来像一个标题或副标题给我,至少是一个电子风格,或者这将是一个链接? :)但肯定我没有看到它可以成为传说的地方。 :)我的建议,你的选择,没有人是错的或正确的,但我仍然认为这是一个风格的问题,而不是使用一些html元素的外观。).....刚刚更新了片段可以放在容器中的任何位置的副标题.... –

0

使用此CSS;请注意,我已经添加评论我更改代码或添加

#outer{ 
    max-width:500px; 
    text-align:center; 
    background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7"); 

} 
#opaq{ 
    background-color: rgba(48, 44, 44, 0.7); 
    padding:5px; 
} 
#inner{ 
    border:1px solid red; 
    margin:10px; 
    color:white; 
    border-bottom:none; 


} 

#shop{ 
    position:relative; 
    top:8px; 
    display: inline-block; 
    z-index:200; /*added*/ 



} 
#shop:after{ 
    content: ""; 
    position: absolute; 
    border-bottom: 1px solid white; 
    top: 9px; 
    width: 364%; /* changed */ 
    left: 100%; 
    margin-left: 15px; 

} 
#shop:before{ 
    content: ""; 
    position: absolute; 
    border-bottom: 1px solid white; 
    top: 9px; 
    width: 364%; /* changed */ 
    right: 100%; 
    margin-right: 15px; 

} 
0

边界划分成表格单元格:

\t body 
 
\t { 
 
\t \t font-family:arial; 
 
\t \t background-image:url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7"); 
 
\t \t background-size:cover; 
 
\t \t margin:0px; 
 
\t } 
 

 
\t .box div 
 
\t { 
 
\t \t border:0px solid RGBa(255,255,255,0.5); 
 
\t } 
 

 
\t .shade 
 
\t { 
 
\t \t background-color:RGBa(50,50,50,0.7); 
 
\t \t padding:20px; 
 
\t \t position:fixed; 
 
\t \t top:0px; 
 
\t \t right:0px; 
 
\t \t bottom:0px; 
 
\t \t left:0px; 
 
\t } 
 

 
\t h1 
 
\t { 
 
\t \t text-align:center; 
 
\t \t text-transform:uppercase; 
 
\t } 
 

 
\t .bottomborder 
 
\t { 
 
\t \t display:table; 
 
\t \t table-layout:fixed; 
 
\t } 
 

 
\t .box .left 
 
\t { 
 
\t \t width:50%; 
 
\t \t border-width:0px 0px 2px 2px; 
 
\t } 
 

 
\t .box .right 
 
\t { 
 
\t \t width:50%; 
 
\t \t border-width:0px 2px 2px 0px; 
 
\t } 
 

 
\t .box .col 
 
\t { 
 
\t \t display:table-cell; 
 
\t } 
 

 
\t .shopall 
 
\t { 
 
\t \t padding: 0px 15px; 
 
\t \t white-space: nowrap; 
 
\t \t position: relative; 
 
\t \t top: 10px; 
 
\t \t color:RGB(200,150,0); 
 
\t \t font-weight:bold; 
 
\t \t font-size:20px; 
 
\t \t text-transform:uppercase; 
 
\t } 
 

 
\t .box 
 
\t { 
 
\t \t margin-left:auto; 
 
\t \t margin-right:auto; 
 
\t \t width:1100px; 
 
\t \t margin-top:15px; 
 
\t \t max-width: 100%; 
 
\t } 
 

 
\t .box .content 
 
\t { 
 
\t \t padding:5px 55px 10px 55px; 
 
\t \t border-width:2px 2px 0px 2px; 
 
\t \t border-top-left-radius:0px; 
 
\t \t border-top-right-radius:0px; 
 
\t \t color:white; 
 
\t }
<body> 
 
\t <div class="shade"> 
 
\t \t <div class="box"> 
 
\t \t \t <div class="content"> 
 
\t \t \t \t <h1>Performance & Parts </h1> 
 
\t \t \t \t Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi efficitur in arcu at placerat. Aenean sed lorem tincidunt, maximus purus eget, ornare metus. Nam interdum lobortis imperdiet. 
 
\t \t \t </div> 
 
\t \t \t <div class="bottomborder"> 
 
\t \t \t \t <div class="left col"> 
 
\t \t \t \t </div> 
 
\t \t \t \t <div class="col"> 
 
\t \t \t \t \t <div class="shopall"> 
 
\t \t \t \t \t \t shop all 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t <div class="right col"> 
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t </div> 
 
\t </div> 
 
</body>