简体   繁体   English

CSS在一侧使用边框,在末端附近没有相同的宽度吗?

[英]CSS using border on one side, does not have same width near end?

Hi I am tring to implement something like below screenshot... 嗨,我正在尝试实现以下屏幕截图...

在此处输入图片说明

Here is what i am using 这是我正在使用的

border-left: 5px solid #7AC0DA;

and it gives me this output 它给了我这个输出

在此处输入图片说明

The border is not crisp enough, as you can see in this screenshot the border does not have same width near the ends. 边框不够清晰,如您在此屏幕截图中所见,边框在两端附近没有相同的宽度。 How do I correct this ? 我该如何纠正?

This is because the element has a border of 1px solid grey already, and the blue has to expand. 这是因为元素已经具有1px solid grey的边框,并且蓝色必须扩展。

Your best best would be to not use border styles on the input , but something like the following: 最好的办法是不要input上使用边框样式,而是类似以下内容:

HTML 的HTML

<label class="highlight clearfix">
  <span>Field name:</span>
  <input />
</label>

CSS 的CSS

label span, label input { float: left }
label.highlight span { border-right: 5px solid blue }

The border shows a bevel because the top and bottom have widths. 边框显示斜角,因为顶部和底部具有宽度。 You can do what you need using the pseudo-element :before 您可以使用伪元素来完成所需的操作:before

http://jsfiddle.net/sEWqW/3/ http://jsfiddle.net/sEWqW/3/

<label><input /></label>

CSS 的CSS

label {
    border: 1px solid #ccc;
    border-left:0;
    padding:.1em .3em;
    position:relative;
}
label:before {
    display:block;
    content:".";
    color:transparent;
    font-size:0;
    border-left:5px solid #f24495;
    height:100%;
    position:absolute;
    left:0;
    padding:1px 0;
    top:-1px;
    bottom:-1px;
}
label input{
    border:0;
}

I'm assuming that somewhere, there is a border-width for your border-top and bottom. 我假设某个地方的顶部和底部边框都有一个边框宽度。 I see that you set a border only on left with border-left. 我看到您只在左侧设置了边框,而border-left。 Maybe you should try first to set border:0 and than in the same selector, use border-left. 也许您应该首先尝试设置border:0,然后在同一选择器中使用border-left。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM