stretching div to fit content, height dictated by image width - html

I ran into problem, I'm CSS newbie and can't figure it out how to dynamically stretch comment section to fit height.
Height of right div is dictated by image width, so I cant set static height of right div, also can't set min-height and max-height on comment div, because it will not fit on bigger picture.
What I want is somehow to fit comment section that has height of like 50% correlating to height of parent div.
Any ideas how to make it work ? Some ideas would be enough to look into right direction. Don't care about old IE versions, so newest CSS additions are viable, and javascript is also an option if it's hassle to do with css.
<div class="post-container">
<div class="image-container">
<div class="image-holder">
<img class="image" src="http://www.onionlegal-fortstjohn.ca/wp-content/uploads/2015/03/300x600-Half-Page-Display-Ad-Placeholder.jpg"/>
</div>
</div>
<div class="post-details-container">
<div class="header">
<div class="image-container">
<div class="image-holder">
<img
class="profile image"
src="https://i.stack.imgur.com/7lf40.gif"
/>
</div>
</div>
<ul class="comments-container">
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
<li class="comment">
<span>
author
</span>
<span>
This is comment text
</span>
</li>
</ul>
<div class="footer">
FOOTER ALWAYS ON BOTTOM
</div>
</div>
CSS
.post-container {
display: flex;
border: 1px solid #e6e6e6;
flex-direction: row;
max-width: 906px;
background-color: #fff;
}
.header {
padding-bottom: 15px;
padding-top: 15px;
margin-right: 20px;
margin-left: 20px;
flex-direction: row;
align-items: center;
}
.image {
height: auto;
width: 100%;
height: auto;
max-width: 100%;
}
.profile {
width: 45px;
height: 45px;
border-radius: 50%;
}
.comments-container {
list-style-type: none;
margin: 0;
padding: 0;
max-width: 280px;
}
.comment {
margin-bottom: 15px;
}
.footer {
bottom: 0;
position: fixed;
}

If the image and the comment section are siblings then
Remove any height attribute(min-height, max-height, height)
Give display: flex; to their parents and
Give align-items: stretch to comment section.
I may make any mistake cause this kind of question should have demo link or you should share your html and css here.

Additional Problems:
Header Tag is not closed.
Footer need not required to be fixed.
Solution:
Add a closing div tag before .comments-container
Remove css for .footer
Make .post-details-container display as flex and direction as column
Set .comments-container to flex-grow as 1
Working code at https://jsfiddle.net/ou21qe09/
.post-details-container {
display: flex;
flex-direction: column;
}
.comments-container {
flex-grow: 1;
}

Related

CSS Issues with word wrapping in an infiinite scrolling div

I am working on a project and want to have infinite horizontal scrolling for cells that each contain a thumbnail and some text. I have everything mostly working. However, I can not get text to wrap. The css and html are below. The first two items in the scroll box have text that should wrap, but overflows.
This is the style (cell 2 is only for demo to alternate background colors):
.container {
display: flex;
flex-direction: row;
padding: 10px;
height: 10%;
overflow-x: auto;
white-space: nowrap;
}
.cell {
background: #818181;
flex: fit-content;
padding: 10px;
width: 220px;
height: 8%;
display: inline-block;
}
.cell2 {
background: #f44336;
flex: fit-content;
padding: 10px;
width: 220px;
height: 8%;
display: inline-block;
}
.data {
justify-content: center;
word-wrap: break-word;
}
<div>
<h2>Scroll Test</h2>
<div class="container">
<div class="cell">
<a href= "#">
<span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
<span class="data"> <h3>Some text here</h3></span>
</a>
</div>
<div class="cell2">
<a href= "#">
<span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
<span class="data"> <h3>Some text here that will over flow</h3></span>
</a>
</div>
<div class="cell">
<a href= "#">
<span class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"></span>
<span class="data"> <h3>Some text here</h3></span>
</a>
</div>
<div class="cell2">
<a href= "#">
<div class="data"> <img src="http://roncabeanz.com/Roncabeanz/images/CoffeeIcon.jpg" width="200px"> </div>
<div class="data"> <h3>Some text here</h3></div>
</a>
</div>
<?php } ?>
</div>
</div>
Link to fiddle: https://jsfiddle.net/jonathannah/3rxcktpm/29/
Just add
h3 { white-space: normal }. The children of .containerinherit white-space: nowrap, which causes the problem.
Another issue in your html is the h3 inside a span, which is invalid. You shouldn't use block elements inside inline elements. You can change it to a div give it the style display: inline

How to align picture with list of html?

I am new to html coding and I could not find exact and clear solution for my problem.
I want to create a page with this format: I want to do the page with list of html.
Here is my html code:
Although I made alignment center my picture is on the left side of the page. What is wrong or missing with my code?
There is no float: center. Only float: left and float: right. You can left-float all of <p> inside the <li> and set the width of them to 33.33%.
In this case the image has to be responsive:
img {
height: auto;
max-width: 100%;
}
Every <li> represent a row
<ul>
<li>
<p>text</p>
<p><img src=""></p>
<p>text</p>
</li>
</ul>
In total
img {
width: 100%;
height: auto;
}
ul {
list-style-type: none;
}
ul>li>* {
box-sizing: border-box;
display: block;
float: left;
word-break: break-all;
padding: 0 5px;
width: 33.333%;
}
.text-center {
text-align: center;
}
.full-width {
width: 100%;
}
<ul>
<li>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
<p class="text-center">
<img src="http://placehold.it/300x200" alt="">
</p>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
<li>
</li>
<li>
<p class="full-width">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
<li>
<p class="full-width">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
<li>
<li>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
<p class="text-center">
<img src="http://placehold.it/300x200" alt="">
</p>
<p>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</p>
</li>
</ul>
You would probably be best looking into using a grid system. I would recommend using Twitter's Bootstrap - definitely the best as easiest to start using
http://getbootstrap.com/

How to align the content of two divs vertically?

I'm trying to align two divs horizontally inside my HTML: the first one contains an image and the second a text, and this is the used code:
<div style="float: left; width: 55px;">
<img src="../img/look.svg" alt="">
</div>
<div style="display: inline-block;">
<span> Look for cases </span>
<span> from people near you. </span>
</div>
I tried many methods, but I've been unable to get the text line in the same level as the image vertical axis, and the text inside the second div gets displayed very far from the image vertically.
So, is there any possibility to fix that?
The problem is with the float. The vertical-align: middle; line-height: 1; will fix the issue:
div {
display: inline-block;
vertical-align: top;
line-height: 1;
}
div:first-child {
width: 55px;
}
<div>
<img src="//placehold.it/50?text=DP" alt="">
</div>
<div style="display: inline-block; vertical-align: middle; line-height: 1;">
<span> Look for cases </span>
<span> from people near you. </span>
</div>
Preview
Top Alignment:
Middle Alignment:
The vertical-align decides the vertical alignment. If you want the image and text to be on the same line, use vertical-align: top.
A few things first:
don't use inline styles
don't mix float with inline-block
Option 1: using flebox
section {
display: flex;
gap: 10px;
}
<section>
<div>
<img src="//dummyimage.com/55x55" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
</section>
Option #2 using inline-block
div {
display:inline-block;
vertical-align:top;
margin-right:10px
}
<div>
<img src="//dummyimage.com/55x55" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
Option #3 using float
div {
float: left;
margin-right:10px
}
<div>
<img src="//dummyimage.com/55x55" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
flexbox to the rescue.
I added your divs inside another one, which will align its items. In my CSS my image has 100px so I changed the width to 100px. Change yours accordingly.
.halign {
display:flex;
align-items: center;
}
<div class="halign">
<div style="width: 100px;">
<img src="http://lorempixel.com/100/100/" alt="">
</div>
<div>
<span> Look for cases </span>
<span> from people near you. </span>
</div>
</div>
Try to seprate the CSS and HTML and do not mix display:inline-block with float:left. Also use clear:both after both div
<style>
.fisrstDiv {
float: left;
display:block;
}
.secondDiv {
float: left;
display:block;
}
.clear {
clear: both;
}
</style>
HTML
<div class="fisrstDiv">
<img src="//placehold.it/50?text=DP" alt="">
</div>
<div class="secondDiv">
<span> Look for cases </span>
<span> from people near you. </span>
</div>
<div class="clear"></div>

Image Positioning at the right corner in jquery mobile

I'm working on mobile app. I'm trying to align 3 images one below the other at the right corner with adjacent to the text. Please suggest me. Thanks in advance. Below is my Code
<div>
<ul data-role="listview" data-filter="true" data-input="#filterBasic-input" data-icon="false">
<li class="custom">
<h3>Week </h3>
<p class="topic">Sun </p>
<p>Mon</p>
<p>Tue </p>
<p class="ui-li-aside"> <span> <img src="images/progressnew.png" alt="download"> </span> <span> <img src="images/progressnew.png" alt="download"> </span> <span> <img src="images/progressnew.png" alt="download"> </span> </p>
</li>
</ul>
</div>
<styles>
.ui-listview .ui-li-aside {
position: absolute;
top: 1em;
right: 0.444em;
margin:24px;
text-align: right;
}
</styles>
Just add:
.ui-listview .ui-li-aside span{
display: block;
}
This tells the SPANS that contain the images to display as block elements instead of inline elements.
DEMO

Vertical text floating in bootstrap div

I created piece of code. In span class mean-head increase horizontally if the text of the span increase. I want to fix it's width for like 30 characters. After that text so go to new line.
EXAMPLE FIEDLE
<span class="top-head"> Recommended URLs </span>
<div class="c1">
<div class="item">
<div class="image">
<img class="media-object" src="http://deathandtaxesmag.wpengine.netdna-cdn.com/wp-content/uploads/2014/02/Screen-Shot-2014-02-27-at-12.39.17-PM.png" >
</div>
<div class="descriptionContainer">
<span class="main-head"> Mashable - Business </span>
<span class="min-head">Title of link Title of link Title of link Title of link </span>
<span class="subcont">
<span class="fa fa-retweet"> RT 100+ | </span>
<span class="fa fa-twitter"> Tweet 100+</span>
</span>
</div>
</div>
</div>
Give fixed width for span class and add display block
.min-head { width:150px; display:block}
Will this help you?
span.min-head {
display: block;
font-size: 9px;
margin-top: 1px;
max-width: 130px;
white-space: pre-wrap;
}
Check the fiddle HERE