Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2012, 06:26 PM   PM User | #1
3magdnim
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
3magdnim is an unknown quantity at this point
Problem using multiple classes within selectors

Hey everyone,

I'm trying to learn to create a page that looks like this:

The problem is, I've ended up with this

I know it has to do with using multiple classes within selectors. I thought I was doing it right and reviewed the code several times without being able to find the problem. Could someone please review my code and see if they can tell me what I'm doing wrong? Thank you in advance!

HTML
Code:
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0" />
		<title>Sample Site</title>
		<link rel="stylesheet" type="text/css" href="css/screen_styles.css" />
		<link rel="stylesheet" type="text/css" href="css/screen_layout_large.css" /> 
		<link rel="stylesheet" type="text/css" media="only screen and (min-width:50px) and (max-width:500px)" href="css/screen_layout_small.css" />
		<link rel="stylesheet" type="text/css" media="only screen and (min-width:501px) and (max-width:800px)" href="css/screen_layout_medium.css" /> 
		<!--[if lt IE 9]>
		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
	</head>
	<body>

		<div class="page">

			<header>
				<a class="logo" href="#"></a>
			</header>

			<article>
				<h1>Welcome</h1>
				<p>Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor 		incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 			nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <a 	href="#">Duis aute irure</a> dolor in reprehenderit in voluptate velit esse 		cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 		proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
			</article>

			<div class="promo_container"></div>

				<div class="promo one">
					<div class="content">
						<h3>Promo Heading Here</h3>
						<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
						<p><a class="cta" href="">Visit our blog</a></p>
					</div>
				</div>

				<div class="promo two">
					<div class="content">
						<h3>Promo Heading Here</h3>
						<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit est laborum.</p>
						<p><a class="cta" href="">Read the article</a></p>
					</div>
				</div>

				<div class="promo three">
					<div class="content">
						<h3>Promo Heading Here</h3>
						<p>Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor inci did unt.</p>
						<p><a class="cta" href="">Learn more</a></p>
					</div>
				</div>

				<div class="clear-fix"></div>

			<nav>
				<a href="#">About Us</a>
				<a href="#">Services</a>
				<a href="#">Portfolio</a>
				<a href="#">Contact Us</a>
			</nav>

			<footer>
				&copy; Johnny Design
			</footer>


		</div>

	</body>
</html>
SCREEN_STYLES.CSS
Code:
@charset "UTF-8";

/* Global Content Formatting and Styles */

body {
	color: #575c7a;
	line-height: 1.5em;
	font-family: arial;
	font-size: 14px;
	background: #515673 url(../img/background_gradient.jpg) repeat-x 0px 0px;
}

.page {
	max-width: 980px;
	margin:0px auto 0px auto;
	position: relative;
	background-color: #fff;
}

