Img showing below div instead of in div? - html

So I've been trying to make a chatroom, and i want admins to be able to delete messages. I have made an img tag which should be inside and in the right side of the div, but its under and to the right side of the div. How should i do that?
HTML Code (snippet was weird, so try in a regular html file)
<div style="border: 5px solid black; border-radius: 5px; overflow-y: scroll; height: 70%;" id="chat">
<div style="width: 95%;">
<span style="color: red"><b>CONSOLE</b></span> <span style="color: grey;">3/11 11.28</span>
<div style="width:100%;"> Chat startet</div>
<img src="https://www.shareicon.net/data/512x512/2015/12/19/690073_sign_512x512.png" style="top: 0px; height: 3.5%; float: right; opacity: 0.7;" > <!-- The img that is a problem -->
<br>
</div>
</div>

I believe you are looking for something like this:
<div style="display: flex; justify-content: space-between;">
<div>
<span style="color: red"><b>CONSOLE</b></span>
<span style="color: grey;">3/11 11.28</span> <br>
<span>Chat started</span>
</div>
<img src="https://www.shareicon.net/data/512x512/2015/12/19/690073_sign_512x512.png" height="40px" width="40px" style="opacity: 0.7;">
</div>
This code uses css flexbox to create such positioning. I recommend you look into the flexbox more, as it will solve 90% of your positioning issues for you, and its usage is at the same time way less problematic than usage of floats. You could find more about the topic here: https://internetingishard.com/html-and-css/flexbox/
I would also recommend not to mix your markup and styling, and use css classes to apply styling to your elements instead. It will allow you to re-use styles without lots of duplication as your page gets more complex, and also allow you to keep your markup much cleaner and more readable.

you should use something like
display: inline-block
for the elements, you want to be in the same row.
or you can use something like
display: flex /*or inline-flex */
in the parent, div to do so.
if you decide to use flex you can see a nice guide https://css-tricks.com/snippets/css/a-guide-to-flexbox/

I'm not sure that I got it right, but I guess you need one of these to solve your problem:
<div style="border: 5px solid black; border-radius: 5px; overflow-y: scroll; height: 70%;" id="chat">
<div style="width: 95%;">
<span style="color: red"><b>CONSOLE</b></span> <span style="color: grey;">3/11 11.28</span>
<div style="width:100%;"> Chat startet
<img src="https://assets.pernod-ricard.com/nz/media_images/test.jpg?hUV74FvXQrWUBk1P2.fBvzoBUmjZ1wct" style="top: 0px; height: 3.5%; float: right; opacity: 0.7;">
</div>
<br>
</div>
</div>
or
<div style="border: 5px solid black; border-radius: 5px; overflow-y: scroll; height: 70%;" id="chat">
<div style="width: 95%;">
<span style="color: red"><b>CONSOLE</b></span> <span style="color: grey;">3/11 11.28</span>
<span style="float: right;">
<img src="https://assets.pernod-ricard.com/nz/media_images/test.jpg?hUV74FvXQrWUBk1P2.fBvzoBUmjZ1wct" style="top: 0px; height: 3.5%; float: right; opacity: 0.7;">
</span>
<div style="width:100%;"> Chat startet</div>
<br>
</div>
</div>
If it helps or not, please let me know :)

Related

Text-Truncate class is not working at various browser size If browser size is small

I am writing a chat room message template. I used a text-truncate class for long message ellipse. But It is not working in my code.
<div style="display: flex; background-color: beige; font-size: 14px; width: 10%;">
<!-- favorite-->
<div>
<img src="./images/ic-mentor.png" style="border-radius: 15px; border: 1px solid #dddddd; width: 75px; height: 75px;"/>
</div>
<div style="flex-grow: 1;">
<div class="clearfix">
<img src="./images/ic-mentor.png"/>
<span>
TEST_USER
</span>
<span>
<!-- | -->
<!-- Characters -->
</span>
<span style="float:right">
PM 01:16
</span>
</div>
<div class="text-truncate">
adssasdaasdsadsaasdadsadssdasdadsaadsadssadasasddassad
</div>
</div>
</div>
Above code is my sample code. I want to write a working at small browser size with truncate class. But my code is not working text truncate.
I don't want to set width. I want to make flexible template, If I set width, then it does not use in small size browser
I don't want to overflow contents.
You need to set the width of the div that's containing the overflowing content. Else truncate class will not produce ellipses.
Try this code:
<div style="display: flex; background-color: beige; font-size: 14px; width: 10%;">
<!-- favorite-->
<div>
<img src="./images/ic-mentor.png" style="border-radius: 15px; border: 1px solid #dddddd; width: 75px; height: 75px;"/>
</div>
<div style="flex-grow: 1;">
<div class="clearfix">
<img src="./images/ic-mentor.png"/>
<span>
TEST_USER
</span>
<span>
<!-- | -->
<!-- Characters -->
</span>
<span style="float:right">
PM 01:16
</span>
</div>
<div class="text-truncate" style="width: 300px;">
adssasdaasdsadsaasdadsadssdasdadsaadsadssadasasddassad
</div>
</div>
</div>
Note: I've added inline-styles for now.
I'm solved this problem myself as follows:
<div style="display: flex; background-color: beige; font-size: 14px; width: 10%;">
<!-- favorite-->
<div>
<img src="./images/ic-mentor.png" style="border-radius: 15px; border: 1px solid #dddddd; width: 75px; height: 75px;"/>
</div>
<div class="text-truncate" style="flex-grow: 1;">
<div class="clearfix">
<img src="./images/ic-mentor.png"/>
<span>
TEST_USER
</span>
<span>
<!-- | -->
<!-- Characters -->
</span>
<span style="float:right">
PM 01:16
</span>
</div>
adssasdaasdsadsaasdadsadssdasdadsaadsadssadasasddassad
</div>
</div>
I just remove the text-truncate div tag and then put parent div tag.

Why my interface look differently in browser and google device toolbar?

my interface in Google chrome browser (Is normal, I set it like this)
But when I click the inspect and click google device toolbar, the interface look like:
.btn {
position: absolute;
top: 85%;
left: 50%;
transform: translate(-50%, -50%);
cursor: pointer;
}
.div_hover {
background-color: #F9F7F2;
}
<div style="width: 80%; margin: auto;">
<div class="div_hover" style="width: 473px; height: 200px; margin: auto;">
<p style="font-size: 18px;">Dear Customer</p>
<hr>
<p style="font-size: 11px">Welcome.......</p>
<hr>
<p style="font-size: 11px">bla..bla...</p>
<hr>
</div>
<div style="width: 49%; margin: auto; position: relative;">
<img src="https://www.rspcasa.org.au/wp-content/uploads/2019/01/Adopt-cat-mobile-banner-600x300-fit-constrain-q70-mobile_banner_image.jpg">
<form action="https://www.google.com/">
<input type="image" src="https://www.freepngimg.com/thumb/download_now_button/25399-6-download-now-button-thumb.png" class="btn" />
</form>
</div>
</div>
How can I make it both same?
Well, you are currently setting the div have the width of 49% but <img> doesn't have any width set. That is causing the image to be its original size. If you want to display the image in the same way for different screen width, you should do something like this:
<div style="width: 80%; margin: auto;">
<div class="div_hover" style="width: 473px; height: 200px; margin: auto;">
<p style="font-size: 18px;">Dear Customer</p>
<hr>
<p style="font-size: 11px">Welcome.......</p>
<hr>
<p style="font-size: 11px">bla..bla...</p>
<hr>
</div>
<div style="width: 473px; margin: auto; position: relative;">
<img width="100%" src="https://www.rspcasa.org.au/wp-content/uploads/2019/01/Adopt-cat-mobile-banner-600x300-fit-constrain-q70-mobile_banner_image.jpg">
<form action="https://www.google.com/">
<input type="image" src="https://www.freepngimg.com/thumb/download_now_button/25399-6-download-now-button-thumb.png" class="btn" />
</form>
</div>
</div>
As you see, don't give the custom width to the second child div. If you have to give the width as 49% for second div, then give the width for <img> as well.
https://jsfiddle.net/2epL85r1/

Last div goes to a new line with padding in percentage

I'm new to html/css and I'm trying to do an adaptive header for the website. I'm using padding-right with 5% for divs, but las div always goes to a new line and the parent div don't want to expand. I want parent div expand depending on the text in child divs. Also when I'm using padding in px, all works properly, but it loses adaptive part.
What am I doing wrong?
With padding in percents
With padding in pixels
HTML and CSS
button{
height:34px;
width:100%;
font-weight:bold;
border:none;
background-color:#fc592d;
color:#ffeded;
border-radius:4px;
}
<div style="width: 100%; background-color: rgb(44, 62, 80); float: left;">
<div style="width: 47.36%; height: auto; margin: auto;">
<div style="display: inline-block; float: left; padding-bottom: 4%; padding-top: 4%;">
<div style="display:inline-block; padding-right:5%;">
<img src="images/icon1.png" alt="farkops">
<a class="href" href="#">One thing</a>
</div>
<div style="display:inline-block; padding-right:5%;">
<img src="images/icon2.png" alt="pricep">
<a class="href" href="#">Second</a>
</div>
<div style="display:inline-block; padding-right:5%;">
<img class="href" src="images/icon3.png" alt="otzivi">
<a class="href" href="#">Three</a>
</div>
<div style="display:inline-block;">
<img src="images/icon4.png" alt="works">
<a class="href" href="#">Fourth thing</a>
</div>
</div>
<div style="float: left; display: inline-block; margin-top: 1.24%; margin-left: 2%;">
<div style="">
<p style="margin: 0px; padding-bottom: 8px; font-weight: bold; font-size: 3vh;"><span>7 (905)</span> 639-29-03</p>
</div>
<div style="">
<button>Call</button>
</div>
</div>
</div>
</div>
UPD1:
When I add one new div, the previous one fits just right (the parent div expands as I want), but the new one goes to new line.

css and html - why does a div which is float-left get placed on the line below?

I have HTML like this:
<div style="float: left; font-family: arial; padding-top: 40px; width: 655px; ">
<div style="float: left;">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" style="border: none;" />
</div>
<div style="float: left; ">
<p>
<h1>mobile business plan, <br />
business ideas, fundraising<br /> and marketing apps
</h1> <!-- font-size: 200%; -->
</p>
</div>
<div style="clear:both;"></div>
And it looks like this. Here is a test page:
http://problemio.com/index_test.php
The blue B is supposed to be on the same line with the text. But possibly because the original image size is very big, it is getting screwed up in size.
Here is the css for the img:
img#above_fold_img
{
width: 30%;
height: 30%;
}
Would anyone know how to make the image and text appear on the same line?
Thanks!
You need to specify a width for both of the child <div>s. According to Chrome DevTools, the first <div> (with the child image) is 512px wide. width: 30%; on img#above_fold_img uses 30% of its parent div.Example:
<div style="float: left; width: 256px; height: 256px; margin: 0">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" style="border: none; width: 256px; height: 256px" />
</div>
<div style="float: left; width: 393px; margin: 0; margin-left: 5px">
<p>
<h1>mobile business plan, <br />
business ideas, fundraising<br /> and marketing apps
</h1> <!-- font-size: 200%; -->
</p>
</div>
I kept all styles inline in my example, but using CSS is better. Also, the 'b' image is 512x512px. If you can shrink it, you will reduce load times.
I think just giving an answer helps but op wanted to know why as well..
You should declare a width on the image that contains the #above_fold_img so that the div takes on the same width that way you can do this
<div style="float: left; font-family: arial; padding-top: 40px; width: 655px;">
<div style="float: left;margin-right:20px">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" width="154">
</div>
<div style="float: left;">
<p></p>
<h1>mobile business plan, <br>
business ideas, fundraising<br> and marketing apps
</h1> <!-- font-size: 200%; -->
<p></p>
</div>
<div style="clear:both;"></div>
</div>
Also you should try not to use <p></p> as spaces but use <br/> to do that
Change your div to have a width of 30% and the image to have a width of 100% or 90% for astetic reasons, so:
<div style="float: left; font-family: arial; padding-top: 40px; width: 655px;">
<div style="float: left; width: 30%;">
<img src="http://www.problemio.com/img/big_logo.png" id="above_fold_img" style="border: none;" />
</div>
and CSS:
img#above_fold_img
{
width: 100%;
height: 100%;
}

display inline not making the div to move upward

how to make the second div properly align with the first div....
i gave display inline for horizontal alignment...
but the second div is still down...
i am talking with respect to 24 inch monitor....
http://jsfiddle.net/ke6Se/1/embedded/result/
<div style=" width: 300px; display: inline-block;">
<span style="color: #000; font-size: 12px; font-family: arial; font-wieght: bold; margin-left: 45px;">Mark Up</span><span style="margin-left: 110px;">10%</span>
<div>
<span style="margin-left: 45px;">Non-Tax Amount</span><span style="margin-left: 59px;">0</span>
</div>
</div>
first of all, as Kevin said in his comment, you're html is wrong. You have one div nested inside the other. Fix that and then apply inline-block to the second div
<div style=" width: 300px; display: inline-block;">
<span style="color: #000; font-size: 12px; font-family: arial; font-wieght: bold; margin-left: 45px;">Mark Up</span><span style="margin-left: 110px;">10%</span>
</div>
<div style="display:inline-block">
<span style="margin-left: 45px;">Non-Tax Amount</span><span style="margin-left: 59px;">0</span>
</div>
Here's the obligatory fiddle
Your fiddle is really busy and I can't find exactly where it is, but it has to do with your margins and widths. You should set a wrapper <div> to a fixed width then float: right the <div> you want and make sure the <div>s widths add up to the wrappers width, including margin and any padding. See this article for a good explination.
http://www.webdesignerdepot.com/2012/09/when-pages-are-not-paper-the-designers-guide-to-layout-code/
Also it might help to set a min width to prevent stacking of divs when the window is shrinked if you don't want to set a static width.
Here is a quick HTML mark up of what I'm talking about.
<div id="wrapper" style="width: 800px;">
<div id="leftDiv" style="width: 600px; float: left;">
I'm the left Div!
</div>
<div id="rightDiv" style="width: 200px; float: right;">
I'm the right Div!
</div>
</div>