2015-12-13 61 views
1

我有这个自定义形状与CSS。我需要给它一个边界,但到目前为止我还没有成功。我怎么能给它一个边界?给边框自定义形状由CSS包含输入类型

.comment-input-container { 
 
    width: 96%; 
 
    float: left; 
 
} 
 
input[type='text'] { 
 
    border: 0px !important; 
 
    box-shadow: none; 
 
    background-color: #f2f2f2; 
 
    box-shadow: inset 0 0px 0px rgba(0, 0, 0, 0.1); 
 
    padding: 5px; 
 
} 
 
.arrow-left { 
 
    float: left; 
 
    width: 0; 
 
    height: 0; 
 
    border-bottom: 10px solid #fff; 
 
    border-right: 10px solid #f2f2f2; 
 
}
<div style="width: 300px;"> 
 
    <div class="arrow-left"> 
 

 
    </div> 
 
    <div class="comment-input-container"> 
 
    <input type="text" placeholder="Reply to comment..." /> 
 
    </div> 
 
</div>

此外,另一个问题是,对于较小的设备中的箭头和输入断,即,在输入被堆叠的箭头的下方。有没有更好的方式来创造这种形状,也是响应和保持完好?

+5

你的箭头。所以,你可以使用这里提到的方法 - http://stackoverflow.com/questions/18057669/border-within-border-css/18058163#18058163添加一个边框。 **编辑:**另一方面,你可以创建整个事情我们这里提到的方法 - http://stackoverflow.com/questions/30011363/transparent-shape-with-arrow-in-upper-corner/30011454# 30011454。 – Harry

+0

感谢您的链接,是否有任何其他的方式来创建也响应的形状?在这个例子中,我给父容器定了一个固定的宽度,但实际上,父容器是响应式的,对于小屏幕来说,形状会中断。我应该用最小宽度来解决这个问题吗? –

+0

如果您使用边框方法,那么使其响应很困难,因为边框不支持百分比。你必须使用视口单元来使它们响应。或者,看看我发布的第二个链接。这应该给出一个响应输出。 – Harry

回答

0

感谢哈利,我能够制定出一个laregely响应的解决方案:已经使用边界创建

.comment-input-container { 
 
    position: relative; 
 
    width: 100%; 
 
    border-left: none; 
 
    /* not required as the shape needs to be transparent */ 
 
    border-top-left-radius: 0px; 
 
    border-bottom-left-radius: 0px; 
 
} 
 
.comment-input-container:before { 
 
    position: absolute; 
 
    content: ''; 
 
    top: 0px; 
 
    left: -7px; 
 
    height: 26%; 
 
    width: 10%; 
 
    background-color: #f6f7fb; 
 
    border-top: 1px solid #e6e6e6; 
 
    border-left: 1px solid #e6e6e6; 
 
    -webkit-transform-origin: bottom right; 
 
    -webkit-transform: skew(45deg); 
 
    -moz-transform: skew(45deg); 
 
    transform: skew(45deg); 
 
} 
 
.comment-input-container:after { 
 
    position: absolute; 
 
    content: ''; 
 
    left: -7px; 
 
    height: 74%; 
 
    width: 5%; 
 
    max-width: 15px; 
 
    bottom: 0px; 
 
    border-left: 1px solid #e6e6e6; 
 
    border-bottom: 1px solid #e6e6e6; 
 
    background-color: #f6f7fb; 
 
} 
 
input[type="text"] { 
 
    border: 1px solid #e6e6e6; 
 
    border-left: none; 
 
    box-shadow: none; 
 
    background-color: #f6f7fb; 
 
    box-shadow: inset 0 0px 0px rgba(0, 0, 0, 0.1) !important; 
 
    margin: 0px; 
 
    padding: 10px; 
 
    outline: none; 
 
} 
 
input[type="text"]:focus { 
 
    border: 1px solid #e6e6e6; 
 
    border-left: none; 
 
    box-shadow: none; 
 
    background-color: #f6f7fb !important; 
 
    box-shadow: inset 0 0px 0px rgba(0, 0, 0, 0.1) !important; 
 
    padding: 10px; 
 
    outline: none; 
 
} 
 
.comment-box { 
 
    margin-left: 50px; 
 
    height: 50px; 
 
}
<div class="comment-box"> 
 
    <div class="comment-input-container"> 
 
    <input type="text" placeholder="Reply to comment..." /> 
 
    </div> 
 
</div>

0

我认为特殊形状是最后一个?它是0px x 0px,但你应该看到一些东西,因为你给它一个10px的边框。不幸的是,边框是白色的,因此它与白色背景融为一体。我制作了1px x 1px的形状和背景黑色,以便您可以更好地看到形状。

body { background: black; } 
 
.comment-input-container { 
 
    width: 96%; 
 
    float: left; 
 
} 
 
input[type='text'] { 
 
    border: 0px !important; 
 
    box-shadow: none; 
 
    background-color: #f2f2f2; 
 
    box-shadow: inset 0 0px 0px rgba(0, 0, 0, 0.1); 
 
    padding: 5px; 
 
} 
 
.arrow-left { 
 
    float: left; 
 
    width: 1px; 
 
    height: 0px; 
 
    border-bottom: 10px solid rgba(0, 0, 0, 0.0); 
 
    border-right: 10px solid #f2f2f2; 
 
    box-shadow: inset 4px 2px 22px 6px rgba(0,0,0,0.57); 
 
    outline: 2px inset rgba(0, 0, 0, .35; 
 
}
<div style="width: 300px;"> 
 
    <div class="arrow-left"> 
 

 
    </div> 
 
    <div class="comment-input-container"> 
 
    <input type="text" placeholder="Reply to comment..." /> 
 
    </div> 
 
</div>

+0

箭头下方有空白区域。我不想那样。 –

+0

箭头在哪里? – zer00ne

+0

在形状的左上角?我运行了你的代码片段,并在箭头下方显示了一个小空白区域。 –