css - 跨度显示内联 block 无法正常工作

标签 css html twitter-bootstrap twitter-bootstrap-3

我有一个 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
}

这是一个Demo同样。

期望的输出是:

enter image description here

任何帮助将不胜感激。谢谢。

最佳答案

最简单的方法是使用 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>

希望这对您有所帮助!

关于css - 跨度显示内联 block 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40838206/

相关文章:

html - 当元素也悬停时,不显示 Tailwind 事件样式

javascript - div 上的 onclick 事件未触发

javascript - 显示/隐藏内表时如何防止外表调整大小

asp.net-mvc-3 - 使用内联 css 或 site.css 文件调整 editorfor box 的大小

html - `float: left;` 问题

css - Pardot 表单的样式 CSS

macos - Perl 网络分析问题

css - Twitter Bootstrap Google+ 登录按钮

html - 自举 |将图像/跨度放在图像之上,并且仍然响应?

javascript - 理解 Jquery 代码以突出显示导航栏项目