繁体   English   中英

使用CSS和Javascript在show hide div中对齐文本

[英]Justify text in show hide div with CSS and Javascript

我有一个显示/隐藏文本的功能,它工作正常。 但是,我有两个问题:

  1. 尽管我已经在CSS和JavaScript中指定了此属性,但我无法证明文本的合理性。
  2. 显示文本时,我无法摆脱换行符。 我想将其连接起来。 使文本合理的唯一方法是将其视为新的段落,我想避免。

这是Javascript函数(可能更好,我知道)

    function showHide(mytext) {
     if (document.getElementById('mytext1')) {
            if (document.getElementById('mytext1' + '-show').style.display != 'none') {
                document.getElementById('mytext1' + '-show').style.display = 'none';
                document.getElementById('mytext1').style.display = 'inline';
                document.getElementById('mytext1').style.textAlign ='justify';
            } else {
                document.getElementById('mytext1' + '-show').style.display = 'inline';
                document.getElementById('mytext1').style.display = 'none';
            }
        }

}

这是一些HTML

     <p class="NeueLite text-justify"> Beginning of the text.<a id="mytext1-show" onclick="showHide('mytext1'); return false;" class ="abstract"> More</a>
               <div id="mytext1" style="display: none;" class="moretext">
    Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.
 <a id="mytext1-hide"  onclick="showHide('mytext1');return false;" href="javascript:void(0)" class="abstract" >Less</a></p></div>

还有我的CSS的类:

div.moretext {
   font-family: 'Comic Neue', sans-serif !important;
    font-weight: 100 !important;
      line-height: 1.2 !important;
      font-size: 0.8rem !important;
      text-align: justify !important;
      }

这是因为您将隐藏的文本放在<div> 请使用<span> 另外,将text-align: justify; <p>

工作实例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM