• 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

    • Just because Windows 10 will stop receiving updates doesn't mean your Windows 10 installed there will stop working. There are people with iPhone 8/9/10 that are still working, even without updates. There are people with Android 8/9/10 that are still working even without receiving any updates for over 5 years. There are people with Windows 7 and 8 that are still working for over 10 years. And most people install Windows and disable updates, so there are still a lot of people running Windows 10 without improvements and security updates for over 10 years.
    • Windows 10 EOL is coming, so how many is “forced”? (to be prepared and not wait until the last moment in October?)
    • I guess more Windows users are switching on their desktops/laptops than people buying new Steam Decks. I wouldn't be surprised. Deck doesn't have the mainstream appeal of other handhelds, usually people who would want one already have one. Glad to see Linux go up!
    • Any news about Windows and Microsoft always brings up crazy people saying; - Windows 11 is terrible, it destroys my hardware, it had sex with my wife, it told the FBI that I visit shemale sites, it collects my data where I get illegal anime. Never use Windows 11, go for Linux and it will never have sex with your wife.
    • QOwnNotes 25.6.0 by Razvan Serea QOwnNotes is a open source (GPL) plain-text file notepad with markdown support and todo list manager for GNU/Linux, Mac OS X and Windows, that (optionally) works together with the notes application of ownCloud (or Nextcloud). So you are able to write down your thoughts with QOwnNotes and edit or search for them later from your mobile device (like with CloudNotes) or the ownCloud web-service. The notes are stored as plain text files and you can sync them with your ownCloud sync client. Of course other software, like Dropbox, Syncthing, Seafile or BitTorrent Sync can be used too. Features: the notes folder can be freely chosen (multiple note folders can be used) sub-string searching of notes is possible and search results are highlighted in the notes application can be operated with customizable keyboard shortcuts external changes of note files are watched (notes or note list are reloaded) older versions of your notes can be restored from your ownCloud server trashed notes can be restored from your ownCloud server differences between current note and externally changed note are showed in a dialog markdown highlighting of notes and a markdown preview mode notes are getting their name from the first line of the note text (just like in the ownCloud notes web-application) and the note text files are automatically renamed, if the the first line changes compatible with the notes web-application of ownCloud and mobile ownCloud notes applications compatible with ownCloud's selective sync feature by supporting an unlimited amount of note folders with the ability to choose the respective folder on your server manage your ownCloud todo lists (ownCloud tasks or Tasks Plus / Calendar Plus) or use an other CalDAV server to sync your tasks to encryption of notes (AES-256 is built in or you can use custom encryption methods like Keybase.io (encryption-keybase.qml) or PGP (encryption-pgp.qml)) dark mode theme support theming support for the markdown syntax highlighting all panels can be placed wherever you want, they can even float or stack (fully dockable) support for freedesktop theme icons, you can use QOwnNotes with your native desktop icons and with your favorite dark desktop theme support for hierarchical note tagging and note subfolders support for sharing notes on your ownCloud server portable mode for carrying QOwnNotes around on USB sticks Evernote import QOwnNotes is available in many different languages like English, German, French, Polish, Chinese, Japanese, Russian, Portuguese, Hungarian, Dutch and Spanish Changes in QOwnNotes 25.6.0: QOwnNotes now builds with with Botan 3, when built with the system Botan library (cmake build parameter -DBUILD_WITH_SYSTEM_BOTAN=ON), because of the end of life of Botan 2 (for #2786) Keep in mind that Botan 3 needs C++20, which causes issues on Qt5 QMake and Qt5 will still use the internal Botan 2 amalgamation Creating an amalgamation Botan 3 did work, but caused major issues with various build processes The filename in checksum files of the Qt6 AppImages in the releases on GitHub was fixed (for #3286) Download: QOwnNotes 25.6.0 | 37.3 MB (Open Source) Download: QOwnNotes for Other Operating Systems View: QOwnNotes Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Epaminombas earned a badge
      Week One Done
    • Week One Done
      Prestige Podiatry Care earned a badge
      Week One Done
    • Week One Done
      rollconults earned a badge
      Week One Done
    • One Month Later
      lilred1938 earned a badge
      One Month Later
    • Week One Done
      lilred1938 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      148
    2. 2
      Xenon
      132
    3. 3
      ATLien_0
      123
    4. 4
      +Edouard
      103
    5. 5
      snowy owl
      96
  • Tell a friend

    Love Neowin? Tell a friend!