I have to create an IRC-like web chat (latest messages have to appear at the bottom of the parent container).
Here's my (unsuccessful) attempt:
.inner-conversation-container {
height: 100px;
position: relative;
overflow: hidden;
width: 500px;
}
.conversation-stream-container {
max-height: 100px;
position: absolute;
bottom: 0;
overflow: auto;
width: 100%;
}
<div class='inner-conversation-container'>
<div class='conversation-stream-container'>
<div class='conversation-item'>
<div class='conversation-message-part' msg-id='137'>
<div class='center-part'>Content</div>
</div>
<div class='conversation-message-part' msg-id='138'>
<div class='center-part'>Content</div>
</div>
<div class='conversation-message-part' msg-id='139'>
<div class='center-part'>Content</div>
</div>
<div class='conversation-message-part' msg-id='140'>
<div class='center-part'>Content</div>
</div>
<div class='conversation-message-part' msg-id='141'>
<div class='center-part'>Content</div>
</div>
<div class='conversation-message-part' msg-id='142'>
<div class='center-part'>Content</div>
</div>
<div class='conversation-message-part' msg-id='143'>
<div class='center-part'>Content</div>
</div>
<div class='conversation-message-part' msg-id='144'>
<div class='center-part'>The latest message that needs to be in the bottom</div>
</div>
</div>
</div>
</div>
The div with msg-id="144" needs to be visible and aligned to the bottom.
jQuery aided solution
Using your HTML mark-up:
<div class='inner-conversation-container'>
<div class='conversation-stream-container'>
<!-- A single item -->
<div class='conversation-item'>
<!-- Message parts -->
<div class='conversation-message-part' msg-id='125'>
<div class='center-part'>test 9</div>
</div>
...
<div class='conversation-message-part' msg-id='143'>
<div class='center-part'>no, it's not</div>
</div>
<div class='conversation-message-part' msg-id='144'>
<div class='center-part'>latest needs to be in the bottom</div>
</div>
</div>
</div>
</div>
you can simplify your CSS as follows:
.inner-conversation-container {
height: 200px;
width: 500px;
border: 2px solid lightgray; /* for demo only */
overflow: auto;
}
.conversation-stream-container {
background-color: yellow; /* for demo only */
}
and set the scroll bar position using jQuery:
$('.inner-conversation-container').scrollTop(
$('.inner-conversation-container')[0].scrollHeight
);
Demo fiddle: http://jsfiddle.net/audetwebdesign/FW6Y5/
Related
I am trying to position the following elements one below the other , but one to the left and other to the right:
my code:
here is the fiddle: https://jsfiddle.net/ak9hxfpt/2/
I want to position the test2 to the right of the test1 div, but it should appear below the test1 div
What I want to achieve is something like: https://jsfiddle.net/ak9hxfpt/3/
however this works only for one div, if I try float: right for all the divs I have this is what I get which is not working out for me:
https://jsfiddle.net/ak9hxfpt/4/
the every "remove link" content should appear below every "some content".
any ideas on how this can be achieved
.test2 {
margin-bottom: 30px;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
just add some margin-left
.test2 {
margin-bottom: 30px;
margin-left:80%;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
<div class="test2">
remove link
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
or
.test2 {
margin-bottom: 30px;
width:93%;
text-align:right;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
I would try nesting your code in a container and use display: flex; with flex-direction: column;
.test2 {
float: right;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
.container {
display: flex;
flex-direction: column;
}
<div class="container">
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
</div>
Another option would be to set display: flex; on test right a flex-direction: row; then you can can set test2 to width: 7%; while test still takes up 93%. Finally, you can space them by adding gap Check the snippet below.
.test2 {
width: 7%;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
.test {
display: flex;
flex-direction: row;
width: 100%;
gap: 10px;
}
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
Just add display: flex; justify-content: flex-end to your test2 class and it will work.enter image description here
I found strange case. when I use html like that :
<div class="card" style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<!-- here -->
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
The div padding-bottom:10em push out others div.card blow the div.card like the padding is some invisible part of the div.card
When I change the internal flex div to block div the bug disapear
It look like the internal flex as it own layout that breach out from the blok and the outer inline-flex
How I prevent that, and make the div with the padding cut out like normal content into overflow hidden element.
It can be I found new bug in chrome flex model ?
Live example :
https://uvzoo.csb.app/
Codesendbox: https://codesandbox.io/s/zen-engelbart-uvzoo
div {
outline: 1px solid pink;
padding: 0.5em;
margin: 0.3em;
}
<div style="display: block; width:30em; height: 40em; padding: 1em;">
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
</div>
Adding vertical-align:top fixes the issue. I don't know exactly why but it seems there is a complex calculation that is affecting the baseline calculation of each box making it outside and far from the bottom. Since baseline is the default alignment, you are getting this strange result
div {
outline: 1px solid pink;
padding: 0.5em;
}
.box {
display: inline-flex;
vertical-align:top;
overflow: hidden;
}
.box>div {
display: block;
width: 10em;
height: 5em;
}
.box>div>div {
display: flex;
}
.box>div>div>div {
padding-bottom: 10em;
}
<div style="display: block; width:30em; height: 40em; padding: 1em;">
<!-- block card -->
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
</div>
If we add some text we can notice this:
div {
outline: 1px solid pink;
padding: 0.5em;
}
.box {
display: inline-flex;
overflow: hidden;
}
.box>div {
display: block;
width: 10em;
height: 5em;
}
.box>div>div {
display: flex;
}
.box>div>div>div {
padding-bottom: 10em;
}
<div style="display: block; padding: 1em;">
<!-- block card -->
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div> some text here
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
</div> some text here
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
</div>
So I'd like my footer to adjust and stay on the bottom of the page no matter the height of the content which is dynamic
Below is the CSS for the body, wrapper and footer .. the footer doesn't not stay in the bottom when the content is too long and gets display in the middle of the page when you have to scroll
body, html{
margin:0px;
padding:0px;
width:100%;
height:100%;
background:#FFFFFF;
}
#wrapper{
position:relative;
top:0px;
left:0px;
width:100%;
padding:0px;
min-height:100%;
overflow-x:hidden;
}
#footer{
position:absolute;
bottom:0px;
left:150px;
width:1600px;
height:500px;
background:blue;
}
...
<div id="wrapper">
<div id="header"></div>
<div id="logo"><img src="images/u176.png" class="logo_pic" style="outline: none;"></div>
<div id="search_bar"><input type="text" name="search_bar" class="search" /></div>
<div id="search_icon"><img src="images/u205.png" width="28px" height="28px" /></div>
<div id="become_a_chef"><span id="become_title">Become </span></div>
<div id="login">Log in</div>
<div id="sign_up">Sign up</div>
<div id="tap-container"><img id="tap-pic" class="food_container_pic" src="images/today_menu/u35.png" /></div>
<div id="tap-content"></div>
<div class="column1">
<div class="tap-links">Become a member</div>
<div class="tap-links">Sign up</div>
<div class="tap-links">Log in</div>
<div class="tap-links">Home</div>
</div>
<div class="column2">
<div class="tap-links">Search</div>
<div class="tap-links">Download the App</div>
<div class="tap-links">How it works</div>
<div class="tap-links">Help</div>
</div>
<div id="chef-rating-responsive">
<div class="subinfo_container3"><img class="food_container_pic" src="images/fusion/u1837.jpg" /></div>
<div class="subinfo_container4">A</div>
<div class="subinfo_container5">Open Now</div>
<div class="subinfo_container6">More...</div>
</div>
<div id="cover_picture_container"><img class="food_container_pic" src="images/u4.jpg" /></div>
<div id="profile_picture_container"><img id="profile_picture" class="img" src="<?php echo $picture;?>"></div>
<div id="chef_description_container">
<div id="kitchen_name"><span id="kitchen_title"><?php echo $name;?></span></div>
<div id="chef_description_summary"><?php echo description;?></div>
<div id="schedule_info_container">
<div class="subinfo_container">
<img id="chef_rating" src="images/fusion/u1837.jpg" width="186px" height="35px">
<span id="number_reviews">64 reviews</span>
</div>
<div class="subinfo_container"><span id="open_now">Open Now</span></div>
<div class="subinfo_container"><span id="chef_location">Chef Location</span></div>
<div class="subinfo_container2"><span id="letter_grade">A</span><span id="chef_grade">since Nov.2016</span></div>
<div class="subinfo_container2">
<div id="clock"><img id="u1341_img" src="images/u1341.png" class="full" ></div>
<span id="schedule_hours"></span>
</div>
<div class="subinfo_container2"><span id="chef_contact">Chef contact</span></div>
</div>
</div>
<div class="today_menu">
<div class="space"></div>
</div>
<div id="footer">
<div class="company_footer">
<div class="title">Company</div>
<div class="column_content_footer">About</div>
<div class="column_content_footer">Careers</div>
<div class="column_content_footer">Press</div>
<div class="column_content_footer">Blog</div>
<div class="column_content_footer">About</div>
<div class="column_content_footer">Help</div>
<div class="column_content_footer">Policies</div>
<div class="column_content_footer">Disaster</div>
<div class="column_content_footer">Terms & Privacy</div>
</div>
<div class="discover_footer">
<div class="title">Discover</div>
<div class="column_content_footer">Trust & Safety</div>
<div class="column_content_footer">Invite friends</div>
<div class="column_content_footer">Gift card</div>
<div class="column_content_footer">pricks</div>
<div class="column_content_footer">Mobile</div>
<div class="column_content_footer">Events support</div>
<div class="column_content_footer">Travel</div>
<div class="column_content_footer">Nearby</div>
</div>
<div class="kitchening_footer">
<div class="title"></div>
<div class="column_content_footer"></div>
<div class="column_content_footer">Serving</div>
<div class="column_content_footer">Responsible</
</div>
<div class="social_media_buttons">Hey</div>
</div>
</div>
</div>
html, body {
padding: 0;
margin: 0;
background: #fff;
}
#wrapper {
position: relative;
width: 100%;
height: 100%;
padding-bottom: 400px;
box-sizing: border-box;
}
#footer {
z-index: 50;
position: fixed;
bottom: 0;
width: 100%;
height: 400px;
background: blue;
}
<div id="wrapper">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div id="footer">
</div>
</div>
This works perfectly fine for me (tweaked it a little bit). I'd advice you not to use fixed widths like 1600px, but to work with percentages and max-widths. Hope this helps
If your footer has a fixed height you could do something like this:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.force-min-height {
min-height: 100%;
position: relative;
}
.header {
background: grey;
}
.content {
/* padding being the same as footer height */
padding-bottom: 4em;
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 4em;
background: grey;
}
<div class="force-min-height">
<div class="header">Header</div>
<div class="content">
line<br>line<br>line<br>line<br>line<br>line<br>line<br>line<br>line
</div>
<div class="footer">Footer</div>
</div>
I am trying to display dynamic generated div's horizontally with scroll bar. There can be n number of div's.
Below is my Code:
HTML (index.html)
<div style="width:100%;float:left;" id="old">
<div>
<h1>First Div</h1>
<div id="R1">
<h1>First Div Internal</h1>
<a id="R1_index" class="close_page" href="javascript:void(0)">Close</a>
</div>
</div>
<div>
<h1>Second Div</h1>
<div id="R2">
<h1>Second Div Internal</h1>
<a id="R2_index" class="close_page" href="javascript:void(0)">Close</a>
</div>
</div>
</div>
I follow this link for solution.
But when dynamic div's load, structure looked messed up.
Here is the messy look:
HTML (index.html)
<div style="width:100%;float:left;" id="old">
<div id="items">Missing Internal Content</div>
<div id="items">Missing Internal Content</div>
</div>
Please help me guys.
i imagin the problem is that the div's in the container (id="old" in your example) are not next to each other, but instead beneath.
if that is your problem, you add the following styles to your container:
#old {
overflow: auto;
white-space: nowrap;
}
and make the childern-divs inline-block elements:
#old > div {
display: inline-block;
}
then it should work as expected. see the working solution:
* {
padding: 0;
margin:0;
}
#container {
width: 300px;
height: 100px;
overflow: auto;
white-space: nowrap;
}
.element {
display: inline-block;
}
.box {
width: 100px;
height: 100px;
background: lightgrey;
}
<div id="container">
<div class="element">
<div class="box">
<h1>1</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>2</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>3</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>4</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>5</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>6</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>7</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>8</h1>
</div>
</div>
</div>
otherwise please provide a better example/description of what the problem exactly is.
I am trying to keep my footer at the bottom of the page. The first way I tried it, the footer would be above the bottom of the page and the background would show. This was with position:static; (like the following image)
The second way I tried is with an absolute footer. This puts the footer at the bottom of pages where there isn't enough content to scroll but on pages with the scroll, it sits at the bottom of the window when it loads and is on top of content.It is not the bottom of the page.
Here is my current code:
<div id="container">
<div id="content">
<div id="slideshow"></div>
<div id="clear"></div>
<div id="boxes">
<div id="box">
<div id="boxheader"></div>
<div id="box1" class="box"></div>
</div>
<div id="box">
<div id="boxheader"></div>
<div id="box2" class="box"></div>
</div>
<div id="box">
<div id="boxheader"></div>
<div id="box3" class="box"></div>
</div>
</div>
<div id="clear"></div>
</div>
</div>
<div id="footer">Content</div>
Here is the CSS
div#container{
position:relative;
margin: 4px;
}
#boxes{
width: 960px;
margin: 50px auto 0px auto;
}
#footer {
clear: both;
margin-top: 50px;
bottom: 0;
left: 0;
height: 200px;
background-color: #fff;
width: 100%;
}
Please let me know if you need any additional information.
set
html, body {
height: 100%;
}
wrap the entire content before the footer in a div.
.wrapper {
height:auto !important;
min-height:100%;
}
You can adjust min-height to your liking based on how much of the footer you want to show in the bottom of the browser-window. If set it to 90%, 10% of the footer will show before scrolling.
So in your example
<body style="height: 100%">
<div id="container" style="min-height: 90%; height: auto !important;">
<div id="content">
<div id="slideshow"></div>
<div id="clear"></div>
<div id="boxes">
<div id="box">
<div id="boxheader"></div>
<div id="box1" class="box"></div>
</div>
<div id="box">
<div id="boxheader"></div>
<div id="box2" class="box"></div>
</div>
<div id="box">
<div id="boxheader"></div>
<div id="box3" class="box"></div>
</div>
</div>
<div id="clear"></div>
</div>
</div>
<div id="footer">Content</div>
I've used the method described in the article liked below many times, and have had no problems with it:
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
Hope it helps!