Put two divs one near the other - html

I have the following html code:
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
and the css/less:
.rtm {
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
position: absolute;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
}
I tried to do like this in order to show the page-icon and page-title one near the other but how it is done now they are one over the other (the icon is on top of the title)
How can I solve this? Thanks

When you say "near each other" I am assuming you mean "beside each other".
You can add flexbox properties to #crumby-title. Then remove position and float properties from .page-icon and page-title. You can also remove height from .page-title
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart {
padding-top: 50px;
}
#crumby-title {
display: flex;
align-items: center;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
font-size: 20px;
font-weight: 5px 10px 10px 75px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>

Give float:left to .page-icon instead of position:absolute and add <div class="clear"></div> after page-title.
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
float: left;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
.clear{
clear:both;
}
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
<div class="clear"></div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>

I want to show u another version of ankita pantel's put them in a table and add padding-top to Demand
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
padding-top: 30px;
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
<div class="demand page">
<div id="crumby-title">
<table>
<tr>
<td>
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
</td>
<td>
<div class="page-title">
Demand
</div>
</td>
</tr>
</table>
</div>
<div id="chart" class="demand-chart">
</div>
</div>

All the cool kids are using flex box.
display:flex; flex-direction:row; makes the child items stack in a row. (flex-direction:row is default so you can skip that)
#crumby-title {
...
display: flex;
flex-direction:row;
}
then you can (if you want) center the text with
.page-title {
....
display: flex;
align-items: center;
}
Fiddle

Related

Replace two div on a row without changing width of parent element

