Content <section> not staying in place - html

I got this problem with my sections which is built up by a container, left menu, right menu and container:
#container {
margin: 40px auto;
width: 70%;
min-height: 400px;
}
#leftmenu {
float: left;
box-sizing: border-box;
width: 20%;
min-height: 600px;
background-color: #111;
}
#content {
float: left;
box-sizing: border-box;
width: 60%;
background-color: #202020;
min-height: 600px;
}
#rightmenu {
float: left;
box-sizing: border-box;
width: 20%;
min-height: 600px;
background-color: #272727;
}
When I'm shrinking the window, the problem starts to appear:
The content box is appearing to the right (looks like beneath) the right menu, and is not shrinking with the others. How is this fixed?
HTML:
<section id="container">
<section id="leftmenu">
<section class="contenthead">
<b style="font-weight: bold; color: #976535; text-align: center;"><center>HOVEDMENY</center></b>
</section>
</section>
<section id="content">
<section class="contenthead">» <? echo $page; ?></section>
</section>
<section id="rightmenu">
<section class="contenthead">
<b style="font-weight: bold; color: #976535; text-align: center;"><center>KOMMUNIKASJON</center></b>
</section>
</section>
</section>
</body>
</html>
Screenshot of the problem:
Help, anyone?!?

I would suggest you to use a fixed sidebar and a fluid content for this case in the desktop mode. Something like this might be a start for you...
.main-content {border: 1px solid #999; padding: 5px; position: relative; min-height: 200px; padding-left: 125px;}
.left-sidebar {position: absolute; left: 0; top: 0px; width: 120px; background-color: #eee; height: 100%;}
<div class="main-content">
<div class="left-sidebar"></div>
<div class="right-fluid">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum libero iure facere quam iste, nostrum laborum in, dolorum beatae optio rem explicabo voluptates qui quos eius accusamus! Accusamus blanditiis, et!
</div>
</div>
Try resizing the window in full screen and check it out.
Update
With your same code, it looks this way:
#container {
margin: 40px auto;
min-height: 400px;
position: relative;
padding: 0 200px;
}
#leftmenu {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 200px;
box-sizing: border-box;
min-height: 600px;
background-color: #111;
text-align: center;
}
#content {
box-sizing: border-box;
background-color: #202020;
min-height: 600px;
color: #fff;
}
#rightmenu {
position: absolute;
right: 0;
top: 0;
bottom: 0;
box-sizing: border-box;
width: 200px;
min-height: 600px;
background-color: #272727;
}
<section id="container">
<section id="leftmenu">
<section class="contenthead">
<b style="font-weight: bold; color: #976535;">HOVEDMENY</b>
</section>
</section>
<section id="content">
<section class="contenthead">» Page</section>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore, illo. Nulla saepe quasi sint nam, beatae adipisci labore mollitia. Minima assumenda corporis perspiciatis veritatis aut distinctio eligendi! Quam, deleniti, eveniet.</p>
</section>
<section id="rightmenu">
<section class="contenthead">
<b style="font-weight: bold; color: #976535; text-align: center;"><center>KOMMUNIKASJON</center></b>
</section>
</section>
</section>

Related

Position element at the bottom of container without flex or position absolute

I'm trying to make a component that uses both a background color for half of the component and
an image for the other half, with the image acting as an element with a margin. The problem I'm having is that I cannot use display flex to space elements correctly in the content area, it breaks the component with the current solution I'm using and I have no idea why.
I'm specifically trying to position .service__link at the bottom of .service__content. I've tried using paddings/margins to get it in place, but at smaller screen sizes it ends up overflowing out of the box.
*, *::before, *::after {
box-sizing: border-box;
}
* {
padding: 0;
margin: 0;
}
body {
min-height: 100vh;
font-family: Arial;
}
.service-container {
max-width: 1800px;
margin-inline: auto;
padding: 40px 15px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 1.5rem;
}
.service {
flex: 1 1 calc(33.3336% - 1.5rem);
display: inline-block;
position: relative;
background: #144088;
min-height: 325px;
border: 2px solid #144088;
color: white;
}
.service::before {
content: "";
float: right;
width: 100%;
height: 100%;
background: url(https://images.unsplash.com/photo-1645069258059-6f5a71256c4a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2076&q=80) left center/150%;
shape-outside: polygon(79% 0, 100% 0, 100% 100%, 42% 100%);
clip-path: polygon(79% 0, 100% 0, 100% 100%, 42% 100%);
shape-margin: .3em;
}
.service::after {
content: "01";
position: absolute;
top: 0;
font-size: 60px;
font-weight: bold;
line-height: 1;
opacity: 25%;
}
.service__content {
padding: 3rem 0 1rem 1rem;
height: 100%;
}
.service__title {
font-size: 26px;
}
.service__description {
font-size: clamp(12px, 3vw + .25rem, 16px);
}
.service__title, .service__description {
margin-bottom: 1rem;
}
.service__link {
display: inline-flex;
justify-content: space-between;
align-items: center;
width: 35%;
}
.service__link a {
color: white;
}
.service__link img {
filter: brightness(0)invert(1);
}
#media screen and (max-width: 1200px) {
.service {
flex: 0 1 518px;
}
}
<body>
<div class="service-container">
<div class="service">
<div class="service__content">
<h4 class="service__title">Lorem</h4>
<p class="service__description">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat doloremque molestiae eligendi voluptas veniam repellendus, aperiam tempora suscipit consectetur sint?</p>
<div class="service__link">
Link
<img src="https://img.icons8.com/ios/26/000000/image.png"/>
</div>
</div>
</div>
<div class="service">
<div class="service__content">
<h4 class="service__title">Lorem</h4>
<p class="service__description">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat doloremque molestiae eligendi voluptas veniam repellendus, aperiam tempora suscipit consectetur sint?</p>
<div class="service__link">
Link
<img src="https://img.icons8.com/ios/26/000000/image.png"/>
</div>
</div>
</div>
<div class="service">
<div class="service__content">
<h4 class="service__title">Lorem</h4>
<p class="service__description">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat doloremque molestiae eligendi voluptas veniam repellendus, aperiam tempora suscipit consectetur sint?</p>
<div class="service__link ">
Link
<img src="https://img.icons8.com/ios/26/000000/image.png"/>
</div>
</div>
</div>
</div>
</body>
What is going on when display: flex is added to .service__content?
Also, if anybody has a better idea of how to make this component in general I'd love to hear it.
Thanks!
I think you could use this:
position: absolute; bottom: 30px
to put it in the bottom part of the div.
If you set service__link to flex instead of inline flex and add margin-top auto it should stay on the bottom
you have to give position : relative for container
than for service__link position: absolute; left:10px; bottom:10px;
there will be no deterioration in smaller screen.
.service__content {
padding: 3rem 0 1rem 1rem;
height: 100%;
position: relative; // Added
}
.service__link {
display: inline-flex;
justify-content: space-between;
align-items: center;
width: 35%;
position: absolute; // Added
left:10px; // Added
bottom:10px; // Added
}
*, *::before, *::after {
box-sizing: border-box;
}
* {
padding: 0;
margin: 0;
}
body {
min-height: 100vh;
font-family: Arial;
}
.service-container {
max-width: 1800px;
margin-inline: auto;
padding: 40px 15px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 1.5rem;
}
.service {
flex: 1 1 calc(33.3336% - 1.5rem);
display: inline-block;
position: relative;
background: #144088;
min-height: 325px;
border: 2px solid #144088;
color: white;
}
.service::before {
content: "";
float: right;
width: 100%;
height: 100%;
background: url(https://images.unsplash.com/photo-1645069258059-6f5a71256c4a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2076&q=80) left center/150%;
shape-outside: polygon(79% 0, 100% 0, 100% 100%, 42% 100%);
clip-path: polygon(79% 0, 100% 0, 100% 100%, 42% 100%);
shape-margin: .3em;
}
.service::after {
content: "01";
position: absolute;
top: 0;
font-size: 60px;
font-weight: bold;
line-height: 1;
opacity: 25%;
}
.service__content {
padding: 3rem 0 1rem 1rem;
height: 100%;
position:relative;
}
.service__title {
font-size: 26px;
}
.service__description {
font-size: clamp(12px, 3vw + .25rem, 16px);
}
.service__title, .service__description {
margin-bottom: 1rem;
}
.service__link {
display: inline-flex;
justify-content: space-between;
align-items: center;
width: 35%;
position:absolute;
left:10px;
bottom:10px;
}
.service__link a {
color: white;
}
.service__link img {
filter: brightness(0)invert(1);
}
#media screen and (max-width: 1200px) {
.service {
flex: 0 1 518px;
}
}
<body>
<div class="service-container">
<div class="service">
<div class="service__content">
<h4 class="service__title">Lorem</h4>
<p class="service__description">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat doloremque molestiae eligendi voluptas veniam repellendus, aperiam tempora suscipit consectetur sint?</p>
<div class="service__link">
Link
<img src="https://img.icons8.com/ios/26/000000/image.png"/>
</div>
</div>
</div>
<div class="service">
<div class="service__content">
<h4 class="service__title">Lorem</h4>
<p class="service__description">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat doloremque molestiae eligendi voluptas veniam repellendus, aperiam tempora suscipit consectetur sint?</p>
<div class="service__link">
Link
<img src="https://img.icons8.com/ios/26/000000/image.png"/>
</div>
</div>
</div>
<div class="service">
<div class="service__content">
<h4 class="service__title">Lorem</h4>
<p class="service__description">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Placeat doloremque molestiae eligendi voluptas veniam repellendus, aperiam tempora suscipit consectetur sint?</p>
<div class="service__link ">
Link
<img src="https://img.icons8.com/ios/26/000000/image.png"/>
</div>
</div>
</div>
</div>
</body>

