Hello I'm just starting with css and I see people in videos and such already have css code written before they write a single line of code like:
body {
padding:0;
margin:0;
}
this is like a really simple example they write like body,div,table..etc like the a:active and stuff like that but like in like really long code they even add a selected attribute so when you selected any words on the page the background and color changes I know this depends from one developer or another but is there a really basic piece of code that I can start with?
People prefer different ways of working with CSS, there is no right or wrong way. But there is certainly ways to get a good head start with your browser resets.
There are a few ways to play it, you can either use a reset or normalise your code to fit the different browsers.
A reset will make everything behave in streamlined way across each browser, whereas normalising your css will make browsers render all elements more consistently and in line with modern standards.
Rememeber there is no right or wrong way to approach this.
Eric Meyes CSS Reset
Normalize.css
it is all just style and opinion, but this is often used and resets just about everything (so you'd have to create all your styles yourself, instead of using browser defaults).
html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}
body {
line-height:1;
}
article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section {
display:block;
}
nav ul {
list-style:none;
}
blockquote, q {
quotes:none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content:'';
content:none;
}
a {
margin:0;
padding:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}
/* change colours to suit your needs */
ins {
background-color:#ff9;
color:#000;
text-decoration:none;
}
/* change colours to suit your needs */
mark {
background-color:#ff9;
color:#000;
font-style:italic;
font-weight:bold;
}
del {
text-decoration: line-through;
}
abbr[title], dfn[title] {
border-bottom:1px dotted;
cursor:help;
}
table {
border-collapse:collapse;
border-spacing:0;
}
/* change border colour to suit your needs */
hr {
display:block;
height:1px;
border:0;
border-top:1px solid #cccccc;
margin:1em 0;
padding:0;
}
input, select {
vertical-align:middle;
}
Related
I have an element like:
<a id='a_id' class='a_class'>Next</a>
The element shows in green, underlined.
When I hover over the element, it changes to a lighter green, not underlined (which is fine).
When I click, during the mouse button down nothing changes.
When I release the mouse button, the element changes briefly showing a green background and goes back to lighter green, not underlined.
How can I change the CSS to prevent the change when I release the mouse button?
I tried the following CSS:
.a_class {
cursor:pointer;
outline:none;
text-decoration:none;
background:#fff;
}
Thanks.
UPDATE #1 - using .a_class:active
I added the following CSS:
.a_class:active {
outline:none;
text-decoration:none;
background:#fff;
color:red;
}
I added the color:red to confirm the CSS was being applied.
When I press down the mouse button, the text color changes to red. And when I release the mouse button, the background flashes in green for a second.
Any other suggestion?
Thanks.
UPDATE #2 - adding full CSS of the link
When I inspect the page with firebug the element has the following CSS:
.a_class {
background:#FFFFFF;
cursor:pointer;
outline:none;
text-decoration:none;
}
a {
color:#24890D;
text-decoration:none; <- crossed out
}
.entry-content a, .entry-summary a, .page-content a, .comment-content a {
text-decoration:underline; <- crossed out
}
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
border:0;
font-family:inherit;
font-size:100%;
font-style:inherit;
font-weight:inherit;
margin:0;
outline:0; <- crossed out
padding:0;
vertical-align:baseline;
}
I'm just wondering if IE 9 has a way to do something similar to Firefox where I can select the "Inspect" option under the Web Developer menu and then see which css classes are being applied to each element on my page.
I did notice in IE 9's F12 feature, I can select "View" -> "Class and ID Information" but it doesn't show me the css details.
My problem is that my site looks completely different in IE than in FF and I'm trying to debug. Any other suggestions would be appreciated.
Thanks.
EDIT 1:
The specific problem is that in FF I have a left and top margin so that all content is centered. However, in IE everything is left justified. I decided to start looking at the first div of the page because even that's appearing differently.
There are several divs nested within each other but I think I may have found the culprit.
In IE, the css for one of the divs looks like this:
#regionHeader .wrapper {
overflow:hidden;
}
.wrapper {
margin:0 auto;
max-width:1140px;
min-width:801px;
width:auto;
}
.wrapper {
margin:0 auto;
}
.wrapper {
margin:0 auto;
}
.wrapper {
zoom:1;
}
.wrapper:after {
clear:both;
}
.wrapper:after {
display:table;
}
.wrapper:before {
display:table;
}
div {
-webkit-text-size-adjust:none;
border-bottom:0;
border-left:0;
border-right:0;
border-top:0;
margin:0;
padding-bottom:0;
padding-left:0;
padding-right:0;
padding-top:0;
}
But the same in FF has the following style:
#regionHeader .wrapper {
overflow:hidden;
}
.wrapper {
margin:0 auto;
min-width:320px;
}
.wrapper, .clearfix, #content {
}
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, address, cite, code, del, dfn, em, img, ins, q, small, strong, sub, sup, dl, dt, dd, ol, ul, li, fieldset, figure, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
border:0 none;
margin:0;
padding:0;
}
Notice the max-width:1140px; in IE vs FF which only has a min width. Would that be causing the problem? Unforunately, this is not my code...
Press F12, click the pointer button in the toolbox, click on the element you want to inspect. The css for that element should be to the right of the dom-window. If it isn't, you may click on the "Style" button above the right window.
Firebuglite is compatable with IE6+ and can be downloaded here:
https://getfirebug.com/firebuglite
Hit F12 to bring up the IE9 Developer Tools.
Or select TOOLS - F12 DEVELOPER TOOLS
How is it possible that there is a 3 px difference in the vertical position of textfields in a form when seen in those 3 diff. browsers?
I am going insane. It is not good trying to fix it in the CSS because if I change it, it is fine in one but not in the others.
#pricefromR
{width:75px;
position:relative;
right:40px;
top: 50px;
}
#pricetoR
{width:75px;
position:relative;
right:-45px;
top: 24px;
}
So this corresponds to two texfields which are supposed to be paralell, at the same leve with each other, but they are not in different browsers, by a difference of 3 px and it happens the same with the other pairs which are each in a LI
<li>
<input type ="text" id = "areafromR" placeholder="area from" name = "areafrom" maxlength = "5">
<input type ="text" id = "areatoR" placeholder="area to" name = "areato" maxlength = "5">
</li>
All browsers are different, they have different defaults, and different wu=idths/heights. The best way that I know of is to either use percents, but that can get complicated. You can make a the CSS seperate for different browsers. For example ...... That is for internet explorer
You should try to reset your CSS
In case you didn’t know, every browser has its own default ‘user
agent’ stylesheet, that it uses to make unstyled websites appear more
legible. For example, most browsers by default make links blue and
visited links purple, give tables a certain amount of border and
padding, apply variable font-sizes to H1, H2, H3 etc. and a certain
amount of padding to almost everything. Ever wondered why Submit
buttons look different in every browser? It limits the difference
between browsers
Using a CSS Reset, you can force every browser to have all its styles reset to null, so less cross-browser differences
With this code:
/**
* Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
* http://cssreset.com
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
A common practice is to put this in another CSS file.
So as most developers, i use a CSS RESET in all my work. One of the small problems i run into is that when developing custom anything in wordpress, i use this reset and the problem ive been having is that, because of said reset when the user is writing a post, the ability to for example, use italics / bold etc isnt available. I mean it is but its not applied because of said reset.
I just went in and removed the em / i / b etc tags from the reset block and its working BUT, theres one more thats giving me the biggest problem and thats that when someone hits the enter key to create space between text etc, nothing happens. they have to manually go in and put in <br/> tags to create the separation.
That said, it got me to thinking that....what exactly IS the css for line breaks/ the enter key?
below is whats in my CSS reset...not sure what else i have to remove.
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, img, ins, kbd, q, s, samp,
small, strike, sub, sup, tt, var, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0px;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a{text-decoration:none;}
Ive tried to google but, aside from the p tag or the div tag etc...not sure what i have to remove to get the enter key/space created by pressing the enter key to go back to default.
Thanks in advanced.
To create separation such as a return, you can use a :after or :before like this:
p:after {
content: '\13';
display: block;
}
This will create a new line before of each paragraph element. You can use this trick with any kind of element.
Here's the fiddle:
http://jsfiddle.net/napy84/VQLTq/
Why is my text being cut off in IE7 and Firefox from left side ? it looks OK only if i add padding-left:1px? why it's happening? I' can't give live link of site.
see problem in this screen-shot alt text http://easycaptures.com/fs/uploaded/458/3132736693.png
letter "W" being cut off from left side.
CSS code
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, em, font, img, ins, sub, sup, dl, dt, dd, ol, ul, li, fieldset, form, label, table, caption, tbody, tfoot, thead, tr, th, td
{
border:0 none;
font-size:100%;
margin:0;
padding:0;
vertical-align:baseline;}
body {font-family:Arial,Helvetica,sans-serif;
font-size:62.5%;
line-height:1.2;}
ul {
list-style-image:none;
list-style-position:outside;
list-style-type:none;}
.home-boxesContainer ul {
font-size:0.9em;
margin:auto;
overflow:hidden;
width:90%;}
.home-boxesContainer ul li {
background:transparent url(Images/dot-grey.gif) repeat-x scroll left bottom;
float:left;
line-height:16px;
margin:10px 0 0;
overflow:hidden;
padding-bottom:5px;
padding-right:10px;}
.home-boxesContainer ul li a {
-moz-background-clip:border;
-moz-background-inline-policy:continuous;
-moz-background-origin:padding;
background:transparent url(Images/arrow-green.gif) no-repeat scroll right center;
color:#6CB025;
padding-right:20px;
text-decoration:none
}
This is an issue with certain fonts on windows, specifically Verdana, from my experience. I spent about three days looking for float bugs and such to solve this, three years ago. It occurs mainly with the capital 'w' character, but can also be a problem with 'v' too, and only with cleartype disabled.
The best solution is to use text-indent:1px; on your paragraphs, if you feel you need to implement a fix.
I can't see well on your screenshot, but I think its the font issue, try with different font.
I suspect there can be three reasons:
The container of your menu is pushed there to left making text that way
It may be font issue too (this happens sometimes due to fonts)
Try adding line-height to your list.