Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

moving a title

How can i move a title around the webpage i see we can move it left or right but what about up or down?

I do need to move a title up and across to the center aswell. i have a picture underneath but im exhausted using padding margins etc CSS3 doesnt seem to support exact movements of titles.

5 Answers

Steven Parker
Steven Parker
231,007 Points

Generally, you won't need to move something "up" unless something else comes before it, and in that case you can swap the order. But if it has margins and/or padding you can move it up a bit by removing them.

And you can add some to move something down (if you don't mind blank space). Examples:

.move-up {
    margin-top: 0;
    padding-top: 0;
}
.move-down {
    margin-top: 30px;
}
Steven Parker
Steven Parker
231,007 Points

Centering can often be done with "auto" margins. And for exact placement, CSS provides absolute positioning and transforms, which can be used individually or in combination. Do a bit of research on those, and show your code if you need help with a specific situation.

Steven Parker
Steven Parker
231,007 Points

As I said, if you need help, show your code (with Markdown formatting to preserve the appearance), or share the entire workspace by making a snapshot and posting the link to it.

The instructor on the videos said to not copy only but create websites and learning like that will help alot which is what im doing so i cant use markdown formatting or snapshot because im coding inside visual studio code...

Steven Parker
Steven Parker
231,007 Points

Markdown is mostly just pasting your code between two lines that each contain just three "backticks" :point_right: ```
It does not matter where the code you paste in comes from, it can be from the Visual Studio screen.

To use the snapshot you would first need to copy/paste your project into a new workspace. Then, it's just clicking on the little "camera" icon on your workspace page, and it will give you a link you can post here.

Steven Parker
Steven Parker
231,007 Points

Ahh. So margins don't have a "center" value. The "auto" value will center them but only on a block element (spans are not), and only when the element has an explicit width. But you can do all those things in the CSS:

.title {
  display: block;
  width: fit-content;
  margin: auto;
  /* other settings ... */

But we seem to have wandered off from the original question, has it been answered?

thank you for your answer it did work! the title is at the center of the picture, i'm not sure how you did this and i dont understand your technical answer, (i'm not at that level of learning yet)

p.s your answer doesnt have a best answer to click on underneath your response..

Steven Parker
Steven Parker
231,007 Points

The choice should be after the first part of the answer, next to "add comment" (and before any of the comments).

https://w.trhou.se/slt0b4wtwk check the NoBestAnswer pic thats what i can see, no best answer under your response.

oh sorry i'm very new to all this, sorry for the headache but thank you for your help..