How To Limit Lines Of Text With CSS Only

Поділитися
Вставка
  • Опубліковано 19 лис 2024

КОМЕНТАРІ • 203

  • @beinyourguard
    @beinyourguard 2 роки тому +169

    what I like about Kyle's videos is that he does not edit the parts where he messes up. he acknowledges and looks for the error instead of recording it again

    • @ontheruntonowhere
      @ontheruntonowhere 2 роки тому +9

      Agreed, and I like that he messes up a lot. Makes me feel better about my own mistakes.

    • @BGdev305
      @BGdev305 2 роки тому +12

      you're 100% correct.. his mistakes and corrections actually help me understand things even more.

    • @MrOmaromran
      @MrOmaromran 2 роки тому +5

      and he rubs his nose immediately when he messes up.

    • @shreekharr3940
      @shreekharr3940 2 роки тому +1

      I am glad you and plenty others like it, but for me, especially in long learning sessions, can be distracting and even irritating at points.

    • @ontheruntonowhere
      @ontheruntonowhere 2 роки тому

      @@shreekharr3940 It's free, whatcha gonna do?

  • @EvertJunior
    @EvertJunior 2 роки тому +33

    That line limit is very nice, but the css only expand button I'm not sure is WCAG compliant and might be confusing for screen readers users so It's probably best to give it an aria-hidden prop since the entire text will be readable because screen readers don't consider css styles.

    • @ontheruntonowhere
      @ontheruntonowhere 2 роки тому

      I was wondering about this myself, but I think aria-hidden is unnecessary in this case since the collapsed state is purely visual decoration. The complete content should always be available to assistive devices, letting the user decide whether to skip on to the next. It's a bit different than an accordion where the entire content block is hidden.

    • @EvertJunior
      @EvertJunior 2 роки тому +6

      @@ontheruntonowhere but the input is a focusable element so it might confuse the user because checking the input won’t do / announce anything

    • @ontheruntonowhere
      @ontheruntonowhere 2 роки тому +1

      @@EvertJunior Yes, great point. I yield!

    • @PhilLesh69
      @PhilLesh69 5 місяців тому

      This also has a very limited use case. Maybe on some sort of dashboard. You wouldn't want this as an index of articles because it creates a distraction click that might reduce the amount of clicks to the actual content. If your abstract needs to be expanded before someone clicks on the link to read your article, the solution is a better written excerpt, not a fancier design pattern and more things for the user to interact with and get lost or distracted by.

  • @MarlonEnglemam
    @MarlonEnglemam 2 роки тому +3

    this is EXACTLY the task I've been working on and was having some trouble with because I had a lot of different scenarios and eventually one of them would just mess everything up, thank you!

  • @NoName-1337
    @NoName-1337 2 роки тому +49

    You can add "text-overflow: ellipsis;" to your styles to add the 3 dots for the overflow text if you want to.

    • @boring91
      @boring91 2 роки тому +5

      That's not gonna work.

    • @opjoter
      @opjoter 2 роки тому +1

      You misunderstood the problem

    • @HorsiMusic
      @HorsiMusic 2 роки тому +1

      This limits to only 1 line.

    • @atchaukhac7731
      @atchaukhac7731 2 роки тому

      @@boring91 it will if use it with "-webkit-box-oriented: vertical;"

    • @PrajwalCoding
      @PrajwalCoding 2 місяці тому

      can we animate when the box expands? if yes how do we do it?

  • @mykalimba
    @mykalimba 2 роки тому +3

    I thought I was experiencing déjà vu, but I wasn't... I was thinking of the video just like this that Kevin Powell released about a week ago! Same thumbnail concept, too!

  • @Marachi23
    @Marachi23 Рік тому

    he does not edit the parts where he messes up. he acknowledges and looks for the error and he is so handsome

  • @Crispypoyo
    @Crispypoyo 2 роки тому +3

    I literally searched this up about two weeks ago because I needed it for a project. Thank you for this vid!

  • @djondavid
    @djondavid 2 роки тому +7

    Best/most useful mini CSS tutorial yet. Thank you so much for your great content.

  • @ilovelctr
    @ilovelctr 2 роки тому +9

    Both you and Kevin and excellent, and so is the content of both of you! This is such an eye-opener. CSS is becoming such that with it it's possible to implement features which were previously only possible using JavaScript.

  • @abrotherinchrist
    @abrotherinchrist Рік тому

    Your videos are a rabbit hole of information that I can't stop watching.

  • @webartem
    @webartem Рік тому +2

    Wonderful solution! The only thing I would do another way is the text into the button - I would use instead CSS prop "content" because it keeps all text content in markup and lets a developer use variables here (from CMS or a translation). I suppose the label is better for accessibility as well.

  • @Tony.Nguyen137
    @Tony.Nguyen137 2 роки тому +3

    Using input checkbox as button is really a cool approach that I didnt know. I always hided the checkbox and used a label inside a button ❤😊

    • @nomad100hd
      @nomad100hd Рік тому +1

      Using a checkbox is bad practice because it is not accessibility friendly.

    • @Tony.Nguyen137
      @Tony.Nguyen137 Рік тому +1

      @@nomad100hd yeah. You‘Re right. Besides accessibility I tried the code on my ipad and didn‘t get the same result.

  • @broadshare
    @broadshare Рік тому

    Thank you. The kings of css, we want a css framework from Kyle and Kevin.

  • @SrinivasReddy07
    @SrinivasReddy07 2 роки тому +4

    Kyle, you simply nailed it as you do always. So much thank you.

  • @isfaharuddinnishan
    @isfaharuddinnishan 2 роки тому +2

    Whatever! I still watch your videos. Love you bro ❣️

  • @Solo_playz
    @Solo_playz 8 місяців тому

    What a dynamic creativity with just CSS 🤯

  • @Amr-ep3vl
    @Amr-ep3vl Рік тому

    I love how you were going nice and slow and explaining things clearly. And then the "has" property kicks in and you go full throttle and I don't understand what the hell just happened :D

  • @wazzadev7209
    @wazzadev7209 2 роки тому +1

    You have no idea how much I needed this, thanks so much man.

  • @kaylemaclou
    @kaylemaclou 2 роки тому +1

    Brilliant! Thanks Kyle ... and Kevin.

  • @aram5642
    @aram5642 2 роки тому +1

    Yes yes yes: for the vendor-prefix-free clamping technique!
    No no no: for text in css content (not localizable, poorly adoptable by framework components).
    A great video as always!

    • @GabrielSoldani
      @GabrielSoldani Рік тому

      Use together with content: attr(data-label-expand); and content: attr(data-label-collapse); if you want to keep it localizable and outside your CSS.

  • @marufmarzuq
    @marufmarzuq Рік тому +1

    Kyle this is d best video on this topic 💜💜

  • @nayemalifahim6701
    @nayemalifahim6701 Рік тому +1

    Make a video on an input box in which height auto increases and max-height 200px scrollbar comes

  • @haidubogdan8712
    @haidubogdan8712 2 роки тому +6

    I think a example using and would have been interesting to see. In this case you can solve the expanding animation without the need of a checkbox.

    • @alex4tm1
      @alex4tm1 2 роки тому

      but then you would always have to click to see the content no matter if it was 3 lines or 20, this solves that problem and when the text is short u see it all, when it's long u see a preview

    • @haidubogdan8712
      @haidubogdan8712 Рік тому +1

      @@alex4tm1 it's related to using the "hack" checkbox as a toggle element to expand / collapse. For me this is a bit counter-intuitive. The same principle of css ~:checked rule, can be applied on details[open] { ... }

  • @FireGames25
    @FireGames25 2 роки тому +1

    Btw you can add lorem as a language to your code spell extension, so it stops detecting it as errors

  • @ElectricKota
    @ElectricKota Рік тому +1

    You can even write it without has selector, just select sibling, by ~ sign, you need to move the input before paragpraph, so you must hide input and pair it with label, and then it will works even on older browsers without has() support. I use this hack for every hsmburger menu, sliding articles and so on.

  • @kyrill19
    @kyrill19 2 роки тому

    Kyle is so good with this. Thnx!

    • @codeWithMete
      @codeWithMete 2 роки тому

      Hello, I just create my channel, can you support?😊

  • @pritampodder12
    @pritampodder12 2 роки тому

    Wow! That's really some advanced level CSS 😘😘

  • @patrickconrad396
    @patrickconrad396 2 роки тому +1

    Damn man the ridiculously complex series of js loops I created to do this with pictures and then seeing the simplicity of pure css is insane.

    • @nomad100hd
      @nomad100hd Рік тому

      Using a checkbox is bad practice because it is not accessibility friendly. It is better to use javascript.

  • @ngochunglongnguyen4523
    @ngochunglongnguyen4523 2 роки тому

    This is awesome, make me want to this, add transition animation, it'll be smooth and look modern.

  • @randomride6057
    @randomride6057 2 роки тому +2

    I probably would have quit web dev by now if it were not for you, Kyle. You are the best web dev teacher out there, no paid course even compares to your videos. Thank you a million times!

  • @stillready6405
    @stillready6405 2 роки тому

    Damn after years of CSS I still can learn new things from you or Kevin :D

  • @Enkrod
    @Enkrod Рік тому +2

    This is really nice but doesn't work with Firefox if you don't manually set a flag in your Browser. I'm sure it will work in a near future version, but right now it's something to keep in mind.

  • @aneliayacheva6671
    @aneliayacheva6671 Рік тому

    oh I so needed this in one of my recent projects.. thank you, I will use it :))))))))))

  • @AndreiNedelus
    @AndreiNedelus 2 роки тому +10

    Great tips, I think instead of the + you can use ~ and will select only the siblings, witch in your code will be only 1 paragraph sibling.

    • @saroj_kumar
      @saroj_kumar 2 роки тому +2

      Plus, it will also work on old browsers.

    • @broadshare
      @broadshare Рік тому

      @@saroj_kumar I get maaaad every time someone mentions those old browsers😥 where are they, who is even using them? win officially killed IE

    • @saroj_kumar
      @saroj_kumar Рік тому +1

      @@broadshare , Though old browsers are not used for personal use, there are still corporate servers and applications that use legacy or may be some previous versions of browsers. On the contrary, as a developer, it's a good practice to always check for the edge case, even if no body uses old browsers, we still have to consider someone around the world might use it and be ready for it.

  • @re-member
    @re-member 4 місяці тому +1

    Thank you. Is there a way to show the button only if the text is overflowing?

  • @7heMech
    @7heMech 2 роки тому +1

    I was just about to search for how to do that!

  • @gioba4912
    @gioba4912 2 роки тому

    You're a genius!
    Thanks for the tutorial.

  • @theDanielJLewis
    @theDanielJLewis 2 роки тому

    I'd love to see a full tutorial!

  • @ay2s389
    @ay2s389 Рік тому +1

    Wow nice tips! Thanks!

  • @dmitry_ainutdinov
    @dmitry_ainutdinov 28 днів тому

    Really cool!
    Thank you Kail.
    ✌️👏🤝👍

  • @zeyouR
    @zeyouR 2 роки тому

    thankyou for teaching. amazing content

  • @dangoldsmith3039
    @dangoldsmith3039 10 місяців тому

    Very cool approach… I love it thanks kyle. The only shame is you can’t smoothly animate between the checked states can you? So the boxes smoothly animate to and from the expanded style.

  • @kuoyulu6714
    @kuoyulu6714 10 місяців тому +1

    this is so cool and useful !

  • @Vir7uaLGameplays
    @Vir7uaLGameplays 2 роки тому

    Holly shoot this is life changing level thanks!

  • @GermanEmmanuel
    @GermanEmmanuel 2 роки тому

    Just what I needed

  • @spoonmanchen7631
    @spoonmanchen7631 7 місяців тому

    Can you provide tips on how to make the transition in 'p' height more smoother?

  • @thienthuannguyenlong6830
    @thienthuannguyenlong6830 2 роки тому

    tks u verry much about your knowledge

  • @GstarYen
    @GstarYen 2 роки тому

    You are my life saver! Thank you!

  • @dand4485
    @dand4485 2 роки тому

    Great video. Just curious when the next CSS battle... 😁

  • @shivshankarshejwal6728
    @shivshankarshejwal6728 2 роки тому

    This was good one , got to learn a lot

  • @___Kevin
    @___Kevin 2 роки тому

    Well explained and very useful. Thank you

  • @paulthomas1052
    @paulthomas1052 2 роки тому

    Excellent little trick. Thanks :)

  • @slim_shdy
    @slim_shdy Рік тому

    You are a wizard ❤

  • @FunBSDpami
    @FunBSDpami 9 місяців тому

    Great job! Thanks

  • @spreadItWide
    @spreadItWide 2 роки тому

    That last minute was wild! Headed to that :has() video now!

  • @wayneswildworld
    @wayneswildworld 2 роки тому

    Love this. Thanks for sharing

  • @PickleRiiiiiiick
    @PickleRiiiiiiick Рік тому

    Great video as always. Keep going.

  • @khoinguyen-ft2ys
    @khoinguyen-ft2ys 2 роки тому

    :has selector is a game changer

  • @studyingasyouwere
    @studyingasyouwere 2 роки тому

    Thank you for the tips as always!

  • @moherna3323
    @moherna3323 2 роки тому

    Great content bro, very useful!

  • @neetsmlam
    @neetsmlam 2 роки тому +2

    nice video! it would be cool to hide the button if it is not required when the text is shorter too.. ;-)

  • @pablitocodes
    @pablitocodes 2 роки тому

    Great content. Congrats on your success.

  • @meganweber5057
    @meganweber5057 2 роки тому +2

    For the second technique, how do I get text-overflow: ellipsis to work?

  • @AleMadLei
    @AleMadLei Рік тому +1

    Thank you! This looks really cool.
    My only concern is accesibility, I think a screen reader would not be able to transmit the CSS text content and will not linit the content shown. Do you think that could be handled CSS only?

  • @mind_of_a_darkhorse
    @mind_of_a_darkhorse 2 роки тому

    Great tips!

  • @thetechie6770
    @thetechie6770 2 роки тому

    Please make a detailed explanation video on Redux

  • @e-benz
    @e-benz 2 роки тому

    cool tutorial, tnx

  • @sneaky-Jay
    @sneaky-Jay 2 роки тому

    There is an older technique here using the siblings css selector on the checked checkbox. But the drawback is the order of the elements inside the HTML.

    • @nomad100hd
      @nomad100hd Рік тому

      It is also not accessibility friendly.

  • @midhakhan3295
    @midhakhan3295 2 роки тому

    Great tip

  • @shneornagar6147
    @shneornagar6147 2 роки тому

    Great content! Thanks a lot 🙏

  • @avneet12284
    @avneet12284 2 роки тому

    This was so amazing

  • @Anonymous-vp5xe
    @Anonymous-vp5xe 2 місяці тому +1

    What if I get 2 lines of text only and don't want to show the button. Then what approach we can take. I tried to remove the button if it is coming inside my max lines but not able to achieve it.

  • @solcloud
    @solcloud 2 роки тому

    I remember amount of time I spend on this like 5 year ago for one client newsletter thingy that want this on web and also inside outlook 😂

  • @AcidiFy574
    @AcidiFy574 2 роки тому

    Ever thought about teaching basics of XML ??

  • @Holy_Frijole
    @Holy_Frijole 2 роки тому +3

    Any accessibility ramifications since we are using a checkbox in the second example?

    • @Martinit0
      @Martinit0 2 роки тому +1

      Why, the use case is actually to switch between two states. A button is actually meant to trigger an action, not switch between two states.

    • @revenge425
      @revenge425 2 роки тому

      my take is not really, it actually makes more sense than a button : It looks like a button but it is a check that toggle if the content is expanded or not. checkbox should be used for true and false situations and this actually is a true and false situation..

  • @-d3d9ex97
    @-d3d9ex97 2 роки тому

    great work

  • @nguyenvuvietanh9268
    @nguyenvuvietanh9268 Рік тому

    can you teach me how to add transition to this wonderful thing?

  • @polymer940c
    @polymer940c 2 роки тому

    great video, learn a ton, but :has is not supported in firefox...

  • @Trazynn
    @Trazynn 2 роки тому

    Can you show us how to make a random image gallery fetching images from a folder?

  • @edgarsilvax
    @edgarsilvax 2 роки тому

    Thanks!

  • @webstercho
    @webstercho 2 роки тому +1

    Nice, but not Firefox friendly with has() 🙂

  • @-leovinci
    @-leovinci 2 роки тому

    checkbox vs button (css vs js)

  • @Martinit0
    @Martinit0 2 роки тому

    Amazing!
    Can you code Doom in CSS?

  • @rama3018
    @rama3018 2 роки тому

    Wow , your vidio so good bro , yeah i like to learn your vidio and practice 😂

  • @calcio437
    @calcio437 2 роки тому

    Thanks

  • @MarcoGarri-co8jn
    @MarcoGarri-co8jn Рік тому

    Great video. Helps a lot. I there any way to implement in wordpress classic editor because after include this is deleted form page and if I use code snippet include ::before

  • @scottmacintyre7385
    @scottmacintyre7385 2 роки тому

    Thanks for the great video. I'm trying to do limited text lines with ellipsis in a table cell using css but can't get it to work. Any suggestions would be a great help.

  • @Antonio-yn4mb
    @Antonio-yn4mb Рік тому

    Great!, but if I have 2 paragraphs?, I should test it..

  • @mfsbo
    @mfsbo 2 роки тому

    Hey Kyle, how did you edit the cursor when you placed the last cursor in multiple cursors at wrong place. It was around 1:35 mark

  • @puspamadak
    @puspamadak 2 роки тому +2

    Currently, the biggest problem in the web technologies is the lack of extensibiity. Till now we don't have any way of extending internal CSS and JavaScript classes. If that would be the case, we could have got more control of things such as font rendering, height calculation, etc. We are having to (kind of) live with workarounds.

  • @offgridvince
    @offgridvince 2 роки тому +1

    Thank you so much for you videos, I'm learning so much. Also, I am having a difficult time with the login tutorial. I can only get the login in route to work in deveplopment. I can't seem to get bcrypt compare to work in production with MongoDB Atlas or Compass. Please help. Thank you.

    • @offgridvince
      @offgridvince 2 роки тому +1

      I'll accept knowledge from the chat as well. I reached out with comments on that video, but it's like 2 years old now. Not too active.

  • @shihab3930
    @shihab3930 2 роки тому

    Just 😲 wow!

  • @TonyStark90743
    @TonyStark90743 2 роки тому

    Plz make videos on Google auth with mern and Rest api with nodejs and sql

  • @kelvinclark3474
    @kelvinclark3474 2 роки тому

    Awesome 👍

  • @AveLenivius
    @AveLenivius 2 роки тому

    Really cool

  • @smohammadhn
    @smohammadhn 2 роки тому

    That was magic ... 😁

  • @alexshel8578
    @alexshel8578 2 роки тому

    this is awesome

  • @FoxiAndMolly
    @FoxiAndMolly 10 місяців тому

    hi and great thanks. Is it possible to somehow get the expansion animate a bit slower? smooth scroll like.

  • @ankitshukla8640
    @ankitshukla8640 2 роки тому

    Hey Kyle, can you move into flutter? or make another channel app dev simplified.

  • @mrbuster3106
    @mrbuster3106 2 роки тому +2

    :has() does not work on firefox, unless you unlock it via configuration. Understandably this means production code cannot use :has() selector :/

    • @theodorealenas3171
      @theodorealenas3171 2 роки тому

      Nor qutebrowser. And I'm meant to be able to use it, websites are text with fancy bullshits why wouldn't I be able to use it.