Is there a way to make css underline by every line? [duplicate] - css

This question already has answers here:
Underline several lines of text + underline to be full width + responsive
(1 answer)
Need to display multiline text with underlining lines of equal length
(5 answers)
Closed 10 months ago.
I'm making hexo blog theme. I'am trying to make line note like style. I want to make css on each line has underline(not like U tag)
want
But if I use border-bottom: 1px solid grey
real

You may also use a gradient to draw a grid below your text.
It has to match the line-height
Here an example with CSS var() to ease the tuning.
p, textarea {
--lineH: 1.6em;
line-height: var(--lineH);
padding:var(--lineH);
padding-block:0;/*reset to set first line right at top */
background:repeating-linear-gradient(to bottom, transparent 0 1.4em, gray 1.4em calc(1.4em + 2px), transparent calc(1.4em + 2px) 1.6em) 50% 0 / calc(100% - var(--lineH) * 2 ) 100% no-repeat ;
}
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
<textarea placeholder="Type your texts here"></textarea>
Added a textarea to the example to show another possible use.
ressources if you need them
https://developer.mozilla.org/en-US/docs/web/css/gradient/repeating-linear-gradient
https://developer.mozilla.org/en-US/docs/Web/CSS/var
https://developer.mozilla.org/en-US/docs/Web/CSS/background
https://css-tricks.com/a-complete-guide-to-calc-in-css/
you can use more gradients to mimic a full note sheet https://codepen.io/gc-nomade/pen/bGLGNWB

You can use text-decoration: underline to get that effect (although the text-underline-offset style rule which is used to space the line from thee normal position is NOT supported in IE at all and some other browsers are a bit spotty with it). The only other way to do it is to split the content into spans and apply the border bottom or ::after pseudo-element to each span.
p {
font-size: 14px;
font-weight: 400;
line-height: 32px;
text-decoration: underline;
text-underline-offset: 4px;
}
<h2>Hello world<h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed mauris a metus ultricies sagittis commodo sed tellus. Cras sodales nunc ut neque feugiat dignissim. Nullam ligula mauris, blandit eu dignissim at, rutrum vitae nisi. Proin facilisis massa vel elit fermentum, sit amet aliquam quam hendrerit. Aenean interdum nisi a metus consequat, vitae viverra ligula scelerisque. Sed in erat dictum, dapibus arcu quis, interdum orci. Suspendisse sit amet gravida purus, eu facilisis felis. Aliquam consectetur dapibus augue a suscipit. In semper pretium erat. Duis eget sollicitudin arcu, volutpat scelerisque est. Proin nisl nisi, tincidunt a justo id, lobortis tempor lacus. Quisque eu tincidunt ex.</p>

The p tag is a block element. Means if you assign a border the border would be assigned for the block. If you change p tag to an inline element then the border would be displayed like you want.
Update
with inside underlined words
p {
display: inline;
border-bottom: 1px solid grey;
}
p span {
text-decoration: underline;
color: red;
}
<h2>Hello world<h2>
<p>Lorem ipsum dolor sit amet, <span>consectetur adipiscing</span> elit. Duis sed mauris a metus ultricies sagittis commodo sed tellus. Cras sodales nunc ut neque feugiat dignissim. Nullam ligula mauris, blandit eu dignissim at, rutrum vitae nisi. Proin facilisis massa vel elit fermentum, sit amet aliquam quam hendrerit. Aenean interdum nisi a metus consequat, vitae viverra ligula scelerisque. Sed in erat dictum, dapibus arcu quis, interdum orci. Suspendisse sit amet gravida purus, eu facilisis felis. Aliquam consectetur dapibus augue a suscipit. In semper pretium erat. Duis eget sollicitudin arcu, volutpat scelerisque est. Proin nisl nisi, tincidunt a justo id, lobortis tempor lacus. Quisque eu tincidunt ex.</p>
p {
display: inline;
border-bottom: 1px solid grey;
}
<h2>Hello world<h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed mauris a metus ultricies sagittis commodo sed tellus. Cras sodales nunc ut neque feugiat dignissim. Nullam ligula mauris, blandit eu dignissim at, rutrum vitae nisi. Proin facilisis massa vel elit fermentum, sit amet aliquam quam hendrerit. Aenean interdum nisi a metus consequat, vitae viverra ligula scelerisque. Sed in erat dictum, dapibus arcu quis, interdum orci. Suspendisse sit amet gravida purus, eu facilisis felis. Aliquam consectetur dapibus augue a suscipit. In semper pretium erat. Duis eget sollicitudin arcu, volutpat scelerisque est. Proin nisl nisi, tincidunt a justo id, lobortis tempor lacus. Quisque eu tincidunt ex.</p>

