how to remove gap of text align end.

i'm trying to align text center and when i do with full width of that heading i see that text has some padding or margin to the end but all the elements that are related to h1 in hero section has margin and padding 0 but it has some gap and when i align text to start it doesn't have gap and when i align text to end or center it has a gap how can i solve it ? i'm working on this project after 5 to 6 days i think so i'm kind of lost already like where is what from html to css so i apologize for that.
82 Replies
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
No description
Simon
Simonโ€ข3mo ago
From looking at this it seems like the h1 element is wider than its parent and overflow is being hidden
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
how can i see it ? there is no 'overflow: hidden' for any element
Simon
Simonโ€ข3mo ago
I could be entirely wrong. What happens if it's aligned right? โ€“ is the second word cut off? ๐Ÿ˜ถโ€๐ŸŒซ๏ธ
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
no. when it is aligned right it's the same you can see in the picture that you modified
แผ”ฯฯ‰ฯ‚
have you tried to justify the text? in your case, you could use an svg with the text element
MarkBoots
MarkBootsโ€ข3mo ago
Are you using letter-spacing? That will add the space behind the last letter as well. you could counter it by adding a margin-left of the same amount on the first letter
MarkBoots
MarkBootsโ€ข3mo ago
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
that's not my problem my problem is i want that end of the letter to not have letter spacing so it can touch width if this make sense
Chris Bolson
Chris Bolsonโ€ข3mo ago
it would really help if you could share your code.
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
as you can see i want that J and C to align
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
i don't have words to describe it but lemme show sample
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
sample
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
wait i will add codepen https://codepen.io/kev00690/pen/zYgpNVV here
Chris Bolson
Chris Bolsonโ€ข3mo ago
That doesn't really reflect the images that you have added here as the "CEO & PRODUCT DESIGNER" text is in no way aligned with the "JON MOON" text so it is not clear what you want to align with what. As a side note, I realize that this may just be due to you creating a quick codepen but bear in mind that you should only have one <h1> tag on each page.
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
it's a mobile first css yes should i change it ? i want that jon text to be responsive and it should get big as width get's bigger i mean screen size
Chris Bolson
Chris Bolsonโ€ข3mo ago
Unless I have missed something, until now you haven't mentioned anything about it being "responsive" or "getting bigger" (not sure if you are referring to the text size, the spacing or the width??) Firstly you said that it should be centered (and that wasn't working as can be seen in your screen captures), then you said that you wanted the J and C to align... I'm afraid that I am struggling to understand what it is that you wish to achieve and what issues you are having ๐Ÿ˜• . You also have some strange CSS going on, eg:
.hero-one {
padding-top: 6em;

.logo-big {
margin: 0;
padding: 0;
outline: 1px dashed red;

h1 {
margin: 0;
padding: 0;
}
}
}
.hero-one {
padding-top: 6em;

.logo-big {
margin: 0;
padding: 0;
outline: 1px dashed red;

h1 {
margin: 0;
padding: 0;
}
}
}
It looks like you are attempting to nest an h1 within .logo-big but in the HTML, the h1 is the element with the class "logo-big".... so this nested element in the CSS does not exist.
peterpumkineaterr
peterpumkineaterrOPโ€ข3mo ago
i'm not gonna lie i'm lost with words this time kinda confused how should i put it in words. i want it to increase by size so i don't have to put size manually on every media query. also it should align to margin i mean if i'm giving margin of 2em then text should start and end to that margin. the images i showed they're for mobile cause i'm working from mobile to desktop. actually design and developing was done but i didn't like the home page design so i changed it. ahh i'm using scss kinda got habit of that from the first day
Chris Bolson
Chris Bolsonโ€ข3mo ago
also it should align to margin i mean if i'm giving margin of 2em then text should start and end to that margin.
So, as I understand it you want the text "JON MON" to extent all the way from left to right of it's parent container (hero-one) and get larger (presumably you are referring to the font size) as the viewport increase in size. Is that correct? if so, as Epic has already suggested, your best bet is probably going to be an SVG. Something like this:
<svg class="logo-name" viewBox="0 0 62 13" fill="currentColor">
<text x="-2" y="12">JON MON</text>
</svg>
<svg class="logo-name" viewBox="0 0 62 13" fill="currentColor">
<text x="-2" y="12">JON MON</text>
</svg>
svg.logo-name{
font-family: "Ailerons", sans-serif;
width: 100%;
fill: white;
}
svg.logo-name{
font-family: "Ailerons", sans-serif;
width: 100%;
fill: white;
}
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
ok that's something i can work with
h1 {
text-align: center;
color: #fff;
font-size: max(3.8rem, calc(100vw / 10.5));
font-family: 'Ailerons Regular', sans-serif;
font-weight: 400;
margin: 0;
padding: 0;
letter-spacing: max(1.4rem, calc(100vw / 20));

span {
letter-spacing: 0;
}
}
h1 {
text-align: center;
color: #fff;
font-size: max(3.8rem, calc(100vw / 10.5));
font-family: 'Ailerons Regular', sans-serif;
font-weight: 400;
margin: 0;
padding: 0;
letter-spacing: max(1.4rem, calc(100vw / 20));

span {
letter-spacing: 0;
}
}
what bout this ? check my codepen @Chris i put last N in span and removed it's letter spacing and the ceo and product designer should be align start at mobile and when width increases it should goto center. check the current situation and let me know if i should switch to svg let me share desktop design
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
No description
Chris Bolson
Chris Bolsonโ€ข2mo ago
You should really go with what works for your situation and needs. Very rarely is there only one solution to the same problem. And each solution may have its pros and its cons. Your solution seems to work well on most viewport sizes and may only need some tweaking (or not if that is how you want it) on smaller viewport widths where it breaks down onto 2 lines (this is happening at 428px on both Firefox and Chrome on my computer)
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
yes i'm also facing that issue. i'm using that SVG solution and it looks good but i have to understand that viewbox and x and y what is that for and how can i properly use it. let me do a google search and if it didn't work i'll ping you @Chris check this out
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
แผ”ฯฯ‰ฯ‚
you can use the text element to set a max width, and the text will shrink in width to fit it it wont change in height, but it's something however, you can tell the svg to keep a specific proportion with aspect-ratio or using the preserveAspectRatio property
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
can you show me this in codepen, so i know what exactly what you mean.
Chris Bolson
Chris Bolsonโ€ข2mo ago
You would just add that to the SVG code that I showed you before. Here is my codepen version that I used to create the screen-capture that I showed you: https://codepen.io/cbolson/pen/VwoOVjr
แผ”ฯฯ‰ฯ‚
you can also put it inside the h1, and it is valid
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
.progress-container {
display: flex;
flex-direction: row;
margin: 0;
margin-top: 1.2em;
align-items: baseline;
width: 100%;

.line {
background-color: #d91111;
height: 0.031rem;
flex-grow: 0.8;
margin: 0 1em 0 1em;
width: 49%;
}

.year {
font-size: 1rem;
font-family: 'Satoshi-Regular';
font-weight: 400;
color: #9a9a9a;
flex-grow: 0;
}
}
.progress-container {
display: flex;
flex-direction: row;
margin: 0;
margin-top: 1.2em;
align-items: baseline;
width: 100%;

.line {
background-color: #d91111;
height: 0.031rem;
flex-grow: 0.8;
margin: 0 1em 0 1em;
width: 49%;
}

.year {
font-size: 1rem;
font-family: 'Satoshi-Regular';
font-weight: 400;
color: #9a9a9a;
flex-grow: 0;
}
}
why can't .line accepting flex-grow: 0.8; ? i had to give width manually
Chris Bolson
Chris Bolsonโ€ข2mo ago
This question doesn't look like it is related to the topic of the original post. If you have a new question you should open a separate post.
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
i thought opening a new post will be too much so i didn't open it and i thought bout svg and all but i want to do it perfectly so let me do other stuff of the website then i will see what to do with that logo in the end
แผ”ฯฯ‰ฯ‚
perfection is impossible
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
haha yes it is ๐Ÿ˜ญ alright i'm done with bottom design let's manage hero section. i'm too confused now what to do
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
the Jon and CEO title are not the way it is suppose to be and i didn't understand how can i implement svg properly or is there any way that we can accomplish same result in text ? let me share the design
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
mobile
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
desktop
No description
แผ”ฯฯ‰ฯ‚
can you define the way it is supposed to be?
Simon
Simonโ€ข2mo ago
I assume the title should stretch across the same width as the name does in both cases, single-line and multi-line. I feel like exporting both the name+title into a single scalable vector graphic instead of having to micro-manage two seperate text-entities would get you closer to what you are trying (opinions?). To prevent the title becoming unreadable (small) maybe even have two file versions, one with the name+line-break-title and one without to switch between the two according to the parents container-size. Solving this with text elements will probably lead you to unpleasant results considering the many factors that play into rendering. ... maybe it's possible, there are always some crazy CSSers out there In any case "pixel perfect" is not to be expected.
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
well the JON MON is working good as svg chris suggested but i want to give it letter spacing but looks like it's close to impossible
แผ”ฯฯ‰ฯ‚
doing the same treatment for the bottom text will just make it vanish there arent enough pixels to represent a line so thin and if, somehow, it doesnt vanish, you will wish it would since it will be missing pixels
แผ”ฯฯ‰ฯ‚
looks so good! ๐Ÿคฎ
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
there's a issue with svg it doesn't stop growing at all like it will grow exponentially
Simon
Simonโ€ข2mo ago
Are you telling it that there should be a max-width?
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
ah shit lemme try how do i forget this kinds of things
Chris Bolson
Chris Bolsonโ€ข2mo ago
You can use letter-spacing on the SVG text.
Simon
Simonโ€ข2mo ago
@peterpumkineaterr have you designed your mobile to desktop layouts โ€“ because that can help you figure out your designs limitations
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
how whenever i do it text goes invisible half of it yes i did plus if i did max-width: 70% then it won't center
Chris Bolson
Chris Bolsonโ€ข2mo ago
You will need to adjust the sag viewBox to allow for the extra space required (assuming you are increasing the letter spacing)
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
let me try nope not working i had to give like 100rem of width
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
why it has this box two times and space at the end ? bro why is this hard ?
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
it's definatly gonna make me cry
Chris Bolson
Chris Bolsonโ€ข2mo ago
I am not sure what you are doing there. You just need to add the letter-spacing in your CSS as normal, then adjust the viewBox width to ensure that it all fits in
Chris Bolson
Chris Bolsonโ€ข2mo ago
<svg class="logo-name" viewBox="0 0 80.8 13" fill="currentColor" preserveAspectRatio="xMidYMid meet">
<text x="-2.2" y="12">JON MON</text>
</svg>
<svg class="logo-name" viewBox="0 0 80.8 13" fill="currentColor" preserveAspectRatio="xMidYMid meet">
<text x="-2.2" y="12">JON MON</text>
</svg>
svg.logo-name {
width: 100%;
font-family: "Ailerons", sans-serif;
fill: white;
letter-spacing: .2rem;
}
svg.logo-name {
width: 100%;
font-family: "Ailerons", sans-serif;
fill: white;
letter-spacing: .2rem;
}
In the SVG I have only adjusted the viewBox width so that it fits exactly the width of the text (for this specific text). In the text element, the small negative x value is to compensate for the space taken up by the letter "J" which doesn't quite start at the beggining.
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
forget it i deleted it all the css code for h1 and h2 i've been trying from hours but this shit isn't working at all is h1 works then h2 doesn't such a headache
Chris Bolson
Chris Bolsonโ€ข2mo ago
What is the HTML and CSS for those 2 elements? (h1 and h2) I assume that the h1 is the SVG with "Jon Mon" and the h2 is the subtext "CEO & Product Designer". Assuming that you now have the h1 working correctly with the SVG, how do you want the h2 to be displayed (small and large screens)?
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
i did this let me share the codepen and full website @Chris Bolson i made the codepen how can i use svg as img in codepen ? svg data is so big https://codepen.io/kev00690/pen/BaXgqrd .mobile .desktop needs svg
Chris Bolson
Chris Bolsonโ€ข2mo ago
If you have an extermal SVG you can include it just as you would include a jpg or png, ie within an image tag. However you will not be able to manipulate an external SVG with CSS in the same way that you can with an inline SVG. If you are referring to the the SVG for the "Jon Mon", the version that I created for you is not big, quite the opposite it is a minimal amount of code that achieves what you were asking for. Far better than including an external asset. Your codepend bears little resemnblance to what you have been discussing so it is impossible to know what you want to do.
Simon
Simonโ€ข2mo ago
syntax
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
oh my freaking god you're a savior HAHA man how did that happened https://codepen.io/kev00690/pen/BaXgqrd alright @Chris Bolson check this out oh i shouldn't have pinged you i won't do it again.
Chris Bolson
Chris Bolsonโ€ข2mo ago
OK, I see it now.
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
that's why i was wondering why the hell .mobile wasn't hiding
Chris Bolson
Chris Bolsonโ€ข2mo ago
But I don't understand why you have opted to create the SVG for the logo like that rather than using the much simpler method that I showed you ๐Ÿ˜• ๐Ÿค”
Chris Bolson
Chris Bolsonโ€ข2mo ago
I have included both texts into a single SVG
<svg class="logo-name" viewBox="0 0 80.8 19" fill="currentColor" preserveAspectRatio="xMidYMid meet">
<text x="-2.2" y="12">JON MON</text>
<text x="0" y="18">CEO & Product Designer</text>
</svg>
<svg class="logo-name" viewBox="0 0 80.8 19" fill="currentColor" preserveAspectRatio="xMidYMid meet">
<text x="-2.2" y="12">JON MON</text>
<text x="0" y="18">CEO & Product Designer</text>
</svg>
svg.logo-name {
width: 100%;
}
svg.logo-name > text:first-child{ /*JON MON*/
fill: white;
letter-spacing: .2rem;
font-family: "Ailerons", sans-serif;
}
svg.logo-name > text:last-child{ /* CEO & product designer */
font-family: system-ui, sans-serif; /* I don't know what font you used for this text*/
font-size: .2rem;
letter-spacing: .126rem;
text-transform: uppercase;
fill: rgba(255 255 255 / .25);
font-weight: 100;
}
svg.logo-name {
width: 100%;
}
svg.logo-name > text:first-child{ /*JON MON*/
fill: white;
letter-spacing: .2rem;
font-family: "Ailerons", sans-serif;
}
svg.logo-name > text:last-child{ /* CEO & product designer */
font-family: system-ui, sans-serif; /* I don't know what font you used for this text*/
font-size: .2rem;
letter-spacing: .126rem;
text-transform: uppercase;
fill: rgba(255 255 255 / .25);
font-weight: 100;
}
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
it has spacing included and letter spacing was taking too much time and i have to finish this website end of the day tomorrow cause i have exams from 30 so i will also have to study damn well i'm not the big fan of my current portfolio design i have one design in mind
Chris Bolson
Chris Bolsonโ€ข2mo ago
But I gave the code to you on a plate! you didn't need to do anything to it other than adjusting a couple of values to suit your design if required. What you have done is far more complicated and more dificult to fine-tune.
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
i will be working on that after my exam
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
i did this
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
this is the first time i was doin it and viewBox i didn't understand it properly it will take some practice to me but yes i liked your way and definitely i will use it for my next design as i have someting awesome in my mind for next design and i will be using most thing as svg now there's only one thing remain
Chris Bolson
Chris Bolsonโ€ข2mo ago
The problem with this solution is that you are still including both images (svgs) so it will take longer to download that is really necessary. Probably not an issue as the SVGs are quite simple but bear in mind that there are better ways to define different images for different screen sizes which allow the browser to only download the image according to the viewport size.
Chris Bolson
Chris Bolsonโ€ข2mo ago
When you have a chance take a look at this MDN article regarding how to use srcset in images. You basically define multiple images within the same img tag and define the viewport sizes for each of them. The browser then decides which one to download accordingly:
<img
srcset="elva-fairy-480w.jpg 480w, elva-fairy-800w.jpg 800w"
sizes="(max-width: 600px) 480px,
800px"
src="elva-fairy-800w.jpg"
alt="Elva dressed as a fairy" />
<img
srcset="elva-fairy-480w.jpg 480w, elva-fairy-800w.jpg 800w"
sizes="(max-width: 600px) 480px,
800px"
src="elva-fairy-800w.jpg"
alt="Elva dressed as a fairy" />
(code copied from that article)
MDN Web Docs
Responsive images - Learn web development | MDN
That's a wrap for responsive images โ€” we hope you enjoyed playing with these new techniques. As a recap, there are two distinct problems we've been discussing here:
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
damnn that's easy as heaven how the hek i did not knew bout this ?
Chris Bolson
Chris Bolsonโ€ข2mo ago
๐Ÿ˜† you can't know about everything - there is too much out there!
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
sizes="(max-width: 600px) 480px, 800px" can you explain me this 600px max width ?
Chris Bolson
Chris Bolsonโ€ข2mo ago
that is saying that, for viewports up to 600px uses the first image, assigning it a slot of 480px, otherwise it will use the second image. You can define as many images (and their corresponding sizes) as you require. From the mdn article:
1. A media condition ((max-width:600px)) โ€” you'll learn more about these in the CSS topic, but for now let's just say that a media condition describes a possible state that the screen can be in. In this case, we are saying "when the viewport width is 600 pixels or less". 2. A space 3. The width of the slot the image will fill when the media condition is true (480px)
As I say, I suggest that you read the article when you have time as mdn does a far better job than me of explaining things
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
okay i will read this article it's a lot easier can we also use this for text ? cause that max and calc(100vw / 20) is quite confusing and this 20 doesn't work above 30 ???? like what the hek
Chris Bolson
Chris Bolsonโ€ข2mo ago
For text (and other things) you can use clamp()
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
yeah understanding clamp is also quite confusing i tried that too chris do you remember that hover effect and that div was showing the image on hover what if we open a that div into that page (just like we open "preview.app" by pressing space button in macos, just like that) so the url of those won't open in new tab instead it will open like preview on that same tab ? is it possible ?
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
like this
Simon
Simonโ€ข2mo ago
๐Ÿค”
No description
peterpumkineaterr
peterpumkineaterrOPโ€ข2mo ago
ok ok i will make a new post

Did you find this page helpful?