Подтвердить что ты не робот

Использование CSS для создания пользовательских границ только с углами, показывающими

Вот вам Brainteaser для CSS. Я хочу создать границу только с углами вокруг текстового поля, как показано ниже:

http://i41.tinypic.com/2yy9lqs.png

Я думал о создании двух прямоугольников divs, один с синей рамкой, а другой белый, а затем наложения их, но это не казалось очень элегантным (например, это не сработает, если я хочу изменить фон).

Любые идеи, как еще я могу это сделать?

EDIT:

Здесь HTML:

<div class="blue white1 white">text</div>

.blue {

border: blue 4px solid;
etc..
}
4b9b3361

Ответ 1

Использование одного div и одного node для таргетинга. http://jsfiddle.net/eCEds/2/

HTML:

<div class="blue white1 white"><p>Text</p></div>

CSS

.blue {position:relative;width:400px;height:300px;}
.blue:before, .blue:after, .blue>:first-child:before, .blue>:first-child:after {
    position:absolute;
    width:80px; height: 80px;
    border-color:blue;
    border-style:solid;
    content: ' ';
}
.blue:before {top:0;left:0;border-width: 4px 0 0 4px}
.blue:after {top:0;right:0;border-width: 4px 4px 0 0}
.blue>:first-child:before {bottom:0;right:0;border-width: 0 4px 4px 0}
.blue>:first-child:after {bottom:0;left:0;border-width: 0 0 4px 4px}

Ответ 2

.text
{
    border: 1px solid #00f;
    height: 200px;
    position: relative;
    width: 200px;
}
.text:after
{
     position:absolute;
     top: 10%;
     height: 80%;
     content: "";
     width: 99%;
     left: -3px;
     border-left: 5px solid #fff;
     border-right: 5px solid #fff;
}
.text:before
{
     position:absolute;
     left: 10%;
     height: 99%;
     content: " ";
     width: 80%;
     top: -3px;
     border-top: 5px solid #fff;
     border-bottom: 5px solid #fff;  
}
<div class="text">test test gfgfgf gfg f</div>

Ответ 3

Что-то подобное достигается с помощью CSS-градиентов и нескольких фонов: http://jsbin.com/usegup/1/edit. Но, вероятно, SVG-фон будет более подходящим для таких случаев.

Ответ 4

Вы имеете в виду что-то вроде этого: http://jsfiddle.net/FlameTrap/F5bC6/

HTML

<div class="text">
    <span class="corner TL"></span>
    <span class="corner TR"></span>
    <span class="corner BL"></span>
    <span class="corner BR"></span>
    <div class="text">Text</div>
</div>

CSS

.text {
    background: #fff;
    width: 300px;
    height: 200px;
    position: relative;
    z-index: 3;
}
.corner {
    position: absolute;
    background: blue;
    width: 20px;
    height: 20px;
    z-index: 2;
}
.TL {
    top: -10px;
    left: -10px
}
.TR {
    top: -10px;
    right: -10px
}
.BL {
    bottom: -10px;
    left: -10px
}
.BR {
    bottom: -10px;
    right: -10px
}

Ответ 5

Что-то вроде этого будет работать и даст вам меньше проблем в старых браузерах для загрузки:

    <style>
.blue {
    width: 500px;
    height: 500px;
    position: relative;
}
.corner {
    position: absolute;
    border-color: blue;
    width: 30px;
    height: 30px;
}
.tl {
    top: 0;
    left: 0;
    border-top: 2px solid;
    border-left: 2px solid;
}
.tr {
    top: 0;
    right: 0;
    border-top: 2px solid;
    border-right: 2px solid;
}

.br {
    bottom: 0;
    right: 0;
    border-bottom: 2px solid;
    border-right: 2px solid;
}

.bl {
    bottom: 0;
    left: 0;
    border-bottom: 2px solid;
    border-left: 2px solid;
}
</style>

<div class="blue">
    <div class="tl corner"></div>
    <div class="tr corner"></div>
    <div class="bl corner"></div>
    <div class="br corner"></div>
</div>