Question

How to exclude some inner divs/elements from inherting parent css property

Asked by: Maverick_Cool

I have div say with class name "xMain"
<div class="xMain>
     <div></div>
.....
     <div></div>
</div>
In my css:
i have code
.xMain div{
    float:left;
    display:inline;
       overflow: hidden;
}

I want to prevent some particular div inside xMain from getting these properties.
how to do that through css or something, I can't change this format because there lot places where it will effect,there only few div(that too sometimes) , which will need to by pass this.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-28 at 14:57:55ID24852875
Tags

css

Topics

Jquery

,

Cascading Style Sheets (CSS)

,

Extensible HTML (XHTML)

Participating Experts
2
Points
100
Comments
28

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CSS - Div Overflow to the left
    Is there a way to make an image inside of a div overflow to the left? Like, If you have an image that is 200px wide, and it's inside a div that's 100px wide, and this div has it's overflow property equal to hidden, the div will mask the image, only displaying 100 horizaontal ...
  2. overflow:hidden and div's wrapping
    I have a container with some divs in it. I want the divs to NOT wrap, but just be hidden when they reach the end of the parent div. I can't seem to prevent them from wrapping. Ideas? What I want is: ---------------------------------- | nested 1 | nested 2 | neste| ------...
  3. CSS divs not taking heigth inside div
    I need some help please. I can not figure out why the menu DIVs are not the same height as their parent DIV. I need them to be buttons the same height as their parent. This whole bar floats to the bottom of the browser and the buttons float to the right. I am sure I have styl...
  4. Floating DIVs are ignoring CSS padding attribute
    I have two DIVs floating side-by-side in a container DIV. I cannot, for the life of me, figure out why the leftmost DIVs will pick up the PADDING attribute from the CSS, while the DIVs on the right are ignoring the PADDING. I'm calling the same class for both the left and r...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: thehagmanPosted on 2009-10-28 at 15:11:43ID: 25688853

If you can mark the special divs as
<div class="foo">
then
.xMain div.foo {
float: none;
display: block;
overflow: visible;
}
should set things to default.

 

by: Maverick_CoolPosted on 2009-10-28 at 15:17:58ID: 25688891

Well, I though of that, There will other upper elemnts which may have impact, hence just dont  want .xMain div to apply to to these element, rest all it should inherit

 

by: qaljimmyPosted on 2009-10-29 at 02:45:54ID: 25691874

What you're trying to accomplsh can't be done without using a more specific selector. You need to find a way to mark with a class name or a specific attribute, but you can only use attribute selectors for IE6+ the exact div's you want to keep the default styles or overwrite the styles defined by you with .xMain div { }.

 

by: Maverick_CoolPosted on 2009-10-29 at 02:46:45ID: 25691877

what about fire fox and safari

 

by: Maverick_CoolPosted on 2009-10-29 at 02:47:23ID: 25691881

If it is possible FF >2.0, give some samples.

 

by: qaljimmyPosted on 2009-10-29 at 03:04:01ID: 25691978

Try this:

