Same Height between child and parent container without Flex - html

I have a section with two articles. I would like that child articles, at all times, get the height of the section, considering that height is auto.
If is possible, I would like to do it without flex.
#section1 {
width: 100%;
height: auto;
display: block;
min-height: 400px;
height: auto;
margin: 0;
padding: 0;
font-size: 18px;
font-family: 'Montserrat';
}
#section1 #article1_section1 {
display: inline-block;
width: 79%;
vertical-align: top;
}
#section1 #article2_section1 {
display: inline-block;
width: 20%;
background-color: #ffc727 !important;
color: #ffc727 !important;
vertical-align: top;
}
<section id="section1">
<article id="article1_section1">
<div class="container_section_m">
<h2 class="h2_m">What is Lorem Ipsum</h2>
<h3 class="h3_m">Lorem ipsum is simply dummy</h3>
<div class="basetitle_m"></div>
<div class="space_m"></div>
<h4 class="h4_m">Where can I get some?</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non porttitor diam. Fusce ac justo id ante blandit malesuada sit amet ac lectus. <br> Praesent maximus non mauris ac pretium. Cras vestibulum quam ac lorem tincidunt venenatis.
Suspendisse vehicula sollicitudin orci vel lobortis. Sed quis enim iaculis, facilisis neque nec, dictum mi.</p>
<p>Sed euismod ante leo, vitae vehicula ex molestie quis. Aenean venenatis nibh nisi. Phasellus sagittis interdum mi a auctor.</p>
</div>
</article>
<article id="article2_section1">
-
</article>
</section>

Try below css.
#section1{
width:100%;
height:auto;
display:table;
min-height:400px;
height:auto;
margin:0;
padding:0;
font-size:18px;
font-family: 'Montserrat';
}
#section1 #article1_section1{
display:table-cell;
width:79%;
vertical-align: top;
}
#section1 #article2_section1{
display:table-cell;
width:20%;
background-color: #ffc727 !important;
color: #ffc727 !important;
vertical-align: top;
}
stackblitz demo: https://stackblitz.com/edit/web-platform-dr7imx

display: inline-block; replace display:table-cell; use it
#section1 {
width: 100%;
height: auto;
display: block;
min-height: 400px;
height: auto;
margin: 0;
padding: 0;
font-size: 18px;
font-family: 'Montserrat';
}
#section1 #article1_section1 {
display:table-cell;
width: 79%;
vertical-align: top;
}
#section1 #article2_section1 {
display:table-cell;
width: 20%;
background-color: #ffc727 !important;
color: #ffc727 !important;
vertical-align: top;
}
<section id="section1">
<article id="article1_section1">
<div class="container_section_m">
<h2 class="h2_m">What is Lorem Ipsum</h2>
<h3 class="h3_m">Lorem ipsum is simply dummy</h3>
<div class="basetitle_m"></div>
<div class="space_m"></div>
<h4 class="h4_m">Where can I get some?</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non porttitor diam. Fusce ac justo id ante blandit malesuada sit amet ac lectus. <br> Praesent maximus non mauris ac pretium. Cras vestibulum quam ac lorem tincidunt venenatis.
Suspendisse vehicula sollicitudin orci vel lobortis. Sed quis enim iaculis, facilisis neque nec, dictum mi.</p>
<p>Sed euismod ante leo, vitae vehicula ex molestie quis. Aenean venenatis nibh nisi. Phasellus sagittis interdum mi a auctor.</p>
</div>
</article>
<article id="article2_section1">
-
</article>
</section>

Related

When page resizes content boxes aren't centred anymore