try this :
text-decoration: underline;
text-underline-offset:6px;

Have you tried using the text-decoration-line property.
text-decoration-line: underline;
https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_text-decoration-line

Related

Use remaining parent height without calc [duplicate]

This question already has answers here:
Fill remaining vertical space with CSS using display:flex
(6 answers)
Why don't flex items shrink past content size?
(5 answers)
Closed 2 years ago.
I've created a layout for a panel system I am working on (see code below). This is working fine, except that I need to use calc() in order to determine the height of the element minus their siblings. Since in the final stage the height of the sibling elements is dynamic it will not scale.
My question is, how could I make the following code example work without calc() where the values used inside of it will be dynamically determined?
body {
display: flex;
margin: 0;
}
.frame {
position: relative;
width: 250px;
height: 500px;
margin: 100px auto;
border: 2px solid black;
}
.panel {
position: absolute;
top: -64px;
bottom: 0;
width: 100%;
background-color: hotpink;
}
.panel-header {
width: 100%;
height: 64px;
background-color: lime;
flex-shrink: 0;
}
.panel-content {
width: 100%;
height: calc(100% - 64px);
background-color: aquamarine;
}
.panel-handle {
width: 100%;
height: 32px;
background-color: purple;
}
.panel-content-inner {
width: 100%;
height: calc(100% - 32px);
overflow-y: scroll;
}
<div class="frame">
<div class="panel">
<div class="panel-header"></div>
<div class="panel-content">
<div class="panel-handle"></div>
<div class="panel-content-inner">
<h4>Lorem impsum</h4>
<p>
orem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum iaculis rutrum pharetra.
Fusce id massa quis felis rutrum scelerisque eget a odio. Sed imperdiet, turpis vel mollis
pretium, lorem ipsum venenatis metus, nec consectetur quam quam blandit nibh. Suspendisse
ullamcorper cursus risus, sed venenatis libero aliquet ut. Aenean auctor porttitor odio eget
sollicitudin. Vestibulum nunc turpis, porta ac libero et, egestas dapibus tortor.
Pellentesque neque augue, mattis eu orci a, tempus ornare erat. Maecenas et ultricies
tellus, eu hendrerit est. Duis feugiat libero sit amet accumsan pharetra. Nulla volutpat sem
nec sapien interdum lobortis. Praesent a tortor leo. Fusce hendrerit fringilla consequat.
Nulla at justo nec risus placerat luctus. Aliquam vulputate ante justo, at auctor elit
porttitor et.
</p>
<h4>Lorem impsum</h4>
<p>
orem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum iaculis rutrum pharetra.
Fusce id massa quis felis rutrum scelerisque eget a odio. Sed imperdiet, turpis vel mollis
pretium, lorem ipsum venenatis metus, nec consectetur quam quam blandit nibh. Suspendisse
ullamcorper cursus risus, sed venenatis libero aliquet ut. Aenean auctor porttitor odio eget
sollicitudin. Vestibulum nunc turpis, porta ac libero et, egestas dapibus tortor.
Pellentesque neque augue, mattis eu orci a, tempus ornare erat. Maecenas et ultricies
tellus, eu hendrerit est. Duis feugiat libero sit amet accumsan pharetra. Nulla volutpat sem
nec sapien interdum lobortis. Praesent a tortor leo. Fusce hendrerit fringilla consequat.
Nulla at justo nec risus placerat luctus. Aliquam vulputate ante justo, at auctor elit
porttitor et.
</p>
<h4>Lorem impsum</h4>
<p>
orem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum iaculis rutrum pharetra.
Fusce id massa quis felis rutrum scelerisque eget a odio. Sed imperdiet, turpis vel mollis
pretium, lorem ipsum venenatis metus, nec consectetur quam quam blandit nibh. Suspendisse
ullamcorper cursus risus, sed venenatis libero aliquet ut. Aenean auctor porttitor odio eget
sollicitudin. Vestibulum nunc turpis, porta ac libero et, egestas dapibus tortor.
Pellentesque neque augue, mattis eu orci a, tempus ornare erat. Maecenas et ultricies
tellus, eu hendrerit est. Duis feugiat libero sit amet accumsan pharetra. Nulla volutpat sem
nec sapien interdum lobortis. Praesent a tortor leo. Fusce hendrerit fringilla consequat.
Nulla at justo nec risus placerat luctus. Aliquam vulputate ante justo, at auctor elit
porttitor et.
</p>
<h4>Lorem impsum</h4>
<p>
orem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum iaculis rutrum pharetra.
Fusce id massa quis felis rutrum scelerisque eget a odio. Sed imperdiet, turpis vel mollis
pretium, lorem ipsum venenatis metus, nec consectetur quam quam blandit nibh. Suspendisse
ullamcorper cursus risus, sed venenatis libero aliquet ut. Aenean auctor porttitor odio eget
sollicitudin. Vestibulum nunc turpis, porta ac libero et, egestas dapibus tortor.
Pellentesque neque augue, mattis eu orci a, tempus ornare erat. Maecenas et ultricies
tellus, eu hendrerit est. Duis feugiat libero sit amet accumsan pharetra. Nulla volutpat sem
nec sapien interdum lobortis. Praesent a tortor leo. Fusce hendrerit fringilla consequat.
Nulla at justo nec risus placerat luctus. Aliquam vulputate ante justo, at auctor elit
porttitor et.
</p>
</div>
</div>
</div>
</div>

