Jump to content

Help positioning div element css

FaiL___

Hi, I have created a div element in my html and I'm just trying to get it a little bit away from the edge of the screen. I've tried using this:

div
{
	margin: 50px;
}

but I just can't get it to move away from the edge. Any help will be appreciated. Cheers in advance.

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

Okay so div are supposed to be named. You use div tags in HTML and give it a name. Check w3schools for more info. 

 

Then in css you do 

.name {

}

 

where name is substituted with the title you gave the division. You need the . Before the name without a space so CSS knows it’s a custom tag you created. 

Normally you’d do something like 

 

p, H1 {

}

 

and that’d style the paragraph and H1 elements. 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, fpo said:

Okay so div are supposed to be named. You use div tags in HTML and give it a name. Check w3schools for more info. 

 

Then in css you do 

.name {

}

 

where name is substituted with the title you gave the division. You need the . Before the name without a space so CSS knows it’s a custom tag you created. 

Normally you’d do something like 

 

p, H1 {

}

 

and that’d style the paragraph and H1 elements. 

My div elements are named, I just wrote a simplified version of what I'm doing (on my phone), so just wanted to know if the margin: 50px; would work.

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

48 minutes ago, FaiL___ said:

My div elements are named, I just wrote a simplified version of what I'm doing (on my phone), so just wanted to know if the margin: 50px; would work.

Did you try it? 

Link to comment
Share on other sites

Link to post
Share on other sites

Above post and margin on it's own is shorthand and has a few different functions.

margin: 10px; //10px of spacing on all sides outside of the element
margin: 10px 5px; //would put spacing on top and bottom of 10px and left and right 5px

or

margin: 10px 8px 6px 4px;

//this does the same
margin-top: 10px;
margin-right: 8px;
margin-bottom: 6px;
margin-left: 4px;

you can also specify them separately with margin-left: 50px;

 

Also why everyone likes w3schools site is beyone me. Mozilla has been much more reliable and thorough for me.

https://developer.mozilla.org/en-US/docs/Web/CSS/margin

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×