html css move img to the top line of div [duplicate] - html

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 4 years ago.
.img_small {
width: 50px;
height: 50px;
}
.wrapper {
max-width: 600px;
}
<div class="wrapper">
<div class="reading_chat_left" align="left">
<div class="reading_chat_img" style="min-width: 50px; display: inline-block">
<img class="img_small" src="https://i.ytimg.com/vi/HCjNJDNzw8Y/maxresdefault.jpg">
</div>
<div class="reading_chat_text" style="display:inline-block; width: 60%">
<div class="reading_chat_left_name">It goes down</div>
<div class="reading_chat_left_text" style="background-color: orange; padding: 5px">abcd blah In this tutorial I will show you how to create Facebook style chat bubbles using CSS only. CSS Code for Chat Bubbles. Here is how chat</div>
</div>
</div>
<div class="reading_chat_left" align="right">
<div class="reading_chat_text" style="display:inline-block; width: 60%">
<div class="reading_chat_left_name">It goes down</div>
<div class="reading_chat_left_text" style="background-color: orange; padding: 5px">abcd blah In this tutorial I will show you how to create Facebook style chat bubbles using CSS only. CSS Code for Chat Bubbles. Here is how chat</div>
</div>
<div class="reading_chat_img" style="min-width: 50px; display: inline-block">
<img class="img_small" src="https://i.ytimg.com/vi/HCjNJDNzw8Y/maxresdefault.jpg">
</div>
</div>
QUESTION:
I want to make it like this:
In other words, move photo to the top of its div.
Regardless of change of width of window or other, I want to make it sticky aligned to the top line.
Maybe it's so easy or noob question, but need help.
Thanks for reading.

Use vertical-align: 'top' to align the image to the top. Check the working snippet
.img_small {
width: 50px;
height: 50px;
}
.wrapper {
max-width: 600px;
}
<div class="wrapper">
<div class="reading_chat_left" align="left">
<div class="reading_chat_img" style="min-width: 50px; display: inline-block;vertical-align:top">
<img class="img_small" src="https://i.ytimg.com/vi/HCjNJDNzw8Y/maxresdefault.jpg">
</div>
<div class="reading_chat_text" style="display:inline-block; width: 60%">
<div class="reading_chat_left_name">It goes down</div>
<div class="reading_chat_left_text" style="background-color: orange; padding: 5px">abcd blah In this tutorial I will show you how to create Facebook style chat bubbles using CSS only. CSS Code for Chat Bubbles. Here is how chat</div>
</div>
</div>
<div class="reading_chat_left" align="right">
<div class="reading_chat_text" style="display:inline-block; width: 60%">
<div class="reading_chat_left_name">It goes down</div>
<div class="reading_chat_left_text" style="background-color: orange; padding: 5px">abcd blah In this tutorial I will show you how to create Facebook style chat bubbles using CSS only. CSS Code for Chat Bubbles. Here is how chat</div>
</div>
<div class="reading_chat_img" style="min-width: 50px; display: inline-block;vertical-align:top">
<img class="img_small" src="https://i.ytimg.com/vi/HCjNJDNzw8Y/maxresdefault.jpg">
</div>
</div>

You should be use this simple trick.
Please add css like:
.reading_chat_left .reading_chat_img {
width: calc(50px - 100%);
float: left;
}
or give inline css in this class .reading_chat_text{float: left;}
Hope this help.
Let me know further clarification.
.img_small {
width: 50px;
height: 50px;
}
.wrapper {
max-width: 600px;
}
.reading_chat_left .reading_chat_img {
width: calc(50px - 100%);
float: left;
}
<div class="wrapper">
<div class="reading_chat_left" align="left">
<div class="reading_chat_img" style="min-width: 50px; display: inline-block">
<img class="img_small" src="https://i.ytimg.com/vi/HCjNJDNzw8Y/maxresdefault.jpg">
</div>
<div class="reading_chat_text" style="display:inline-block; width: 60%">
<div class="reading_chat_left_name">It goes down</div>
<div class="reading_chat_left_text" style="background-color: orange; padding: 5px">abcd blah In this tutorial I will show you how to create Facebook style chat bubbles using CSS only. CSS Code for Chat Bubbles. Here is how chat</div>
</div>
</div>
<div class="reading_chat_left" align="right">
<div class="reading_chat_text" style="display:inline-block; width: 60%;
float: left;">
<div class="reading_chat_left_name">It goes down</div>
<div class="reading_chat_left_text" style="background-color: orange; padding: 5px">abcd blah In this tutorial I will show you how to create Facebook style chat bubbles using CSS only. CSS Code for Chat Bubbles. Here is how chat</div>
</div>
<div class="reading_chat_img" style="min-width: 50px; display: inline-block">
<img class="img_small" src="https://i.ytimg.com/vi/HCjNJDNzw8Y/maxresdefault.jpg">
</div>
</div>

