html - Multiple borders around a div with a transparent layer -


i trying create button 3 layers of border around middle layer showing background of containing div. examples worth thousand words here go

http://jsfiddle.net/e5sxt/2/

html

<div id="content">     <p>generic content</p>     <button class="button">search</button> </div>         

css

#content{     width: 500px;     height: 500px;     background-color: black;     padding: 50px;     color: white; }  button{     margin-top: 50px;     padding: 20px;     text-align: center;     background-color: #333;     box-shadow: 0 0 0 5px #666, 0 0 0 10px red, 0 0 0 15px #bbb;     border: none;     cursor: pointer; } 

the red box-shadow black of containing div should come through. if box-shadow set transparent layer, box-shadow under shows through instead.

i have tried utilizing outlines, borders, , box-shadows no avail far. of right now, think have wrap button in div outer border , padding show background, wanted see if without adding html element.

thanks!

the answer depends on browsers need support (and whether you'd happy fall-back solution older browsers).

there css feature called border-image, which, frankly, can pretty think of border. achieve effect using style.

with border-image, specify small image 2 colours , transparent middle section. job done.

learn more border image here: http://css-tricks.com/understanding-border-image/

however... there big down-side: browser support. border-image relatively new addition css spec. firefox , chrome users should okay, ie users miss out -- feature didn't make ie10.

full browser support details can found here: http://caniuse.com/#search=border-image

if poor browser support border-image enough kill idea you, viable answer use :before or :after css selectors create pseudo-element sitting behind main element. have transparent background , sized larger main element , it's own border. give appearance of triple border you're looking for.

of course, can use solution if aren't using :before , :after else.

hope gives ideas.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -