样式不适用于子元素

时间:2015-04-03 14:54:41

标签: css

我已将background-color应用于容器,但容器内定义的<ul>似乎不应用背景颜色。有什么想法吗? 另外,有没有办法对<ul>项目应用均匀间距,以便它们均匀地跨越容器的宽度而不应用填充?

#smedia-container {
	
	max-width: 302px;
	max-height: 110px;
	text-align: center;
	background-color: #fbf4e8;
}
.smedia-header {
	background-color: #b90021;
	color: #000;
	min-height: 32px;
	
}
.smedia-icons {
	text-align: justify;
	width: 100%;
}
ul.smedia-icons li {
	float: left;
	display: inline-block;
	text-decoration: none;

}
.smedia-icons li a {
	text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>social media bar</title>
<link rel="stylesheet" type="text/css" href="smedia-bar.css">
</head>
<body>
<div id="smedia-container">
	<div class="smedia-header">
		<span>Social Media</span>
	</div>
	<span> Follow Us </span>
	<ul class="smedia-icons">
		<li><a href="#"><img src="some.png" alt=" "> </a> </li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
	</ul>
</div> <!--container-->
</body>
</html>

2 个答案:

答案 0 :(得分:1)

由于您浮动列表项,因此列表基本上会折叠,因此父级操作就像它不存在一样。您可以通过将overflow:auto添加到容器的CSS中来恢复您所追求的行为:

#smedia-container {
	
	max-width: 302px;
	max-height: 110px;
	text-align: center;
	background-color: #fbf4e8;
  overflow:auto;
}
.smedia-header {
	background-color: #b90021;
	color: #000;
	min-height: 32px;
	
}
.smedia-icons {
	text-align: justify;
	width: 100%;
}
ul.smedia-icons li {
	float: left;
	display: inline-block;
	text-decoration: none;

}
.smedia-icons li a {
	text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>social media bar</title>
<link rel="stylesheet" type="text/css" href="smedia-bar.css">
</head>
<body>
<div id="smedia-container">
	<div class="smedia-header">
		<span>Social Media</span>
	</div>
	<span> Follow Us </span>
	<ul class="smedia-icons">
		<li><a href="#"><img src="some.png" alt=" "> </a> </li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
		<li><a href="#"><img src="some.png" alt=" "></a></li>
	</ul>
</div> <!--container-->
</body>
</html>

答案 1 :(得分:0)

这将有效:

#smedia-container {
    overflow: auto;
    max-width: 302px;
    max-height: 110px;
    text-align: center;
    background-color: #fbf4e8;
}