2012-12-07 85 views
0

PLease help!如何在div內保留div

這就是我到目前爲止:http://beauxlent.com/nicole 當你點擊「一個」「兩個」或「三個」,它會帶你到一個仍然在同一頁面上的div。不過,我希望div保留在正確的div中,並仍然在同一頁面上使用#tags。我以前見過這個。

<style type="text/css"> 
{  
padding: 0; 
margin: 0; 
} 
body { 
text-align: justify; 
overflow: hidden; 
background: #F8F8F8; 
font: -blocked- arial; 
} 
table, p { 
display: none; 
} 
div { 
width: 100%; 
} 

.container {width: 800px; display:block; margin:0px auto} 

.left {width:200px; float:left; background: #eee; display:block; height:200px; 
line-  height:2} 


.right {width:600px; float:right; background: #808080; display:block; height: 200px; 
line-height:2; } 

#o {position:absolute; right: 2000px;} 


.blog { 
background: 0; 
position: absolute; 
top: 150px; 
left: 500px; 
width: 290px; 
height: 140px; 
} 
#omg { 
z-index: 7; 
position: absolute; 
top: 1000px; 
right: 0; 
color: #000; 
height: 1000px; 
} 
#plz { 

z-index: 7; 
position: absolute; 
top: 9000px; 
right: 0; 
color: #000; 
height: 9000px; 
} 

} 
#nande a:hover { 
color: #000; 
} 
#nande { 

z-index: 7; 
position: absolute; 
top: 7000px; 
right: 0; 
color: #000; 
height: 1000px; 
} 
body, table { 
color: #fff; 
} 
font, table, tr, td, br, p { 
font: -blocked- franklin gothic medium; 
color: #fff; 
} 
#content { 
width: 100%; 
    } 
#main, #content { 
border: 0px none; 
background: #fff; 
} 

} 

.framed { 
background: #fff; 
padding: 5px; 

overflow: auto; 
position: absolute; 
top: 20px; 
left: 0px; 
} 

</style> 
<div id="boxed"> 







<div class="container"> 





<div class="left"> 




<a href="#uno" class="big">1</a> 

<a href="#dos" class="big">2</a> 


<a href="#tres" class="big">3</a> 




</div> 



<div class="right"> 


<div id="omg"> 
<a name="uno"></a> 
<div class="framed"> 
one 
</div> 


</div> 



<div id="nande"> 
<a name="dos"></a> 
<div class="framed"> 
two 
</div> 
</div> 


<div id="plz"> 
<a name="tres"></a> 
<div class="framed"> 


three 
</div> 
</div> 



</div> 
+0

,我想左側邊欄留在屏幕上。現在它不會停留在屏幕上 –

+1

您能否告訴我們一個你想要完成的事情的例子?我假設你希望每個div(#omg #nande #plz)中的內容在用戶單擊鏈接時出現在#right div內? Javascript/jQuery將成爲你的朋友,但你必須爲你想要隱藏/顯示的div添加一個獨特的id/class。 –

回答

2

表示您的意思。這也可以在CSS中完成。試着點擊此處查看 - >http://css-tricks.com/functional-css-tabs-revisited/

HTML代碼:

<div class="tab"> 
     <input type="radio" id="tab-1" name="tab-group-1" checked> 
     <label for="tab-1">Tab One</label> 

     <div class="content"> 
      stuff 
     </div> 
    </div> 

    <div class="tab"> 
     <input type="radio" id="tab-2" name="tab-group-1"> 
     <label for="tab-2">Tab Two</label> 

     <div class="content"> 
      stuff 
     </div> 
    </div> 

    <div class="tab"> 
     <input type="radio" id="tab-3" name="tab-group-1"> 
     <label for="tab-3">Tab Three</label> 

     <div class="content"> 
      stuff 
     </div> 
    </div> 

</div> 

CSS代碼:

.tabs { 
    position: relative; 
    min-height: 200px; /* This part sucks */ 
    clear: both; 
    margin: 25px 0; 
} 
.tab { 
    float: left; 
} 
.tab label { 
    background: #eee; 
    padding: 10px; 
    border: 1px solid #ccc; 
    margin-left: -1px; 
    position: relative; 
    left: 1px; 
} 
.tab [type=radio] { 
    display: none; 
} 
.content { 
    position: absolute; 
    top: 28px; 
    left: 0; 
    background: white; 
    right: 0; 
    bottom: 0; 
    padding: 20px; 
    border: 1px solid #ccc; 
} 
[type=radio]:checked ~ label { 
    background: white; 
    border-bottom: 1px solid white; 
    z-index: 2; 
} 
[type=radio]:checked ~ label ~ .content { 
    z-index: 1; 
} 
+0

請注意,此解決方案與低於9的IE版本不兼容。對於回退,您可能希望使用類似Twitter Bootstrap的[tabs.js](http://twitter.github.com/bootstrap/javascript.html#標籤) –

+0

@lota是的,你有一個點。這可能不適用於IE,所以最好添加Twitter Bootstrap或任何jQuery代碼。不管怎麼說,還是要謝謝你。 – boang3000

0

jQuery UI Tabs看看 - 很容易實現。

包括

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 

jQuery的

$(function() { 
    $("#tabs").tabs(); 
}); 

的HTML

<div id="tabs"> 
<ul> 
    <li><a href="#tabs-1">Nunc tincidunt</a></li> 
    <li><a href="#tabs-2">Proin dolor</a></li> 
    <li><a href="#tabs-3">Aenean lacinia</a></li> 
</ul> 
<div id="tabs-1"> 
    <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p> 
</div> 
<div id="tabs-2"> 
    <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p> 
</div> 
<div id="tabs-3"> 
    <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p> 
    <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p> 
</div> 
</div>