In Microsoft Word, and undoubtedly most other (modern) word processors, you can have a "list" of items (I use the term "list" loosely here), with a hanging initial character(s), and then insert a TAB to force the first character of actual text to align with your left margin of the block. E.g. if I had a bunch of symbols as identifiers, I could have:
# Foo bar on a long line
Where this is part of the "#" symbol identifier above
%% And this is a new line broken over many lines, but the
left-most edge still aligns
$__$ Isn't that fine?
I am trying to perform a similar action in HTML5 using CSS. I've found out about indents, a la:
<p style="padding-left: 100px; text-indent: -100px"># Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam lectus dolor, ultrices at euismod eu, dapibus sit amet mauris. Etiam maximus pulvinar sollicitudin.</p>
However, while the paragraph is left with a hanging indent, the first character of significance ("L" in "Lorem") does not align with the first character of significance when the line wraps. For example, it comes out like this:
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam lectus dolor, ultrices at euismod eu, dapibus
sit amet mauris. Etiam maximus pulvinar sollicitudin.
When I want it to come out like so:
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam lectus dolor, ultrices at euismod eu, dapibus
sit amet mauris. Etiam maximus pulvinar sollicitudin.
Looking further I found out about hanging-punctuation, but this does not seem to be supported anywhere; moreover, it is specific to punctuation marks - what if I want to use a letter instead of a symbol?
Any suggestions on how to accomplish this?
Many thanks.
This could be done a few different ways.
One method would be to use the ::before pseudo selector in CSS.
p {
position: relative;
margin: 40px; /* added just to move snippit away from window edges. */ }
/* this applies to all p tags */
p::before {
position: absolute;
left: -30px; /* moves character on top of left margin, away from text */ }
/* below merely inserts a character based on the class of the p tag */
p.hash::before { content: '#'; }
p.bang::before { content: '!'; }
p.huh::before { content: '?'; }
p.dbl::before { content: "%%"; }
p.law::before { content: "ยง"; }
<p class="hash">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p class="bang">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p class="huh">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p class="dbl">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p class="law">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
As #Scott mentioned in his good answer, this could be achieved in few different ways, so alternatively you may do it by using a span with position:absolute and zero left, and a combination of margin-left and padding-left to form the gap, something like this:
jsFiddle
p{
margin-left:10px;
padding-left:40px;
position:relative;
}
p .symbols{
position:absolute;
left:0;
}
<p><span class="symbols">#</span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p><span class="symbols">!</span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p><span class="symbols">^_^</span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.</p>
<p><span class="symbols">%%</span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p><span class="symbols">$$</span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
Related
Is it possible to make a fixed div scroll along when page scrolls, using CSS? And yes, it needs to remain fixed for other reasons.
.fixedDiv{
width:100%;
height:200px;
font-size:4em;
position:fixed;
}
.otherDiv{
position: relative;
width:250px;
height:auto;
}
<div class="fixedDiv">THIS IS A FIXED DIV</div>
<div class="otherDiv">The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
1914 translation by H. Rackham
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
1914 translation by H. Rackham
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."
</div>
You need to listen to onscroll and, based on that, update the position of the fixed element, relative to the viewport and taking into account the scroll percentage (rather than its absolute value) and the available vertical space left by the fixed element.
You can then move it using window.requestAnimationFrame and transform: translate(0, <Y>) to get an smoother and more performant animation:
const fixedDiv = document.getElementById('fixedDiv');
document.onscroll = () => {
const { documentElement } = document;
const { scrollTop, scrollHeight, clientHeight } = documentElement;
const availableSpace = clientHeight - fixedDiv.offsetHeight;
const scrollPercentage = scrollTop / (scrollHeight - clientHeight);
/*
scrollTop = How many pixels the page has scrolled vertically.
scrollHeight = Total height of the page, including content that overflows the visible area.
clientHeight = Viewport height.
availableSpace = How much unused vertical space does #fixedDiv leave.
Using requestAnimationFrame and transform, rather than not using it and updating top or
margin-top, will make the scrolling effect smoother and more performant:
*/
requestAnimationFrame(() => {
fixedDiv.style.transform = `translate(0, ${ availableSpace * scrollPercentage }px)`;
});
};
body {
margin: 0;
font-family: monospace;
}
#fixedDiv {
position: fixed;
top: 0;
z-index: 1;
width: 100%;
font-size: 32px;
padding: 16px;
box-shadow: 0 2px 0 black, 0 -2px 0 black;
background: rgba(255, 255, 255, .5);
}
#lorem {
width: 250px;
padding: 0 16px;
}
<div id="fixedDiv">THIS IS A FIXED DIV</div>
<div id="lorem">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut porta vitae nunc ut fermentum. Nam cursus eu neque eu tincidunt. Praesent libero eros, pellentesque ut est id, consectetur vestibulum nisi. Nunc eget arcu tortor. Quisque tempus erat eros, ac interdum ligula ullamcorper luctus. Praesent ultricies tristique magna, non tempor quam porttitor eget. Vestibulum volutpat vel turpis eget auctor. Vestibulum sagittis odio pulvinar tortor vestibulum, sed pharetra lacus mollis. Mauris sollicitudin sem mi, quis placerat turpis commodo quis. Nam non blandit justo. Morbi cursus metus orci, efficitur condimentum purus vehicula vel. Sed vel pulvinar risus, at posuere mauris. Suspendisse a enim quis arcu porttitor finibus. Sed eu turpis iaculis, gravida quam non, hendrerit ipsum. Integer id commodo eros, sit amet tempus velit. Aliquam velit tortor, faucibus eu elit ut, volutpat pulvinar nisi.
</p>
<p>
Quisque aliquam quam at orci tempor, sit amet suscipit mauris congue. Aenean id orci venenatis, iaculis nisi non, dictum mi. Duis a purus sed dui iaculis pharetra nec eu nunc. Ut tincidunt imperdiet felis, maximus dapibus sem congue ac. Nullam eget risus iaculis, blandit urna vel, dignissim tellus. Curabitur viverra, nisi eu blandit cursus, ante lacus maximus lacus, eget auctor ante ante id nibh. Vivamus interdum, ex ac placerat laoreet, tortor nisl efficitur elit, eu elementum felis ex ut magna. Vivamus tempor neque nec sodales consectetur. Suspendisse finibus tempor metus, varius euismod nulla. Cras maximus metus a viverra interdum. Duis sagittis mollis volutpat. Nulla lacinia ultricies scelerisque. Sed elementum sem eu suscipit pretium. Suspendisse potenti. Maecenas ut sollicitudin quam. Maecenas congue vehicula maximus.
</p>
<p>
Sed dictum aliquam nibh vel facilisis. Donec nec erat ut justo pretium hendrerit at a ex. Aliquam sollicitudin nulla sed consectetur venenatis. Mauris facilisis nisl purus, sit amet tristique ligula sollicitudin sit amet. Donec non erat lorem. Praesent posuere ultricies fermentum. Donec rhoncus aliquet metus sed porttitor. Mauris semper nibh suscipit volutpat gravida. Morbi vulputate nulla eget convallis aliquet. Quisque velit dolor, finibus sed porttitor sit amet, dictum ac metus. Ut ultricies porttitor orci vel iaculis. In quis odio ornare, scelerisque lacus quis, auctor eros.
</p>
<p>
Duis elementum, mauris eu facilisis porta, eros sem fermentum ex, in laoreet velit mauris sit amet massa. In nec ex euismod, ullamcorper magna quis, rutrum quam. Sed volutpat vel nisl quis placerat. Suspendisse auctor enim eu tempor congue. Quisque condimentum, ligula ut suscipit blandit, elit leo condimentum ante, auctor porttitor ante libero eu erat. Mauris et purus pulvinar, tristique leo eu, fermentum mauris. Suspendisse mollis vel odio a gravida. In euismod gravida massa. Donec in sem nunc. Etiam rutrum quis ex sed vestibulum. Nam aliquet tristique mi vel suscipit. Fusce et nisl et odio vulputate dignissim eget sed nisl.
</p>
<p>
Integer non malesuada sapien, at tincidunt diam. Fusce id metus metus. In volutpat sem vel risus euismod vulputate. Pellentesque tincidunt ante nisi, id feugiat enim finibus a. Mauris scelerisque vestibulum nunc, scelerisque egestas mauris aliquet auctor. Nunc vel nulla molestie, tempor lacus sed, interdum sapien. Nam luctus quis tellus quis elementum. Donec lorem enim, semper consectetur massa quis, convallis vulputate lectus. Suspendisse ultricies ultricies orci, at molestie neque bibendum nec. Nullam hendrerit eget arcu vel laoreet. Praesent vestibulum leo sit amet libero venenatis, sit amet finibus lorem fermentum. Nullam quis tellus pulvinar, ultrices tellus nec, aliquet ante. Nam eu libero id orci volutpat egestas.
</p>
</div>
I want to display my div's as this image dynamically because .box is in for, actually i don't find idiom for this problem to search in SO or Google.
.box {
width: 25%;
height: auto;
float: left;
}
.box-1 {
background: red;
}
.box-2 {
background: green;
}
.box-3 {
background: orange;
}
.box-4 {
background: #263139;
}
.box-5 {
background: #d11d69;
}
.box-6 {
background: #14ea41;
}
<div class="box box-1">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue
duis dolore te feugait nulla facilisi.
</div>
<div class="box box-2">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
</div>
<div class="box box-3">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor
</div>
<div class="box box-4">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor
</div>
<div class="box box-5">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor
</div>
<div class="box box-6">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor
</div>
One option is to use css columns, which might require you to reorder your boxes:
.boxes {
columns: 3;
}
.box {
height: auto;
margin-bottom: 15px;
}
.box-1 {
background: red;
}
.box-2 {
background: green;
}
.box-3 {
background: orange;
}
.box-4 {
background: #263139;
}
.box-5 {
background: #d11d69;
}
.box-6 {
background: #14ea41;
}
<div class="boxes">
<div class="box box-1">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
augue duis dolore te feugait nulla facilisi.
</div>
<div class="box box-2">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
</div>
<div class="box box-3">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor
</div>
<div class="box box-4">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor
</div>
<div class="box box-5">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor
</div>
<div class="box box-6">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor
</div>
</div>
The other would be using a Javascript based solution like Masonry:
$(function() {
$('.boxes').masonry()
});
.box {
height: auto;
width: calc(100% / 3);
float: left;
}
.box-1 {
background: red;
}
.box-2 {
background: green;
}
.box-3 {
background: orange;
}
.box-4 {
background: #263139;
}
.box-5 {
background: #d11d69;
}
.box-6 {
background: #14ea41;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/masonry-layout#4/dist/masonry.pkgd.min.js"></script>
<div class="boxes" data-masonry='{ "itemSelector": ".box" }'>
<div class="box box-1">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
augue duis dolore te feugait nulla facilisi.
</div>
<div class="box box-2">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
</div>
<div class="box box-3">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor
</div>
<div class="box box-4">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor
</div>
<div class="box box-5">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor
</div>
<div class="box box-6">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor
</div>
</div>
I want to make a login page like flickr website. I tried to learn how they designed it and the conclusion was they made a div autoscroll. My question is how to make a div auto scrollable on page load. And if there is any other way to achieve the same design then share.
I don't know what flickr is but this is an auto scrolling div curtesy of sitepoint: https://www.sitepoint.com/community/t/auto-scrolling-a-div-with-overflow-scroll-auto/2291 I imagine it would be easy enough to bend this to what you are looking for, make it horizontal etc.
<body>
<div id="ecran" style='overflow:auto;width:200px;height:200px;border:solid 1px green;'>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
<script type='text/javascript'>
function ScrollDiv(){
if(document.getElementById('ecran').scrollTop<(document.getElementById('ecran').scrollHeight-document.getElementById('ecran').offsetHeight)){-1
document.getElementById('ecran').scrollTop=document.getElementById('ecran').scrollTop+1
}
else {document.getElementById('ecran').scrollTop=0;}
}
setInterval(ScrollDiv,50)
</script>
</body>
I want to create simple toggle button, that will expand/hide text paragraph. I wan't to use as little javascript as possible.
I tried it this way: Fiddle
The problem occurs when I want to hide expanded content. The content will be hidden after an unwanted delay - When user clicks the button the animation won't start immediately. I have tried it in chrome and firefox. In both I get the same behaviour.
Can someone explain me why is my code behaving this way and how to fix it?
Here is source code that is identical to the one in the fiddle link:
HTML:
<div class="container">
<h1 class="header">Header</h1>
<p class="content">
content
</p>
toggle
</div>
CSS:
.content {
max-height: 0;
overflow: hidden;
transition: max-height 1s ease-in-out;
}
.expanded .content {
max-height: 1000px;
}
Javascript:
var $container = $('.container');
$('.toggle').click(function() {
$container.toggleClass('expanded');
});
Add min-height instead:
.content {
max-height: 0;
overflow: hidden;
transition: min-height 1s ease-in-out;
}
.expanded .content {
min-height:20px;
}
Use min-height rather than max-height.
When you click 'toggle' and the div is expanded, the height of the div is reduced in 2 steps... first to it's "auto" height, then to the max-height in the original class. So what looks like a delay is actually 2 steps of height reduction.
max-height: is not an absolute value, it's ambiguous unless the content itself forces the height to be greater. The script has to calculate what the actual height is upon the transition then determine if it is greater than the max-height setting which is being transitioned to.
You can see this by just adding a defined height to the expanded class:
var $container = $('.container');
$('.toggle').on('click', function() {
$container.toggleClass('expanded');
});
.content {
max-height: 0px;
overflow: hidden;
background: #ddd;
transition: max-height .2s ease-in-out;
}
.expanded .content {
max-height: 300px;
height: 150px;
background: #ddd;
transition: max-height .2s ease-in-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<p class="content">
content
</p>
toggle
</div>
If your content is actually greater and it causes the div to be taller than the max-height value, you won't have this problem. It's only an issue when the original height is less than the max-height value in the transition.
var $container = $('.container');
$('.toggle').on('click', function() {
$('.container').toggleClass('expanded');
});
.content {
max-height: 0px;
overflow: hidden;
background: #ddd;
transition: max-height .2s ease-in-out;
}
.expanded .content {
max-height: 1000px;
background: #ddd;
transition: max-height .2s ease-in-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<p class="content">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
</p>
toggle
</div>
If you adjust and use min-height you get a smooth transition. You also need to add height: 0; to the main class to completely hide the div on collapse.
var $container = $('.container');
$('.toggle').on('click', function() {
$container.toggleClass('expanded');
});
.content {
min-height: 0px;
height: 0;
overflow: hidden;
background: #ddd;
transition: min-height .2s ease-in-out;
}
.expanded .content {
min-height: 150px;
background: #ddd;
transition: min-height .2s ease-in-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<p class="content">
content
</p>
toggle
</div>
Here's an image of what I'm trying to accomplish: http://i.imgur.com/XKPuV.png
I want an outside container with a border and an inner container with a gray background. Within the inner container are two blocks: text on the left, image on the right (the elements on either side are of no importance - they can be whatever). Pretty basic stuff.
With the code below, I have my two div's that span 6 columns breaking apart (Here's what it looks like: http://i.imgur.com/BEIVl.png). What's the best way to fix this issue?
<div class="container" style="border: 1px solid gray;height:490px;margin-top:20px;">
<div id="inner-container" style="background:gray;margin:5px;">
<div class="row">
<div class="span6">
<p style="margin:5px;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
</div>
<div class="span6">
<p style="margin:5px;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
</div>
</div>
</div>
The problem is that you can't specify inline margins and paddings with spanX classes, as these in override boostrap's own padding/margin settings (this is why the 2nd div goes on the next line.
I suggest that you create what you need without using spanX definitions for inner divs. See fiddle: http://jsfiddle.net/periklis/KGMEF/1/