Search code examples
csscentermargin

center content with full background


Inside a div I want a full width background color and center the content inside. I have read in some other posts that it needs an outer div to set the background-color there, and then an inner div with the width of my content and margin:0 auto;. I tried that but it doesn't work. I tried floating my content left and this didn't work either.

Here is my code. The problem is in the div class="themeDesign" where i put the background color. In the div class="themeDesignicons" when i put width:1000px the one of the li elements extends onto the next line, but with width:1300px they appear on the same line without centering. Why? Does it matter first-child? I cant go on. Thanks in advance

*{
	margin:0px;
	padding:0px;	
}
body{
	width:100%;
}
header{
	background-color:#088da5;
	overflow:hidden;
	padding:15px 0;
}
.main-header{
	width:1300px;
	margin:0 auto;
}
.main-header .left-mainheader{
	float:left;
	margin-right:400px;	
}
.main-header .left-mainheader ul li{
	display:inline-block;
	margin-right:26px;
}
.main-header .left-mainheader li a{
	text-decoration:none;
	color:white;
}
.main-header .right-mainheader{
	float:left;
}
.main-header .right-mainheader ul li{
	display:inline-block;
	margin-right:15px;
}
.main-header .right-mainheader ul li a{
	text-decoration:none;
	color:white;
}
.left-mainheader img{
	padding-right:8px;
}
header .header h1{
	background-image:url(images/logoheader.png);
	width:440px;
	height:84px;
	margin:60px auto;
	overflow:hidden;
	clear:both;
}
.header ul{
	margin:25px auto;
	width:440px;
}
.header li {
	display:inline-block;
	margin:0 15px 0 0;
}
.header li a{
	color:black;
	text-decoration:none;
	font-size:15px;
	font-family: tahoma;
}
header li a:hover{
	text-decoration:underline;
}
.header .headermesa{
	border-top:1px solid #666633;
}
.slider{
	background-color:#f7f8fa;
}
.slidermesa{
	margin:0 auto;
	width:1200px;
	height:421px;
}
.slide img{
	border-top:1px solid #666633;
	width:1200px;
	height:421px;
}
.themeDesign{
	background-color:#f7f8fa;
}
.themedesignheadings{
	margin:0 auto;
	width:1000px;
	padding:35px 0;
	border-bottom:1px dashed #877676;
}
.themeDesignicons{
	width:1000px;
	margin:0 auto;
}
.themeDesignicons ul li{
	display:inline-block;
	width:250px;
}
<!DOCTYPE html>
<html>
<head>
<title>-Tutorial for psd-revenant</title>
<meta charset="utf-8">
</head>
<body>
	<header>
		<div class="main-header">
			<div class="left-mainheader">
				<ul>
					<li>
						<a href="#"><img src="images/phoneIcon-header.png"/> +565 975 658</a>
					</li>
					<li>	
						<a href="#"><img src="images/emailheader3.png"/>[email protected]</a>
					</li>	
					<li>	
						<a href="#"><img src="images/timeheader2_03.png"/>Monday-Friday : 8.00-20.00</a>		
					</li>
				</ul>
			</div>
			<div class="right-mainheader">	
				<ul>
					<li><a href="#">Latest News</a></li>
					<li><a href="#">Login</a></li>
					<li><a href="#">Register</a></li>
					<li><a href="#">About Us</a></li>
			</div>
		</div>
		<div class="header">
			<h1></h1>
		<div class="headermesa">	
			<ul>
				<li><a href="#">Home</a></li>
				<li><a href="#">Apparel</a></li>
				<li><a href="#">Fashion</a></li>
				<li><a href="#">News</a></li>
				<li><a href="#">Portfolio</a></li>
				<li><a href="#">Contact</a></li>
			</ul>
		</div>	
		</div>
	</header>
	<div class="slider">
		<div class="slidermesa">
			<div class="slide">
				<img src="images/mainslide.png"/>
			</div>
		</div>
	</div>
		<div class="themeDesign">
			<div class="themedesignheadings">
				<h2>Check our latest Wordpress Theme which implements a Page Builder and a Revolution Slider</h2>
				<p>Learn how to build Wordpress Themes with ease with a premium Page Builder which allows you to add new Pages in seconds!</p>
			</div>	
			<div class="themeDesignicons">
				<ul>
					<li>
						<div class="disc-cam">
							<div class="icon cam2"></div>
						</div>
						<div class="disc-text">
							<h3>Responsive Design</h3>
							<p>Lorem ipsum dolor sit amet, co
							ctetuer adipiscing elit, sed di
							nonummy nibh euismod te.</p>
							<a href="#">Read More<img src="images/arrow.png"/></a>
						</div>
					</li>
					<li>
						<div class="disc-cam">
							<div class="icon cam2"></div>
						</div>
						<div class="disc-text">
							<h3>Responsive Design</h3>
							<p>Lorem ipsum dolor sit amet, co
							ctetuer adipiscing elit, sed di
							nonummy nibh euismod te.</p>
							<a href="#">Read More<img src="images/arrow.png"></a>
						</div>
					</li>
					<li>
						<div class="disc-cam">
							<div class="icon cam2"></div>
						</div>
						<div class="disc-text">
							<h3>Responsive Design</h3>
							<p>Lorem ipsum dolor sit amet, co
							ctetuer adipiscing elit, sed di
							nonummy nibh euismod te.</p>
							<a href="#">Read More<img src="images/arrow.png"></a>
						</div>
					</li>
					<li>
						<div class="disc-cam">
							<div class="icon cam2"></div>
						</div>
						<div class="disc-text">
							<h3>Responsive Design</h3>
							<p>Lorem ipsum dolor sit amet, co
							ctetuer adipiscing elit, sed di
							nonummy nibh euismod te.</p>
							<a href="#">Read More<img src="images/arrow.png"></a>
						</div>
					</li>
				</ul>
			</div>
		</div>


Solution

  • Try this

    .themeDesignicons {
    width: auto;
    margin: 0 auto;
    text-align: center;
    }