+ 11

How does line-height works?[SOLVED]

I used it to center arrow but now by clicking on first div ,click event is triggered even tho it is set for second div,how can I avoid it and center the arrow? https://code.sololearn.com/W5dn3WwKKdlW/?ref=app

31st Jul 2020, 2:04 PM
Abhay
Abhay - avatar
29 Antworten
+ 6
I believe you should write display: inline-table to make the div display as a table, then it allows you to align it vertically. I'm still noob tho, that's just something I read somewhere recently. Edit: here is the source: https://www.sololearn.com/learn/CSS/1091/
31st Jul 2020, 3:55 PM
Karak10
Karak10 - avatar
+ 4
Kode Krasher you are right about that viewport thing ,I changed height to 50% and it didn't scaled at all since body has no default height size and takes the content size so surely vh is a better option. That arrow definitely looks good but again if you increase the size of it and make it 3em ,the same problem arises ,so adjusting line-height is still a better option considering there is a lot of blank space around that arrow one can't see and it overflows the block size(if it's too small) just like the normal text will and center align won't work
1st Aug 2020, 7:13 AM
Abhay
Abhay - avatar
+ 3
The position of the text from the top🤔
31st Jul 2020, 2:27 PM
Namit Jain
Namit Jain - avatar
31st Jul 2020, 4:05 PM
Calviղ
Calviղ - avatar
+ 2
Kode Krasher Android ,it's in the center of red div ,possibly it has something do with default font-size ,my is 16px,and my arrow size is 48px
31st Jul 2020, 11:02 PM
Abhay
Abhay - avatar
+ 2
Kode Krasher I know ,for me it was quite frustrating as well until I went through some articles ,if you set display:flex to parent element and set margin:auto to child it centers it ,for text , text-align :center and line-height about the height of container works well for centering text and I haven't looked into viewport stuff at all , positioning isn't a good idea if you wanna make a responsive website ,tho it can be controlled using values in %(I believe so).
31st Jul 2020, 11:37 PM
Abhay
Abhay - avatar
+ 2
Line height decides the height of an inline element . Can be used for vertical aligning. But mainly used for text
1st Aug 2020, 6:26 AM
Satvik Virmani
Satvik Virmani - avatar
+ 1
Use SVG
1st Aug 2020, 12:04 PM
Łukasz Kamiński
Łukasz Kamiński - avatar
2nd Aug 2020, 2:47 AM
S.Gopi Reddy™🔵
S.Gopi Reddy™🔵 - avatar
0
Abhay I don't get want you mean
31st Jul 2020, 2:09 PM
Calviղ
Calviղ - avatar
0
Calviղ if you click on first element ,hello is logged out but I have attached event handler to second element only ,remove that line-height property and clicking on first div won't log out hello
31st Jul 2020, 2:10 PM
Abhay
Abhay - avatar
0
Set line-height:1;
31st Jul 2020, 2:13 PM
Calviղ
Calviղ - avatar
0
Calviղ that is the problem i want to center the arrow inside div two and line-height was the only option I could find but it creates a problem as I mentioned before
31st Jul 2020, 2:15 PM
Abhay
Abhay - avatar
0
Set line height to 1 would make it align to center (vertically)
31st Jul 2020, 2:17 PM
Calviղ
Calviղ - avatar
0
text-align: center; would align it center (horizontally)
31st Jul 2020, 2:19 PM
Calviղ
Calviղ - avatar
0
Calviղ it doesn't center it inside a div
31st Jul 2020, 3:12 PM
Abhay
Abhay - avatar
0
Abhay yes, it's center inside the div.
31st Jul 2020, 3:13 PM
Calviղ
Calviղ - avatar
0
Calviղ can you rewrite the code and paste it in here please? I don't understand how it's inside the div ,because it's appearing outside
31st Jul 2020, 3:26 PM
Abhay
Abhay - avatar
0
Calviղ I want the arrow to be inside div in that blue box 🙄
31st Jul 2020, 4:08 PM
Abhay
Abhay - avatar
0
Abhay yes, it's inside and right at the center of the blue box.
31st Jul 2020, 4:10 PM
Calviղ
Calviղ - avatar