Skip to content

Conversation

@anjannair
Copy link

From trial and error characters over 75 often caused alignment issues. To fix this a truncation was introduced at the cost of the title.

All caps titles also caused alignment issues. To fix this only the first letter of the word was capitalized.

Often with big titles it often used to overlap with the author name. To fix this a small padding to remove overlap has been introduced.

Comment on lines +44 to +47
// 75 characters above spoils the alignment
if (titles[i].innerHTML.length > 75) {
titles[i].innerHTML = titles[i].innerHTML.substring(0, 73) + "...";
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this more elegantly achieved using text-overflow: ellipsis; (and possibly some other CSS properties) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text-overflow: ellipsis is a good property but I could not get it to work even with other properties. However I found this in the MDN docs

The text-overflow property only affects content that is overflowing a block container element in its inline progression direction (not text overflowing at the bottom of a box, for example).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just a question - What is the problem with JavaScript? (A generalized question for both the comments)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem with JS, I think it's more about just using the right tool for the job.

I'd like to have a go at seeing if text-overflowcould work, hope that's ok. Otherwise this should be an okay way to deal with it. I appreciate the help 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I just had a go at trying to fix this and yeah, it's very difficult to get it perfect using just CSS. I got close but not quite. The issue is dealing not just with long titles but specifically long words.

Anyway, your solution works well, however your chosen values didn't work for me. I had to reduce the character length to 40 in the JS. I experimented with various different titles with long words, many short words, etc... Are you able to confirm?

Copy link
Author

@anjannair anjannair May 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

40 instead fits perfectly for me and my chosen values goes out of bounds
Browser - Firefox v100
Size - 1920x968 px

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

bookshelf.js Outdated
Comment on lines 49 to 54
//If all caps capitalize the first letter of each word as all capitals also spoil the alignment
if (titles[i].innerHTML.toUpperCase() === titles[i].innerHTML) {
titles[i].innerHTML = titles[i].innerHTML.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can text-transform: capitalize; not be used instead?

Copy link
Author

@anjannair anjannair May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am using this to only capitalize the first letter of the already capitalized string

For example - HELLO WORLD gets converted to Hello World

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I don't think you need all that JS for that though.

text-transform: capitalize will take lower case text and turn it into "title case" (hello world -> Hello World) so to make it work with all caps input you can just use toLowerCase()

I'm just wondering if this is really necessary though; the user defines the input after all. Need to think about it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yes this makes sense, I totally skipped the part where is the user is the one who enters the data. Should I put in a commit removing this piece of code?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think ultimately this isn't needed. However, adding:

    text-transform: capitalize;
    text-align: left;

to .spine-title is a good addition I think.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason text-align: left; makes it look bad. The center alignment should stay I feel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants