Live data from Hacker News

Tough time building components of a site using vanilla CSS. What to do?

news.ycombinator.com

11–20 of 26 posts

Re: Tough time building components of a site using vanilla CSS. What to do?

#11

For this timeline there are for me at least 2 easy ways ... each point is relative and got before and after elements and both positioned absolute (one becomes the dot - the other the line). You have to think through what you need and how you can reach your goal with at least effort as possible (in this case with virtual elements). If more complex graphics should be painted you have to think about alternatives like SV…

And stay away from this frameworks like Bootstrap or Tailwind because with that you only learn to build something fast but you do not know how it works. But you can use this frameworks for studying how something can be done.

Re: Tough time building components of a site using vanilla CSS. What to do?

#13
post #7

Have you tried learning hours to use dev tools? I would look at the original web page source computed styles; override them and see how it breaks. I assume the red line with circles is the hard part? Maybe each element on the timeline has a really long vertical line with circle that’s ‘overflow: hidden;’ Maybe it’s done with JS? The best way to learn is to take apart existing examples. And dev tools is the easiest wa…

Definitely this;

You've built up a small repository of techniques, adding images/headers/etc, that can be combined to build something larger, a hero section.

Now that you're looking at a mockup of a timeline, you need to break it apart into various parts that you may or may not know how to implement. For example, I assume you could get the text, dates, and icons set up easily and may have trouble with the line on the side as OP mentioned - it's possible that this is something you haven't encountered before and finding a few examples of something similar can help. This is not uncommon early in the journey, you can ask around (I guess this counts) or try coming up with the right queries (vertical timeline css?) to search for to find some examples/info.

There are other comments with suggestions along the lines of "use a pre-made component" which I wouldn't fully support as it's a shortcut, but perhaps you could use it while also investigating how that that component implements what you were looking for.

Once you have some insight, try messing around with it on your own, this is where DevTools experience may come in handy.

Overall, the important thing is to not get discouraged!

And for my inital take that most likely won't work perfectly - circles by line of text suggest bullet points i.e ul/li elements decorated by css and the line can be achieved with a left border and some more css (I see the bullet is aligned in a different way which is why I assume it won't be perfect and the border is not too customizable)

Re: Tough time building components of a site using vanilla CSS. What to do?

#14
post #4

I took a few courses from Lynda.com to learn more css. It helped immensely and was free with my library card.

I think the key to building components like this id learning a few key tools in CSS. The first is Flexbox. Take a look at CSS Tricks' guide. You will give you the structure.

Then learn the position attribute thru and thru: absolute and relative will help you with pixel perfect tweaks like the vertical line and circles.

Make sure you have a mental model of the layout algorithm. If you add absolute to a div, how will its height and with change? What is the size and position of a div or span when height is specified?

Re: Tough time building components of a site using vanilla CSS. What to do?

#15
> The scary thing here is that if I can't build these stuffs then there is 0 point of me learning css.

You can build literally anything with CSS. It’s a very powerful language. To learn how to do it the only way really is to get your hands wet and try stuff. Inspect pages made by other people. Read through some courses.

To build the component you linked and basically any other component what you need to do is to look at it and visually decompose it to a bunch of primitives that you know how to do. In your example - you probably know how to place the text and icons on the right. The timeline on the left is basically a straight line (which can be drawn with a border property) and some circles on top of it (background color + border radius: 50% gives you a circle, add a border color and you have exactly what you want). Then all you’re left with is laying all these elements down, in this case I would use CSS Grid to align the dots with the text on the right properly, and relative positioning to align the colored circles in the correct place on the line.

Re: Tough time building components of a site using vanilla CSS. What to do?

#16
You're asking to jump straight from basic HTML/CSS to advanced. That's not a reasonable assumption. Instead, you'll have to invest the time to make incremental progress from where you are. Fortunately you can do that by studying other people's code.

Did you even try Googling "html css timeline"? There are many tutorials/examples, e.g. https://www.w3schools.com/howto/howto_css_timeline.asp

Re: Tough time building components of a site using vanilla CSS. What to do?

#17
post #15

> The scary thing here is that if I can't build these stuffs then there is 0 point of me learning css. You can build literally anything with CSS. It’s a very powerful language. To learn how to do it the only way really is to get your hands wet and try stuff. Inspect pages made by other people. Read through some courses. To build the component you linked and basically any other component what you need to do is to look…

> You can build literally anything with CSS. It’s a very powerful language. To learn how to do it the only way really is to get your hands wet and try stuff.

CSS is good at what it does, but it is difficult to master. I can see where someone learning would really struggle because a lot of the techniques required to implement components aren't exactly intuitive. A lot of the advice people give reads like, OK, first, put the sandwich in the plastic bag, then assemble the fusion reactor and set it next to the refrigerator - here's a handy youtube video showing how I did it in 5 minutes! It's easy!

> Inspect pages made by other people. Read through some courses.

You are telling someone who clearly is doing exactly this to... do this.

Re: Tough time building components of a site using vanilla CSS. What to do?

#19
Number one, realize that CSS is challenging. And this task with the lines and circles on the left is not a normal CSS task. Some people might even decide to do it a different way with JavaScript or SVG or something.

Secondly, focus on the skill of decomposition: breaking down problems into smaller pieces.

For example, start by taking the easiest part of the timeline and reproducing it.

Then tackle the next hardest part.

When you are done, the only problem left is how to connect the parts. Take one connection at a time.

Also, its not cheating to use Google or Stack Overflow or ChatGPT etc. The same way as its not cheating for an accountant to use a calculator or spreadsheet.

Re: Tough time building components of a site using vanilla CSS. What to do?

#20
Hey I literally just built one of these! Web Inspector is going to be your friend moving forward. Find a major site that's built one, inspect the code, and learn how the pros do it (top tip: not all pros do it right, so find multiple examples).

Then try out different approaches. As you get further along in CSS, the thought "huh that didn't work, what about..." will become quite familiar to you. After a while you'll build up a stable of tools: flexbox, grid, absolutely position a pseudo:after element, making use of calc for things like calc(50% - 4px), and so on.

CSS feels a lot like painting, there's different techniques depending on what you're putting on canvas. You're done with school, now time to study the masters.

Post reply on HN