Search code examples
htmlcsslistunordered

Unordered list issue


My unordered list seems to be going out of it's parent element and going under it. I'm sure this is an easy fix but I just can't figure it out. I'm new to html and css.

I've added my codes here in hope of someone figuring something out for me. I think i've asked this question before. I'm not sure, anyways. Thanks in advance.

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>


Solution

  • That paragraph element is a block level element so it's going to push your ul down. To solve the problem, you can float:left your p tag in the header

    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>