aligning svg's with text and creating underlines that don't "chop" at the end due to margins.

It could just be my eyesight, but these SVG's look to not be lining up correctly with my text (also, do you hate the font as much as I do right now?) I'm also wanting to add an underline/border-bottom the Projects, which is fine if I have no margin, but when I add margin it creates gaps at the end.. reason I'm using margin is because the SVG sits right at the very end of the page without anything there to bring it in a little.
145 Replies
CDL
CDLOPā€¢16mo ago
This is the top 3 lines, they're the exact same code as this
<button id="upcomingLink" class="sidebar-btn">
<svg class="btn-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<title>calendar-week</title>
<path
d="M6 1H8V3H16V1H18V3H19C20.11 3 21 3.9 21 5V19C21 20.11 20.11 21 19 21H5C3.89 21 3 20.1 3 19V5C3 3.89 3.89 3 5 3H6V1M5 8V19H19V8H5M7 10H17V12H7V10Z" />
</svg>
Upcoming
</button>
<button id="upcomingLink" class="sidebar-btn">
<svg class="btn-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<title>calendar-week</title>
<path
d="M6 1H8V3H16V1H18V3H19C20.11 3 21 3.9 21 5V19C21 20.11 20.11 21 19 21H5C3.89 21 3 20.1 3 19V5C3 3.89 3.89 3 5 3H6V1M5 8V19H19V8H5M7 10H17V12H7V10Z" />
</svg>
Upcoming
</button>
Projects is the below code
<h3 class="projectTitleText"><svg class="btn-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<title>list-box-outline</title>
<path
d="M11 15H17V17H11V15M9 7H7V9H9V7M11 13H17V11H11V13M11 9H17V7H11V9M9 11H7V13H9V11M21 5V19C21 20.1 20.1 21 19 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5M19 5H5V19H19V5M9 15H7V17H9V15Z" />
</svg>
Projects</h3>
<h3 class="projectTitleText"><svg class="btn-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<title>list-box-outline</title>
<path
d="M11 15H17V17H11V15M9 7H7V9H9V7M11 13H17V11H11V13M11 9H17V7H11V9M9 11H7V13H9V11M21 5V19C21 20.1 20.1 21 19 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5M19 5H5V19H19V5M9 15H7V17H9V15Z" />
</svg>
Projects</h3>
vince
vinceā€¢16mo ago
Wait why are they buttons Does it change something on the page rather than redirect you? Bruh you are doing this all wrong šŸ˜‚
CDL
CDLOPā€¢16mo ago
only this area should be changing D:
vince
vinceā€¢16mo ago
Ah that's a tricky one. So you basically want SPA functionality without making an SPA If I understand correctly Usually SPAs still use links but they change the functionality based off the route in the URL
CDL
CDLOPā€¢16mo ago
Basically I have no idea what I'm doing and i'm winging it šŸ˜„
vince
vinceā€¢16mo ago
Lol if this is just for practice using buttons is fine You should still have them in a list though
CDL
CDLOPā€¢16mo ago
I believe the projects are in a list
vince
vinceā€¢16mo ago
Oh is the projects button a dropdown?
CDL
CDLOPā€¢16mo ago
vince
vinceā€¢16mo ago
Got it
CDL
CDLOPā€¢16mo ago
nah the + brings up an input field
vince
vinceā€¢16mo ago
Oh okay So you're trying to align the svg on the left of the projects with the projects text right?
CDL
CDLOPā€¢16mo ago
Yep It's a h3 with the svg inside the h3 tags <h3><svg blablabla>Projects</h3>
vince
vinceā€¢16mo ago
I wouldn't put it in a heading, I'm making a codepen rn What font is this again?
CDL
CDLOPā€¢16mo ago
doesn't matter, I don't like the font honestly the entire thing needs refactoring, it's super scuffed šŸ˜›
vince
vinceā€¢16mo ago
Haha me on every project I make ever Font probably matters because of their glyphs so it might not be perfectly aligned unless you add some hacky margins
b1mind
b1mindā€¢16mo ago
yea don't use h3 or any heading level for a nav/buttons
CDL
CDLOPā€¢16mo ago
it was originally just a p tag
vince
vinceā€¢16mo ago
No negative margins
vince
vinceā€¢16mo ago
margin-bottom: 2px
CDL
CDLOPā€¢16mo ago
going back to a point earlier, you said buttons are a bad idea for the links?
vince
vinceā€¢16mo ago
https://codepen.io/vince1444/pen/Yzdyqpb Yea, if they're affectively changing a page I'd imagine you want them to be anchors, but what you're doing is basically an SPA without client-side routing. I have no idea how you'd set that up yourself You'd probably want to leverage any SPA framework out there instead of making it yourself but it might be a good learning opportunity
b1mind
b1mindā€¢16mo ago
he is following some BS from Odin project
CDL
CDLOPā€¢16mo ago
It's supposed to just be a site built using modules
b1mind
b1mindā€¢16mo ago
its not by his own doing lol
CDL
CDLOPā€¢16mo ago
I've kinda just done.... it oddly yeah if I had svelte or reacte this would've been done much much easier šŸ˜„
b1mind
b1mindā€¢16mo ago
stay on topic though only needs help with align center xD
CDL
CDLOPā€¢16mo ago
mod power šŸ’€ so in general, you display: flex, align-items: center;
vince
vinceā€¢16mo ago
Ya you can use grid too
CDL
CDLOPā€¢16mo ago
and then if there's any irregularities it's likely a font issue?
vince
vinceā€¢16mo ago
You don't even need flex or grid either you can use inline elements too I'd imagine if you really want too lol
CDL
CDLOPā€¢16mo ago
any idea how I sort the underline issue I had also? (also in the title, don't hit me b1)
b1mind
b1mindā€¢16mo ago
lol
vince
vinceā€¢16mo ago
If you care about backwards compatibility flex gap isn't supported <2020 in Safari I don't think so you'd want to use grid if you want to use gap or use margin-right/left
b1mind
b1mindā€¢16mo ago
I've influence Vince enough I just watch him. <,<;;
vince
vinceā€¢16mo ago
Yea each font is different, so adjust line heights and margins to get it pixel perfect
b1mind
b1mindā€¢16mo ago
Nod nod
vince
vinceā€¢16mo ago
I've learned a lot from you šŸ™‚ Wym?
CDL
CDLOPā€¢16mo ago
oh get a room šŸ˜‚
vince
vinceā€¢16mo ago
Did we just both add the rofl emote at the same time that's crazy
CDL
CDLOPā€¢16mo ago
So I have this
CDL
CDLOPā€¢16mo ago
notice how the svg is right up at the edge
vince
vinceā€¢16mo ago
You want to add padding and remove the underline? I don't see anything in your code that would cause it I don't think, that you sent here
CDL
CDLOPā€¢16mo ago
Ah actually that one is fine
CDL
CDLOPā€¢16mo ago
I think it all lines up
CDL
CDLOPā€¢16mo ago
(I'll fix the projects svg)
vince
vinceā€¢16mo ago
Cool. Also I'm not competent with accessibility so this could be wrong but if you keep the buttons I think you'd want to add aria attributes like aria-controls/aria-expanded
CDL
CDLOPā€¢16mo ago
I'll probably change them later mate, no worries reading through the code, the entire thing's a bit of a mess šŸ˜›
megaByte
megaByteā€¢16mo ago
yo cdl are you doing css today
CDL
CDLOPā€¢16mo ago
Bit of everything!
megaByte
megaByteā€¢16mo ago
nice css is a nightmare
b1mind
b1mindā€¢16mo ago
I'd advise him to just complete the project to specs he is following a lesson plan.
megaByte
megaByteā€¢16mo ago
chatgpt cant even do that shit
b1mind
b1mindā€¢16mo ago
I mean its one thing if you have a good idea nad want to expand on the project sure. but adding complexity when he is trying to nail down specifics is not always great.
vince
vinceā€¢16mo ago
Ya that makes a lot of sense
b1mind
b1mindā€¢16mo ago
like its easy for you to say that cause you think about and have been already xD
CDL
CDLOPā€¢16mo ago
have you seen my code, and the specs, b1? I don't think I'm anywhere close šŸ˜‚
b1mind
b1mindā€¢16mo ago
but I don't disagree totally but I would use proper summary/details then if you are going to break their lessons break them right xD
CDL
CDLOPā€¢16mo ago
it says use modules and webpack, I used vite and i have 2 modules for random parts, then ive just bundled everything into a main.js file then my mentor was like "hey we need state, let's add render functions"
b1mind
b1mindā€¢16mo ago
hahaha
CDL
CDLOPā€¢16mo ago
and now im like WHAT IS GOING ON
b1mind
b1mindā€¢16mo ago
Yea idk man...
megaByte
megaByteā€¢16mo ago
uh oh
b1mind
b1mindā€¢16mo ago
I really wanna make a from html to frameworks* course lol
CDL
CDLOPā€¢16mo ago
quick favour b1, if you don't mind. Look at the code, and let me know how over-complicated i've made it? I'm genuinely curious
b1mind
b1mindā€¢16mo ago
I see the struggles and so wanna provide something better... these roadmaps are stupid
megaByte
megaByteā€¢16mo ago
wow
b1mind
b1mindā€¢16mo ago
specially with the industry taking a full circle right now with SSR/SSG/Hybrid/Transitional apps when most devs had no idea how the web has worked for generations they see the hype and think its how its done to get a job 10% of websites work like that xD 70% are php
megaByte
megaByteā€¢16mo ago
damn youre literally talking to me rn
b1mind
b1mindā€¢16mo ago
lol I also got switched up thought we were in general again sorry CDL hijacked walks away bad mod
CDL
CDLOPā€¢16mo ago
unbelievable.
megaByte
megaByteā€¢16mo ago
@CDL who are you being mentored by creating SPA with plain javascript is like extremely hard bro
b1mind
b1mindā€¢16mo ago
its really not that hard though xD
megaByte
megaByteā€¢16mo ago
nah youre a senior dev its easy for you
b1mind
b1mindā€¢16mo ago
I think its not the best thing if you don't full understand what its doing but xD I'm a mid at most <,<;;
megaByte
megaByteā€¢16mo ago
how many years exp? just curious
b1mind
b1mindā€¢16mo ago
DOM manipulation is a must know though mixed had 8 years of old web knowledge left for a decade and been relearning modern web for 3 years now? I been making websites for long time though fo sure
megaByte
megaByteā€¢16mo ago
DAMN literally a Veteran thats dope
b1mind
b1mindā€¢16mo ago
yea I was learning when it was born xD
CDL
CDLOPā€¢16mo ago
I think the issue with my code is I've gone hybrid I have a SPA root id div, the i have hard-coded html. I have a main js file, then i have some random module files šŸ˜„
b1mind
b1mindā€¢16mo ago
no hybrid would be if you had static/ssr with a client side router
CDL
CDLOPā€¢16mo ago
by hybrid i mean, a monstrosity
b1mind
b1mindā€¢16mo ago
That is where I think odin project is missleading you did it even go into http ? like post/get?
CDL
CDLOPā€¢16mo ago
this project however, has been the one that has made me question my life decisions
b1mind
b1mindā€¢16mo ago
or its just like we going to show you the JS way...
CDL
CDLOPā€¢16mo ago
Uhhhh
b1mind
b1mindā€¢16mo ago
like you know how a http request works?
CDL
CDLOPā€¢16mo ago
I know post/get yea
megaByte
megaByteā€¢16mo ago
what is odin project?
CDL
CDLOPā€¢16mo ago
not to derail this too much but here's the specs for this project https://www.theodinproject.com/lessons/node-path-javascript-todo-list and this is my absolute nightmare of an attempt https://github.com/callum-laing/todo-list should put a NSFW on my github tbh, it's a hard read I don't know any better but it feels like I'm mixing up like 5 different concepts/ways of building this piece of this, piece of that, peice of this, throw it all into 1
megaByte
megaByteā€¢16mo ago
ohhhh i had no idea about this its been like a year i started coding, i just learnt from youtube lol
CDL
CDLOPā€¢16mo ago
TOP's been good to me in general, but some of it is a little sus
b1mind
b1mindā€¢16mo ago
yea its a odd mix
CDL
CDLOPā€¢16mo ago
this is the first project where I've actually hit a wall, like a literal wall usually i get through it after a few days ive been on this a week and im still very confused
b1mind
b1mindā€¢16mo ago
yea ngl I'd have a hard time following this lol not your code but the lesson
CDL
CDLOPā€¢16mo ago
the todo-list? I read it as "create a project object, and inside that you can create tasks" open a project -> reveals the current tasks
b1mind
b1mindā€¢16mo ago
CDL
CDLOPā€¢16mo ago
I'm somewhat tempted to just bench it and come back to it later on as I'm grinding my teeth here
b1mind
b1mindā€¢16mo ago
didn't even align center and that looks great just saying <,<;;
b1mind
b1mindā€¢16mo ago
b1mind
b1mindā€¢16mo ago
24px font with 24px svg ig oo no you have it on button xD pulling from flex override
CDL
CDLOPā€¢16mo ago
vince has already scolded me for using a button -.-
b1mind
b1mindā€¢16mo ago
I mean it is a button
megaByte
megaByteā€¢16mo ago
1 week time on a problem is enough, i think you should look at other peoples solution now and learn from it
b1mind
b1mindā€¢16mo ago
a hrefs are for links buttons are for actions
CDL
CDLOPā€¢16mo ago
I would've used a href but my thought process was
b1mind
b1mindā€¢16mo ago
why you never change pages
CDL
CDLOPā€¢16mo ago
button for onclick to call a function
b1mind
b1mindā€¢16mo ago
you are injecting it all exactly you are fine
vince
vinceā€¢16mo ago
It's what I was talking about with the client side routing though
b1mind
b1mindā€¢16mo ago
if this was a mpa I would scold you
vince
vinceā€¢16mo ago
He's basically doing that but with buttons instead of links
b1mind
b1mindā€¢16mo ago
right but he is not going to manage the history api and all that so
vince
vinceā€¢16mo ago
Ye
b1mind
b1mindā€¢16mo ago
yea idk šŸ˜®
CDL
CDLOPā€¢16mo ago
next project is weather app šŸ˜Ž
b1mind
b1mindā€¢16mo ago
making things overt for a simple todo
CDL
CDLOPā€¢16mo ago
So you agree this is overly complex for a todo right
b1mind
b1mindā€¢16mo ago
if this was something I was releasing to the public then I would worry about all that ig. when I do proejcts to learn its very focused on the thing/concept I want to learn. So this would be like local storage/dom injection/dom surfing. honestly it could do with some Classes too but I'm not one to do that either haha
CDL
CDLOPā€¢16mo ago
I could've just copied my restaurant app tbh and tweaked some styling https://callum-laing.github.io/restaurant/ as far as the modules goes anyway
b1mind
b1mindā€¢16mo ago
So the other thing would be how to make it with a different approach but again you are following lessons so.
CDL
CDLOPā€¢16mo ago
clearly not, it says use webpack, im using vite šŸ˜„
b1mind
b1mindā€¢16mo ago
I don't blame you there though
CDL
CDLOPā€¢16mo ago
they're using DOM state, my mentor guided me through using a render function
b1mind
b1mindā€¢16mo ago
not like they really had you dong that much in webpack either though
CDL
CDLOPā€¢16mo ago
function renderProjects() {
return state.projects
.map((project) => {
return `<div class="project-title-list"><li> ${project.title} </li> <button class="project-btn" id="btn-${project.id}"> X </button></div>`;
})
.reduce((acc, elm) => acc + elm, []);
}

function renderContent() {
const projectListEl = document.querySelector("#project-list");
projectListEl.innerHTML = renderProjects();
state.projects.forEach((project) => {
document
.querySelector(`#btn-${project.id}`)
.addEventListener("click", () => removeProject(project.id));
});

if (state.page == "home") {
renderHome();

const addTaskBtn = document.getElementById("addTaskBtn");
addTaskBtn.addEventListener("click", () => {
taskCreation();
});
}
}

const homeLink = document.querySelector("#homeLink");
homeLink.addEventListener("click", () => {
renderContent();
});
function renderProjects() {
return state.projects
.map((project) => {
return `<div class="project-title-list"><li> ${project.title} </li> <button class="project-btn" id="btn-${project.id}"> X </button></div>`;
})
.reduce((acc, elm) => acc + elm, []);
}

function renderContent() {
const projectListEl = document.querySelector("#project-list");
projectListEl.innerHTML = renderProjects();
state.projects.forEach((project) => {
document
.querySelector(`#btn-${project.id}`)
.addEventListener("click", () => removeProject(project.id));
});

if (state.page == "home") {
renderHome();

const addTaskBtn = document.getElementById("addTaskBtn");
addTaskBtn.addEventListener("click", () => {
taskCreation();
});
}
}

const homeLink = document.querySelector("#homeLink");
homeLink.addEventListener("click", () => {
renderContent();
});
enjoy
b1mind
b1mindā€¢16mo ago
yea see I see that so much differently but again I think of HTML first then JS later event delegation and classes would brrrr for a vanilla todo though
CDL
CDLOPā€¢16mo ago
I'm somewhat tempted to restart this entire and just treat what I've built already as a learning experience because I have no idea how to finish the bloody thing
megaByte
megaByteā€¢16mo ago
character development
b1mind
b1mindā€¢16mo ago
I have a great video from CMgriffing about unfinished projects
CDL
CDLOPā€¢16mo ago
please share I'm not even mad about ditching this one tbhy
b1mind
b1mindā€¢16mo ago
cmgriffing
YouTube
Side Project Hell: Do you have too many unfinished side projects?
In this video, I discuss "Side Project Hell" and how it's not actually that bad when you gain some perspective. A comic from "CommitStrip" called "West Side Project Story" hits very close to home and might make us feel bad about it. Instead, we can dig deeper and recognize the subtext that I am almost certain they intended but they don't make i...
CDL
CDLOPā€¢16mo ago
I think having a few people assist me has made it overcomplicated for me to get on the right track if that makes sense
b1mind
b1mindā€¢16mo ago
yea too many chefs
CDL
CDLOPā€¢16mo ago
Yea and they all have their own styles
b1mind
b1mindā€¢16mo ago
yup xD
CDL
CDLOPā€¢16mo ago
so now I look at it like "what in the hell is going on"
b1mind
b1mindā€¢16mo ago
that is why you must find "your" style
CDL
CDLOPā€¢16mo ago
I'm 10000% sure this could'e been done with half the code I've currently written in my defence, I have 15 github repos, this is my first unfinished project šŸ˜„ Ahhh ok I get what he's saying.. Yeah I definitely need to work on some DOM specific things, object specific things and some localStorage, as those 3 are weaknesses (and I've never done localStorage) btw he banned me from his twitch because I said I was learning React and i find it extremely tedious because React is painful compared to Svelte šŸ˜‚
b1mind
b1mindā€¢16mo ago
Chris is so funny ...
CDL
CDLOPā€¢16mo ago
anyway lets close this one, thanks for the helps peeps, I'll consider my options, but I may bench this and come back to it/make a new version once I practise some of the concepts
b1mind
b1mindā€¢16mo ago
Like he hates the framework debates so comments like that he gets mad at and claims no bias but he is a React famboi
CDL
CDLOPā€¢16mo ago
yeah exactly šŸ˜› he raged then banned me
b1mind
b1mindā€¢16mo ago
šŸ˜‚ heard it many times
Want results from more Discord servers?
Add your server