• 0

"default" CSS code for every project


Question

12 answers to this question

Recommended Posts

  • 0

there's no "default" stylesheet that I use per-se, but what I do is I take the stylesheet of my previous project then blank out everything that doesnt apply, and start from there, saves me time from re-typing the styles that I will use later on. There are a few common styles that could be found in most of my stylesheets:

* {
 margin:0;
 padding:0;
}

This is in EVERY one of my recent stylesheets. Resets all margin and padding back to zero, goes BEFORE all other styles. This saves a LOT of time debugging because it overrides all default margins and paddings of different browsers.

img {
 border:0;
}

Removes all image boarders.

html,body {
 color:#000;
 font:86% Calibri, Tahoma, Verdana, sans-serif;
 text-align:justify;
}

Default body styles. There are other attributes in here that vary depending on the design.

a {}, a:hover {}, h1,h2,h3,h4,h5,h6 {}, p {}

These are usually found in my stylesheets, they define the basic elements' styles. Although the attributes vary depending on design.

  • 0

I use the following:

The font and colouring different depending on the site, but it's always there as a "global" setting.

html, body, form, fieldset, h1, h2, h3, h4, h5, h6, p, pre, blockquote, ul, ol, dl, address {
	margin: 0;
	padding: 0;
}

body {
	font: normal 12px "Calibri", Arial, Helvetica, sans-serif;
	background: #FFFFF;
	color: #00000;
}

ul,li {
	list-style-type: none;
}

hr {
	clear: both;
	visibility: hidden;
}

fieldset, img {
	border: 0;
}

  • 0
  Primexx said:
...

img {
  border:0;
 }

Removes all image boarders(sic).

Strictly an image shouldn't have the border attribute anyway as it is deprecated (as that should be applied by styling), and it is only when it is wrapped by a hyperlink that a border will be applied (to denote its "clickability"), which incidentally aids accessibility, so I always have:

a img { border-style: none; }

at the top of my stylesheets.

I also tend to wrap styles in their relevant media type as a means of stopping older browsers attempting to (incorrectly) render pages using them:

@media all{
/* all mediatype selectors here such as the global no-margin etc. */
}

@media screen{
/* screen selectors here */
}

Other tricks to lock out older browsers include using the @imports rule and using a media attribute in the <link /> / <style></style> tags.

Edited by mrbester
  • 0
  jukeboxhero52 said:
I don't fully follow how it goes against the guidelines of semantics...seems to make sense to me.

k, to elaborate, semantic markup is part of the whole separation of content and style principle that aims to make it both easier for the coder to update websites and also for the reader to better understand what each element actually is (benefits screen readers mostly). It basically means that you should refrain from giving IDs or CLASSes that describe how it looks, but rather what it does. For instance a footer could be cleared, but instead of giving it class="clear" (or id="clear" for that matter) the better way would be to give it id="footer" (assuming there's only 1 footer) and then clear the footer. But what about redundant styles? Well if you have 3 elements that share a style, instead of giving them all the same class, name them according to what they do, like say #content, #navBar, #linkBar (note: leftBar and rightBar are not good either, because "left" and "right" describe how it looks) and then just put #content, #navBar, #linkBar {styles_here;} in the styleheet. Even in my example the word "Bar" suggests a certain look, and even that should be avoided, leaving something like #nav and #links would be sufficient. Yes it's a very tedious principle and very easy to be forgotten or overlooked, I make the same mistakes sometimes too, but at least try to separate the content and style whenever you can, instead of using obvious bad practise like that section suggests.

  • 0

speaking of classes, you can also assign multiple classes to the same element, and then reference them that way (e.g. <span class="alert important"> then do .alert {} and .important {})

The aim is of course, to stop describing how the document looks in HTML, and instead describe what the document means (e.g. you can include a image of a mathematical equation, or insert some real MathML and then it becomes a much richer source of information)

Same thing could be accomplished with SVG and SMIL (e.g. can search google for subtitles in videos or such), anyway, gone way off topic here.

Default styles i try to use are basically setting a set of fonts i like (with a fallback like sans-serif of course), and a background colour, where possible i use the browser defaults

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • lol See... one is only 100% when it's by itself. I live for exceptions to the rule... our talk point was in reference in comparing Vista (not SP1/2) release vs. 7. Any OS will run stable once enough work has been put into it... hell, even Windows 95 had six versions before she was finally complete(d)... just about, what, six or seven months before 98 became available?
    • 3uTools 3.26.007 by Razvan Serea 3uTools is a powerful iOS management tool that allows users to efficiently handle their iPhone or iPad without relying on iTunes. It offers seamless data transfer, one-click backup and restore, firmware updates, and a built-in file explorer for easy access to system files. Users can also manage apps, contacts, and media, including photos, videos, and ringtones, all within a simple and intuitive interface. For optimization and maintenance, 3uTools provides battery health monitoring, real-time device information, and system cleanup tools. It also includes features like screen recording, video conversion, and iCloud backup management, making it an essential tool for iOS users looking for greater control over their devices. Key features of 3uTools: iOS device management App installation and removal Firmware downloads and updates Backup and restore functions Data transfer between iOS and PC Ringtone creation Custom wallpaper management Device flashing File system explorer Battery health monitoring Screen capture and recording Video and photo management iCloud backup support Flashing and restoring iOS without data loss 3uTools 3.26.007 changelog: Easy Flash supports iOS 26.0 flashing. Optimized Virtual Location. Fixed some known bugs. Download: 3uTools 3.26.007 | 186.0 MB (Freeware) Download: 3uTools 32-bit | 192.0 MB View: 3uTools Home Page | macOS | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • The development time of this Operating System will have competition with the development time of Star Citizen 😂
    • I saw the 300 in the image and thought it was the number of cores! 🤣
    • Threads is getting a feature Reddit has had for nearly a decade by David Uzondu Back in January, reverse engineer Alessandro Paluzzi (@alex193a) first uncovered that Threads was working on spoiler tags. Now, Meta CEO Mark Zuckerberg (@zuck) has made it official: the feature is in testing. It is a straightforward tool for hiding content, especially text, behind a block that you have to click to reveal, perfect for discussing the ending of your favorite show without ruining the experience for others. It is also, notably, a feature that Reddit has had since January 2017. https://www.threads.com/@zuck/post/DK-BydcJHkF For a platform aiming to be a town square for public discourse, not having a native way to handle spoilers is a small but noticeable handicap for communities focused on pop culture. In a press release, Meta told TechCrunch that popular shows like The Last of Us trended heavily on the app, which the company frames as a sign of a "growing community of entertainment and pop culture enthusiasts." The new feature also supports images so that you can hide shocking visuals or text-filled screenshots. From the images Meta shared, it seems to work just as Paluzzi uncovered months ago. Users with access to the test can highlight text in the composer, and a "mark spoiler" option will appear in a small menu. This method is purely button-based, unlike on Reddit, where users have the option of either using a similar editor button or manually typing out the markdown command >!like this!< to hide their text. This update does not exist in a vacuum. After several months of feeling incomplete, the platform has been getting features that users have actually been asking for. We have seen this with the recent DMs feature, also in testing, which finally gives people a way to have private chats without jumping over to other platforms like Instagram.
  • Recent Achievements

    • Explorer
      treker_ed went up a rank
      Explorer
    • Apprentice
      CHUNWEI went up a rank
      Apprentice
    • Veteran
      1337ish went up a rank
      Veteran
    • Rookie
      john.al went up a rank
      Rookie
    • Week One Done
      patrickft456 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      659
    2. 2
      ATLien_0
      271
    3. 3
      +FloatingFatMan
      176
    4. 4
      Michael Scrip
      157
    5. 5
      Steven P.
      136
  • Tell a friend

    Love Neowin? Tell a friend!