这是一个CSS错误吗?左边界没有出现

时间:2014-08-11 11:21:46

标签: html css

我遇到以下问题:当我第一次选择两个框中的一个时,左边框丢失(Google Chrome 36);在我选择另一个后,出现左边框。 的jsfiddle:

 http://jsfiddle.net/emrfcuu7/

编译代码后立即观察 - 当选择两个框中的一个时,左边框丢失;这是一个错误还是我做错了什么?

@import url(http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,300,400,600,700,800);
.main {
  position: relative;
  background-color: #16A085;
  width: 550px;
  height: 350px;
}

.mainRibbon {
  position: relative;
  background-color: #ECF0F1;
  width: 70%;
  height: 60%;
  margin: 0 auto;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  border-radius: 6px;
}

.textBoxStyle {
  position: relative;
  border: 1px solid rgba(26, 188, 156, 0);
  border-radius: 4px;
  width: 80%;
  text-indent: 20px;
  box-shadow: none;
  -webkit-box-shadow: none;
  line-height: 1.4285;
  -webkit-transition: border-color .25s linear;
  transition: border-color .25s linear;
  margin: 6% 10% 0 10%;
  padding-top: 6px;
  padding-bottom: 6px;
}

.textBoxStyle:focus {
  outline: 0;
  border-color: rgba(26, 188, 156, 1);
}

.btnLogin {
  background-color: #16A085;
  width: 80%;
  border-radius: 6px;
  margin: 6% 10% 0 10%;
  -webkit-transition: background .25s linear;
  transition: background .25s linear;
}

.btnLogin:hover {
  background-color: #1ABC9C;
  cursor: pointer;
  cursor: hand;
}

.btnLogin>p {
  color: white;
  margin: 0;
  padding-top: 1%;
  padding-bottom: 1%;
  font-family: 'Open Sans';
  -webkit-font-smoothing: subpixel-antialiased;
  font-size: 17px;
  text-align: center;
}

.icon {
  position: absolute;
  background: rgba(0, 0, 0, 0);
  width: auto;
  height: auto;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}

.icon>p {
  color: white;
  font-size: 60px;
  line-height: 60px;
  padding: 0;
  margin: 0;
}


/*de sters
    .test{
        position:relative;
        background-color:blue;
        width:80%;
        height:30%;
        top:50%;
        -webkit-transform: translateY(-50%);
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
    }*/
<div class="main">
  <div class="icon">
    <p class="text icon">&#61584;</p>
  </div>
  <div class="mainRibbon">
    <input type="text" class="textBoxStyle" placeholder="Enter your username">
    <input type="text" class="textBoxStyle" placeholder="Password">
    <div class="btnLogin">
      <p>Log in</p>
    </div>
  </div>
</div>

4 个答案:

答案 0 :(得分:2)

问题解决了:问题是&#34;左边距&#34;落在半像素上,因此无法显示;我改变了#34;宽度&#34;来自&#34; .main&#34;来自&#34; 550px&#34;到&#34; 560px&#34;现在左边距显示完美;

感谢所有建议的风格&#34;概述&#34;适合我的风格;这是一个很好的解决方案,只是轮廓不能有我想要的圆角。

答案 1 :(得分:0)

我不确切地知道为什么会这样做但是当你将padding-left:1px添加到.textBoxStyle时,它会解决问题但不是一直都是非常奇怪的。

http://jsfiddle.net/emrfcuu7/3/

另外我看到问题可能来自margin:6% 10% 0% 10%;,也许没有足够的空间用于边框这些边距,你应该使用像素边距

<强>更新

真正的解决方案: 您必须从outline:0中移除.textBoxStyle:focus,然后执行以下操作:

.textBoxStyle:focus{
    border-color:rgba(26,188,156,1);
}

http://jsfiddle.net/emrfcuu7/7/

答案 2 :(得分:0)

给边框超过1px

.textBoxStyle{
    position:relative;
    border:2px solid rgba(26,188,156,0);
    border-radius:4px;
    width:80%;
    text-indent:20px;
    box-shadow:none;
    -webkit-box-shadow:none;
    line-height:1.4285;
    -webkit-transition: border-color .25s linear;
    transition: border-color .25s linear;
    margin:6% 10% 0 10%;
    padding-top:6px;
    padding-bottom:6px;
}

如果删除边距,则问题无法重现。

  

保证金:6%10%0 10%;

答案 3 :(得分:0)

Make use of this fiddle

.textBoxStyle:focus{
outline:none;
    border:2px solid rgba(26,188,156,1);
}