<style type="text/css"/>
.xMain {background-color:#fc0; display:block; overflow:hidden;}/*--CSS for emphasizing purpose--*/
.xMain div{float:left;display:inline;overflow: hidden; /*--your original CSS--*/
background-color:#f00; margin:5px;/*--CSS for emphasizing purpose--*/
}
.xMain div[title~="marker"] {background-color:transparent;}
.xMain div.markerClass {background-color:transparent;}
</style>


     
###

     
###

      
##

      
##

      
##

      
##

      
##



Technically, all child div's should have a red background and a margin of 5 px. To overwrite that you either need to mark the divs you want excluded from that selector with a class name or an attribute. In the example above, class name would be "markerClass" and the attribute name would have to contain the word "marker".
Should work for most browsers except IE6 and below, also some older versions of Opera.
You can read more here http://css.maxdesign.com.au/selectutorial/selectors_attribute.htm

The class name approach would be easiest

 

by: qaljimmyPosted on 2009-10-29 at 03:05:13ID: 25691983

Err, tags got replaced in comment so here goes the HTML structure

<div class="xMain">
	<div title="marker attribute">###</div>
	<div class="markerClass">###</div>
	<div>##</div>
	<div>##</div>
	<div>##</div>
	<div>##</div>
	<div>##</div>
</div>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: Maverick_CoolPosted on 2009-10-29 at 03:07:35ID: 25691998

can you provide a small sample , with full code.

 

by: Maverick_CoolPosted on 2009-10-29 at 03:09:51ID: 25692010

with class name approach

 

by: qaljimmyPosted on 2009-10-29 at 03:17:15ID: 25692040

I did. I assume you're not inserting the DIV elements on your own and you have some script that generates that markup. In the above snippet, for the DIV elements you want to rewrite CSS properties, you need to alter the script so that whenever it's about to generate a DIV element that you don't want to inherit the properties, you just create a conditional to append  class="markerClass". Then the CSS code provided above should do the rest.

 

by: Maverick_CoolPosted on 2009-10-29 at 03:25:32ID: 25692067

Its working firefox, but not in I.E8

 

by: Maverick_CoolPosted on 2009-10-29 at 03:28:09ID: 25692084

and ~= does not work, it only takes =

 

by: qaljimmyPosted on 2009-10-29 at 03:31:18ID: 25692108

It works in IE8 as well. The fact that the 2nd element has a transparent background proves it. The attribute approach (first element) seems I was wrong about. IE8 is unable to figure out what the CSS says.

 

by: Maverick_CoolPosted on 2009-10-29 at 03:34:34ID: 25692130

I am looking for a not equal to select for id or classname, is it possible.

 

by: qaljimmyPosted on 2009-10-29 at 03:35:54ID: 25692143

You mean you want to generate a class for the elements you actually WANT to inherit the properties ?

 

by: Maverick_CoolPosted on 2009-10-29 at 03:40:19ID: 25692172

see its like this:

in css,
I want specify like this

.xMAin div[class or id not equal to maker] : {......}

 

by: Maverick_CoolPosted on 2009-10-29 at 03:42:33ID: 25692184

I want specify like this

.xMAin div[class or id not equal to maker]   {......}

 

by: qaljimmyPosted on 2009-10-29 at 03:53:06ID: 25692238

If we're talking about CSS Level 3, there's the :not selector available, but it's poorly supported across browsers. Firefox, Chrome and Safari (not sure about this one) have support for it.
Here's what I suggest though, because we seem to be drifting away from the problem.
From what I understand, you wish to style only certain < div > tags nested within the < div > tag that has a class "xMain".
Say you have the markup generated something like the snippet below. What you need to do in this case is choose one of the following:
- either you style the elements that actually need styling by specifing the class name:
.xMain div.iCanInheritTheStyle {...}
- or you can style the child div elements globally by using your original css
.xMain div {...}
and then revert back the styles to the default values for the elements you wish to be left alone, by using:
.xMain div.keepMeOnDefaultStyles {...}

Either solution requires you to generate a class name on one of the types of elements. Else there's no way for the CSS or the browser for that matter to figure out which element you're trying to tell him to not style.

<div class="xMain">
	<div class="iCanInheritTheStyle">###</div>
	<div class="keepMeOnDefaultStyles">###</div>
	<div class="iCanInheritTheStyle">##</div>
	<div class="iCanInheritTheStyle">##</div>
	<div class="iCanInheritTheStyle">##</div>
	<div class="iCanInheritTheStyle">##</div>
	<div class="keepMeOnDefaultStyles">##</div>
</div>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: Maverick_CoolPosted on 2009-10-29 at 04:00:28ID: 25692276

See the actuall problem:

Most of inner divs will follow

.XMain div {}


but there are few, which will inherit from other top order element but not .xMain din one,

The cascading effect of .xMain div, is causing problem for this div,
hence I dont want these few to get .xMain div values, but on ther other hand i dont know the css values of these few divs , it will be inherited from some top order element, which i cant decode.

 

by: qaljimmyPosted on 2009-10-29 at 04:09:00ID: 25692327

I see. In that case easiest way is still to generate some class for "these few div's" and when you wish to ignore them, you actually overwrite their values (hopefully you know which css properties get changed) by using a more specific selector, using the generated class name ( for example i called it "keepMeOnDefaultStyles").

If that still doesn't work, you'd have to resort to javascript and more specifically the jQuery library, which has a very good support for selectors. You could use that to fix the CSS for those elements. (Also has a good implementation of :not selectors)

 

by: Maverick_CoolPosted on 2009-10-29 at 04:10:54ID: 25692337

Can give example

 

by: Maverick_CoolPosted on 2009-10-29 at 04:11:18ID: 25692338

The jquery not selector.

 

by: Maverick_CoolPosted on 2009-10-29 at 04:13:46ID: 25692353

Do you know, php or have mac installation. if so I will upload my code and increase thepoint.

 

by: Maverick_CoolPosted on 2009-10-29 at 04:14:39ID: 25692358

do you have Mac OS x 10.6 with firefox 2 and safari

 

by: qaljimmyPosted on 2009-10-29 at 04:33:07ID: 25692465

I'm running on Win Vista atm, I don't own a Mac, but at home I have a unix machine which can pretty much replicate your computing environment.
Anyway, here's a link about how to use the hasClass method
http://docs.jquery.com/Traversing/hasClass (could be useful for your purpose)
and the " :not() " selector http://docs.jquery.com/Selectors/not#selector

Explanations should be pretty straight forward and hopefully suit your purpose.

 

by: Maverick_CoolPosted on 2009-10-29 at 04:37:26ID: 25692492

how to do we implement .xMain div not here(jquery)

 

by: qaljimmyPosted on 2009-10-29 at 04:48:26ID: 25692561

Hopefully i remembered it right. Here goes.

/*selector returns a collection of elements therefore the need to loop 
 *through each one that the selector has to apply the styles to
*/
$(document).ready(function(){
	$('.xMain div:not(.excludedClass)').each(function(){
		$(this).css({
		'float':'left',
		'display':'inline',
		'overflow':'hidden'
		});
	});
});
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window

 

by: Maverick_CoolPosted on 2009-11-13 at 06:28:21ID: 31647251

sorry, I was out town so couldnt follow up.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...