Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using two CSS classes on one element [duplicate]

Tags:

css

class

What am I doing wrong here?

I have a .social div, but on the first one I want zero padding on the top, and on the second one I want no bottom border.

I have attempted to create classes for this first and last but I think I've got it wrong somewhere:

.social {     width: 330px;     height: 75px;     float: right;     text-align: left;     padding: 10px 0;     border-bottom: dotted 1px #6d6d6d; }  .social .first{padding-top:0;}  .social .last{border:0;} 

And the HTML

<div class="social" class="first">     <div class="socialIcon"><img src="images/facebook.png" alt="Facebook" /></div>     <div class="socialText">Find me on Facebook</div> </div> 

I'm guessing it's not possible to have two different classes? If so how can I do this?

like image 404
Francesca Avatar asked Aug 11 '12 23:08

Francesca


People also ask

Can an element have 2 CSS classes?

To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.

Can we use two classes in same element?

Multiple classes can be applied to a single element in HTML and they can be styled using CSS.

Can you add 2 classes to a div?

Multiple ClassesHTML elements can belong to more than one class. To define multiple classes, separate the class names with a space, e.g. <div class="city main">. The element will be styled according to all the classes specified.


2 Answers

If you want two classes on one element, do it this way:

<div class="social first"></div> 

Reference it in css like so:

.social.first {} 

Example:

https://jsfiddle.net/tybro0103/covbtpaq/

like image 80
tybro0103 Avatar answered Oct 07 '22 04:10

tybro0103


You can try this:

HTML

<div class="social">     <div class="socialIcon"><img src="images/facebook.png" alt="Facebook" /></div>     <div class="socialText">Find me on Facebook</div> </div> 

CSS CODE

.social {   width:330px;   height:75px;   float:right;   text-align:left;   padding:10px 0;   border-bottom:dotted 1px #6d6d6d; } .social .socialIcon{   padding-top:0; } .social .socialText{   border:0; } 

To add multiple class in the same element you can use the following format:

<div class="class1 class2 class3"></div> 

DEMO

like image 33
Codegiant Avatar answered Oct 07 '22 03:10

Codegiant