Why does the overflow:hidden didn't applied to my <p> element?

The overflow property didn't hide my overflown content which overflows the width of the element.
HTML
<section><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed feugiat lacus. Morbi auctor, nibh vitae scelerisque cursus, nisl purus imperdiet lacus, quis porttitor ante mauris eget tortor. Vestibulum id molestie dui. Nullam sit amet ultrices ante. Nulla venenatis pellentesque mi, vel condimentum orci facilisis pellentesque. Aenean a enim ac dui tempus ornare eget nec nisl. In facilisis varius ullamcorper. Aliquam magna erat, pellentesque ut arcu et, accumsan placerat urna. Vestibulum porta justo ut laoreet dapibus.
Etiam dictum semper dolor, in laoreet turpis aliquam eget. Aliquam pulvinar sem lectus, vitae hendrerit libero pellentesque eu. Duis nec tincidunt felis, sed feugiat.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sed feugiat lacus. Morbi auctor, nibh vitae scelerisque cursus, nisl purus imperdiet lacus, quis porttitor ante mauris eget tortor. Vestibulum id molestie dui. Nullam sit amet ultrices ante. Nulla venenatis pellentesque mi, vel condimentum orci facilisis pellentesque. Aenean a enim ac dui tempus ornare eget nec nisl. In facilisis varius ullamcorper. Aliquam magna erat, pellentesque ut arcu et, accumsan placerat urna. Vestibulum porta justo ut laoreet dapibus.
Etiam dictum semper dolor, in laoreet turpis aliquam eget. Aliquam pulvinar sem lectus, vitae hendrerit libero pellentesque eu. Duis nec tincidunt felis, sed feugiat.</p></section>
CSS
*, *::after, *::before {
box-sizing: border-box;
}
html, body, div, p{
margin: 0;
padding: 0;
}
section{
width: 50%;
background-color: pink;
height: 150px;
}
p{
font-size: 1em;
color: blue;
overflow: hidden;
}
Codepen :: https://codepen.io/StinsonTheNoob/pen/oNbxjWx
If your goal is to not let the <p> start on a new line and rather not overflow, you need to set overflow:hidden to your <section>.
If you want the text to disappear if it exceeds the first line on the right side of the tag then put overflow: hidden; to its parent container which, in your case is the ...
But if you want that text remains inside the container only then you have to make the tag and the "font-size" responsive so that it adapts according to the width and then will not overflow!!!
If you simply don't want any scrolling of the page then kindly put overflow in html or body's CSS commands....

make only vertical scrolling invisible