I am really struggling to move two div in a row.
I tried to display flex in row but when I do that the current width of my two div remain the same while I'd like not to change the final width of the parent element.
I also tried inline display but it does not work too...
I want to place the two div inside the div with class "statusDetails" on the same row without interfering the current width of the div with class "status".
the objective is to have something like the end of this screen:
Any help will be appreciated!
Thx,
EDIT: the fiddle example :
body {
background-color: #edebe9;
}
.ddl-container .ddl-list {
position: absolute;
display: flex;
flex-direction: column;
border-left: 3px solid #3286d5;
background-color: white;
z-index: 1;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container>div {
cursor: pointer;
border: solid 3px transparent;
font-size: 1.1rem;
}
.horizontal-icon-menu .ddl-container>div:hover {
color: black;
}
/* .ddl-container:hover */
.horizontal-icon-menu .ddl-container .ddl-list {
right: 0;
border-left: 0px;
background-color: white;
z-index: 1;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container:hover>div {
background-color: white;
}
.horizontal-icon-menu .ddl-container:hover .ddl-list div .changeColorOnHover:hover {
background-color: #629924;
color: white;
}
.solid-border-bottom {
border-bottom: solid 1px #5e5e5e;
padding: 0px !important;
}
.statusDetails {
box-sizing: content-box;
}
.status div {
padding: 0px !important;
}
.statusDetails div>span {
text-transform: uppercase;
}
.statusDetails div span:last-of-type {
text-transform: lowercase;
}
<main>
<div class="horizontal-icon-menu">
<div class="ddl-container">
<div class="icon-param"><span class="username">ystalio</span></div>
<div class="ddl-list">
<div class="solid-border-bottom">
<div class="changeColorOnHover">Profil</div>
<div class="changeColorOnHover">Boîte de réception</div>
<div class="changeColorOnHover">Préférences</div>
<div class="changeColorOnHover">Déconnexion</div>
</div>
<div class="status">
<div class="statusDetails">
<div><span>ping </span><span id="ping">10</span><span> ms</span></div>
<div><span>server </span><span id="server">0.1</span><span> ms</span></div>
</div>
<div class="signal">
test
</div>
</div>
</div>
</div>
</div>
</main>
Since you dont have a working example, I assume you only want to have two div side by side aligned.
I will suggest you using "Bootstrap Grid System" in this case;
Otherwise, for vanilla html and css:
try adding CSS:
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
}
.col-sm-5 {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
And HTML class tag for:
<div class="status row">
<div class="statusDetails col-sm-5">
<div><span>ping </span><span id="ping">10</span><span> ms</span></div>
<div><span>server </span><span id="server">0.1</span><span> ms</span></div>
</div>
<div class="signal col-sm-5">test</div>
</div>
See Snippet below:
body {
background-color: #edebe9;
}
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
}
.col-sm-5 {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
.ddl-container .ddl-list{
width: 300px;
position: absolute;
display: flex;
flex-direction: column;
border-left: 3px solid #3286d5;
background-color: white;
z-index: 1;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container > div {
cursor: pointer;
border: solid 3px transparent;
font-size: 1.1rem;
}
.horizontal-icon-menu .ddl-container > div:hover {
color:black;
}
/* .ddl-container:hover */
.horizontal-icon-menu .ddl-container .ddl-list {
right: 0;
border-left: 0px;
background-color: white;
z-index: 1;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container:hover > div {
background-color: white;
}
.horizontal-icon-menu .ddl-container:hover .ddl-list div .changeColorOnHover:hover {
background-color: #629924;
color: white;
}
.solid-border-bottom {
border-bottom: solid 1px #5e5e5e;
padding: 0px !important;
}
.statusDetails {
box-sizing: content-box;
}
.status div {
padding: 0px !important;
}
.statusDetails div > span {
text-transform: uppercase;
}
.statusDetails div span:last-of-type {
text-transform: lowercase;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="test.css">
</head>
<body>
<main>
<div class="horizontal-icon-menu">
<div class="ddl-container">
<div class="icon-param"><span class="username">ystalio</span></div>
<div class="ddl-list">
<div class="solid-border-bottom">
<div class="changeColorOnHover">Profil</div>
<div class="changeColorOnHover">Boîte de réception</div>
<div class="changeColorOnHover">Préférences</div>
<div class="changeColorOnHover">Déconnexion</div>
</div>
<div class="status row">
<div class="statusDetails col-sm-5">
<div><span>ping </span><span id="ping">10</span><span> ms</span></div>
<div><span>server </span><span id="server">0.1</span><span> ms</span></div>
</div>
<div class="signal col-sm-5">
test
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>

How to display a forum link and user who posted it in my forum?

I would like to display a forum link, which at right side should also display a user with latest post or thread in a forum.
Apparently here is what I have done.
CODE HTML:
<div class="container">
<div class="toggle"></div>
<h2>INFORMACJE</h2>
<div class="city">
<ul>
<li>ogłoszenia i nowości</li>
<li>Feedback</li>
</ul>
</div>
</div>
CODE CSS:
.toggle {
display:inline-block;
height:48px;
width:48px;
float: right;
background:url("http://cdn2.iconfinder.com/data/icons/onebit/PNG/onebit_32.png");
}
.toggle.expanded{
background:url("http://icons.iconarchive.com/icons/pixelmixer/basic/48/plus-icon.png");
}
h2 {
color: white;
background-color: rgb(36, 37, 38);
padding: 11px 10px 11px 10px;
margin: 0;
border-width: 0;
border-radius: 4px;
border: 1px solid rgb(70, 70, 70);
margin-bottom: 10px;
}
Here is what I get :(
Here is how the final results should look.
How can I achieve that? am newbie please help
check it in jsfiddle: https://jsfiddle.net/kh3u0q0r/
Is this is what you looking for???
.toggle {
display: inline-block;
height: 48px;
width: 48px;
float: right;
background: url("http://cdn2.iconfinder.com/data/icons/onebit/PNG/onebit_32.png");
}
.first {
float: left;
}
.second {
float: right;
}
.toggle.expanded {
background: url("http://icons.iconarchive.com/icons/pixelmixer/basic/48/plus-icon.png");
}
h2 {
color: white;
background-color: rgb(36, 37, 38);
padding: 11px 10px 11px 10px;
margin: 0;
border-width: 0;
border-radius: 4px;
border: 1px solid rgb(70, 70, 70);
margin-bottom: 10px;
}
<div class="container">
<div class="toggle"></div>
<h2>INFORMACJE</h2>
<div class="city">
<ul>
<li class="first">ogłoszenia i nowości
</li>
<li class="second">
Feedback
</li>
</ul>
</div>
</div>

children not staying inside parent divs

Fiddle: https://jsfiddle.net/uatzust3/
Here is the fiddle for my problem, you'll observe that the children are not staying inside the parent div card and also I want the divs to take full width of parent which they are not taking.
Also, where should I be learning best practices? I am new to the community. Thanks in advance.
The left div(black_container) is short of content but should arrange the height according to the width of the right div(content_container) all the while staying inside the card div.
.card {
box-shadow: 0 25px 45px rgba(0, 0, 0, 0.30), 0 15px 15px rgba(0, 0, 0, 0.22);
max-width: 800px;
margin: auto;
position: relative;
}
.black_container {
height: inherit;
background: #333;
display: inline-block;
vertical-align: top;
padding: 3%;
font-family: 'Nunito', sans-serif;
}
.content_container {
display: inline-block;
padding: 3%;
/* position: absolute;
top:0;
bottom: 0; */
}
.small_bar {
padding: 3px;
width: 30px;
margin: 0 auto;
background: #e4e4e4;
margin-top: 35px;
}
.name {
color: #fff;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 5px;
margin: 30px auto 5px auto;
text-align: center;
font-weight: 800;
}
.designation {
font-size: 10px;
margin: 0 auto;
}
.qrcode_container {
float: right;
}
.qr_container {
overflow: auto;
width: 100%;
}
.qr_text {
display: inline-block;
list-style-type: none;
}
.qr_text>li {
font-size: 18px;
font-weight: 600;
letter-spacing: 2.5px;
color: #9a9a9a;
}
.bars {
display: inline-block;
position: relative;
top: 10px;
}
.bars .small_bar {
width: 15px;
background: #777;
}
.bar {
position: absolute;
top: -80px;
}
.qr_code {
display: inline-block;
height: inherit;
border: 1px solid #e4e4e4;
padding: 5px;
}
.button {
width: 150px;
letter-spacing: 1;
text-transform: uppercase;
font-weight: 600;
color: #fff;
text-align: center;
background: #333;
padding: 5px 10px;
}
<div class="card">
<div class="black_container">
<div class="circular">
</div>
<p class="small_bar"></p>
<p class="name">wow</p>
<p class="name designation">Front-End Designer</p>
</div>
<div class="content_container">
<!-- qr code container ends -->
<div class="qr_container">
<div class="qrcode_container">
<ul class="qr_text">
<li>LOREM</li>
<li>IPSUM</li>
<li>DPOLER</li>
</ul>
<div class="bars">
<div class="small_bar bar"></div>
<div class="small_bar"></div>
</div>
<div class="qr_code"></div>
</div>
</div>
<!-- qr code container ends -->
<div class="card_content">
<p>Hello!</p>
<p>My name is lorem</p>
<p>I am a web designer</p>
<p>Im stuck</span>
</p>
<div class="button">button</div>
</div>
<div class="card_footer"></div>
</div>
</div>
A parent cannot take the height of a direct child if the child is absolute because the absolute elements are removed from the document flow(like floats), so in this case "card" doesn't even know "content_container" even exists .
https://jsfiddle.net/OmarIsComing/eq4L86g9/1/
update:
solution with flexbox: https://jsfiddle.net/OmarIsComing/eq4L86g9/2/
solution without flexbox: https://jsfiddle.net/OmarIsComing/eq4L86g9/3/
If flexbox is an option, this is easy :
Add display: flex to your card
Add flex: 1 to the content-container
See demo below:
.card {
box-shadow: 0 25px 45px rgba(0, 0, 0, 0.30), 0 15px 15px rgba(0, 0, 0, 0.22);
max-width: 800px;
margin: auto;
position: relative;
display: flex;
}
.black_container {
height: inherit;
background: #333;
display: inline-block;
vertical-align: top;
padding: 3%;
font-family: 'Nunito', sans-serif;
}
.content_container {
display: inline-block;
padding: 3%;
/* position: absolute;
top:0;
bottom: 0; */
flex: 1;
}
.small_bar {
padding: 3px;
width: 30px;
margin: 0 auto;
background: #e4e4e4;
margin-top: 35px;
}
.name {
color: #fff;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 5px;
margin: 30px auto 5px auto;
text-align: center;
font-weight: 800;
}
.designation {
font-size: 10px;
margin: 0 auto;
}
.qrcode_container {
float: right;
}
.qr_container {
overflow: auto;
width: 100%;
}
.qr_text {
display: inline-block;
list-style-type: none;
}
.qr_text>li {
font-size: 18px;
font-weight: 600;
letter-spacing: 2.5px;
color: #9a9a9a;
}
.bars {
display: inline-block;
position: relative;
top: 10px;
}
.bars .small_bar {
width: 15px;
background: #777;
}
.bar {
position: absolute;
top: -80px;
}
.qr_code {
display: inline-block;
height: inherit;
border: 1px solid #e4e4e4;
padding: 5px;
}
.button {
width: 150px;
letter-spacing: 1;
text-transform: uppercase;
font-weight: 600;
color: #fff;
text-align: center;
background: #333;
padding: 5px 10px;
}
<div class="card">
<div class="black_container">
<div class="circular">
</div>
<p class="small_bar"></p>
<p class="name">wow</p>
<p class="name designation">Front-End Designer</p>
</div>
<div class="content_container">
<!-- qr code container ends -->
<div class="qr_container">
<div class="qrcode_container">
<ul class="qr_text">
<li>LOREM</li>
<li>IPSUM</li>
<li>DPOLER</li>
</ul>
<div class="bars">
<div class="small_bar bar"></div>
<div class="small_bar"></div>
</div>
<div class="qr_code"></div>
</div>
</div>
<!-- qr code container ends -->
<div class="card_content">
<p>Hello!</p>
<p>My name is lorem</p>
<p>I am a web designer</p>
<p>Im stuck</span>
</p>
<div class="button">button</div>
</div>
<div class="card_footer"></div>
</div>
</div>
Use the class card-body, this will keep the contents inside of the card.
<div class="card border-success">
<div class="card-header border-success">
<h3 class="card-title">Card Title</h3>
</div>
<div class="card-body border-success">
<dl>
<dt>
Stuff
</dt>
<dd>
Stuff Details
</dd>
</dl>
</div>
</div>
replace the .content_container css with:
.content_container {
display: inline-block;
padding: 3%;
vertical-align: top;
}
I think the CSS attribute position: absolute; is causing this issue. In short, absolute position removes the element from the flow of other elements; therefore, its height is simply ignored, and never counted in your .card container.

Align items based on title availability in CSS

I have created a panel as shows in the screenshots below. my panel will have a title heading and different icons which performs various operations. both these title heading and the icons are optional or in other words either one will not be available in many cases.
whenever i have title, i want all my icons to be at the extreme right side of the panel header which works fine as in first screenshot with the CSS i have written.
when i don't have a title i want all my icons to be on the extreme left side of the panel header as shown in second screenshot which i am facing difficulty to achieve.
SCREENSHOTS
HTML
<div class="panel">
<div class="panel-header ">Title Goes Here
<div class="toolbar-button-group">
<button class="toolbar-button-stroke icon-add"></button>
<button class="toolbar-button-stroke icon-hide"></button>
<button class="toolbar-button-stroke icon-edit"></button>
<button class="toolbar-button-stroke icon-options"></button>
</div>
</div>
<div class="panel-content "></div>
</div>
CSS
.panel {
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.23), 0 3px 12px rgba(0, 0, 0, 0.16);
background: #fff;
width: 100%;
height: 100%;
}
.panel-header {
color: #354052;
text-transform: capitalize;
font-size: 20px;
height: 40px;
line-height: 40px;
margin: 0;
padding-left: 24px;
border-bottom: 2px #BBBBBB solid;
}
.panel-content {
padding: 24px;
background: white;
}
.toolbar-button-stroke{
background:white;
border: none;
border-radius: 4px;
padding: 6px;
margin: 0px 3px;
color:black;
font-size: 15px;
text-transform: uppercase;
cursor:pointer;
outline: none;
}
.toolbar-button-group{
float: right;
}
i prefer CSS solutions with out positioning. Fiddle link here
Thanks in advance
If you can change your HTML around a bit to add an extra element, you can use :empty to target it based on the span having content or not with the next sibling selector.
.panel {
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.23), 0 3px 12px rgba(0, 0, 0, 0.16);
background: #fff;
width: 100%;
height: 100%;
}
.panel-header {
color: #354052;
text-transform: capitalize;
font-size: 20px;
height: 40px;
line-height: 40px;
margin: 0;
padding-left: 24px;
border-bottom: 2px #BBBBBB solid;
}
.panel-content {
padding: 24px;
background: white;
}
.toolbar-button-stroke {
background: white;
border: none;
border-radius: 4px;
padding: 6px;
margin: 0px 3px;
color: black;
font-size: 15px;
text-transform: uppercase;
cursor: pointer;
outline: none;
}
.toolbar-button-group {
float: right;
}
span:empty + .toolbar-button-group {
float: left;
}
<div class="panel">
<div class="panel-header "><span>Title Goes Here</span>
<div class="toolbar-button-group">
<button class="toolbar-button-stroke icon-add">A</button>
<button class="toolbar-button-stroke icon-hide">B</button>
<button class="toolbar-button-stroke icon-edit">C</button>
<button class="toolbar-button-stroke icon-options">D</button>
</div>
</div>
<div class="panel-content "></div>
</div>
<br/>
<div class="panel">
<div class="panel-header "><span></span>
<div class="toolbar-button-group">
<button class="toolbar-button-stroke icon-add">A</button>
<button class="toolbar-button-stroke icon-hide">B</button>
<button class="toolbar-button-stroke icon-edit">C</button>
<button class="toolbar-button-stroke icon-options">D</button>
</div>
</div>
<div class="panel-content "></div>
</div>
Solution is simple: https://jsfiddle.net/45kuucbn/1/
Add span tag around your title, if is present use + to add style to button group.
<div class="panel">
<div class="panel-header ">
<span>Title Goes Here</span>
<div class="toolbar-button-group">
<button class="toolbar-button-stroke icon-add">a</button>
<button class="toolbar-button-stroke icon-hide">a</button>
<button class="toolbar-button-stroke icon-edit">a</button>
<button class="toolbar-button-stroke icon-options">a</button>
</div>
</div>
<div class="panel-content "></div>
</div>
<div class="panel">
<div class="panel-header ">
<div class="toolbar-button-group">
<button class="toolbar-button-stroke icon-add">a</button>
<button class="toolbar-button-stroke icon-hide">a</button>
<button class="toolbar-button-stroke icon-edit">a</button>
<button class="toolbar-button-stroke icon-options">a</button>
</div>
</div>
<div class="panel-content "></div>
</div>
.panel {
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.23), 0 3px 12px rgba(0, 0, 0, 0.16);
background: #fff;
width: 100%;
height: 100%;
}
.panel-header {
color: #354052;
text-transform: capitalize;
font-size: 20px;
height: 40px;
line-height: 40px;
margin: 0;
padding-left: 24px;
border-bottom: 2px #BBBBBB solid;
}
.panel-content {
padding: 24px;
background: white;
}
.toolbar-button-stroke{
background:white;
border: none;
border-radius: 4px;
padding: 6px;
margin: 0px 3px;
color:black;
font-size: 15px;
text-transform: uppercase;
cursor:pointer;
outline: none;
}
.toolbar-button-group{
display:inline-block;
}
.panel-header span + .toolbar-button-group {
float:right;
}
when text heading block code works like what you want
here is codepen.io live example
if( $('.left').is(':empty') ) {
$('.right').addClass('full');
$('.left').addClass('hidden');
}
.title-container {
width: 300px;
margin: 100px auto;
outline: 1px solid #333;
padding: 15px 25px;
font-family: Arial, sans-serif;
font-size: 12px;
}
.title-container .col-2 {
width: 50%;
float: left;
outline: 1px solid #ccc;
padding: 5px;
box-sizing: border-box;
}
.title-container .hidden {
display: none;
}
.title-container .icon {
display: inline-block;
outline: 1px solid #ccc;
width: 20px;
text-align: center;
}
.title-container .right {
text-align: right;
}
.title-container .full {
width: 100%;
}
.title-container .full.right {
text-align: left;
}
.title-container::after {
display: table;
content: "";
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="title-container">
<div class="col-2 left heading">Delete me and see result</div> <!-- heading block-->
<div class="col-2 right icons"> <!-- icons block -->
<span class="icon">1</span>
<span class="icon">2</span>
<span class="icon">3</span>
</div>
</div>

Why is my div moving to right whenever I add "overflow-y: scroll"?

Why is my div moving to right whenever I specify overflow-y: scroll on the .messages element?
Even when I use margin-left: -10px;, it doesn't move to the left!
#import url(http://fonts.googleapis.com/css?family=Roboto:300,400,900);
#import url(http://weloveiconfonts.com/api/?family=entypo);
[class*="entypo-"]:before {
font-family: 'entypo', sans-serif;
}
* {
box-sizing: border-box;
margin: 0;
}
body {
background: #BDC1C6;
font-family: 'Roboto';
}
p {
font-weight: 300;
}
.chat {
width: 300px;
background: #fff;
margin: 0 auto;
}
header {
background: #35323C;
height: 50px;
padding: 5px 10px;
}
.menu-icon {
background: #2F2E33;
padding: 5px 10px;
float: left;
font-size: 3em;
line-height: 0.5em;
color: #fff;
border-radius: 3px;
}
.menu-icon:hover {
background: #39caad;
cursor: pointer;
}
h1 {
float: right;
color: #fff;
margin: 5px;
font-weight: 300;
font-size: 1.3em;
}
.menulist {
background: #39caad;
color: #fff;
text-align: center;
padding: 10px;
}
.menulist:hover {
cursor: pointer;
background: rgb(255, 0, 0);
text-align: center;
padding: 20px;
}
.openchat {
background: #39caad;
color: #fff;
text-align: center;
padding: 5px;
}
.new {
background: rgb(57, 202, 173);
color: #fff;
text-align: center;
padding: 20px;
}
.new:hover {
cursor: pointer;
background: rgba(57, 202, 173, 0.9);
}
.messages {
padding: 10px;
overflow-y: scroll;
height: 300px;
}
.message {
float: left;
width: 100%;
margin: 10px 0;
border-bottom: 1px solid #ccc;
}
.message p {
font-size: 0.8em;
width: 90%;
margin: 5px 0;
}
.message:hover {
background: #39caad;
cursor: pointer;
}
.messageSender {
text-align: right;
float: right;
width: 100%;
margin: 10px 0;
border-bottom: 1px solid #ccc;
}
.messageSender p {
font-size: 0.8em;
width: 90%;
margin: 5px 0;
}
.messageReceiver {
float: left;
width: 100%;
margin: 10px 0;
border-bottom: 1px solid #ccc;
}
.messageReceiver p {
font-size: 0.8em;
width: 90%;
margin: 5px 0;
}
img {
border-radius: 100%;
float: left;
margin: 0 10px 15px 0;
}
img.sender {
border-radius: 100%;
float: right !important;
margin: 0 10px 15px 0;
width: 35px;
height: 35px;
}
img.receiver {
border-radius: 100%;
float: left;
margin: 0 10px 15px 0;
width: 35px;
height: 35px;
}
p.time {
color: rgba(0, 0, 0, 0.5);
font-weight: 400;
}
p.chattime {
color: rgba(0, 0, 0, 0.5);
font-weight: 400;
font-size: 10px;
}
h2 {
font-size: 1em;
font-weight: 400;
}
h2:after {
content: '';
display: inline-block;
height: 10px;
width: 10px;
background: #39caad;
border-radius: 100%;
margin-left: 5px;
}
h2.send:before {
content: '';
display: inline-block;
height: 10px;
width: 10px;
background: #39caad;
border-radius: 100%;
margin-left: 5px;
}
h2.send:after {
content: '';
height: 0px;
width: 0px;
border-radius: 00%;
margin-right: 5px;
}
footer {
width: 100%;
background: #fff;
padding: 10px;
text-align: center;
font-size: 0.8em;
}
footer p:before,
footer p:after {
content: ' - ';
}
<div class="chat">
<header>
<div class="menu-icon" id="menubutton"><span class="entypo-menu"></span>
</div>
<h1>Chats</h1>
</header>
<?php include( "menu.php"); ?>
<div class="openchat" id="openchat">
<img style="width:35px; height: 35px;" src="http://dtechnomist.com/clients/chat/assets/users/2.jpg" />
<h2>XYZ</h2>
<p class="time">Online</p>
</div>
<section class="messages" id="chatBox">
<div class="messageReceiver">
<img class="receiver" src="assets/users/1.jpg">
<h2 class="receive">Admin 1</h2>
<p class="chattime">12:00:00 AM, 3rd Jan16</p>
<p>There ?</p>
</div>
<br>
<br>
<div class="messageSender">
<img class="sender" src="assets/users/2.jpg">
<h2 class="send"> You</h2>
<p class="chattime">12:00:00 AM, 4th Jan16</p>
<p>Yes</p>
</div>
<br>
<br>
<div class="messageReceiver">
<img class="receiver" src="http://dtechnomist.com/clients/chat/assets/users/1.jpg">
<h2 class="receive">Admin 1</h2>
<p class="chattime">08:59:33 PM, 4th Jan16</p>
<p></p>
</div>
<div class="messageReceiver">
<img class="receiver" src="assets/users/1.jpg">
<h2 class="receive">Admin 1</h2>
<p class="chattime">09:05:55 PM, 4th Jan16</p>
<p>hi</p>
</div>
<br>
<br>
<div class="messageReceiver">
<img class="receiver" src="http://dtechnomist.com/clients/chat/assets/users/1.jpg">
<h2 class="receive">Admin 1</h2>
<p class="chattime">09:06:02 PM, 4th Jan16</p>
<p>ok</p>
</div>
<br>
<br>
<div class="messageSender">
<img class="sender" src="http://dtechnomist.com/clients/chat/assets/users/2.jpg">
<h2 class="send"> You</h2>
<p class="chattime">09:06:58 PM, 4th Jan16</p>
<p>hello</p>
</div>
<br>
<br>
<div class="messageSender">
<img class="sender" src="http://dtechnomist.com/clients/chat/assets/users/2.jpg">
<h2 class="send"> You</h2>
<p class="chattime">09:07:08 PM, 4th Jan16</p>
<p>hi</p>
</div>
<br>
<br>
<div class="messageSender">
<img class="sender" src="http://dtechnomist.com/clients/chat/assets/users/2.jpg">
<h2 class="send"> You</h2>
<p class="chattime">09:07:31 PM, 4th Jan16</p>
<p>asd</p>
</div>
</section>
<section class="write">
<textarea type="text" name="msg" id="msg" style="width:85%; height: 30px; margin: 0px 0px 0px 2%; resize: none" placeholder="Type your message here..."></textarea>
<button name="send" id="sendMsg" style="width: 9%;"><span class="entypo-plus"></span>Send</button>
</section>
<footer>
<p>Designed by Kashan Shah
</p>
</footer>
</div>
You're seeing this behavior due to collapsing margins.
When you add overflow-y: scroll to the element, a new block formatting context is established, which means that the .openchat element's vertical margin no longer collapses with the .messages element. Since the margins no longer collapse, the element is shifted to the right.
Margins of elements that establish new block formatting contexts (such as floats and elements with overflow other than visible) do not collapse with their in-flow children.
To resolve this issue, you could either add overflow: hidden to the .openchat element in order hide the overflowing margin (which essentially prevents the margin from adjoining):
Updated Example
.openchat {
background: #39caad;
color: #fff;
text-align: center;
padding: 5px;
overflow: hidden;
}
Alternatively, you could also just remove the margin-bottom from the child img element:
Updated Example
.openchat img {
margin-bottom: 0;
}