简体   繁体   English

如何让 div 中的文本在扩展 div 内保持相同的大小宽度

[英]How to have text in a div keep the same size width inside of an expanding div

I have some code that expands a div from the left side of the screen by increasing its width.我有一些代码通过增加宽度来从屏幕左侧扩展 div。 In this div I have a list with text that wraps down the div.在这个 div 中,我有一个包含 div 的文本列表。 My question is;我的问题是; when it expands you can see the text expanding character-by-character with it as it resizes, is there a way to have the text remain the same size so that when the div expands, the text does not move (almost like the text is just hidden behind it until it moves out)?当它扩展时,您可以看到文本在调整大小时逐个字符地扩展,有没有办法让文本保持相同的大小,以便当 div 扩展时,文本不会移动(几乎就像文本一样只是隐藏在它后面直到它移出)? Trying to use purely JavaScript, HTML, and/or CSS.尝试使用纯粹的 JavaScript、HTML 和/或 CSS。

Expand
</button>
<div id="listmenu" class="list">
        <span onclick="document.getElementById('listmenu').style.width = '0%'">&times;</span>
        <ul>
            <li>Placeholder text that is long enough to go to the next line</li>
            <li>Placeholder</li>
            <li>Placeholder</li>
            <li>Placeholder</li>
            <li>Placeholder</li>
        </ul>
</div>
CSS:
.list {
  position: fixed;
  overflow-x: hidden;
  background-color: black;
  width: 0%;
  height: 100%;
  left: 0;
  top: 0;
  transition: 1s all ease-in-out;
}

.list li {
  color: white;
}

.list span {
  float: right;
  padding-right: 5px;
  color: white;
  cursor: pointer;
}

JSFiddle JSFiddle

You can try like this:你可以这样尝试:

 .list { position: fixed; overflow-x: hidden; background-color: black; width: 30%; height: 100%; left: -30%; top: 0; transition: 1s all ease-in-out; }.list li { color: white; }.list span { float: right; padding-right: 5px; color: white; cursor: pointer; }
 <button onclick="document.getElementById('listmenu').style.left = '0'"> Expand </button> <div id="listmenu" class="list"> <span onclick="document.getElementById('listmenu').style.left = '-30%'">&times;</span> <ul> <li>Placeholder text that is long enough to go to the next line</li> <li>Placeholder</li> <li>Placeholder</li> <li>Placeholder</li> <li>Placeholder</li> </ul> </div>

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

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