The content boxes look good when they're full size, but when the page shrinks they are no longer centred. I've tried messing around with a bunch of things but can't for the life of me figure out what's wrong.
I've only been learning to code for a few weeks to please be kind lol, however if you have any off topic tips they are also appreciated
* {margin: 0; padding: 0}
main {
margin: 35px 50px;
padding: 0px 15px;
}
.mainContent {
display:block;
height:auto;
width: 60%;
float:left;
background-color: rgba(29,1,52,1);
padding: 30px;
color: #01b3ff;
text-align:center;
}
.newsHolder {
display: block;
height:auto;
width: 30%;
float:right;
background-color: rgba(29,1,52,1);
padding: 20px 15px;
color: #01b3ff;
}
.newsHolder img {
float:left;
padding: 15px;
}
#media screen and (min-width: 1141px) {
.mainContent {
margin-right: 10px;
}
}
#media screen and (max-width: 1140px) {
.mainContent {
width: 100%;
margin-bottom: 40px;
clear:both;
}
.newsHolder {
width:100%;
clear:both;
}
}
<body>
<main>
<div class="mainContent">
<h1> Welcome to my website! </h1><br>
<br>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis laoreet eros. Sed tristique felis quis turpis aliquet, sed hendrerit massa tincidunt. Phasellus consequat finibus lectus id euismod. Sed orci nunc, tempus id condimentum vitae, pharetra ultrices nibh. Quisque erat ipsum, aliquam vitae pretium ac, consequat at nisi. Pellentesque vehicula, neque ac varius aliquam, lectus nisi sodales ante, bibendum lobortis justo metus nec sem. Duis a imperdiet lectus, ut interdum enim. Quisque eu commodo elit. Mauris massa lorem, ullamcorper luctus diam quis, lacinia lobortis arcu. Vestibulum facilisis feugiat nisl, eget tempus erat tempor sed.
</p>
</div>
<div class="newsHolder">
<h1 style="text-align: center;"> BREAKING NEWS </h1><br>
<br>
<img src="images\angryluke.png">
<h2> Lorem ipsum </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis laoreet eros. </p>
</div>
</main>
</body>
You have to read more about box-sizing, just add box-sizing: border-box; to all elements and it will fix your problem.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
main {
margin: 35px 50px;
padding: 0px 15px;
}
.mainContent {
display:block;
height:auto;
width: 60%;
float:left;
background-color: rgba(29,1,52,1);
padding: 30px;
color: #01b3ff;
text-align:center;
}
.newsHolder {
display: block;
height:auto;
width: 30%;
float:right;
background-color: rgba(29,1,52,1);
padding: 20px 15px;
color: #01b3ff;
}
.newsHolder img {
float:left;
padding: 15px;
}
#media screen and (min-width: 1141px) {
.mainContent {
margin-right: 10px;
}
}
#media screen and (max-width: 1140px) {
.mainContent {
width: 100%;
margin-bottom: 40px;
clear:both;
}
.newsHolder {
width:100%;
clear:both;
}
}
<body>
<main>
<div class="mainContent">
<h1> Welcome to my website! </h1><br>
<br>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis laoreet eros. Sed tristique felis quis turpis aliquet, sed hendrerit massa tincidunt. Phasellus consequat finibus lectus id euismod. Sed orci nunc, tempus id condimentum vitae, pharetra
ultrices nibh. Quisque erat ipsum, aliquam vitae pretium ac, consequat at nisi. Pellentesque vehicula, neque ac varius aliquam, lectus nisi sodales ante, bibendum lobortis justo metus nec sem. Duis a imperdiet lectus, ut interdum enim.
Quisque eu commodo elit. Mauris massa lorem, ullamcorper luctus diam quis, lacinia lobortis arcu. Vestibulum facilisis feugiat nisl, eget tempus erat tempor sed.
</p>
</div>
<div class="newsHolder">
<h1 style="text-align: center;"> BREAKING NEWS </h1><br>
<br>
<img src="images\angryluke.png">
<h2> Lorem ipsum </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus quis laoreet eros. </p>
</div>
</main>
</body>
Here is a link where you could know more about it: https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing

Stack divs vertically & keep 2 column layout

