Css help for positioning elements on screen - css

I need to position a few elements responsively on the screen for my chat application. I have tried the grid system, but it doesn't seem to be working out.
I need a layout like the following:
The typing area shows which user is typing and online shows which user is online. Messages show the messages and chat contains the input. Using the grid system I got :
[![enter image description here][1]][1]
The typing for one should come above the input, and the input should not take the entire space. The chat area is like this:
<form id="form" action="">
<div id="typing"> </div>
<input id="input" autocomplete="off" /><button>Send</button>
</form>
Css:
#form {
background: rgba(0, 0, 0, 0.15);
padding: 0.25rem;
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
height: 3rem;
box-sizing: border-box;
backdrop-filter: blur(10px);
}
#input {
border: none;
padding: 0 1rem;
flex-grow: 1;
border-radius: 2rem;
margin: 0.25rem;
}
#input:focus {
outline: none;
}
#form>button {
background: #333;
border: none;
padding: 0 1rem;
margin: 0.25rem;
border-radius: 3px;
outline: none;
color: #fff;
}
Any help is greatly appreciated. Thanks!
[1]: https://i.stack.imgur.com/uIY86.png

As for the layout, use a flexbox to divide the left and right (online) panel
<div style="display:flex;width:100%;height:100vh">
<div id="left-side">
<div id="messages"></div>
<div id="typing"></div>
<div id="chat"></div>
</div>
<div id="online"></div>
</div>
The left-side div should have display:block, and as for the measurements choose whatever is to your liking.
Color coded the end result should look like this

Related

Ionic v4 ion-img eagerly loads the images instead of lazy-loading

I have a horizontal scroller that I built with FlexLayoutModule that basically let's me have a horizontally scrollable list where every item is a column of image and text. Here's the relevant code from my scroller.component.html
<div class="ion-activatable container" fxLayout="column" fxLayoutAlign="start center" fxLayoutGap="10px" *ngFor="let item of items">
<ion-ripple-effect></ion-ripple-effect>
<div *ngIf="item.movie || item.title" [routerLink]="'/tabs/discover/movie/'+ (item.movie? item.movie.ids.tmdb: item.ids.tmdb)">
<ion-img class="poster" [src]="(images$[item.movie? item.movie.ids.tmdb: item.ids.tmdb] | async) || preloaderGif"></ion-img>
<div class="item-titles">
{{item.movie? item.movie.title: item.title}}
</div>
</div>
</div>
But when the page loads up, all the hundreds of image requests are fired which I can see from the network tab as well as my API reporting I have hundreds of pending requests and that I have hit rate-limiting. Maybe I'm not using the ion-img right or maybe some of the styles are messing with it? Here's my scroller.component.scss:
.horizontal {
white-space: nowrap;
overflow-x: auto;
}
.poster {
width: 92px;
height: 138px;
}
.container {
position: relative;
cursor: pointer;
user-select: none;
}
.item-titles {
width: 100px;
white-space: normal;
text-align: center;
}
I'm open to suggestions. Maybe I should use virtual-scroll? But I don't see how I can make that horizontal.
I have done this kind of design using ion-slide. Better to do some scss change to show the part of next element. Please have a look following code.
Html
<ion-slides [options]="slideOpts" class="recent-search">
<ion-slide *ngFor="let item of recentSearch" class="slide-container" float-left text-left>
<div class="history-item" (click)="gotoDetailPage(item.id)">
<div class="container" float-left text-left>
<div class="bold-text">{{item.companyName}}</div>
<div>{{item.productName}}</div>
<div>{{item.descriptor}}</div>
</div>
</div>
</ion-slide>
</ion-slides>
Scss
.slide-container {
.history-item {
width: 100%;
padding: 3px;
.container {
padding: 15px;
background-color: #fafafa;
box-shadow: 2px 2px 11px 3px rgba(0, 0, 0, 0.12);
width: 80%;
font-size: 12px;
color: #767676;
.bold-text {
font-weight: 700;
}
div {
padding: 4px 0;
}
}
}
}
This is how it looks like.
This works nice for me with huge list of data.
Hope this may help to someone else.

keep button in div positioned along with parent div

