I have a list and I want line items with long text to flow to the second row which would have a shorter line height than the line height between regular line items. For example:
<ul style="list-style:none">
<li>
Hotel Chain
</li>
<li>
Taxi Service
</li>
<li>
Tourist Trap & Retail Plaza
</li>
<li>
Travel Company
</li>
<li>
Local Olive Oil Company
</li>
</ul>
So hopefully that makes it clear what I'm wanting. Thanks for helping!
{EDIT}
I changed the code above.
The design is responsive, so when the screen shrinks the list width shrinks and some lines that took up one line then takes up two lines. I want those with two lines to have a shorter line height.
It's not clear what effect you are trying to achieve but there is a pseudo-element of ::first-line which might be what you are after
ul {
width: 200px;
}
li {
margin-bottom:1rem;
line-height: 1;
}
li::first-line {
line-height: 2;
}
<ul>
<li>lorem</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam soluta ex ipsam dignissimos, provident assumenda!</li>
<li>lorem</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, magni!</li>
<li>Lorem ipsum dolor sit.</li>
</ul>
::first-line # MDN
You can do that natively this paragraphs.
<p>First line item</p>
<p>Second line item</p>
<p>This is the third line item that will<br>wrap on a new line but have a<br>smallerline-height than others</p>
<p>Fourth line item</p>
<p>This fifth line item is the same as<br>the third in that its line-height<br>is different because it has multiple lines</p>
<p>And the sixth line is the same with<br>a smaller line-height</p>
No need to css, or you can specify a width to your paragraphs if you don't want do write the BRs.
http://jsfiddle.net/8q6wgw2x/
Related
I have div block with ul list inside. And depending on the number of items div height getting bigger.And if the last item is not fit of div max-height it just cut it which is not very good(pic-1).
How to scroll per one element and if last item does not fit of div max-height hide it below(pic-2)?
PIC-1 https://i.ibb.co/0Bwnp02/Screenshot-9.png
PIC-2 https://i.ibb.co/jvmX9HN/Screenshot-10.png
<ul>
<li class="table-elem">
<p class="info-step">-1-</p>
<p class="info-text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Beatae
mollitia id neque?</p>
</li>
...
</ul>
I have a big block of text including a list <li> </li> that I'd like to hide in ellipses overflow. However, I realize that when the <li> element is nested in a <span> for which I've added the overflow and ellipses properties to, it won't apply to the <li> element! i.e., the list will not be hidden within the ellipses as overflow, it still gets displayed.
What is a workaround here?
You can't put a <li> element inside a span. <li> elements must stay directly under the <ul> tag. And, text-overflow does not works on inline elements (the default display for a span). For the text overflow, try this:
li {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
max-width: 40%;
}
<ul>
<li>Lorem ipsum, dolor sit amet consectetur</li>
<li>Lorem ipsum, dolor sit consectetur</li>
<li><span>Loremconsectetur ipsum, dolor sit amet consectetur</span></li>
<li>Lorem ipsum, consectetur</li>
</ul>
I have written a Knockout binding for a MegaMenu which has a hamburger component
The hamburger contains a bunch of Categories and items within these Categories
The Categories act as a header and are bolded. They then display their items underneath indented slightly
Categories and Items are just strings retrieved from a database
The rules of the hamburger are as follows:-
Don't split a Category across columns
Use 3 columns first before scrolling. i.e Don't fill only two columns and have a scroll bar (vertical)
Even up the columns as much as possible
3 columns max
The hamburger has a max height restriction
Categories are to be ordered alphabetically -
An example of the ordering is a follows:-
Assume I have the following Categories (ignore the items within them as it is the categories that are ordered)
Dogs, Cars, Cats, Beds, Furniture, Hobbies, Homes, Gyms, Horses
and if these were split across 3 columns they would be rendered as follows
Col 1 Col 2 Col 3
----- ----- -----
Beds Dogs Hobbies
Cars Furniture Homes
Cats Gyms Horses
I am able to construct html lists as follows:-
<div>
<ul>
<li>Beds
<ul>
<li>Item 1</li>
<li>Item 2
</ul>
</li>
<li>Cars
<ul>
<li>Item 1</li>
</ul>
</li>
<li>Cats
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>Dogs
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
</ul>
</div>
Can I use pure css to adjust it in the hamburger columns according to my rules?
That way I can avoid the messy looping etc that I am currently doing in my html
Your best bet is to use column layout with break-inside: avoid
From: https://css-tricks.com/almanac/properties/b/break-inside/
Fortunately, you can tell the browser to keep specific elements
together with break-inside.
-webkit-column-break-inside: avoid; /* Chrome, Safari, Opera */
page-break-inside: avoid; /* Firefox */
break-inside: avoid; /* IE 10+ */
I've made an example here
http://codepen.io/HerrSerker/pen/obgddJ
.outer {
-moz-columns: 3;
-webkit-columns: 3;
columns: 3;
display: block;
}
.outer > li {
display: block;
padding-top: 30px;
-webkit-column-break-inside: avoid;
/* Chrome, Safari, Opera */
page-break-inside: avoid;
/* Firefox */
break-inside: avoid;
/* IE 10+ */
}
.outer > li > span {
text-decoration: underline;
}
.inner {
width: 200px;
display: block;
text-decoration: none;
}
.inner > li {
display: block;
padding-left: 10px;
padding-top: 3px;
}
.wrapper {
width: 600px;
margin: 0 auto;
max-height: 400px;
overflow-y: auto;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
<div class="wrapper"><ul class="outer">
<li><span>Lorem ipsum dolor.</span>
<ul class="inner">
<li>Fuga, ratione blanditiis commodi.</li>
<li>Obcaecati dicta ut, pariatur!</li>
<li>Earum, illum sapiente enim.</li>
</ul>
</li>
<li><span>Vel, ratione cum!</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Accusamus, odio ipsum nemo!</li>
<li>Molestiae unde natus odio.</li>
<li>Lorem ipsum dolor sit.</li>
<li>Corporis, tempora nisi minus.</li>
</ul>
</li>
<li><span>Aliquid, tenetur, similique.</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Repellendus repellat placeat odit!</li>
</ul>
</li>
<li><span>Quibusdam, necessitatibus aliquid.</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>At nisi, quas veritatis!</li>
<li>Perferendis laudantium nesciunt dolor!</li>
<li>Distinctio quidem veniam impedit!</li>
</ul>
</li>
<li><span>Sed, quam, beatae.</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Voluptates temporibus provident dolores.</li>
<li>Explicabo non minus ullam!</li>
<li>Tenetur, molestias, debitis. Voluptatum.</li>
<li>Quibusdam incidunt unde, laboriosam!</li>
<li>Fugiat perferendis eligendi, dignissimos.</li>
</ul>
</li>
<li><span>Lorem ipsum.</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Perspiciatis, a dolore officia!</li>
</ul>
</li>
<li><span>Voluptatum, ipsum?</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Odit, aliquam voluptates alias!</li>
</ul>
</li>
<li><span>Dolorem, quos!</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Quae quos quas, fugit?</li>
</ul>
</li>
<li><span>Cum, excepturi.</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Libero distinctio, necessitatibus laborum!</li>
</ul>
</li>
<li><span>Blanditiis, harum.</span>
<ul class="inner">
<li>Lorem ipsum dolor sit.</li>
<li>Corporis fuga accusamus, ab?</li>
</ul>
</li>
</ul>
</div>
Is this compatible? See here: http://caniuse.com/#feat=css-grid
As for the sorting: you cannot do this with CSS You have to do it in HTML or with JS
Can I use pure css to adjust it in the hamburger columns according to my rules?
No, CSS cannot perform the required even-distribution arithmetics. You're stuck with pre-formatting in HTML in this case.
You can set the value display:table to your parent div , and then set display:table-cell to your children items.That's not going to break your columns.
I think I can achieve what you want using css column:
ul{
...
column-gap: 2em;
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
}
Demo: http://jsfiddle.net/pg2xy9h2/3/
I don't understand how it is possible to have Even up the columns as much as possible and a dynamic number of columns. Even up is a division calculation, how can you perform a division if the divisor is unknown?
I am no guru at CSS so please excuse what might be a basic question. I have an annoying problem which I can't seem to fix:
Here is my text without CSS line-height:
I would like to move the text up closer to the heading tags so I did this:
<h2>Loren Ipsum Dol Tjovanuu</h2>
<p style="line-height:0px;">
<i>Lorem ipsum dolor sit amet, consectetur adipiscing elit ...</i>
</p>
<h2>Neque porro quisquam est qui dolorem ipsum</h2>
<p style="line-height:0px;">
<i>Lorem ipsum dolor sit amet, consectetur adipiscin.</i>
</p>
The Result
The result is perfect and exactly what I want, but... the problem comes when I resize the browser.
Problem Resizing the browser
My Question
Why is the text condensing on browser resize? What am I doing wrong? Should I not use the line-height property? Any workaround for this?
The line-height property is used to control how much vertical space is allocated for each line. In general, it is used to adjust how much space there is between lines within an element.
line-height: 1 means that lines are exactly big enough to fit the tallest letters and lowest descenders, with no space between. A line-height of more than 1 means there is some extra space between lines, and less than 1 will result in lines overlapping.
line-height: 0 means that a line of text has no vertical space allocated to it, so all lines will overlap each other in one line. That is what you are seeing here: the text is wrapping onto a second line, which is rendered over the top of the first line.
What you are trying to do is adjust the space between elements, not the space between lines in a single element. For this, the recommended approach is to adjust either margin or padding. Consider adjusting the margins of your elements until you have your desired vertical rhythm.
For a really detailed explanation of how all three properties work, see this CSS Tricks article on the box model.
Example
body { font-family: sans-serif; }
.cramped h2 {
margin: 0.4em 0 0.2em;
}
.cramped p {
font-style: italic;
margin: 0;
}
<section class="cramped">
<h2>Loren Ipsum Dol Tjovanuu</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit ...</p>
<h2>Neque porro quisquam est qui dolorem ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscin.</p>
</section>
Add this to your CSS:
h2 {
margin-bottom: -10px;
}
h2 tags have margins by default
Here is the JSFiddle demo
<h2>Loren Ipsum Dol Tjovanuu</h2>
<p style="line-height:23px;">
<i>Lorem ipsum dolor sit amet, consectetur adipiscing elit ...</i>
</p>
<h2>Neque porro quisquam est qui dolorem ipsum</h2>
<p style="line-height:23px;">
<i>Lorem ipsum dolor sit amet, consectetur adipiscin.</i>
</p>
try this it works fine on my browser
try this
p{margin-top:-10px; font-style:italic;}
#media screen and (max-width:768px){
h2{font-size:18px;}
p{font-size:14px}
}
Line height usage is for setting the distance (height) of each line. 0 value gives no distance so you have this problem.
You should let the line-height in the default value and reset default h2 and p element margin.
line-height
On block level elements, the line-height property specifies the
minimum height of line boxes within the element.
On non-replaced inline elements, line-height specifies the height that
is used to calculate line box height. On replaced inline elements such
as buttons or other input element, line-height has no effect. [1]
h2, p {
margin: 0;
}
<h2>Loren Ipsum Dol Tjovanuu</h2>
<p>
<i>Lorem ipsum dolor sit amet, consectetur adipiscing elit ...</i>
</p>
<h2>Neque porro quisquam est qui dolorem ipsum</h2>
<p>
<i>Lorem ipsum dolor sit amet, consectetur adipiscin.</i>
</p>
Reference: MDN - line-height - w3.org - line-height
Does anyone know the CSS that makes the bullet point sit at the top of a multi-line bulleted list? For some reason with the template that I am using the bullet point centers to the left instead of simply sitting next to the first word if I have more than one line of text.
Set the list style position to inside the list item, see this demo fiddle.
CSS:
ul {
list-style-position: inside;
}
This is not an answer per-se but it may give others an insight to a similar visual situation with a different set of circumstances.
I had the same issue, like so:
My HTML looked like this:
<ul>
<li>
Link with several lines. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia, commodi!
<p>Lorem ipsum dolor sit amet.</p>
</li>
<li>
Link with several lines. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia, commodi!
<p>Lorem ipsum dolor sit amet.</p>
</li>
</ul>
And the CSS like this:
a {
display: inline-block;
vertical-align: middle;
}
See the offending part? The vertical-align: middle; declaration.
There are two solutions:
Solution 1
Remove the vertical-align: middle; declaration altogether.
Solution 2
Change the value: vertical-align: middle; to vertical-align: top;.
Result (as expected in the beginning):
Hope this helps.
You could do something like this:
(css)
li div:before
{
background-image:url('bullet.png');
}
(html)
<ul>
<li>
<div>
text<br />
more text
</div>
</li>
</ul>