I want to have two stacked divs on one side, and then have a single column on the other side with the same height as the left divs.
Kind of like this:
I have the two divs and a side bar, but the two divs won't stack.
Here is what I have so far Fiddle
#import url(https://fonts.googleapis.com/css?family=Oxygen);
body {
background-color: #222;
}
.description h1 {
text-align: left;
padding: 20px;
}
#wrapper {
text-align: center;
}
.description,
.sidebar,
.demo-container {
display: inline-block;
vertical-align: top;
}
.description {
background: #eee;
width: 50%;
font-family: "Oxygen";
font-size: 14px;
color: #000;
line-height: 1.2;
}
.sidebar {
background: #eee;
width: 15%;
height: 575px;
}
.demo-container {
background: #eee;
width: 50%;
font-family: "Oxygen";
font-size: 14px;
color: #000;
line-height: 1.2;
}
<div id='wrapper'>
<div class="demo-container">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum.</p>
</div>
<div class="description">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum.</p>
</div>
<div class="sidebar">
</div>
</div>
you are complicating a lot, here is a basic demo of what you want using flexbox
*,
*::before,
*::after {
box-sizing: border-box
}
body {
margin: 0
}
.flex {
display: flex;
flex-basis: 100%
}
.fl {
flex: 1;
display: flex;
flex-direction: column;
margin: 0 5px;
justify-content: space-between
}
.flex-item {
border: 1px solid black
}
.flex-item:not(:first-of-type) {
margin: 10px 0 0
}
.sidebar {
border: 1px solid black;
}
<div class="flex">
<div class="fl">
<div class="flex-item">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum, et aliquam erat feugiat. Duis interdum enim vitae justo cursus pulvinar eu ac nulla. Donec consectetur vehicula turpis. Nunc laoreet tincidunt elit</p>
</div>
<div class="flex-item">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium lorem nec tortor elementum, et aliquam erat feugiat. Duis interdum enim vitae justo cursus pulvinar eu ac nulla. Donec consectetur vehicula turpis. Nunc laoreet tincidunt elit
ultrices elementum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Curabitur augue magna, posuere id tortor vel, condimentum consectetur lacus. Pellentesque dui est, ornare vitae semper et, dapibus ut lacus.
Etiam sed porta dui. Phasellus non nisl eget dolor commodo imperdiet.</p>
</div>
</div>
<div class="fl sidebar"></div>
</div>
Just put <div class="sidebar"></div> before the other two divs, then float them all right. See fiddle https://jsfiddle.net/y71tkmtw/1/
.description,
.sidebar, .demo-container {
float: right;
margin: 40px;
}
Just add another <div> surrounding the 2 divs on the left-hand side, with float:left. Add float:right to the sidebar.
.left-container
{
width: 85%;
float:left;
}
.sidebar {
background: #eee;
width: 15%;
height: 575px;
float:right;
}
Fiddle: https://jsfiddle.net/dncgytef/2/

Why is the paragraph not floating beside the profilePic?

Somehow, the paragraph is not floating beside the profilePic. It starts from the bottom of the profilePic. I am not able to understand why.
What is the mistake here?
.content {
margin-top: 30px;
margin-left: 20px;
padding-bottom: 20px;
}
.infoBit {
width: 800px;
float: left;
display: inline-block;
font-size: 1.1em;
padding-right: 10px;
padding-top: 10px;
}
.profilePic {
border: 1px blue solid;
height: 49px;
display: inline-block;
width: 49px;
float: left;
}
.infoText {
display: inline-block;
float: left;
}
<div class="content">
<div class="infoBit">
<div class="profilePic"></div>
<div class="infoText">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quis enim ut sapien sodales commodo. Fusce congue, elit a finibus fermentum, diam eros mollis massa, at eleifend sapien dui eget mauris. Donec nec diam enim. Vivamus commodo placerat risus
vitae auctor. Cras leo elit, egestas eget dolor vitae, facilisis consequat sem. Mauris facilisis ipsum in porttitor ullamcorper. Nam vel massa sed quam venenatis facilisis. Quisque vitae mollis urna. In egestas nunc sed felis consequat, in malesuada
dolor feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
</div>
</div>
</div>
https://jsfiddle.net/4sbzos1r/
It works fine even if is wrapped inside a . Defining width of resolves issue
Please change styles as below
.content
{
margin-top : 30px;
margin-left: 20px;
padding-bottom: 20px;
}
.infoBit
{
width: 800px;
/* float: left; */
display: inline-block;
font-size: 1.1em;
padding-right: 10px;
padding-top: 10px;
}
.profilePic
{
border:1px blue solid;
height: 49px;
display: inline-block;
width: 49px;
float: left;
}
.infoText
{
display: inline-block;
width: 700px;
}
As others have mentioned, it is because you have your <p> wrapped in a <div> with class infoText, which applies the styling display: inline-block; float:left; from the css you wrote. I would suggest either taking out the <div> entirely, or just remove the infoText styling you have. Furthermore, you probably want margin-top:0 on .infoText to bring the text to the top.
Does that make sense?
hope this help you
.content
{
margin-top : 30px;
margin-left: 20px;
padding-bottom: 20px;
}
.infoBit
{
width: 800px;
float: left;
display: inline-block;
font-size: 1.1em;
padding-right: 10px;
padding-top: 10px;
}
.profilePic
{
border:1px blue solid;
height: 49px;
display: inline-block;
width: 49px;
float: left;
}
.infoText
{
display: inline-block;
width:250px
}
.infoText p{
margin-top:0
}
<div class="content">
<div class="infoBit">
<div class="profilePic"></div>
<div class="infoText">
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quis enim ut sapien sodales commodo. Fusce congue, elit a finibus fermentum, diam eros mollis massa, at eleifend sapien dui eget mauris. Donec nec diam enim. Vivamus commodo placerat risus vitae auctor. Cras leo elit, egestas eget dolor vitae, facilisis consequat sem. Mauris facilisis ipsum in porttitor ullamcorper. Nam vel massa sed quam venenatis facilisis. Quisque vitae mollis urna. In egestas nunc sed felis consequat, in malesuada dolor feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
</div>
</div>
</div>