How to create a responsive div where inside it have a squre and some texts

Below i write the code, in this code i want to make responsive 'rectangle' and 'square' and i also want to make resopnsive text in the p tag.
#rectangle
{
display: flex;
width: 500px;
height: 150px;
background-color: brown;
}
#square
{
width: 300px;
height: 130px;
background-color: chocolate;
margin: 10px;
}
<div id="rectangle">
<div id="square">
</div>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente fugiat illo
dolorum assumenda commodi!
</p>
</div>
For the widths and heights, use % instead of px. For the text, add an id or class that defines a font using the vw unit. For example:
<div id="rectangle">
<div id="square">
</div>
<p id='text'>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente
fugiat illo dolorum assumenda commodi!
</p>
</div>
#rectangle
{
background-color: brown;
display: flex;
height: 8%;
position: relative;
width: 10%;
}
#square
{
background-color: chocolate;
height: 8%;
margin: 10px;
position: relative;
width: 10%;
}
#text
{
font-size: 2vw;
}
Here you go. If you want responsiveness, use % or vh / vw
#rectangle
{
display: flex;
width: 70vw;
height: 40vh;
background-color: brown;
font-size: 2.3vw;
}
#square
{
width: 100%;
height: 100%;
background-color: chocolate;
margin-right: 3%;
display: flex;
align-items: center;
justify-content: center;
}
.arrow-up {
display: flex;
align-items: center;
justify-content: center;
width: 0;
height: 0;
border-left: 10vw solid transparent;
border-right: 10vw solid transparent;
border-bottom: 10vw solid black;
}
<div id="rectangle">
<div id="square">
<div class="arrow-up"></div>
</div>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente fugiat illo
dolorum assumenda commodi!
</p>
</div>

Timeline with images in center