I have the following:
https://codepen.io/anon/pen/KXYLrq
<header>
<input type="text" id="textfield" placeholder="Get it done!" autofocus>
<button id="add"><i class="fa fa-plus" aria-hidden="true"></i></button>
</header>
with css that is too long to list. I'd like to focus on the #media query. Due to larger screen sizes i need to limit the width of the input bar. If i set a max-width, or fixed width the button will move along with the screen size and continually move to the right.
How do i fix the button in one position past a certain screen size ? (In codepen, if you take out the media query it works just fine, presumably because i set the width to 100%)
Add this also in media query
header button{
right: auto;
left: 695px
}
It will help you to align the button with the text box.
I placed a Container over your input and button, assuming you'll have other elements in the header later.
I then set the section as display: inline-block to make it take the width of the content and also made it position: relative for the child absolute elements. So that those elements will take the section as a starting point and not the header.
https://codepen.io/anon/pen/jGRooL
Just wrap input and button in one parent div and set position relative in it and add width in it.
header {
background: #25b99a;
border-radius: 0 0 10px 10px;
box-shadow: 0px 2px 4px rgba(44, 62, 80, 0.15);
box-sizing: border-box;
height: 80px;
padding: 15px 25px 0 25px;
position: fixed;
top: 0;
width: 100%;
z-index: 5;
}
header input {
background: rgba(255, 255, 245, 0.2);
border-radius: 5px 25px 25px 5px;
border: 0;
box-sizing: border-box;
color: rgba(255, 255, 255, 1);
float: left;
font-size: 15px;
height: 50px;
padding-right: 65px;
outline: none;
text-indent: 15px;
width: 100%;
}
.search-box {
position: relative;
width:100%;
max-width: 700px;
}
.search-box button {
background-color: white;
border-radius: 25px;
border: 0;
cursor: pointer;
height: 50px;
outline: none;
position: absolute;
right: 0;
width: 50px;
z-index: 2;
}
#media screen and (max-width: 767px) {
.search-box {
max-width: none;
}
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<header>
<div class="search-box">
<input type="text" id="textfield" placeholder="Get it done!" autofocus>
<button id="add"><i class="fa fa-plus" aria-hidden="true"></i></button>
</div>
</header>
Updated Codepen Demo

Padding for placeholder without changing the size of input

I do adaptive search form. Search field should take 100% width of the parent div (the width of the parent div will change depending on the resolution of the device). The button "Search" should always be at the right of the field, do not shift down.
A working version.
But there's a problem: The text "Search now" (placeholder) too close to the edge of the field and I can't move it to the right. In other examples, it moves by the set value for the field padding. But if I change the padding — field itself is shifted to the left, but I only need to move the text!
#searchfield {
padding: 10px 0 13px 0; /* Try to change the left padding here! All field shifts to the left! But I need only shift the placeholder text to right! */
}
Try adding text-align:center for id searchfield or add box-sizing: border-box; declaration.
try with any one of below examples, it will move the placeholder to right as you expected, these will support Ie lower versions too.
Example1 (using box-sizing:border-box declaration)
#searchfield {
padding: 10px 0 13px 0px;
box-sizing: border-box;
}
Example2 (using text-align:center declaration)
#searchfield {
text-align:center;
}
You can still use padding to move the placeholder text, with the flavor of box-sizing: border-box; declaration.
box-sizing: border-box; make user-agents include padding/border to the width/height of the box.
#searchfield {
width: 100%;
border: 1px solid #ccc;
padding: 10px 0 13px 10px;
box-sizing: border-box;
/* other declarations... */
}
Vendor prefixes omitted due to brevity.
#sidebar {
width: 20%;
background: #ccc;
height: 300px;
padding: 20px;
}
#search {
width: 100%;
height: 50px;
position: relative;}
#searchfield {
width: 100%;
border: 1px solid #ccc;
margin: 0;
padding: 12px 0 13px 10px;
box-sizing: border-box;
position: absolute;
right: 0;
}
#searchsubmit {
width: 60px;
height: 41px;
background: red 0 0;
border: 0;
overflow: hidden;
cursor: pointer;
right: 0;
position: absolute;
}
<html>
<body>
<div id="sidebar">
<div id="search">
<form id="searchform" method="get" action="/index.php" _lpchecked="1">
<input type="text" name="s" id="searchfield" placeholder="Search now">
<input type="submit" id="searchsubmit" value="Search">
</form>
</div>
</div>
</body>
</html>
It's worth mentioning that border-box is supported in IE8+ as well as modern web browsers.
This could do the trick for you. It solved the issue I was having.
Tried on firefox and chrome
.random-class-name{
text-indent: 10px;
}
Text written inside the input is indented as well.
No need to use position absolute. try this code:
<html>
<body>
<div id="sidebar">
<div id="search">
<form id="searchform" method="get" action="/index.php" _lpchecked="1">
<input type="text" name="s" id="searchfield" placeholder="Search now">
<input type="submit" id="searchsubmit" value="Search">
</form>
</div>
</div>
</body>
</html>
#sidebar {
width: 20%;
background: #ccc;
height: 300px;
padding: 20px;
}
#search {
width: 100%;
height: 50px;
position: relative;}
#searchfield {
width: calc(100% - 60px);
border: 1px solid #ccc;
margin: 0;
padding: 10px 0 13px 20px; /* Try to change the left padding here! All field shifts to the left! But I need only shift the placeholder text to right!
position: absolute;*/
right: 0;
float:left;
box-sizing:border-box;
}
#searchsubmit {
width: 60px;
height: 41px;
background: red 0 0;
border: 0;
overflow: hidden;
cursor: pointer;
right: 0;
float:left;
box-sizing:border-box;
}
live demo on code pen