3 column layout rendering issue

I have a 3 col layout, left and mid col are images, and the last col is text. I want to keep the height of all col the same at all times even when the browser resizes. I don't mind having scroll bar on the last col with text.
HTML:
<div class="mid-col">
<img src=""/>
</div>
<div class="right-col">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed semper, eros nec sollicitudin porta, nibh justo consectetur elit,
a ultricies libero est ac justo. Nulla dictum dignissim placerat.
Donec non eros nisl. Morbi diam est, volutpat a orci tempus, mollis
maximus dui. Quisque consequat risus et sagittis dapibus. Mauris nulla
quam, ullamcorper a mattis sed, pretium sit amet dolor. Etiam pharetra
velit id lacus cursus imperdiet. Phasellus ex ipsum, finibus vitae
rhoncus et, suscipit at risus. Nam dignissim sapien tortor, ut
egestas tortor pulvinar ut.
</p>
</div>
</div>
CSS:
#content-container {
width: 100%;
height: 33.333%;
}
.left-col img {
width: 33.333%;
float: left;
display:block;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.mid-col img {
width: 33.333%;
float: left;
display:block;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.right-col {
width: 33.333%;
height: 33.333%;
height: 100%;
display:block;
overflow: scroll;
}
you can achieve that by using display:table-[cell]
#content-container {
width: 100%;
display: table;
}
#content-container > div {
display: table-cell;
width: 33%;
vertical-align: top;
border: 1px solid green
}
img {
width: 100%;
display: block;
height: auto;
}
<div id="content-container">
<div class="left-col">
<img src="http://lorempixel.com/100/100" />
</div>
<div class="mid-col">
<img src="http://lorempixel.com/100/100" />
</div>
<div class="right-col">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed semper, eros nec sollicitudin porta, nibh justo consectetur elit, a ultricies libero est ac justo. Nulla dictum dignissim placerat. Donec non eros nisl. Morbi diam est, volutpat a orci tempus,
mollis maximus dui. Quisque consequat risus et sagittis dapibus. Mauris nulla quam, ullamcorper a mattis sed, pretium sit amet dolor. Etiam pharetra velit id lacus cursus imperdiet. Phasellus ex ipsum, finibus vitae rhoncus et, suscipit at risus.
Nam dignissim sapien tortor, ut egestas tortor pulvinar ut.
</p>
</div>
</div>
The browser renders from top to bottom so you are getting the opposite effect. Try:
<div class="container">
<div class="child1"></div>
<div class="child2"></div>
<div class="child3"></div>
</div>
.container {
height: 100%;
}
.child1 {
width: 33.333%;
height: 33.333%;
float: left;
box-sizing: border-box;
}
.child2 {
width: 33.333%;
height: 33.333%;
float: left;
box-sizing: border-box;
}
.child3 {
width: 33.333%;
height: 33.333%;
float: left;
box-sizing: border-box;
overflow-y: auto;
}
The parent container can take up all the space. Each child can float to the left. Changing the box sizing keeps a consistent width for percentages.
I like #beautifulcoder's answer but I have the same thing on one of my sites and handled it with jquery.
$(function() {
var divHeight = $(window).height()/3;
$('.left-col').css('height',divHeight));
$('.mid-col').css('height',divHeight);
$('.right-col').css('height',divHeight);
$('.right-col').css('overflow-y','auto');
})