Can someone please help me?!
I'm trying to code a PSD file to HTML and CSS, but I'm struggling with one of the sections. Here's an image of what I want to do:
Click Here
The problem is I don't know how to put the image in the timeline line. I tried to add the image in the ::after psuedo, but I don't think this is the right way of doing that.
This is my HTML Code :
<section class="about">
<div class="wrapper">
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
<div class="container left">
<div class="content">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
<div class="container right">
<div class="content">
<h5>January 2011<br> Facing Startups Battles</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</section>
This is my CSS code:
.about .wrapper{
padding: 80px 10%;
text-align: center;
position: relative;
}
.about .wrapper::after{
content: '';
position: absolute;
top: 200px;
bottom: 0;
width: 6px;
background: red;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.about .container{
position: relative;
width: 50%;
top: 60px;
margin: 0 0 60px 0;
}
.about .container::after{
content: 'How Can I Add an Image Here in this circle?';
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
top: 20px;
right: -104px;
background-color: blue; /* Just because there is no image */
background-image: url(assets/img/about-1.png);
background-repeat: no-repeat;
background-size: cover;
z-index: 2;
}
.left{
text-align: right;
}
.right{
text-align: right;
}
.content{
padding: 30px 0px 80px 0px;
}
.left .content{
padding-right: 140px;
}
.right .content{
padding-left: 140px
}
.right{
text-align: left;
left: 50%;
}
.right:after {
left: -104px;
}
I think this is called a timeline, there is a lot of tutorials talking about how to do something like this, but I don't know how to make the images in the timeline line. Can you please help me do this?
Thanks
To build this, you could use css grid layout (guide: https://css-tricks.com/snippets/css/complete-guide-grid/)
Treat each of the content+image as a row in the layout. And each row as a container for a grid.
You can visually break every row down to 3 columns. One column for left-side content, the second one for the image and the third one for right-side content.
Example css grid for a layout like this:
.grid-container {
display: grid;
grid-template-columns: 1fr 10em 1fr;
grid-template-rows: 1fr;
grid-template-areas: "content-left image content-right";
text-align: center;
}
.content-left { grid-area: content-left; background: lightblue; }
.image { grid-area: image; background: lightgreen; }
.content-right { grid-area: content-right; background: lightblue; }
<div class="grid-container">
<div class="content-left">Left content</div>
<div class="image">Image</div>
<div class="content-right">Right content</div>
</div>
(grid generated with: https://grid.layoutit.com/)
To alternate between content on the left and on the right, you can use css even/odd selectors (How can I style even and odd elements?) to set which grid area is used for the element.
Example:
I've built an example of a timeline layout for this answer which you can find at https://codepen.io/hendrysadrak/pen/VwLEraz
Try this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="main.css" />
<title></title>
</head>
<body>
<section class="about">
<div class="wrapper">
<div>
<h3>About Us</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div id="container">
<div class="row">
<div id="col1" class="col right">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
<div id="col2" class="col"><img class="img" src="assets/img/about-1.png"/></div>
</div>
<div class="row2" >
<div id="col3" class="col"><img class="img" src="assets/img/about-1.png"/></div>
<div id="col4" class="col left">
<h5>JULY 2010<br> Our Humble Beginnings</h5>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum officia labore fugit nihil nulla laboriosam praesentium harum ut, odio ea facere, recusandae reprehenderit repellat.</p>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
in main.css file:
.about .wrapper{
padding: 80px 10%;
text-align: center;
}
.about h5{
line-height: 1.5;
font-size: 1em;
padding-bottom: .5em;
}
.row {
width: 59%;
margin-right: 41%;
display: flex;
}
.row2 {
width: 59%;
display: flex;
margin-left: 41%;
}
.col {
flex:1;
}
.col.left {
text-align: left;
}
.col.right {
text-align: right;
}
#col2 {
flex-basis: 30%;
}
#col1 {
flex-basis: 70%;
}
#col3 {
flex-basis: 30%;
}
#col4 {
flex-basis: 70%;
}
.img {
margin: 10% 5%;
width: 90%;
border-radius: 50%;
}
#container {
background-image: linear-gradient(lightgrey,lightgrey);
background-size: 2px 100%;
background-repeat: no-repeat;
background-position: center center;
}
put this in assets/img/about-1.png

