簡體   English   中英

跨度顯示內聯塊無法正常工作

[英]Span display inline-block not working properly

我有一個textbox和分配給它的驗證消息。 我試圖將驗證消息內聯到textbox ,但它只是在它下面。 我嘗試了不同的選擇,但沒有一個是有效的。 以下是相同的代碼:

HTML

<div class="col-lg-3 wrap">
  <span>
    <input class="mandatoryText vtooltips form-control textbox validationInput" style="width: 100%; vertical-align: top; border-radius: 4px;" maxlength="100" name="tradeName" type="text">
    <span class="vspan" style="display: inline-block;">Please enter Name</span> 
  </span>
</div>

CSS

input[type=text].vtooltips {
    position: relative;
    display: inline;
}
input[type=text].vtooltips + span.vspan {
    /*position: absolute;*/
    display:none;
    font-size:12px; 
    font-family: Arial; 
    color:white;
    border-radius:3px; 
    background: #DC000C;
    width:50%;
    border: 1px solid #6D6D6D;
    line-height: 0px;
    text-align: center;
    /*visibility: hidden;*/
    border-radius: 4px;
    box-shadow: 2px 2px 0px #AFB1B1;
    margin-left:5px;
    line-height:15px;

}
.validationInput,
.validationInput:focus,
.validationInput:hover {
    background-color: #FFFFE0!important;
    border: 1px solid red!important;
    height: 20px
}
.wrap span:first-child {
    display: inline-block;
    position: relative;
    overflow: hidden;
    width: 100%
}
.wrap span:first-child:after {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 0;
    height: 0;
    border-width: 5px;
    border-color: red;
    border-style: solid;
    transform: rotate(45deg);
    box-shadow: 0 0 0 1px #FFFFE0
}

這是一個相同的演示

所需的輸出是:

在此輸入圖像描述

任何幫助將不勝感激。 謝謝。

最簡單的方法是使用CSS Flexbox 使<span>成為一個flex容器而不是inline-block ,就像這樣:

span {
  display: flex;
}

看看下面的代碼:

 /* CSS used here will be applied after bootstrap.css */ input[type=text].vtooltips { position: relative; display: inline; height: 20px; } .vspan { /*position: absolute;*/ display:none; font-size:12px; font-family: Arial; color:white; border-radius:3px; background: #DC000C; width:50%; height: 20px; border: 1px solid #6D6D6D; line-height: 0px; text-align: center; /*visibility: hidden;*/ border-radius: 4px; box-shadow: 2px 2px 0px #AFB1B1; margin-left:5px; line-height:15px; } .validationInput, .validationInput:focus, .validationInput:hover { background-color: #FFFFE0!important; border: 1px solid red!important; height: 20px } .wrap span:first-child { display: flex; position: relative; overflow: hidden; width: 100% } .wrap span:first-child .input-holder:after { content: ''; position: absolute; top: -5px; right: -5px; width: 0; height: 0; border-width: 5px; border-color: red; border-style: solid; transform: rotate(45deg); box-shadow: 0 0 0 1px #FFFFE0 } body { margin: 30px; } 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="col-lg-3 wrap"> <span> <span class="input-holder"> <input type="text" class="mandatoryText vtooltips form-control textbox validationInput" style="width: 100%; vertical-align: top; border-radius: 4px;" maxlength="100" name="tradeName"></span> <span class="vspan" style="display: inline-block;">Please enter Name</span> </span> </div> 

希望這可以幫助!

請進行以下更改:

<div class="col-lg-3 wrap">
  <span>
    <input class="mandatoryText vtooltips form-control textbox validationInput" style="width: 70%; vertical-align: top; border-radius: 4px;" maxlength="100" name="tradeName" type="text">
    <span class="vspan" style="display: inline;">Please enter Name</span> 
  </span>
</div>

請從這里參考演示

只需添加以下css ..

span.vspan{
    margin-top: 5px;
    display: flex;
}
.wrap span:first-child {
       display: flex;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM