我需要在div中添加两个元素的效果。我尝试选择他们的ID(以及其他一些方式)但是没有按预期工作。也许我没有成功,因为我对HTML / CSS没有深入的了解。
以下是我最近尝试过的一个示例 -
<style>
#container {
margin: 0 auto;
max-width: 890px;
}
.toggle, [id^=drop] {
display: none;
}
nav {
margin: 0;
padding: 0;
width: 100%;
padding-top: .4em;
padding-bottom: .4em;
background-color: #FFF;
border-bottom: 2px solid #BBB;
box-shadow: 3px 3px 5px 3px #CCC;
z-index: 100;
position: fixed;
top: 0;
left: 0;
right: 0;
}
#menuBar{
background-color: #2D2D2D;
}
#logo {
display: block;
padding: 0 20px;
float: left;
font-size: 20px;
line-height: 40px;
}
nav ul {
float: right;
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
margin: 0px;
display: inline-block;
float: left;
background-color: #2D2D2D;
}
nav a {
display: block;
padding: 0 20px;
color: #4CAF50;
font-size: 18px;
font-weight: 700;
line-height: 40px;
text-decoration: none;
}
</style>
</head>
<body id="top" data-gr-c-s-loaded="true">
<nav>
<div id="menuBar">
<div id="logo">nMess</div>
<label for="drop" class="toggle menu">Menu</label> <input type="checkbox" id="drop">
<ul class="menu">
<li><a href="homepage">Home</a></li>
<li><a href="bazarExchange">Bazar Exchange</a></li>
<li><a href="bazarValidate">Bazar Validate</a></li>
<li><a href="profile">Profile</a></li>
<li><a class="alertBtn" href="logout">Logout</a></li>
</ul>
</div>
</nav>
</body>
</html>
注意:我不希望整个背景颜色变灰,在白色背景中想要灰色。
答案 0 :(得分:3)
import tkinter as tk
root = tk.Tk()
root.title("Untitled")
titleVar = tk.StringVar()
titleVar.set("Something")
def change_title():
titleVar.set("Title changed!")
print(titleVar.get())
tk.Button(text="Update", command=change_title).pack()
root.mainloop()
与浮动你已将clearfix
放在background-color: #2D2D2D;
上,但它会折叠到零高度 - 因为它的所有子项都是浮动或隐藏的。您应该使用clearfix来避免它(注意#menuBar
上的.clearfix
类):
#menuBar
#container {
margin: 0 auto;
max-width: 890px;
}
.toggle, [id^=drop] {
display: none;
}
nav {
margin: 0;
padding: 0;
width: 100%;
padding-top: .4em;
padding-bottom: .4em;
background-color: #FFF;
border-bottom: 2px solid #BBB;
box-shadow: 3px 3px 5px 3px #CCC;
z-index: 100;
position: fixed;
top: 0;
left: 0;
right: 0;
}
#menuBar{
background-color: #2D2D2D;
}
#logo {
display: block;
padding: 0 20px;
float: left;
font-size: 20px;
line-height: 40px;
}
nav ul {
float: right;
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
margin: 0px;
display: inline-block;
float: left;
background-color: #2D2D2D;
}
nav a {
display: block;
padding: 0 20px;
color: #4CAF50;
font-size: 18px;
font-weight: 700;
line-height: 40px;
text-decoration: none;
}
.clearfix:after {
content: ".";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
<body id="top" data-gr-c-s-loaded="true">
<nav>
<div id="menuBar" class="clearfix">
<div id="logo">nMess</div>
<label for="drop" class="toggle menu">Menu</label> <input type="checkbox" id="drop">
<ul class="menu">
<li><a href="homepage">Home</a></li>
<li><a href="bazarValidate">Bazar Validate</a></li>
<li><a href="profile">Profile</a></li>
<li><a class="alertBtn" href="logout">Logout</a></li>
</ul>
</div>
</nav>
</body>
您可以使用线性渐变来制作多色背景(请注意linear-gradient
上的.gradient
类):
nav
#container {
margin: 0 auto;
max-width: 890px;
}
.toggle, [id^=drop] {
display: none;
}
nav {
margin: 0;
padding: 0;
width: 100%;
padding-top: .4em;
padding-bottom: .4em;
background-color: #FFF;
border-bottom: 2px solid #BBB;
box-shadow: 3px 3px 5px 3px #CCC;
z-index: 100;
position: fixed;
top: 0;
left: 0;
right: 0;
}
#logo {
display: block;
padding: 0 20px;
float: left;
font-size: 20px;
line-height: 40px;
}
nav ul {
float: right;
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
margin: 0px;
display: inline-block;
float: left;
}
nav a {
display: block;
padding: 0 20px;
color: #4CAF50;
font-size: 18px;
font-weight: 700;
line-height: 40px;
text-decoration: none;
}
.gradient {
background: linear-gradient(to bottom, #fff 0%, #fff 10%, #2d2d2d 10%, #2d2d2d 90%, #fff 90%, #fff 100%);
}
答案 1 :(得分:2)
您可以更改背景的HTML元素导航,如下所示:
nav {
background-color: #2D2D2D;
}
如果你仍然想要在顶部和底部有一个白色边框,你可以像这样添加一个:
nav {
background-color: #2D2D2D;
border-top: 5px solid #fff;
border-bottom: 5px solid #fff;
}
答案 2 :(得分:0)
https://jsfiddle.net/Liamm12/onjxwz88/
你好!
这就是你要做的事情!
HTML:
<nav>
<div id="menuBar">
<ul class="menu">
<li> <div id="logo">nMess</div>
<label for="drop" class="toggle menu">Menu</label> <input type="checkbox" id="drop">
</li>
<div class="right">
<li><a href="homepage">Home</a></li>
<li><a href="bazarExchange">Bazar Exchange</a></li>
<li><a href="bazarValidate">Bazar Validate</a></li>
<li><a href="profile">Profile</a></li>
<li><a class="alertBtn" href="logout">Logout</a></li></div>
</ul>
</div>
</nav>
CSS:
#container {
margin: 0 auto;
max-width: 890px;
}
.toggle, [id^=drop] {
display: none;
}
#menuBar{
background-color: #2D2D2D;
}
#logo {
display: block;
padding: 0 20px;
float: left;
font-size: 20px;
line-height: 40px;
color:#fff;
}
nav {
margin: 0;
padding: 0;
width: 100%;
padding-top: .4em;
padding-bottom: .4em;
background-color: #FFF;
border-bottom: 2px solid #BBB;
box-shadow: 3px 3px 5px 3px #CCC;
z-index: 100;
position: fixed;
top: 0;
left: 0;
right: 0;
}
nav ul {
float: left;
padding: 0;
margin: 0;
list-style: none;
width:100%;
background-color: #2D2D2D;
}
nav ul div.right{
float:right;
}
nav ul li {
float: left;
}
nav a {
display: block;
padding: 0 20px;
color: #4CAF50;
font-size: 18px;
font-weight: 700;
line-height: 40px;
text-decoration: none;
}