2017-01-07 316 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>