Icon in input box with content and :before instead of background-image

My issue was I have this nice font set and I use that to place custom icons next to my buttons. (ie: see here)
But now I want to create an input box and put an icon before it like HERE
But instead of a background image I want to put a font in the before content, is this possible?
CSS
.input-box { position: relative; }
input { display: block; border: 1px solid #d7d6d6; background: #fff; padding: 10px 10px 10px 20px; width: 195px; }
.unit { position: absolute; display: block; left: 5px; top: 10px; z-index: 9; }
HTML
<div class="input-box">
<input value="" autofocus="autofocus"/>
<span class="unit">To;</span>
</div>
check following example here
http://jsfiddle.net/pZLcg/52/

2px difference FF and Chrome

I need your help. How to fix that 2px difference? I really have no idea...
<nav id="navigation" class="col-full" role="navigation">
<ul class="nav fr parent">
<li id="menu-item-99" class="menu-item menu-item-type-custom">
<div id="search">
<form method="get" action="site" >
<input type="text" name="s" placeholder=" search..." />
<input type="submit" value="" name="submit" />
</form>
</div>
</li>
</ul>
</nav>
And here is CSS:
#search {
float: left;
background: #000;
color: #fff;
}
#search input[type="text"]{
width: 95px;
background: #000;
color: #fff;
border: 0;
margin-left: 1px solid #fff;
#navigation {
float: right;
clear: none;
border: 0;
box-shadow: none;
width: 850px;
background: 0;
}
#navigation ul.nav {
float: right;
}
The Screenshot: http://i.stack.imgur.com/fYcBs.png
Your reset CSS doesn't work as you'd expect it to.
Styles computed for the submit input in FF are:
[name=submit] {
width: 6px;
padding: 3px 6px;
border-width: 3px;
}
which makes it 24px wide in total.
And for the Chrome:
[name=submit] {
width: 0;
padding: 1px 6px;
border-width: 2px;
}
which makes it 16px wide in total.
Here's an example: http://jsfiddle.net/n5u9L/2/
You should reset the padding, border-width and the width for this input, like this:
#search [name=submit] {
padding: 0;
width: 6px; /* or whatever you want */
border-width: 0;
}
Well, it's hard to read anything from the image you provided but I guess the problem is font rendering. As we can see from the CSS the #search is float: left, so its position will depend on the element that is on the left hand side of it. I assume that there is some text in the left container. Unfortunately you covered it with black rectangle and you didn't provide us any HTML of it.
The problem is, every browser renders font faces different even if they're the same font-family. Each letter might differ in width and spacing.
You must style your #search so that its position doesn't depend on the width of the element on the left side.

Resources