如何将两个段落连接在一起以内联方式显示,而不会使文本移动
How can I Join two paragraphs to display inline together without jusitified text moving around?
我正在尝试将两个段落连接在一起以内联显示。我知道我可以使用span标记而不是p标记,但我的问题是这个。我希望这两段的案文都是合理的。我想将第二段设置为显示:none(隐藏)以开始。使用jQuery,我将切换display:none以显示第二段中隐藏的文本。我不希望第一段最后一行的文本在第二段出现时开始移动。这就是我陷入困境的地方。我可以把段落连接在一起,但我在最后一行文本上移动,因为我在第一段的最后一行添加了新的文本。这是在重新论证最后一行文字。这种情况发生时看起来不太好。
请记住,第二段中的文本将在第一段末尾继续,没有换行符。
$(function() {
$('span[id=span2]').addClass('hidepar');
$('span[id=span1]').click(function() {
$('span[id=span2]').fadeToggle(1000);
});
});
.hidepar {
display: none;
}
#div1 {
text-align: justify;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div1">
<span id="span1" style="display:inline">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</span>
<span id="span2">Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</span>
</div>
谢谢!
我不知道你的设计是什么样子的,但如果你的第二段只是需要出现,你可以用几种方法:
-
在第二段中添加一个类,以内联方式显示,但将其设置为与背景颜色相同。然后,使用jQuery事件将颜色调整为文本颜色。问题是谷歌会反对这些恶作剧。
-
您也可以调整第二段的不透明度,而不是使用display:none。
这是假设没有其他页面元素会受到影响。只有两个想法。
也许您可以将代码更改为:
.hidepar {
visibility: hidden;
}
#div1 {
text-align: justify;
}
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(function() {
$('span[id=span2]').addClass('hidepar');
$('span[id=span1]').click(function() {
$('span[id=span2]').css('visibility', 'visible');
});
});
相关文章:
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 在ng重复循环中显示条件内容的最佳方式是什么
- 显示可链接的搜索结果+对齐方式
- 在网站上显示.mov作为加载屏幕的最佳方式
- 将不同上传的文件显示为缩略图或任何其他方式
- 另一种显示和隐藏按钮的方式
- 显示全屏Ajax加载程序的最佳方式
- DC.js数据表没有按应有的方式显示
- 显示数据的最快方式
- 将JavaScript检测与MVC4显示模式集成的最佳方式是什么
- 货到付款选择隐藏/显示付款方式
- 为什么某些Javascript属性没有在调试器中以交互方式显示
- 数据在确认框中的显示方式存在问题
- 在googlechrome中,没有www子域的页面会有不同的显示方式
- 重复的页面显示方式不同
- 当用户使用 ASP.NET 从 Web 窗体中的“下拉列表列表”中选择“其他”时,文本框的显示方式
- Javascript 对象属性值因显示方式而异
- 如何查找元素的当前显示方式
- 如何重新组织此页面缩略图的显示方式
- 改变数据在高图中的显示方式