How do I bring these two elements closer together?

I'm trying to get the #bigimage and #textarea elements to sit closer together, but then still be centered when laid out as col-12 on a small screen.
Should I use a media query for this? I've tried putting them in a separate container, but strange stuff starts happening when I test that on a small screen.
The colored borders in my attempt below are for my own clarity. I'm just a beginner so if you have any other comments about my code I'd really appreciate it.
header {
border: 3px solid red;
text-align: center;
margin-top: 30px;
}
li {
display: inline;
text-align: center;
padding: 3%;
}
img {
width: 300px;
}
ul {
border: 2px solid green;
margin-bottom: 20px;
margin-top: 40px;
}
h2 {
border: 2px solid yellow;
margin-top: 30px;
}
#textarea {
border: 3px solid green;
text-align: justify;
margin-top: 30px;
width: 200px;
}
#bigimage {
border: 3px solid green;
text-align: center;
}
p {
border: 2px solid red;
position: relative;
top: 50%;
transform: translateY(-50%);
width: 300px;
margin: 0 auto;
}
#mainstuff {
width: 50% margin: 0 auto;
border: 3px solid yellow;
}
.container {
border: 5px solid blue;
}
.row {
margin-top: 30px;
position: relative;
}
img {
border: 2px solid red;
}
#textandphoto {
width: 800px;
}
#media (min-width: 1500px) {
.container {
max-width: 900px;
}
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-12">
<header>
<h1>Raphael Hetherington</h1>
<h2>11+ Tutor</h2>
<ul>
<li>About Me</li>
<li>11+ Tuition</li>
<li>Programming</li>
<li>Testimonials</li>
<li>Contact</li>
</ul>
</header>
</div>
</div>
<div class="row" id="mainstuff">
<div class="col-12 col-md-6" id="bigimage">
<img src="//lorempixel.com/400/200/abstract/5/" alt="">
</div>
<div class="col-12 col-md-6" id="textarea">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illum omnis harum nesciunt repellendus laudantium quam quo ea, placeat, totam rem laboriosam vero, asperiores architecto. Dolores earum, architecto nemo molestiae quo. Lorem ipsum dolor sit
amet, consectetur adipisicing elit. Corporis accusamus modi eaque placeat voluptates nihil quasi non et similique magnam architecto itaque nobis expedita amet, provident doloribus eveniet quis explicabo?</p>
</div>
</div>
</div>
#textarea {
border: 3px solid green;
text-align: justify;
margin-top: 0; /* 0 instead of 30px*/
width: 200px;
}

Make nested div stretch to parent height

