我正在尝试在如下所示的范围内显示一条消息
<span class="glyphicon glyphicon-exclamation-sign alert alert-danger" id="ErrorMessage" style="display: none;" aria-hidden="true"></span>`
此范围默认情况下没有文本,但会根据发生的错误填充错误文本。
问题是文本在元素中看起来很拉伸并且看起来很糟。我不确定该采用哪种方式。任何意见,将不胜感激。
编辑:仅当我添加“ glyphicon”类时,才会出现此问题。
我正在使用JS填充:
var msg = document.getElementById("ErrorMessage");
msg.innerHTML = "There has been an error";`
我这里没有涉及自定义CSS样式。
<div role="main">
<span id="maincontent"/>
<div class="container">
<div class="jumbotron">
<div style="height: 50px; float: center;">
<h3>List Herd Numbers in Commonage</h3>
</div>
<form role="form" id="HerdForm">
<div class="form-inline">
<label class="control-label" for="commonage_id">Enter Commonage ID:</label>
<input id="commonage_id" type="text" class="form-control" autofocus="autofocus"
placeholder="Enter ID here " />
<button id="submitButton" type="submit" class="btn btn-primary">View</button>
</div>
</form>
</div>
<span class="glyphicon glyphicon-exclamation-sign alert alert-danger"
id="ErrorMessage" style="display: none;" aria-hidden="true"></span>
<div id="loader" class="loader" hidden></div>
<div id="result_table" hidden>
<table class="table table-striped" id="herdTable">
<thead>
<tr>
<th class="threeTH">Herd Number</th>
<th class="threeTH">Share</th>
<th class="threeTH">Active Farmer</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
答案 0 :(得分:1)
一个glyphicon期望除了图标本身之外没有其他内容。问题在于glyphicon类具有附加的更多样式,这对于常规文本是不希望的。在这种情况下,字体家族!
解决方案是将glyphicon本身放在ErrorMessage跨度内的跨度中。
span[aria-hidden='true'] {display:none}
a:active + span[aria-hidden='true'] {display:block}
a:active + span[aria-hidden='true']::after {content:'There has been an error.';}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" rel="stylesheet">
<a>Press here to show text</a>
<span class="alert alert-danger" id="ErrorMessage" aria-hidden="true">
<span class="glyphicon glyphicon-exclamation-sign"></span>
</span>
答案 1 :(得分:0)
您可以在单独的span标签中使用glyphicon图标,如下所示:
<span class="glyphicon glyphicon-exclamation-sign"></span>
<span class="alert alert-danger" id="ErrorMessage" style="display: none;" aria-hidden="true"></span>