html - 无序列表问题

标签 html css list unordered

我的无序列表似乎超出了它的父元素并进入了它的下方。我确定这是一个简单的解决方法,但我就是想不通。我是 html 和 css 的新手。

我在这里添加了我的代码,希望有人能帮我解决问题。我想我以前问过这个问题。反正我不确定。提前致谢。

header {
	width: 100%;
	height: 36px;
	border-bottom: 1px solid #f0efef;
	box-shadow: 0 0 5px 0 #f0efef;
}

.header-content {
	width: 1030px;
	height: 36px;
	background-color: red;
}

.header-content p {
	margin: 0;
	font-size: 14px;
	padding: 7px 15px 0 15px;
}

.header-content ul {
	margin: 0;
	float: right;
	list-style: none;
	padding: 5px 15px 0 15px;
}

.header-content ul li {
	padding-left: 10px;
	display: inline;
}

.header-content ul li a, a:visited {
	color: #404040;
	font-size: 14px;
	text-decoration: none;
}
<header>
		<div class="header-content">
			<p>Welcome, please sign or register</p>
			<ul>
				<li><a href="#">My Account</a></li>
				<li><a href="#">Gift Cards</a></li>
				<li><a href="#">Customer Care</a></li>
				<li><a href="#">Community</a></li>
			</ul>
		</div>
	</header>

最佳答案

该段落元素是一个 block 级元素,因此它会将您的 ul 向下推。为了解决这个问题,你可以 float :在标题中留下你的p标签

header {
	width: 100%;
	height: 36px;
	border-bottom: 1px solid #f0efef;
	box-shadow: 0 0 5px 0 #f0efef;
}

.header-content {
	width: 1030px;
	height: 36px;
	background-color: red;
}

.header-content p {
	margin: 0;
	font-size: 14px;
	padding: 7px 15px 0 15px;
        float:left;
}

.header-content ul {
	margin: 0;
	float: right;
	list-style: none;
	padding: 5px 15px 0 15px;
}

.header-content ul li {
	padding-left: 10px;
	display: inline;
}

.header-content ul li a, a:visited {
	color: #404040;
	font-size: 14px;
	text-decoration: none;
}
<header>
		<div class="header-content">
			<p>Welcome, please sign or register</p>
			<ul>
				<li><a href="#">My Account</a></li>
				<li><a href="#">Gift Cards</a></li>
				<li><a href="#">Customer Care</a></li>
				<li><a href="#">Community</a></li>
			</ul>
		</div>
	</header>

关于html - 无序列表问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31944728/

相关文章:

android - 使用 HTML5 应用程序访问 Android/iPhone 音量按钮

jquery - 重新定位网页上的 'absolute' 元素 - CSS

html - 浏览器在 mac 中显示纯文本而不是 HTML

jquery - 翻转时如何在 UL 中添加类并在 LI 中处于事件状态

javascript - 使用 jquery .css() 属性根据浏览器大小动态清除绝对定位的 div

list - 最大算法haskell

python - 如何遍历 Python 中的元组列表?

python - 编写这个 for 循环的更有效方法?

javascript - 使用 CSS 和 wicket 操作 HTML 表格中 div 类的高度

javascript - 向日期添加天数并显示它,不包括周末和节假日