gpt4 book ai didi

php - 一个滚动条用于 2 个独立的 div

转载 作者:太空宇宙 更新时间:2023-11-03 18:36:00 25 4
gpt4 key购买 nike

我有两个并排的 DIV。一个 div 是我的侧边栏(屏幕左侧),另一个 div 是我的主要内容(屏幕右侧)。

我要找的是:我想要的是屏幕最右侧的一个可见滚动条。我希望滚动条可以左右滚动 div。

我的问题:目前我的左侧边栏有一个树形菜单。当我伸展树(Splay Tree)形菜单时,我没有滚动条来向下滚动展开的侧栏内容。我可以在我的侧边栏中添加一个滚动条,但这看起来非常难看。我只想要最右边的 1 个滚动条来处理两个 div。
有人可以帮我解决这个问题吗?

我的 index.php 文件

<?php

include 'sidebar.php';
include 'main_body.php';

?>

我的sidebar.php

<?php

echo '<link rel="stylesheet" href="css/style.css" type="text/css">';
echo '<script type="text/javascript" src="js/jquery1_3_2.js"></script>';

include 'function/functions.php';
// Establish a connection to our database
db_connect();

echo'
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".content").hide();
//toggle the componenet with class msg_body
jQuery(".heading").click(function()
{
jQuery(this).next(".content").slideToggle(500);
});
});
</script>
';

echo'<div class="sidebar">';

// Side Bar Start
echo '
<img src="images/hdc_logo.png">
<br>
<br>

<p class="heading"><strong>CUSTOMER</strong></p>
<div class="content">';

//Display all customers from database
query_all_customers();

echo '</div>
<p class="heading"><strong>CABINET</strong></p>
<div class="content">';

// Display all cabinets from database
query_all_cabinets();
echo'</div>
</div>';

?>

我的主要内容区

<?php

ini_set('display_errors', 1);

echo '<div class="main">';

echo'
<br>
<br>
Some data can go here
<br>
<br><br>
<br>
and here
<br>
<br>
and here
<br>
<br>
Some data can go here
<br>
<br><br>
<br>
and here
<br>
<br>
and here
<br>
<br>
Some data can go here
<br>
<br><br>
<br>
and here
<br>
<br>
and here
<br>
<br>
Some data can go here
<br>
<br><br>
<br>
and here
<br>
<br>
and here';
?>

我的.css 文件

.sidebar {
width:200px;
position:fixed;
top:0px;
left:0px;
height:100%;
background-color:#54524F;
/*overflow-y: scroll;*/
}
.main {
width: auto;
margin-left: 200px;
}
.heading {
margin: 1px;
color: #fff;
padding: 3px 10px;
cursor: pointer;
position: relative;
background-color:#000000;
}
.content {
padding: 5px 10px;
}
#submit {
width:185px;
background-color: black;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius:6px;
color: #fff;
font-family:'Oswald';
font-size: 16px;
text-decoration: none;
cursor: pointer;
border:none;
}
#submit:hover {
border: none;
background:#FF9933;
box-shadow: 0px 0px 1px #777;
}
tr:nth-of-type(odd) {
background-color:#D4D4D4;
}
.container0 {
height: 100%;
width: 100%;
overflow-x: hidden;
position: relative;
padding-bottom: 30px;
background-color:black;
}

JSFiddle

最佳答案

在你的 css 中,将侧边栏的位置设置为 relative 并将 float 设置为左​​侧,如下所示:

.sidebar {
width:200px;
position:relative;
top:0px;
left:0px;
height:100%;
background-color:#54524F;
float:left
}

您的 jsfiddle 的更新版本向您展示它可以工作:) http://jsfiddle.net/BrJDE/3/

因为你不想在页面的一侧有滚动条,我为你做了更多的例子。告诉我它们是否是您想要的,如果不是,我很乐意再次帮助您。

与您提供的内容相比,这两个示例都使用了 2 个额外的 div。这些将使您可以将滚动条定位在那些 div 内,而不是在浏览器的一侧。如果您需要我解释我所做的更改,请告诉我。

页面内的滚动条: http://jsfiddle.net/BrJDE/6/

页面内的滚动条位于滚动 div 的左侧: http://jsfiddle.net/BrJDE/5/

关于php - 一个滚动条用于 2 个独立的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18658470/

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