gpt4 book ai didi

javascript - 使用 off-canvas 时如何避免文本换行?

转载 作者:太空宇宙 更新时间:2023-11-04 08:30:53 25 4
gpt4 key购买 nike

我有以下页面作为我正在构建的 Web 应用程序原型(prototype)的一部分,我想知道是否有任何方法(仅使用 CSS 或 JS),以避免段落的文本换行从我的 Canvas 外菜单。

我对构建这种菜单非常“陌生”,并且我使用这个原型(prototype)实现了当前的结果,这要归功于 W3Schools 中的示例.

<!DOCTYPE html>
<html>

<head>

<style>

body {
font-family: "Lato", sans-serif;
}

.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #ff0000;
overflow-x: hidden;
transition: 0.6s;
padding-top: 180px;
}

.sidenav a {
padding: 10px 0px 10px 35px;
text-decoration: none;
font-size: 20px;
color: #ffffff;
display: block;
transition: 0.5s;
}

.sidenav a:hover, .offcanvas a:focus{
color: #a6a6a6;
}

.sidenav .closebtn {
position: absolute;
top: 0;
right: 0px;
font-size: 35px;
margin-right: 20px;
}

#main {
transition: margin-left 0.6s;
padding: 26px;
}

@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}

</style>

</head>

<body>

<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<a href="#">Customers</a>
<a href="#">Pupils</a>
<a href="#">Teachers</a>
<!-- Try to separate the word ""AndroidNotices" and you'll see... -->
<a href="#">AndroidNotices</a>
</div>

<div id="main">
<h2>Off-Canvas Menu</h2>
<p>Click on button to open the side navigation menu.</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; Menu</span>
</div>

<script>

function openNav() {
document.getElementById("mySidenav").style.width = "200px";
document.getElementById("main").style.marginLeft = "200px";
}

function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft= "0";
}

</script>

</body>

</html>

最佳答案

如果我没理解错的话,你需要设置样式 white-space: nowrap对于段落 ( <p> ) 元素,以防止文本换行 ...

p {
white-space: nowrap;
}

关于javascript - 使用 off-canvas 时如何避免文本换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44794234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com