Span 元素中不需要的拉伸文本 HTML
Unwanted stretched text within Span element HTML
我正在尝试在如下范围内显示一条消息
<span class="glyphicon glyphicon-exclamation-sign alert alert-danger" id="ErrorMessage" style="display: none;" aria-hidden="true"></span>`
此范围默认没有文本,但会根据发生的错误填充错误文本。
问题是元素中的文本看起来被拉伸了,看起来很糟糕。我不确定用什么方法来解决这个问题。任何意见,将不胜感激。
编辑:问题仅在我添加 "glyphicon" class 时出现。
我正在使用 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>
您可以像这样在单独的 span 标签中使用字形图标:
<span class="glyphicon glyphicon-exclamation-sign"></span>
<span class="alert alert-danger" id="ErrorMessage" style="display: none;" aria-hidden="true"></span>
glyphicon 不希望包含图标本身以外的其他内容。问题是字形 class 附加了更多样式,这对于普通文本来说是不需要的。在这种情况下,字体系列!
解决方案是将字形本身放在它自己的范围内,在 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>
我正在尝试在如下范围内显示一条消息
<span class="glyphicon glyphicon-exclamation-sign alert alert-danger" id="ErrorMessage" style="display: none;" aria-hidden="true"></span>`
此范围默认没有文本,但会根据发生的错误填充错误文本。
问题是元素中的文本看起来被拉伸了,看起来很糟糕。我不确定用什么方法来解决这个问题。任何意见,将不胜感激。
编辑:问题仅在我添加 "glyphicon" class 时出现。
我正在使用 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>
您可以像这样在单独的 span 标签中使用字形图标:
<span class="glyphicon glyphicon-exclamation-sign"></span>
<span class="alert alert-danger" id="ErrorMessage" style="display: none;" aria-hidden="true"></span>
glyphicon 不希望包含图标本身以外的其他内容。问题是字形 class 附加了更多样式,这对于普通文本来说是不需要的。在这种情况下,字体系列!
解决方案是将字形本身放在它自己的范围内,在 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>