简体   繁体   English

跨度显示内联块无法正常工作

[英]Span display inline-block not working properly

I have a textbox and a validation message assigned to it. 我有一个textbox和分配给它的验证消息。 I am trying to put the validation message inline to the textbox , but it comes just under it. 我试图将验证消息内联到textbox ,但它只是在它下面。 I have tried different options but none of them is working. 我尝试了不同的选择,但没有一个是有效的。 Below is the code for the same: 以下是相同的代码:

HTML 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 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
}

Here is a Demo for the same. 这是一个相同的演示

The desired output is: 所需的输出是:

在此输入图像描述

Any help will be appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。

The easiest way is to use CSS Flexbox . 最简单的方法是使用CSS Flexbox Make your <span> a flex container instead of inline-block , just like this: 使<span>成为一个flex容器而不是inline-block ,就像这样:

span {
  display: flex;
}

Have a look at the snippet below: 看看下面的代码:

 /* 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> 

Hope this helps! 希望这可以帮助!

Please do below changes : 请进行以下更改:

<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>

please refer Demo from here : 请从这里参考演示

Just add below css.. 只需添加以下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