h1 { font-size: 2em; font-weight: normal; color: #a6430a; margin: 0 0 .5em 0; }
h2 { font-size: 1.7em; margin: 0 0 1em 0; }
h3 { font-size: 1.5em; margin: 0 0 1em 0; }
p { margin: 0 0 .75em 0; }
a { color: #de9000; }
a:hover { color: #009eff; }

footer { font-size: .85em; color: #9ba0bd; background-color: #575c7a; padding: 10px 10px 10px 10px; }

a.cta {
	text-transform: uppercase;
	font-size: .9em;
	font-weight: bold;
	text-decoration: none;
	margin: .5em 0 0 0 ;
	padding:0px 12px 0px 0px;
	background: url(../img/cta_arrow.png) no-repeat right 0px;
}
a.cta:hover { background-position: right -50px; }

.promo h3 { font-size: 1.1em; margin 0; }
.promo p { line-height: 1.2em; font-size: .9em; margin-bottom: .5em; }

.promo { background-repeat: no-repeat; }
.promo.one { background-image: url(../img/promo_1.jpg); }
.promo.two { background-image: url(../img/promo_2.jpg); }
.promo.three { background-image: url(../img/promo_3.jpg); }

nav a {
	color: #f5a06e;
	text-transform: uppercase;
	text-decoration: none;
	display: inline-block;
	font-weight: bold;
	font-size: .9em;
}

nav a:hover { color: #fff; }

.clear-fix { clear: both; line-height: 1px; }

SCREEN_LAYOUT_LARGE.CSS
Code:
@charset "UTF-8";

/* Layout (global rules for all sizes) */

body { margin: 0; padding: 0; }

header a.logo{
	display: block;
	position: absolute;
	background-position: 0px 0px;
	background-repeat: no-repeat;	
}

nav {
	width: 100%;
	display: block;
	position: absolute;
	border-color: #a6430a;
}

/* Layout Large Screens (default for older browsers) */

header { 
	height: 275px;
	background: url(../img/banner_large.jpg) no-repeat right 0px;
}

header a.logo {
	width: 150px;
	height: 85px;
	top: 28px;
	right: 30px;
	background-image: url(../img/logo_large.png); 
}

article { padding: 60px 20px 10px 20px; }

.promo_container { padding: 0px 0px 15px 20px; }

.promo_container .promo {
	 width: 33%; float: left;
background-position: 0px 3px;
}

.promo_container .promo .content { padding: 0px 30px 0px 70px; }

nav { top: 275px; }
nav a { margin: 12px 0px 10px 20px; }

@media screen and (max-width:990px) {
	footer { padding-left: 20px;}
}
3magdnim is offline   Reply With Quote
Old 11-08-2012, 08:35 PM   PM User | #2
harvs899
New Coder

 
Join Date: Oct 2012
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
harvs899 is an unknown quantity at this point
Try using the <figure> and <figcaption> elements and then floating your promo items to the left

Last edited by harvs899; 11-08-2012 at 08:39 PM..
harvs899 is offline   Reply With Quote
Old 11-08-2012, 10:39 PM   PM User | #3
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
I just bounced over your code quickly, but this probably won't work:

Code:
.promo { background-repeat: no-repeat; }
.promo.one { background-image: url(../img/promo_1.jpg); }
.promo.two { background-image: url(../img/promo_2.jpg); }
.promo.three { background-image: url(../img/promo_3.jpg); }
.. should be something like ..

Code:
.promo { background-repeat: no-repeat; }
.one { background-image: url(../img/promo_1.jpg); }
.two { background-image: url(../img/promo_2.jpg); }
.three { background-image: url(../img/promo_3.jpg); }
At least, I think it does; I'm guessing at what you're trying to achieve. You are adding multiple classes in your HTML — as separated by spaces — but you don't need to reference the classes you're using together in the CSS.

Last edited by Custard7A; 11-08-2012 at 10:42 PM..
Custard7A is offline   Reply With Quote
Old 11-08-2012, 10:43 PM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Quote:
Originally Posted by Custard7A View Post
You are adding multiple classes in your HTML — as separated by spaces — but you don't need to reference the classes you're using together in the CSS.
Besides that, what the OP wrote is perfectly legal and should work. However, I see this:
Code:
<div class="promo_container"></div>
	<div class="promo one">
…
…
So this: .promo_container .promo {…} will never apply since the promos are not descendants of promo_container.
__________________
Don’t click this link!

Last edited by VIPStephan; 11-08-2012 at 10:45 PM..
VIPStephan is offline   Reply With Quote
Users who have thanked VIPStephan for this post:
3magdnim (11-09-2012)
Old 11-08-2012, 10:51 PM   PM User | #5
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
Quote:
Originally Posted by VIPStephan View Post
Besides that, what the OP wrote is perfectly legal and should work.
Huh, so .class.class is actually valid? Learned my something new for the day.
Custard7A is offline   Reply With Quote
Old 11-08-2012, 11:12 PM   PM User | #6
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Yes, if you have, for example:
Code:
<div class="message warning"></div>
<div class="message error"></div>
<div class="alert warning"></div>
<div class="alert error"></div>
And you want do style “messages” and “alerts” differently and have different styles for “warnings” and “errors” each you need a way to differentiate:
Code:
.message.warning {…style 1…}
.alert.warning {…style 2…}
.message.error {…style 3…}
.alert.error {…style 4…}
… because just “warning” or “error” wouldn’t do it.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Users who have thanked VIPStephan for this post:
Custard7A (11-08-2012)
Old 11-09-2012, 02:52 PM   PM User | #7
3magdnim
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
3magdnim is an unknown quantity at this point
Thanks everyone for your replies and thank you VIPStephan for solving my problem...code works great now!
3magdnim is offline   Reply With Quote
Old 11-09-2012, 09:14 PM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Custard7A View Post
Huh, so .class.class is actually valid? Learned my something new for the day.
It doesn't work in antiquated versions of Internet Explorer though.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Tags
html css

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:11 PM.


Advertisement
Log in to turn off these ads.