2016-02-02 66 views
0

首先讓我說一下這個網站對我的小項目有多大幫助。無論如何對我的問題。在div中添加填充以及背景圖片和顏色消失

所以現在我正在爲自己創建一個個人網站,我想爲某些東西添加一些填充,但是當我添加填充時,它最終會在一些東西之間創建空間並使其完全變白,而不使用背景圖像或顏色。這就是我的意思。

When I open up the "About" tab (I added padding to that one but not the one above), do you see how there's a lot of white space? How can I have that colored in grey and use the background image aswell?

And when I close the tab, there is a big white gap, which is (I'm pretty sure) the padding not closing

我只加填充,以「關於」選項卡,你可以看到,它搞砸了比別人(This is the jsfiddle)

.small2{ 
font-family: 'Ubuntu', serif; 
font-size: 30px; 
padding: 15px; 
margin: auto; 
} 

這是CSS代碼爲持有信息的類。

+0

爲什麼你不能給背景顏色相同的元素? –

+0

https://jsfiddle.net/ar8twqvw/1/ –

+0

@ArunPJohny不錯!因此,當我展開組件時,它可以工作,但是當它關​​閉時,About和Projects之間仍然有奇怪的空間。有沒有隱藏或刪除它,並顯示內容時擴大可能嗎?或者無論如何解決,我的意思是 –

回答

0

嘗試將填充移動到.four類,我認爲它會給你你想要的結果。

+0

哇,解決了所有問題!非常感謝你哈哈,不敢相信我沒有想到那 –

+0

沒問題!祝你的項目好運! –

1

以填充過.two,如果你想圍繞.four內容的白色邊框,可以使用保證金:

$(document).ready(function(event) { 
 

 
    $('.one').click(function() { 
 
    $('.two').slideToggle(); 
 
    }) 
 

 

 
    $('.three').click(function() { 
 
    $('.four').slideToggle(); 
 
    }) 
 

 
    $('.five').click(function() { 
 
    $('.six').slideToggle(); 
 
    }) 
 

 

 
    $('.seven').click(function() { 
 
    $('.eight').slideToggle(); 
 
    }) 
 

 
    setTimeout(function() { 
 
    $('.two').slideToggle(); 
 
    }, 500); 
 

 
});
body { 
 
    margin: 0; 
 
} 
 
.container { 
 
    overflow: hidden; 
 
} 
 
.one { 
 
    position: relative; 
 
    top: 0; 
 
    background-color: #605F5F; 
 
    z-index: 1; 
 
    cursor: pointer; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
} 
 
.two { 
 
    background-color: #333333; 
 
    display: none; 
 
    text-align: center; 
 
    color: white; 
 
    background-image: url("noise.png"); 
 
} 
 
.three { 
 
    position: relative; 
 
    top: 0; 
 
    background-color: #605F5F; 
 
    z-index: 1; 
 
    cursor: pointer; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
} 
 
.four { 
 
    background-color: #333333; 
 
    display: none; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
    margin: 15px; 
 
} 
 
.five { 
 
    position: relative; 
 
    top: 0; 
 
    background-color: #605F5F; 
 
    z-index: 1; 
 
    cursor: pointer; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
} 
 
.six { 
 
    background-color: #333333; 
 
    display: none; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
} 
 
.seven { 
 
    position: relative; 
 
    top: 0; 
 
    background-color: #605F5F; 
 
    z-index: 1; 
 
    cursor: pointer; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
} 
 
.eight { 
 
    background-color: #333333; 
 
    display: none; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
} 
 
.botbar { 
 
    background-color: #2b2a2a; 
 
    text-align: center; 
 
    color: white; 
 
    background-image: url("noise.png"); 
 
} 
 
.big1 { 
 
    font-family: 'Megrim', serif; 
 
    font-size: 210px; 
 
} 
 
.small1 { 
 
    font-family: 'Ubuntu', serif; 
 
    font-size: 80px; 
 
} 
 
.small2 { 
 
    font-family: 'Ubuntu', serif; 
 
    font-size: 30px; 
 
    background-clip: initial; 
 
    margin: auto; 
 
} 
 
.botinfo { 
 
    font-family: 'Ubuntu', serif; 
 
    font-size: 25px; 
 
}
<div class="container"> 
 
    <div class="big1"> 
 
    <div class="one">Main</div> 
 
    </div> 
 
    <div class="small1"> 
 
    <div class="two">Welcome to my page! 
 
     <br>Click around 
 
     <br>Learn a thing or two about me</div> 
 
    </div> 
 
    <div class="big1"> 
 
    <div class="three">About</div> 
 
    </div> 
 
    <div class="small2"> 
 
    <div class="four">My name is Bob and I currently attend University of Bob. 
 
     <br>If a passionate student that is always trying to learn new and exciting things and broaden their knowledge in the field of programming is someone you need, then I'm your guy. 
 
     <br>I have worked on projects ranging from this website that was created by yours truly, a game of solitaire with my own personal twist, and much more. 
 
     <br>All my projects can be found in the tab below!</div> 
 
    </div> 
 
    <div class="big1"> 
 
    <div class="five">Projects</div> 
 
    </div> 
 
    <div class="small1"> 
 
    <div class="six">My projects can be found here</div> 
 
    </div> 
 
    <div class="big1"> 
 
    <div class="seven">Contact</div> 
 
    </div> 
 
    <div class="small1"> 
 
    <div class="eight">You can contact me here</div> 
 
    </div> 
 
    <div class="botinfo"> 
 
    <div class="botbar">Made by Bob | Copyright 2016</div> 
 
    </div> 
 
</div>

+1

我很好奇爲什麼這是downvoted沒有解釋... –

0

你可以做一些代碼重構簡化它就像

$(document).ready(function(event) { 
 

 
    $('.header').click(function() { 
 
    $(this).next('.content').slideToggle(); 
 
    }) 
 

 
    setTimeout(function() { 
 
    $('.content').first().slideToggle(); 
 
    }, 500); 
 

 
});
body { 
 
    margin: 0; 
 
} 
 
.container { 
 
    overflow: hidden; 
 
} 
 
.header { 
 
    position: relative; 
 
    top: 0; 
 
    background-color: #605F5F; 
 
    z-index: 1; 
 
    cursor: pointer; 
 
    text-align: center; 
 
    background-image: url("noise.png"); 
 
    color: white; 
 
} 
 
.content { 
 
    background-color: #333333; 
 
    display: none; 
 
    text-align: center; 
 
    color: white; 
 
    background-image: url("noise.png"); 
 
} 
 
.botbar { 
 
    background-color: #2b2a2a; 
 
    text-align: center; 
 
    color: white; 
 
    background-image: url("noise.png"); 
 
} 
 
.big1 { 
 
    font-family: 'Megrim', serif; 
 
    font-size: 210px; 
 
} 
 
.small1 { 
 
    font-family: 'Ubuntu', serif; 
 
    font-size: 80px; 
 
} 
 
.small2 { 
 
    font-family: 'Ubuntu', serif; 
 
    font-size: 30px; 
 
    background-clip: initial; 
 
    padding: 15px; 
 
    margin: auto; 
 
} 
 
.botinfo { 
 
    font-family: 'Ubuntu', serif; 
 
    font-size: 25px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="container"> 
 
    <div class="big1 header"> 
 
    Main 
 
    </div> 
 
    <div class="small1 content"> 
 
    Welcome to my page! 
 
    <br>Click around 
 
    <br>Learn a thing or two about me 
 
    </div> 
 
    <div class="big1 header"> 
 
    About 
 
    </div> 
 
    <div class="small2 content"> 
 
    My name is Bob and I currently attend University of Bob. 
 
    <br>If a passionate student that is always trying to learn new and exciting things and broaden their knowledge in the field of programming is someone you need, then I'm your guy. 
 
    <br>I have worked on projects ranging from this website that was created by yours truly, a game of solitaire with my own personal twist, and much more. 
 
    <br>All my projects can be found in the tab below! 
 
    </div> 
 
    <div class="big1 header"> 
 
    Projects 
 
    </div> 
 
    <div class="small1 content"> 
 
    My projects can be found here 
 
    </div> 
 
    <div class="big1 header"> 
 
    Contact 
 
    </div> 
 
    <div class="small1 content"> 
 
    You can contact me here 
 
    </div> 
 
    <div class="botinfo"> 
 
    <div class="botbar">Made by Bob | Copyright 2016</div> 
 
    </div> 
 
</div>

0

在css中使用display : none;.small2。即使它被隱藏,它也在UI上佔據了空間。 (如果你需要填充時可見)

.small2{ 
font-family: 'Ubuntu', serif; 
font-size: 30px; 
background-clip: initial; 
padding: 15px; 
margin: auto; 
display : none; 
}