Hi I want to make vertical scrolling invisible, but i want to left the horizontal scrollbar visible.
Also I want my page be scrollable both vertically and horizontally.
I used:
.my_class::-webkit-scrollbar{
display: none;
}
but it make both scrollbar invisible.
overflow-y: hidden; // hide vertical
overflow-x: hidden; // hide horizontal
These two CSS properties can be used to hide the scrollbars.
I have to say that using simple css trick, you wont be able to achieve this.
I suggest you d use custom scrollbar plugins, by which you can simply apply css trick for each scrollbar type, like following:
$(document).ready(function() {
$(".container").customScrollbar();
});
.container {
max-width: 300px;
max-height: 100px;
}
.container .overview {
width: 800px;
}
.scrollable .scroll-bar.horizontal {
background: #eee; height: 5px; border-radius: 20px;
}
.scrollable .scroll-bar.horizontal .thumb {
background: #999;
border-radius: 20px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/mzubala/jquery-custom-scrollbar/master/jquery.custom-scrollbar.css" />
<script src="https://rawgit.com/mzubala/jquery-custom-scrollbar/master/jquery.custom-scrollbar.js"></script>
<div class="container">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam. Quisque semper justo at risus. Donec venenatis, turpis vel hendrerit interdum, dui ligula ultricies purus, sed posuere libero dui id orci. Nam congue, pede vitae dapibus aliquet, elit magna vulputate arcu, vel tempus metus leo non est. Etiam sit amet lectus quis est congue mollis. Phasellus congue lacus eget neque. Phasellus ornare, ante vitae consectetuer consequat, purus sapien ultricies dolor, et mollis pede metus eget nisi. Praesent sodales velit quis augue. Cras suscipit, urna at aliquam rhoncus, urna quam viverra nisi, in interdum massa nibh nec erat. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem. Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam. Quisque semper justo at risus. Donec venenatis, turpis vel hendrerit interdum, dui ligula ultricies purus, sed posuere libero dui id orci. Nam congue, pede vitae dapibus aliquet, elit magna vulputate arcu, vel tempus metus leo non est. Etiam sit amet lectus quis est congue mollis. Phasellus congue lacus eget neque. Phasellus ornare, ante vitae consectetuer consequat, purus sapien ultricies dolor, et mollis pede metus eget nisi. Praesent sodales velit quis augue. Cras suscipit, urna at aliquam rhoncus, urna quam viverra nisi, in interdum massa nibh nec erat.
</div>
Use over flow property :
overflow-y: hidden

CSS Automatically changing space width to align text lines

I have text inside div.
What I want to do is make lines same width, so space automatically changes to align lines, like you can do in Word.
Can it be done with html and css?
You can try with text-align: justify;
Working copy is here:
p {
text-align: justify;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eros velit, dictum id libero quis, porttitor volutpat odio. In et lectus a ligula pulvinar egestas. Nullam ornare turpis ac dui efficitur commodo. Mauris laoreet cursus lorem, quis congue neque venenatis vel. Nullam eu maximus nulla, vitae fermentum nisl. Sed eu euismod elit, eget consequat lorem. Suspendisse eget interdum elit. Nullam convallis massa magna, quis scelerisque orci sollicitudin eget. Curabitur porta nibh nisl, at tempor leo vulputate quis. Nam eget nibh turpis. Suspendisse ac ex finibus, consectetur nunc ac, dapibus sapien. Curabitur eleifend ut mauris quis sodales. Aenean viverra ante non mauris egestas, sed pellentesque dolor tempus. Donec rhoncus quis magna posuere fermentum.swdjsdlkalksdnlds jdhjfhdskjnhckjdsnc
</p>
You can use:
div {
text-align: justify;
text-justify: inter-word;
}
More info here

Make paragraph text fill container

I've seen a property that allow you to fill the entire width of a container with text, ala magazine style. It simply increases the space between words to accommodate for the additional space.
What is this property?
You're thinking of text-align: justify.
div {
text-align: justify;
}
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nec nisl ipsum, at ullamcorper justo. Vivamus ac dui lorem. Aliquam nec diam urna, in semper augue. Etiam commodo dui velit. Vestibulum in nibh nulla, a feugiat justo. Proin accumsan, tellus et condimentum laoreet, lacus lorem consequat nisi, ac fermentum velit eros at metus. Aliquam lacinia mollis felis, vel pretium nulla condimentum consectetur. Quisque in mattis nibh. Nunc adipiscing tincidunt elit, vitae pellentesque felis molestie ac. Fusce vestibulum dui in nibh gravida ut placerat ligula porta. Ut sem lectus, condimentum nec tincidunt a, imperdiet vitae risus.</div>

Resources