Related

Why do my table columns all shift to the left for instead of being evenly spaced?

I'm having some trouble with this not running properly. It won't align the text correctly and it also won't distribute the cells across the available space. Not sure what I'm doing wrong here, so any help would be appreciated.
While we're at it, I'm also trying to figure out how to get it to show 2 columns instead of 1 when it switches to mobile sized. The way it's setup now, it just transitions to 1 column.
This is for a website on Shopify that uses an html block to insert custom code. I have other blocks that I've inserted into it and they all seem to be working fine, it's just this one that's giving me issues.
.table2 {
display: table;
}
.table-row2 {
display: table-row;
}
.table-cell2 {
display: table-cell;
vertical-align: top;
width: 20%;
padding: 2.5%;
}
.icontext {
display: text;
vertical-align: middle;
width: 20%;
padding: 2.5%;
float: middle;
}
#media screen and (max-width: 768px) {
.table2,
.table-row2,
.table-cell2 {
display: block;
width: 100%;
float: middle;
}
}
<h1><center>Materials</center></h1>
<div class="table2">
<div class="table-row2">
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/0ce94db3-8b05-4d84-a64c-dc6de006151c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Durable
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/b6ff1bd5-4c2e-4db0-bacc-3aa76678e92c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Quick Dry
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/e09a4c7e-c262-415f-b491-599bd0bc3a66/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Lightweight
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/03df04db-7851-4f80-ad8f-0438cc7e0397/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Breathable
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/8034c6ad-6c30-406d-8865-a4bdb4060bca/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Moisture Wicking
</div>
</div>
</div>
</div>
I would recommend using flex something like below will fix your issue. There was a few issues with your previous code being out of date. This will also flex on mobiles to show 2 columns as you stated.
.table-row2 {
width: 100%;
height:auto ;
display: flex;
flex-direction: row;
flex-wrap:wrap;
justify-content:space-around;
}
.table-cell2 {
vertical-align: top;
padding: 2.5%;
}
.icontext {
padding: 2.5%;
text-align: center;
}
#media screen and (max-width: 768px) {
.table2,
.table-row2,
.table-cell2 {
// removed all
}
}
<meta name="viewport" content="width=device-width" />
<h1><center>Materials</center></h1>
<div class="table2">
<div class="table-row2">
<div class="table-cell2">
<img src="https://ucarecdn.com/0ce94db3-8b05-4d84-a64c-dc6de006151c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Durable
</div>
</div>
<div class="table-cell2" >
<img src="https://ucarecdn.com/b6ff1bd5-4c2e-4db0-bacc-3aa76678e92c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Quick Dry
</div>
</div>
<div class="table-cell2" >
<img src="https://ucarecdn.com/e09a4c7e-c262-415f-b491-599bd0bc3a66/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Lightweight
</div>
</div>
<div class="table-cell2" >
<img src="https://ucarecdn.com/03df04db-7851-4f80-ad8f-0438cc7e0397/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Breathable
</div>
</div>
<div class="table-cell2">
<img src="https://ucarecdn.com/8034c6ad-6c30-406d-8865-a4bdb4060bca/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Moisture Wicking
</div>
</div>
</div></div>

div not expand to full width when apply overflow:auto

[enter image description here][1]currently i am facing one problem.
I generated table using div with fix header and scrollbar to div row section.
but problem is both div are not taking whole 50% 50% width.
I have tried following code.but not working.
.brd2 {
height: auto;
max-height: 100px;
overflow: auto;
position: absolute;
width: 100%;
}
.back-clr {
background-color: red;
}
HTML PART
<div class="container">
<div class="row">
<div class="col-md-8">
<div style="display: table;width:100%">
<div style="display: table-row">
<div style="width:50%; display: table-cell;">
Test
</div>
<div style="width:50%; display: table-cell;">
test
</div>
</div>
<div class="brd2" style="display: table-row;">
<div class="content" style="width:50%; display: table-cell;">
<p>sdfds
fdsf</p>
<p>dsfds
fds</p>
<p> fds
fsf
dsf</p>
<p>sdfds
fdsf</p>
<p>dsfds
fds</p>
<p> fds
fsf
dsf</p>
</div>
<div class="content back-clr" style="width:50%;display: table-cell;">
this is second div
</div>
</div>
</div>
</div>
</div>
</div>

Centering icons on website

