473,378 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

CSS @import Rules

Hello,

If you have a main style sheet (main.css) that imports, let's say, 2 others, like so:

@import url(first.css);
@import url(second.css);

would anything on first.css override repeated values in main.css? And then second.css would override both first.css and main.css?

I'm curious because I read that the last imported style sheet has the last say, but I have a main style sheet that imports a reset one (resets all margins and padding to 0). All of my margins and padding show up properly in multiple browsers, but I would think that the reset.css rules would override my given margins because it's imported last.

Or does this only apply to the imported style sheets and not the main linked one?
Apr 26 '07 #1
8 5252
drhowarddrfine
7,435 Expert 4TB
Yes, the last imported stylesheet overrides previous imported rules. The order of specifying them is important and determines which is applied first.
Apr 26 '07 #2
Ok, so my main.css imports my reset.css (main.css has padding & margins and the reset.css resets all padding & margins to 0). So the reset.css should override the main.css, right? But it doesn't it any of the browsers I've tested it in (Safar, Opera (Mac/Win), FF (Mac/Win), IE).
Apr 27 '07 #3
drhowarddrfine
7,435 Expert 4TB
If the import rule is the first line then that is looked at first, but if a property is changed further down by something else then that's what you get. Am I following you correctly?

It's like an "insert" in a word processor. @import is saying "insert this other code here".
Apr 27 '07 #4
iam_clint
1,208 Expert 1GB
computers read top to bottom left to right just like (most) people do.


so say in your first css you have

.blah { margin-left: 0px; }

now you import another that says

.blah { margin-left: 1px; }


the margin-left will be 1px because it always reads top to bottom left to right.
Apr 27 '07 #5
I'm still confused.

Let's say I have a main.css that looks like this:
Expand|Select|Wrap|Line Numbers
  1. @import url(reset.css);
  2. @import url(ieonly.css);
  3.  
  4. div#container  { margin: 20px auto; width: 600px; }
reset.css
Expand|Select|Wrap|Line Numbers
  1. div  { margin: 0; padding: 0; }
and the ieonly.css has a bunch of hacks in it.

Do the rules in the main.css override the imports because they come after imports in the flow of the file, or does the computer read all of main.css first, and then override those rules with the rules from the imports?

As of right now, I have my css set up like the example, and it works properly. I'm just trying to figure out the correct way.
Apr 30 '07 #6
iam_clint
1,208 Expert 1GB
ok so you have an import
main.css
and another ie.css

it reads all of main.css then reads ie.css second replacing anything styles that are different in main.css

its like this

c = c
c = b
c = a
c = d
c = f
c = c
c = 500
c = 2020


c will be 2020 no matter what those others say because it reads top to bottom left to right
Apr 30 '07 #7
In my html pages, I link to main.css and then from there the other style sheets are imported.

So when the @import for reset.css is at the top, the computer sort of inserts all of it's rules there and then travels down the rest of main.css, overriding anything that repeats? What about an an ie hacks css? Will is still work properly even if it comes before the main.css?
Apr 30 '07 #8
drhowarddrfine
7,435 Expert 4TB
Yes to both.
May 1 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Olivier Noblanc ATOUSOFT | last post by:
Hello, When i want to import a .py fire from another subdirectory i make import inc/setupxml but that make me an error message.
1
by: Joachim Spoerhase | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I am a XSLT-beginner and i read the XSLT-recommendation of the W3C through. But I did'nt really understand section 5.5 of the latest...
4
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not...
3
by: ninrulz | last post by:
I will try to explain my situation. I know that it is hard to offers solutions without fully understanding what people would like to achieve. I receive 2 csv files every month. The csv files...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
10
by: BostonNole | last post by:
Using Visual Studio 2005, .NET 2.0 and VB.NET: I am looking for the fastest possible way to import a very large fixed width file (over 6 million records and over 1.2 GB file size) into a...
3
by: Markus | last post by:
Hello While googling for this topic I found lots of advice on how to use @media rules to _hide_ stuff from Mac IE. Anyway, actually _using_ @media to write media specific CSS for both Win and...
0
by: Gabriel Genellina | last post by:
En Fri, 25 Apr 2008 15:03:18 -0300, Luca <lucafbb@gmail.comescribió: The short answer is: don't do that! __init__.py may import any module, but other modules in the package should not import...
1
jbt007
by: jbt007 | last post by:
Hi All, I am using the following code to import a spreadsheet into my Access 2003 tblWeekly table: DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "tblweekly", strOutFile, True,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.