Text out of limit of box in Css

In the follwing example the text goes out of the box. And when I reduce the size of the borowser the size of the boxes shring resposively but the text becomes mixed and unorganized. How can solve this?
<html>
<head>
<meta charset="utf-8">
<title>This is an email template</title>
<style>
body {
background-color: rgba(79, 183, 227, 0.4);
direction: rtl;
}
body * {
font-family: Tahoma;
}
a:link {
text-decoration: none;
margin-right: 25px;
color: #46B1F9;
}
#wrap {
background-color: #e0f2f6;
margin: auto;
width: 75%;
padding: 15px;
border: 1px solid grey;
}
.item {
border: 1px solid #95A5A6;
border-radius: 5px;
margin-bottom: 25px;
width: 60%;
display: inline-block;
}
.item p {
font-size: 1em;
}
.item img {
float: left;
width: 30%;
}
.item .notice {
text-align: center;
float: right;
padding-top: 25px;
padding-right: 25px;
width: 50%;
height: 1em;
}
/*clearfixes*/
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {
display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfix {
height: 1%;
}
.clearfix {
display: block;
}
/* End hide from IE-mac */
</style>
</head>
<body>
<div id="wrap">
<div style="padding:15px;">
<div class="item clearfix">
<div class="notice">
<p><strong>Lorem ipsum</strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus sollicitudin aliquet. Fusce dolor leo, egestas non nisi in, aliquam ullamcorper diam. Quisque placerat tortor in porta egestas. Aenean et elementum purus. Nunc eget nulla blandit, volutpat libero non, finibus purus. Vivamus vitae tellus at risus commodo varius.</p>
</div>
<img src="http://s14.postimg.org/wqzq39iht/image.jpg" alt="" />
</div>
<div class="item clearfix">
<div class="notice">
<p>
<strong>اLorem ipsum</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus sollicitudin aliquet. Fusce dolor leo, egestas non nisi in, aliquam ullamcorper diam. Quisque placerat tortor in porta egestas. Aenean et elementum purus. Nunc eget nulla blandit, volutpat libero non, finibus purus. Vivamus vitae tellus at risus commodo varius.</p>
</div>
<img src="http://s10.postimg.org/y4kk17q21/image.jpg" alt="" />
</div>
<div class="item clearfix">
<div class="notice">
<p><strong>Lorem ipsum</strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus sollicitudin aliquet. Fusce dolor leo, egestas non nisi in, aliquam ullamcorper diam. Quisque placerat tortor in porta egestas. Aenean et elementum purus. Nunc eget nulla blandit, volutpat libero non, finibus purus. Vivamus vitae tellus at risus commodo varius.</p>
</div>
<img src="http://s3.postimg.org/xca6ju1kj/image.jpg" alt="" />
</div>
</div>
</div>
</div>
</div>
</body>
</html>
If you are trying to expand the block by content, removing height from .item .notice should fix the issue.
In all cases your text will overflow the box , so you should add overflow:scroll to notice class
Depends on what you are trying to do.
If the boxes must be a fixed height there are couple of different strategies.
The easiest thing to do is to turn off the height restriction to the notice class. However, this will reflow your document and push everything down.
On the other hand, if you want to keep the current layout, I cannot provide you a unilateral decision as the padding, height and overflow will conflict with each other on this element.