I have a problem.
I would like to center three icons on a website like so:
http://prntscr.com/cte4kt
Including the text under it.
I have searched on google, but I had no good results.
If somebody could show a simple example that would be really greatfull.
this is what I tried:
<div class="testDiv">
<img style="width: 100px; height: 100px;" src="https://s21.postimg.org/jc5m4w0av/search.png">
<h3>Insert text</h3>
<h4>This is an actual test<br>
I really mean it lol.
</h4>
<img style="width: 100px; height: 100px;" src="https://s21.postimg.org/jc5m4w0av/search.png">
<h3>Insert text</h3>
<h4>This is an actual test<br>
I really mean it lol.
</h4>
<img style="width: 100px; height: 100px;" src="https://s21.postimg.org/jc5m4w0av/search.png">
<h3>Insert text</h3>
<h4>This is an actual test<br>
I really mean it lol.
</h4>
CSS:
http://pastebin.com/v0cc1cXg
Thankyou.
I think you already know some basic HTML/CSS stuff so I'd recommend you use some of popular front-end frameworks like Bootstrap or Zurb Foundation. It's almost copy/paste only thing.
You can use something like bootstrap or primercss which give you classes to add rows and columns to layout your content.
You could also create your own like the example I did here
<div class="container">
<div class="row">
<div class="col3 center">
<div class="inner-container">
<i>icon</i>
<div>text</div>
</div>
</div>
<div class="col3">
<div class="inner-container">
<i>icon</i>
<div>text</div>
</div>
</div>
<div class="col3">
<div class="inner-container">
<i>icon</i>
<div>text</div>
</div>
</div>
</div>
</div>
.container {
position: relative;
width: auto;
height: 200px;
}
.row {
width: 100%;
height: 100%;
}
.col3 {
float: left;
width: 33.3%;
height: 100%;
background: grey;
}
.inner-container {
position: relative;
top: 30%;
text-align: center;
}
Basically you need to create some type of layout container(width:100%) with three columns split by thirds(width:33.3%). Then inside each of those columns you position the contents with (text-align:center) to horizontally center align the content and vertically align it via something like top:30% or if you could also do an inline-block with vertical-align: middle.

HTML to split a section into two columns

I am trying to split the page into two sections. One left area and right will be the content page. I have the following html but looks like it is not working. Any ideas, what I am not doing right?
<div id="wuiMainArea">
<div id="wuiMainContent">
<div id="wuiLeftArea">
<div id="wuiLefthandNavRoot">
<h2 class="wui-hidden">Section Navigation</h2>
<h3 class="wui-navigation-title"><p>Applications</p><p> </p></h3>
<div id="tree" style="float: left; width: auto; background-color: #f2f4f5;"> </div>
</div>
</div>
<div id="wuiInpageNav">
<div class="wui-inpage-container" id="in_100">
<p>This is the div I will be using for charts </p>
</div>
</div>
</div>
</div>
Like this
<div id="wuiMainArea" style="border: 1px solid;">
<div id="wuiMainContent" style="border: 1px solid;">
<div id="wuiLeftArea" style="border: 1px solid;float: left;">
<div id="wuiLefthandNavRoot">
<h2 class="wui-hidden">Section Navigation</h2>
<h3 class="wui-navigation-title"><p>Applications</p><p> </p></h3>
<div id="tree" style="float: left; width: auto; background-color: #f2f4f5;"> </div>
</div>
</div>
<div id="wuiInpageNav" style="border: 1px solid; float: left;">
<div class="wui-inpage-container" id="in_100">
<p>This is the div I will be using for charts </p>
</div>
</div>
<div style="clear: both;"></div>
</div>
</div>
#wuiMainArea, #wuiMainContent{
margin: 0 auto;
width: 960px;
}
#wuiLeftArea, #wuiInpageNav{
/* use half of the main content div's width */
/* -2 because of 1px-border on both sides */
width: 478px;
display: inline-block;
float: left;
}
It'll be better to use CSS styling HTML.
Define the widths to fit your needs. Also I recommend using classes instead of ids when appling same styles to multiple elements.

remove vertical gaps between divs and put in a sequence [duplicate]

This question already has answers here:
How to Create Grid/Tile View? [duplicate]
(8 answers)
Closed 7 years ago.
It is now like this:
I want like this:
my css:
.maindiv{
width:410px;
}
.innerdiv{
display: inline-block;
width: 200px;
height: auto;
}
JSFIDDLE
this is an example page
Here's an easy implementation ,just use display:flex on main div and make two columns div to wrap inner div
<div class="maindiv">
<div class="col-1">
<div class="innerdiv">
<img style="width: 100%; height: 200px;"/>
</div>
<div class="innerdiv">
<img style="width: 100%; height: 120px;"/>
</div>
<div class="innerdiv">
<img style="width: 100%; height: 220px;"/>
</div>
</div>
<div class="col-1">
<div class="innerdiv">
<img style="width: 100%; height: 260px;"/>
</div>
<div class="innerdiv">
<img style="width: 100%; height: 180px;"/>
</div>
</div>
</div>
css
.maindiv {
width: 410px;
display: flex;
}
Result