Html css coding error with

Asked By 0 points N/A Posted on -
qa-featured

Why is that when I make a <div> in html the output sometimes changes and separates too far from where I declared it. It is around 50 pixels away from the other div but I didn't add any margin or padding.

How can I fix it to make it stick to the div on top of it.

 

 

SHARE
Best Answer by Chriss
Best Answer
Best Answer
Answered By 0 points N/A #82707

Html css coding error with

qa-featured
  • This happens because you are just applying margin and padding to your div container. But this is the problem of positioning. Your div container is not set on any position. So there are two method of positioning
  • First one that you mention the position from top and left/right. That mean from how much top and how much left or right your div will be.
  • Top: 0px;
  • right: 0px;
  • For example the above code will set your div to the top right corner because you set 0px distance from top and 0px distance from right. You can also set "position" property to absolute/fixed/relative/static/inherit to fix or move your div. 
  • Now coming to the second method which is called float. This property will set you div to left or right. You can show 2 divs attached to each other by changing their float. One's float to right and second's to left. The css code of float is
  • Float: left;

Hope this will solve your problem

 

Answered By 0 points N/A #82708

Html css coding error with

qa-featured

Hello,

  • First and foremost in coding CSS make sure all div's has 0px positions so that you cannot encounter weird positioning. Because CSS has default values,
  • Just do it like this
  • div{
  • top:0px;
  • left:0px;
  • margin: 0px 0px 0px 0px;
  • padding: 0px 0px 0px 0px;
  • }

I hope this answers your question

Goodluck

 

Login/Register to Answer

Related Questions