I've posted a question or an answer, and I have received one or more downvotes. I am not really sure why I was down voted, or I think I know why, but I disagree.
Why did this happen, and what should I do about it?
A downvote is an opportunity to consider that perhaps your post could be improved somehow. If you are at all bothered by a downvote, I encourage you to consider the following.
Note: Votes are slightly different on Meta. You may be more quickly down voted on a meta site because people simply disagree with your thoughts on a topic. For example, on questions tagged feature-request, others may downvote if they disagree with your proposed feature. This is a valid reason for downvoting on a Meta site. You may still apply the ideas below, but just understand that opinions and thoughts are more freely expressed on Meta sites, both in posts and in votes.
First, you should never take a downvote personally. Remember that a downvote only takes away 2 reputation, while upvotes add considerably more (5 for questions and 10 for answers). Everyone who uses any Stack Exchange site for any length of time will gather down votes here and there. The "best" will take every down vote as an opportunity to rethink a post, and ponder how it could be improved.
That's the short version of the answer, and it has been stated before here on Meta. If you are looking for some more detailed explanations of where you could look, read on!
There are many reasons someone could down vote, which might include:
There are other less "legitimate" reasons someone might downvote your post, but it's generally not helpful to spend too much time thinking about those. For instance, if you see a large number of down votes across many different posts of yours in a short period of time, it's possible you have experienced something we call "serial voting". This post does not address that situation specifically; please see What is serial voting and how does it affect me?
Otherwise, when you get a downvote, consider if any of the above reasons could possibly apply to your post, and consider if you can improve it in relation to that issue. Even if that's not why the person downvoted, you will end up improving your post!
This is literally one of the things mentioned when you hover over the down vote arrow, and it's possible this is the most frequent reason for down votes on questions. How much effort did you put into solving your problem/answering your question before posting? Most Stack Exchange sites expect questions to be based on well-researched issues, and to reflect the effort you have made, so people posting answers don't waste their (and your) time covering ground you've already been through. So be sure that 1) you have spent reasonable effort trying to find an answer yourself and 2) that your post reflects that effort.
If you simply say something vague like "I have searched online, but couldn't find an answer", that might get classified as showing a lack of research effort - anyone can add this to their post, regardless of how little research effort they've done. Include links you've explored, stating how these didn't help, show some code that didn't work, and how it failed - while including these things may seem pointless to you, it's essential to show us that you've actually tried to find an answer yourself - many may not look kindly on you if you appear to be using Stack Exchange to do your work / thinking for you - it's here to help you do it.
Consider carefully; is your post factually accurate? Check each and every fact you have included, and consider linking to authoritative resources to back up your claims. Check your big facts and your small facts. Even if something you mentioned is only tangentially related, be sure you have the details of those facts correct, as well.
Most Stack Exchange sites do not encourage questions/answers based on opinions. Expressing an opinion that someone else might disagree with is a surefire way to invite someone to downvote. Was your opinion vital to the post? Could it be removed or its applicability limited, such that those with an opposing opinion are not encouraged to downvote?
Keep in mind that you are wanting people to have a positive reaction to your post: to answer your question, or to upvote your question/answer. Be sure you have not expressed yourself negatively. Did you rant about the technology you are using? Your post is being read by people who use that technology every day. Yes, your rant may find a great many people who agree with your point of view, but it will also find some who disagree, and will vote accordingly.
Also, take care with your formatting. For example, people may downvote when you use ALL CAPS for your title or content, because this is often interpreted as shouting.
For questions, be sure you have read the help center of the Stack Exchange site on which you are posting. Think about what is posted there according to both the letter and the spirit, and be open to being wrong - and being told so. Off-topic questions will usually get voted to be closed, and sometimes people will leave comments letting you know it is off-topic. But also, some people will downvote such a question. If this is why your question was downvoted, it will likely also be voted to be closed. Be open-minded in such a case; listen to what those who comment have to say, and if you really still have a doubt, consider going to that site's per-site meta to inquire about the question's appropriateness on the site in question. Make your case in comments on your answer, but beware getting involved in an extended "debate".
For answers, keep in mind that most Stack Exchange sites expect answers to specifically answer the question that was asked. Perhaps you think the person has a different problem than they are expressing in their question, and so you are trying to get "to the root of the problem". Be mindful if you do this, as some will not see the connection at all, and will think your answer is simply off-topic. Also note that you might be wrong in your assumption about where the real problem is. Either way, someone might downvote your answer if they think it doesn't answer the question at hand.
If you are very sure that you have identified a real, unspoken issue in a question, it's usually best if you first answer the question they are asking briefly and correctly, and then explain why you think their issue might be something else... then explain that answer. This makes sure that people won't think you simply ignored the question and posted what you want. But note: someone might still down vote if they think your assumption is wrong.
Some users leave a comment on their post asking for the downvoter(s) to explain themselves. Be aware that this may not have the effect you want. It may, in fact, just attract more downvotes. If anyone responds to your query, it's likely as not to be the person(s) who downvoted originally, so your response might not be as accurate as you would like.
But it could, potentially, be helpful. Some helpful user might later come along and offer what they guess could be the reason for the downvote(s). Just don't hold your breath, and keep these other things in mind:
Don't take a downvote here or there personally. If you are 100% sure that your post can't be considered to fall under any of the above, just ignore the down vote. If you've gotten more than one down vote, you should probably try to improve your question - even though it could look perfect, some may be looking at it differently than you do. Even if you're sure nothing's wrong, it always good to take the time to see how your post can be improved. It can only help!