Well basically I'm creating some forums, and for example we're looking at a thread and the user information is on the left, and the content of the thread is on the right, and then under is the user's signature.
Now, I'm trying to get the user information on the left to stretch down to the height of its container...
http://prntscr.com/7dbdww
.topic {
width: 100%;
display: inline-block;
border: 1px solid #444;
margin-bottom: 20px;
position: relative;
}
.topic-header {
width: 100%;
height: 40px;
display: block;
background-color: #CD422B;
border-left: 1px solid #CD422B;
border-right: 1px solid #CD422B;
}
.topic-header h4 {
color: #fff;
font-family: 'Titillium Web', sans-serif;
font-size: 18px;
font-weight: 700;
padding-left: 10px;
line-height: 40px;
margin: 0;
}
.topic-userinfo {
width: 20%;
min-height: 200px;
display: inline-block;
position: relative;
float: left;
left: 0;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
.topic-usersig {
width: 80%;
height: 150px;
max-height: 300px;
display: inline-block;
overflow-y: auto;
position: relative;
float: right;
right: 0;
background-color: #323232;
border-top: 1px dashed #444;
}
.topic-body {
width: 80%;
min-height: 200px;
display: inline-block;
position: relative;
float: right;
right: 0;
background-color: #323232;
color: #fff;
}
That's css ^ here's html
<div class="topic">
<div class="topic-header">
<h4><i class="fa fa-fw fa-comment"></i> Test</h4>
</div>
<div class="topic-userinfo">
<div class="userinfo-box">
<center>
<span class="userinfo-name admin-color">
deaL
</span>
<span class="userinfo-rank">
Administrator
</span>
<img src="http://www.skruffysdeveloper.com/assets/img/user_img_default.png" style="border: 1px solid #333; width: 90px; height: 90px;">
</center>
</div>
<center>
Joel Evans
</center>
</div>
<div class="topic-body">
<div class="topic-content">test2</div>
</div>
<div class="topic-usersig">
<div style="margin: 10px"></div>
</div>
</div>
use these css for parent
.parent {
overflow: hidden;
position: relative;
width: 100%;
}
use these css for child
.child {
background:blue;
height: 100%;
width: 50%;
position: absolute;
right: 0;
top: 0;
}
Just setting the height alone to 100% didn't work for me. I also changed the position to absolute for that div.
CSS
.topic-userinfo {
width: 20%;
height: 100%;
display: inline-block;
position: absolute;
float: left;
left: 0;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
JSFiddle
Some serious issues with this code, and most of the answers as well:
The <center> tag has been deprecated for a very, very long time. Use the CSS text-align property.
Using float: right / left and display: inline-block together doesn't make sense. The computed value of display will be block, regardless.
Using float and then position: absolute also makes no sense. The computed value of float will be none.
Using display: inline-block on elements that are clearly intended as block level elements.
Percentage width on a sidebar that contains elements with a fixed width. That won't scale down nicely.
Rogue inline styles.
Your CSS is muddled, because your markup is structured poorly. By balancing your markup and styles, you can achieve the intended look without so much hacking about on either side. Sometimes more is less.
Here's a simple example where the .topic-user-info will always match the height of the .topic-message and .topic-signature elements combined. No floats, only one position: absolute, and some nice, semantic markup.
DEMO
.topic {
width: 100%;
border: 1px solid #444;
}
.topic-header {
width: 100%;
height: 40px;
background-color: #CD422B;
}
.topic-content {
padding-left: 180px;
position: relative;
box-sizing: border-box;
width: 100%;
color: white;
}
.topic-user-info {
position: absolute;
width: 180px;
height: 100%;
left: 0;
background-color: #444;
text-align: center;
}
.topic-body {
width: 100%;
background-color: #323232;
}
.topic-message,
.topic-signature {
padding: 10px;
box-sizing: border-box;
}
.topic-message {
min-height: 180px;
}
.topic-signature {
min-height: 120px;
border-top: 1px dashed #444;
}
<div class="topic">
<header class="topic-header">Header</header>
<section class="topic-content">
<div class="topic-user-info">User Info</div>
<article class="topic-body">
<div class="topic-message">
<p>Message</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sed et deleniti rem, odio sit perspiciatis quasi dignissimos repellat inventore sequi cupiditate vel quam, asperiores nisi magni, quaerat at autem id dolorem! Dolor, nobis! Fuga nisi aut deserunt in delectus nam quidem ea asperiores, animi nihil. Delectus, ab nisi. Possimus, laborum quos impedit atque eius ex ab enim a amet omnis ullam totam facere sed necessitatibus aut nihil reprehenderit sequi optio doloremque rerum voluptatum ea adipisci minus, molestias modi. Numquam iste, ducimus consequatur deleniti dolores explicabo. Doloremque odio placeat deleniti ipsam consequatur beatae eius doloribus reiciendis ut sit unde distinctio modi voluptates expedita sint ad, earum asperiores aliquid est architecto autem in, quibusdam officiis! Distinctio, eos quaerat, id illum aliquam aut.</p>
</div>
<aside class="topic-signature">
<p>Signature</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti delectus laudantium minima magni temporibus distinctio, aut modi saepe deserunt praesentium eligendi qui quod, ratione omnis exercitationem officiis repellendus adipisci eum molestias vitae, sed. Atque dicta in veniam ducimus voluptatem quasi accusantium, temporibus esse, aliquid itaque explicabo omnis, delectus expedita rem.</p>
</aside>
</article>
</section>
</div>
Use height:100%
.topic-userinfo {
width: 20%;
min-height: 200px;
display: inline-block;
height:100%;
position: relative;
float: left;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
Marks Answer is almost perfect, except that it stretches a bit to far because of the header. If we offset for the header, it's perfect.
.topic-userinfo {
width: 20%;
height: calc(100% - 40px);
display: inline-block;
position: absolute;
float: left;
left: 0;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
https://jsfiddle.net/1pntme1x/1/
The main issue at hand is that you need the left-floated child .topic-user-info to take 100% height of the parent. But the parent's height is auto by default, meaning it will adjust its height to fit the children. And that is why simply putting height:100% on the floated left child won't work.
The solution is to absolutely position the left child, and float the thread content and signature to the right. If your markup is done properly, it becomes very easy to do. I personally think the HTML is pretty poor - non-semantic tags, use of deprecated tag <center>, plenty of inline styles. The best thing to do would actually be to rewrite them.
* {
box-sizing: border-box;
}
.topic {
width: 100%;
display: inline-block;
border: 1px solid #444;
margin-bottom: 20px;
position: relative;
}
.topic-header {
display: block;
width: 100%;
height: 40px;
background-color: #CD422B;
border-left: 1px solid #CD422B;
border-right: 1px solid #CD422B;
}
.topic-header h4 {
color: #fff;
font-family: 'Titillium Web', sans-serif;
font-size: 18px;
font-weight: 700;
padding-left: 10px;
line-height: 40px;
margin: 0;
}
.topic-user-info {
position: absolute;
padding: 0 10px;
height: calc(100% - 40px);
width: 20%;
min-width: 130px;
background-color: #555;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
text-align: center;
}
.topic-user-info > .public-profile {
position: relative;
margin: 10px auto;
background-color: #fff;
}
.topic-user-info > .public-profile > .screen-name {
color: red;
}
.topic-user-info > .public-profile > .rank {
color: #000;
}
.topic-user-info > .public-profile > .avatar {
width: 90px;
height: 90px;
border: 1px solid #333;
}
.topic-body {
float: right;
width: 80%;
min-height: 500px;
background-color: #323232;
color: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 15px;
font-weight: bold;
}
.topic-content {
padding: 20px;
min-height: 200px;
}
.topic-usersig {
padding: 20px;
height: 150px;
max-height: 300px;
background-color: #323232;
border-top: 1px dashed #444;
}
<article class="topic">
<header class="topic-header">
<h4>Test</h4>
<!-- maybe other things in header -->
</header>
<section class="topic-user-info">
<article class="public-profile">
<div class="screen-name">deaL</div>
<div class="rank">Administrator</div>
<img class="avatar" src="http://www.skruffysdeveloper.com/assets/img/user_img_default.png" alt="" />
</article>
<div class="user-real-name">Joel Evans</div>
</section>
<section class="topic-body">
<section class="topic-content">
<h3>Test2</h3>
</section>
<section class="topic-usersig">
Some signature here
</section>
</section>
</article>
height 100% some times doesn't seem to work as it should . We can use a small Js function to handle this.
We have added same class 'EqHeightDiv' to both the divs which we want to have same heights. then add following code in document ready js .
function equalHeight(group) {
var tallest = 0;
group.each(function() {
var thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
equalHeight($(".EqHeightDiv"));
the Function will return the height of tallest div from the two divs and append that height to the shorter div.