I seem to be constantly running into this problem, and I'm not sure where I'm making the mistake.
I have a main-body div that is holding a background-color that I want as the background of the page. Within the dive I've got a section class with the little sections that are going to be copied over and over again with just the content changed.
If you scroll to the bottom, you'll notice that the background of the main-body div isn't really 100% and leaves this white bar. How might I go about fixing this?
*
{
margin: 0;
padding: 0;
}
#header
{
height: 230px;
width: 100%;
background-color: #0099CC;
display: block;
}
#headerFixedWidth
{
width: 85%;
height: 230px;
//border: 1px solid #ccc;
margin: 0 auto;
}
#nav
{
//border: 1px solid #ccc;
height: 35px;
width: 700px;
margin: 0 auto;
margin-top: 40px;
}
#mainBody
{
background-color: #F1F4F9;
width: 100%;
//height: 100%;
margin-bottom: 30px;
}
.left-content
{
height: 550px;
width: 581px;
background-color: white;
margin-left: 20px;
}
.title
{
font-family: 'Lato', sans-serif;
color: #ccc;
font-size: 37px;
font-weight: bold;
color: #4E5E6A;
margin: 20px 30px;
text-shadow: rgba(78, 94, 106, .2) .1px .1px 2px -1px;
}
.author-subline
{
font-family: 'Lato', sans-serif;
font-size: 18px;
font-weight: bold;
color: #4E5E6A;
margin-top: 20px;
margin-bottom: 10px;
margin-left: 30px;
}
.article-text
{
font-family: 'Lato', sans-serif;
font-size: 17px;
color: #4E5E6A;
margin-top: 20px;
margin-bottom: 10px;
margin-left: 30px;
margin-right: 10px;
line-height: 1.56;
}
.readMore
{
font-family: 'Lato', sans-serif;
font-size: 13px;
color: #4E5E6A;
margin-top: 15px;
margin-bottom: 30px;
margin-left: 30px;
margin-right: 10px;
}
<div id="header">
<div id="headerFixedWidth"></div>
</div>
<div id="mainBody">
<section class="left-content">
<p class="title">Minim perferendis placeat</p>
<p class="author-subline">Minim perferendis placeat modi</p>
<p class="article-text">Minim perferendis placeat modi, vitae porttitor exercitation dolorum duis atque ridiculus luctus earum!.</p>
<p class="readMore">Read More</p>
</section>
<section class="left-content">
<p class="title">Minim perferendis placeat</p>
<p class="author-subline">Minim perferendis placeat modi</p>
<p class="article-text">Minim perferendis placeat modi, vitae porttitor exercitation dolorum duis atque ridiculus luctus earum!.</p>
<p class="readMore">Read More</p>
</section>
<section class="left-content">
<p class="title">Minim perferendis placeat</p>
<p class="author-subline">Minim perferendis placeat modi</p>
<p class="article-text">Minim perferendis placeat modi, vitae porttitor exercitation dolorum duis atque ridiculus luctus earum!.</p>
<p class="readMore">Read More</p>
</section>
<section class="left-content">
<p class="title">Minim perferendis placeat</p>
<p class="author-subline">Minim perferendis placeat modi</p>
<p class="article-text">Minim perferendis placeat modi, vitae porttitor exercitation dolorum duis atque ridiculus luctus earum!.</p>
<p class="readMore">Read More</p>
</section>
</div>
It is because of the #mainBody having a margin:
Just remove the margin-bottom and it will be alright.
#mainBody {
background-color: #F1F4F9;
width: 100%;
margin-bottom: 0; /* Do this... */
}
Yo do not need a margin at the body (I also don´t know why are you using this...):
#mainBody {
background-color: #F1F4F9;
width: 100%;
}
If you just change the #mainBody CSS property margin-bottom you should be fine!
#mainbody{
background-color: #F1F4F9;
width: 100%;
//height: 100%;
margin-bottom: 30px;
}
To this
#mainbody{
background-color: #F1F4F9;
width: 100%;
//height: 100%;
}
Related
Hi I'm new in web dev and i really want to know why in the next code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
border: 1px solid black;
}
html {
font-family: "Rubik", sans-serif;
color: #444;
}
.container {
margin: 0 auto;
width: 1200px;
background-color: #107b72;
}
header {
background-color: rgb(31, 210, 103);
/* height: 100vh; */
}
nav:first-child {
font-size: 20px;
font-weight: 700;
display: flex;
justify-content: space-between;
background-color: green;
}
h1 {
/* value of space scale */
font-size: 52px;
margin-bottom: 32px;
}
p {
font-size: 20px;
line-height: 1.5;
margin-bottom: 48px;
}
.btn:link,
.btn:visited {
font-size: 20px;
font-weight: 600;
background-color: #e67e22;
color: #fff;
text-decoration: none;
display: inline-block;
padding: 16px 32px;
border-radius: 9px;
}
h2 {
font-size: 44px;
margin-bottom: 48px;
}
section {
padding: 96px 0;
background-color: rgb(7, 183, 148);
}
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght#400;600;700&family=Rubik:wght#400;500;700&display=swap" rel="stylesheet" />
<header>
<nav class="container">
<div>LOGO</div>
<div>NAVIGATION</div>
</nav>
<div class="container">
<h1>A healthy meal delivered to your door, every single day</h1>
<p>
The smart 365-days-per-year food subscription that will make you eat healthy again. Tailored to your personal tastes and nutricional needs
</p>
Start eating well
</div>
</header>
<section>
<div class="container">
<h2>Some random heading</h2>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Vel quas officia illum laudantium, sit sint, assumenda magnam nisi vitae nihil impedit! Ad molestiae sapiente laboriosam corporis impedit. Velit aliquid natus a amet voluptates unde perferendis,
consequuntur deserunt maiores nihil ipsum.
</p>
</div>
</section>
codepen
https://codepen.io/kimo-007/pen/WNymqgr
my containers (.containers) are taking like only the width of the viewport, as we move to the right side we can see that the child elements (ones that i centered with margin: 0 auto;) are overflowing, this ones have a fixed width in order to center them. But i really don't understand why the containers stays like in that width, the one of the viewport, why not go all the way and occupy the same as the child elements width?, so this ones are block elements and in the dev tools marks also the complete body with this width, so i didn’t provided any fixed one for this element, so the block elements take 100% of the viewport width? so can you clarify me why this behavior, please!!!!
I really want to understand the behavior behind this html and css visualization on the viewport
You need to add another property max-width:100% in .container like below:
.container {
margin: 0 auto;
width: 1200px;
max-width:100%;
background-color: #107b72;
}
See the example below:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
border: 1px solid black;
}
html {
font-family: "Rubik", sans-serif;
color: #444;
}
.container {
margin: 0 auto;
width: 1200px;
max-width:100%;
background-color: #107b72;
}
header {
background-color: rgb(31, 210, 103);
/* height: 100vh; */
}
nav:first-child {
font-size: 20px;
font-weight: 700;
display: flex;
justify-content: space-between;
background-color: green;
}
h1 {
/* value of space scale */
font-size: 52px;
margin-bottom: 32px;
}
p {
font-size: 20px;
line-height: 1.5;
margin-bottom: 48px;
}
.btn:link,
.btn:visited {
font-size: 20px;
font-weight: 600;
background-color: #e67e22;
color: #fff;
text-decoration: none;
display: inline-block;
padding: 16px 32px;
border-radius: 9px;
}
h2 {
font-size: 44px;
margin-bottom: 48px;
}
section {
padding: 96px 0;
background-color: rgb(7, 183, 148);
}
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght#400;600;700&family=Rubik:wght#400;500;700&display=swap" rel="stylesheet" />
<header>
<nav class="container">
<div>LOGO</div>
<div>NAVIGATION</div>
</nav>
<div class="container">
<h1>A healthy meal delivered to your door, every single day</h1>
<p>
The smart 365-days-per-year food subscription that will make you eat healthy again. Tailored to your personal tastes and nutricional needs
</p>
Start eating well
</div>
</header>
<section>
<div class="container">
<h2>Some random heading</h2>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Vel quas officia illum laudantium, sit sint, assumenda magnam nisi vitae nihil impedit! Ad molestiae sapiente laboriosam corporis impedit. Velit aliquid natus a amet voluptates unde perferendis,
consequuntur deserunt maiores nihil ipsum.
</p>
</div>
</section>
i'm not sure to understand your question, but if you want a full width container why you write "width:1200px" to your container" ?
.container {
margin: 0 auto;
width: 1200px;
background-color: #107b72;
}
Remove the fixed width, and your div take all the size who need
You don't need to precise them
.container {
margin: 0 auto;
background-color: #107b72;
}
Hi,
Because you mentioned 1200px as a fixed width for containers;
use this
.container {
margin: 0 auto;
width: 100%;
background-color: #107b72;
}
so basically I'm creating a fake Italian restaurant site and the images in the img-container wont fit the box, leaving a line below the image. Also, the img-container overflows past the image which I don't want it to do. Any help appreciated.
Here is my code
#import url("https://fonts.googleapis.com/css2?family=Open+Sans:wght#400;600;700;800&display=swap");
#import url("https://fonts.googleapis.com/css2?family=Libre+Baskerville:wght#400;700&display=swap");
/* CSS RESET */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Body styling */
body {
background-color: #dee7e7;
font-family: "Open Sans", sans-serif;
}
/* Nav */
nav {
margin-top: -35px;
height: 70px;
background-color: #fff;
margin: 0px 0px 35px 0px;
height: 60px;
padding: 20px;
}
nav a {
text-decoration: none;
}
nav a:visited {
color: #000;
}
nav a:hover {
cursor: pointer;
}
.nav-links {
float: right;
margin-top: -25px;
margin-bottom: 20px;
font-family: "Libre Baskerville", serif;
}
.nav-links .current {
font-weight: 700;
text-decoration: underline;
}
.nav-links a {
padding-right: 10px;
font-size: 16px;
text-decoration: none;
color: #000;
font-weight: 400;
}
.nav-links a:hover {
text-decoration: underline;
}
.nav-links a:visited {
color: #000;
}
header nav h3 {
font-family: "Libre Baskerville", serif;
font-size: 26px;
}
/* Showcase 1 */
.showcase {
display: grid;
grid-template-columns: 2fr 3fr;
grid-column-gap: 1em;
text-align: left;
margin-bottom: 20px;
}
.text-container {
place-items: center;
margin: 20px 30px 20px 60px;
font-size: 18px;
}
.text-container h1 {
margin-bottom: 20px;
font-family: "Libre Baskerville", serif;
}
.text-container p {
font-size: 16px;
padding-right: 10px;
}
.btn-primary {
width: 150px;
height: 40px;
margin-top: 20px;
border: none;
border-radius: 5px;
background: #06a77d;
color: #fff;
font-family: "Open Sans", sans-serif;
font-weight: 600;
box-shadow: 1px 1px 2px 1px grey;
}
.btn-primary:hover {
color: lightgrey;
text-decoration: underline;
cursor: pointer;
}
.img-container {
background: #c9d7d7;
}
.img-container img {
margin-left: 80px;
overflow: auto;
height: 500px;
}
/* Showcase 2 */
.showcase-2 {
display: grid;
grid-template-columns: 2fr 3fr;
grid-column-gap: 1em;
text-align: left;
margin-bottom: 30px;
background: #192534;
color: #fff;
}
.text-container-2 {
place-items: center;
margin: 20px 30px 20px 60px;
font-size: 16px;
order: 1;
}
.text-container-2 h1 {
margin-bottom: 20px;
font-family: "Libre Baskerville", serif;
}
.text-container-2 p {
font-size: 16px;
padding-right: 10px;
}
.btn-secondary {
width: 150px;
height: 40px;
margin-top: 20px;
border: none;
border-radius: 5px;
background: #cc224e;
color: #fff;
font-family: "Open Sans", sans-serif;
font-weight: 600;
box-shadow: 1px 1px 2px 1px black;
}
.btn-primary:hover {
color: lightgrey;
text-decoration: underline;
cursor: pointer;
}
.img-container-2 {
background: #3d5777;
padding-right: -300px;
order: 2;
}
.img-container-2 img {
margin-left: 80px;
max-width: 100%;
height: 510px;
}
.img-good-food img {
float: right;
max-width: 100%;
height: 130px;
margin-right: 20px;
}
.page-title {
text-align: center;
margin-bottom: 30px;
font-family: "Libre Baskerville";
}
.about-container {
place-items: center;
margin: 10px 30px 20px 60px;
font-size: 18px;
}
.text-container h1 {
margin-bottom: 20px;
font-family: "Libre Baskerville", serif;
}
.about-container p {
font-size: 16px;
padding-right: 10px;
margin-left: 20px;
}
.about-container button {
margin-left: 20px;
}
.menu-text {
text-align: center;
margin-left: 70px;
margin-right: 70px;
margin-bottom: 20px;
}
.menu-container {
display: flex;
justify-content: center;
background: #3d5777;
margin-left: 200px;
margin-right: 200px;
margin-bottom: 20px;
}
.fa-chevron-left {
font-size: 30px;
float: left;
margin-right: 200px;
margin-top: 300px;
color: #fff;
}
.fa-chevron-right {
font-size: 30px;
float: left;
margin-left: 200px;
margin-top: 300px;
color: #fff;
}
.menu-container img {
max-width: 100%;
height: 650px;
margin: 10px;
}
iframe {
margin-top: 40px;
float: right;
margin-right: 100px;
width: 600px;
box-shadow: 1px 1px 1px 1px grey;
}
.contact {
background: #3d5777;
width: 400px;
height: 200px;
color: #fff;
margin-left: 120px;
margin-top: 160px;
place-items: center;
justify-content: center;
padding-top: 30px;
}
.contact p {
margin-bottom: 5px;
}
.fas {
margin-bottom: 5px;
font-size: 16px;
}
/* Footer */
footer {
width: 100%;
text-align: center;
background: #192534;
padding: 10px;
}
footer h2 {
color: #fff;
font-size: 14px;
}
footer a {
color: #8abeff;
}
<header>
<nav>
<a href="">
<h3 class="logo">Chef Italia</h1>
</a>
<div class="nav-links">
<a class="current" href="index.html">Home</a>
About Us
Menu
Contact
</div>
</nav>
</header>
<div class="showcase">
<div class="img-container">
<img src="img/home-showcase.jpg" alt="Photo of Italian cheese on wooden board">
</div>
<div class="text-container">
<h1>Welcome to Chef Italia</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis voluptas inventore quae. Dolores sapiente officiis, reprehenderit fugiat aliquam veritatis, distinctio doloremque minima facere maxime voluptatibus sunt suscipit animi error molestias
adipisci. Officia, quae adipisci quas quod incidunt, dolores vero ipsa pariatur, necessitatibus ullam ea aspernatur eveniet quisquam eaque molestiae.</p>
<button class="btn-primary">Find out more</button>
</div>
</div>
</div>
<div class="showcase-2">
<div class="img-container-2">
<img src="img/authenic-italian.png" alt="Photo of 2 pizzas on plates with glasses of water and cutlery on a table">
</div>
<div class="text-container-2">
<h1>Authentic Italian Food</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis voluptas inventore quae. Dolores sapiente officiis, reprehenderit fugiat aliquam veritatis, distinctio doloremque minima facere maxime voluptatibus sunt suscipit animi error molestias
adipisci. Officia, quae adipisci quas quod incidunt, dolores vero ipsa pariatur, necessitatibus ullam ea aspernatur eveniet quisquam eaque molestiae.</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Incidunt praesentium reiciendis accusamus reprehenderit saepe accusantium vero quas quam asperiores aliquam quia, laboriosam necessitatibus sequi autem aperiam maxime quidem temporibus adipisci
nemo minus doloremque possimus? Iste.</p>
<button class="btn-secondary">View Our Menu</button>
</div>
</div>
<div class="showcase">
<div class="img-container">
<img src="img/good-food-picture.jpeg" alt="Photo outside of resteraunt with green leaf tree covering one third of the yellow building">
</div>
<div class="text-container">
<h1>Good Food Awards Winner 2019</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis voluptas inventore quae. Dolores sapiente officiis, reprehenderit fugiat aliquam veritatis, distinctio doloremque minima facere maxime voluptatibus sunt suscipit animi error molestias
adipisci. Officia, quae adipisci quas quod incidunt, dolores vero ipsa pariatur, necessitatibus ullam ea aspernatur eveniet quisquam eaque molestiae.</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Incidunt praesentium reiciendis accusamus reprehenderit saepe accusantium vero quas quam asperiores aliquam quia, laboriosam necessitatibus sequi autem aperiam maxime quidem temporibus adipisci
nemo minus doloremque possimus? Iste.</p>
<button class="btn-primary">Find Out More</button>
<div class="img-good-food">
<img src="img/good-food.png" alt="Good Food Awards Logo">
</div>
</div>
</div>
<footer>
<h2>© Chef Italia 2021. Designed and developed with 💙 by Tyler Lechowski</h2>
</footer>
Did you try to just add:
.img-container {
position:relative
}
.img-container img {
height: 100%;
width: 100%;
}
To define image size you can add for example:
.img-container {
position:relative;
width: 200px;
height: 200px;
}
but be sure you add it to .img-container, not .img-container img. In .img-container you define size in pixels but in .img-container img you make it 100% for width and height to fill whole container
Try adding this:
.img-container {
position: relative;
overflow: hidden;
}
.img-container img {
height: 100%;
min-width: 100%;
object-fit: cover;
position: absolute;
}
Oveflow hidden to hide any part of the picture that comes outside the container. Object-fit cover to make it cover the container. If you want smaller picture just specify height and width on the container.
This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
Why does this CSS margin-top style not work?
(14 answers)
Closed 4 years ago.
why is there space at the top of my header and above my body?
body {
background-color: #efefef;
font-family: "verdana";
max-width: 1000px;
border: solid #ffffff 3px;
margin: auto;
}
#container {
background-color: #8a8a8a;
}
#header {
background-color: #8a8a8a;
}
h1 {
background-color: #F47D31;
color: #FFFFFF;
text-align: center;
font-family: "verdana";
text-transform: uppercase;
padding: 10px 0 10px 0;
}
h2 {
background-color: #F47D31;
color: #ffffff;
font-family: "verdana";
text-transform: uppercase;
text-align: center;
padding: 10px 0 10px 0;
}
h3 {
background-color: #F47D31;
color: #ffffff;
font-family: "verdana";
text-transform: uppercase;
text-align: center;
padding: 10px 0 10px 0;
}
p {
font-family: "verdana";
line-height: 1.5em;
color: #ffffff;
text-align: justify;
}
#nav {
display: block;
width: 25%;
float: left;
}
#nav ul {
list-style-type: none;
}
#nav a:link, #nav a:visited {
display: block;
border-bottom: 2px solid #fff;
padding: 10px;
text-decoration: none;
font-weight: bold;
margin: 5px;
}
#nav a:hover {
color: white;
background-color: #F47D31;
text-decoration: underline;
}
hr {
border: solid #efefef 1px;
}
table {
padding: 10px;
}
tr:nth-child(even) {
background-color: #E9EAE8;
color: #2a2a2a;
}
tr:nth-child(odd) {
background-color: #ffffff;
color: #2a2a2a;
}
tr:hover {
background-color: #F47D31;
}
#products_list {
list-style: none;
padding: 20px
}
figure {
display: block;
width: 202px;
height: 170px;
float: left;
margin: 10px;
background-color: #e7e3d8;
padding: 9px;
}
figure img {
width: 200px;
height: 150px;
border: 1px solid #d6d6d6;
}
figcaption {
text-align: center;
color: #F47D31;
}
fieldset {
background-color: #f1f1f1;
border: none;
border-radius: 2px;
margin-bottom: 0px;
overflow: hidden;
padding: 0 10px;
}
ul {
background-color: #fff;
border: 1px solid #eaeaea;
list-style: none;
margin: 12px;
padding: 12px;
}
li {
margin: 0.5em 0;
}
label {
display: inline-block;
padding: 3px 6px;
text-align: right;
width: 150px;
vertical-align: top;
}
.paragraph {
padding: 0 10px 0 10px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Innovative Multimedia Seminar 1</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>Hello World</h1>
<h2>Hello World 2</h2>
<h3>Innovative Multimedia Rocks!</h3>
</div>
<div id="container">
<div id="nav">
<!--Add Links Here -->
<ul>
<li> Home Page </li>
<li> Products Page </li>
<li> Register Page </li>
<li> SHU website homepage </li>
</ul>
</div>
<div>
<figure>
<img src="img/image1.jpg" alt="Horses in a field">
<figcaption>
A horse and two foals
</figcaption>
</figure>
<figure>
<img src="img/image2.jpg" alt="Flowers growing">
<figcaption>
Three Flowers Growing
</figcaption>
</figure>
<figure>
<img src="img/image3.jpg" alt="Butterfly on flower">
<figcaption>
Butterfly on flower
</figcaption>
</figure>
<div class="paragraph">
<p>
Lorem ipsum dolor sit amet, oporteat hendrerit id pro. His munere virtute facilis ex. Detracto concludaturque vel ea, quo id iusto deseruisse accommodare. Ea sit habeo audiam concludaturque, an usu vero numquam eruditi. Ex scripta neglegentur pri, timeam
omittam theophrastus ne mel, mea simul perpetua no.
</p>
<hr>
<p>
Vel aliquid fierent te, per quas elaboraret in. Eu mei omittam prodesset, vel liber complectitur concludaturque an. Nihil choro at qui, rebum legendos mei ex, vis ex choro quaeque reprimique. No pri bonorum expetenda liberavisse, sed ut erat senserit.
</p>
<hr>
<p>
No duo habemus vivendum euripidis. Et mutat populo constituto per, veniam populo honestatis sit ex. Propriae lucilius at ius, qui tale invidunt te. In vitae probatus explicari nec, ex prima delenit moderatius sit, putent mentitum gloriatur pro in. Justo
volumus eum an.
</p>
</div>
</div>
</div>
</body>
</html>
Just remove the margin from the h1 by putting margin-top: 0;
h1 {
background-color: #F47D31;
color: #FFFFFF;
text-align: center;
font-family: "verdana";
text-transform: uppercase;
padding: 10px 0 10px 0;
margin-top: 0;
}
Code Pen Example
and I'm not sure what you mean by the body having padding.
As you can see in the h1 breakdown picture, the h1 tag gets its styling from styles.css, and there is padding set to 10 pixels above and under the h1 tag.
So you could try to remove the padding-style from styles.css and see if it removes the space. Or yet easier, just uncheck the checkbox for the padding style in the DevTools shown in the picture.
I have taken two divs say "Panel1" and "Panel2" where Panel1 is having property affix (hard-coded in HTML so have to forcefully apply position:relative on other screen sizes) attached to it in HTML with col-md-3 and Panel2 is col-md-8.
Now the problem is I have to apply left value of around 25% for my Panel2 to align as per Panel1 otherwise it goes beneath it but doing this has broken responsiveness. The design breaks on all other screen sizes and just violates the purpose of using bootstrap for responsive design. (I have to use header and footer from original design and creating a dashboard based on that).
What would be the approach to design without writing and managing screen sizes again manually so that, all I use is bootstrap and design should work on low rez screens.
HTML:
<!-- DASHBOARD SECTION STARTS (Bootstrap Components) -->
<div class="container-fuild dash-panel">
<div class="row">
<div class="col-md-3 left-panel" data-spy="affix">
<ul class="dash-items">
<li class="dash-li"><a class="list-links" href="index.html"><!-- <img class="profile-image" src="../images/ad.jpg" alt=""> -->Profile</a></li>
<li class="dash-li"><a class="list-links" href="my-ads.html">My Advertisements</a></li>
<li class="dash-li"><a class="list-links" href="fav-ads.html">My Favouraite Advertisments</a></li>
<li class="dash-li"><a class="list-links" href="reported-ads.html">Reported Advertisments</a></li>
</ul>
</div>
<div class="col-md-8 right-panel">
<img class="profile-image" src="../images/ad.jpg" alt="">
<div class="profile-info">
<p class="profile-detail-para"><label>Name: </label>John Doe</p>
<p class="profile-detail-para"><label>Email: </label>doejohn#xyz.com</p>
<p class="profile-detail-para"><label>Summary: </label><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nesciunt natus dicta assumenda, velit quae officia accusantium explicabo similique possimus veniam illo, dolor delectus saepe quis in eveniet voluptatem adipisci, repudiandae.</span><span>Veritatis at saepe labore explicabo, voluptas asperiores unde accusantium tempore harum, numquam porro doloremque aliquid assumenda. Maiores voluptates aliquid dicta autem commodi eveniet voluptas exercitationem ut, hic laborum laudantium veritatis.</span></p>
<p class="profile-detail-para">
<a class="profile-edit" href="edit-info.html">Edit info <i class="fa fa-edit"></i></a>
</p>
</div>
</div>
</div>
</div>
<!-- DASHBOARD SECTION ENDS -->
Overridden CSS
/* Contains custom css for dashboard */
#import url(https://fonts.googleapis.com/css?family=Montserrat|Dosis);
#import url(https://fonts.googleapis.com/css?family=Open+Sans);
body{
background: #1D1D1D none repeat scroll 0px 0px;
}
.dash-panel{
padding-top: 1%;
padding-bottom: 1%;
height: 480px;
}
.left-panel{
background: #000;
margin-right: 4%;
height: 100%;
left: 5%;
}
.dash-items{
list-style: none;
margin-left: -10%;
}
.dash-li{
margin-top: 2px;
padding: 3%;
}
.dash-li:hover{
background: #3F3030;
}
.list-links{
text-decoration: none !important;
color: #F0B101;
font-family: 'Montserrat', sans-serif;
}
.list-links-profile{
text-decoration: none !important;
color: #F0B101;
font-family: 'Montserrat', sans-serif;
margin-left: -20%;
}
.right-panel{
background: #000;
padding: 2%;
margin-left: 32.4%;
}
.right-panel-2{
background: #000;
padding: 2%;
left: 24%;
}
.profile-image{
max-width: 100%;
width: 100px;
height: 100px;
border-radius: 100%;
float: left;
}
.profile-info{
float: left;
margin-left: 2%;
font-family: 'Dosis', sans-serif;
background: #1D1D1D;
width: 80%;
padding: 2%;
}
.profile-detail-para{
margin-bottom: 2%;
}
.set-BG{
background: #1D1D1D;
}
.listing-image{
width: 180px;
}
.profile-edit{
background: #D7DFE6;
padding: 1%;
color: #000;
}
/* Status */
.pub{
color: #369536;
}
.pen{
color: #D13D3D;
}
/* Status Ends */
.edit-profile{
font-family: 'Open Sans', sans-serif;
padding: 2%;
}
.text-area{
background-color: transparent;
border: 1px solid #464646;
border-radius: none !important;
color: #B8B8B8;
height: 40px;
padding: 5px 10px;
width: 100%;
box-shadow: none;
}
input[type=file]{
background: #000;
}
.submit-btn{
width: 15%;
background: #000;
border: 1px solid #E1B101;
}
#media (max-width: 768px) {
.left-panel {
position: relative;
left: 1.5%;
width: 34%;
float: left;
}
.right-panel{
left: 0%;
float: right;
}
.right-panel-2{
left: 0%;
}
.profile-info{
left: 0%;
}
}
#media (max-width: 480px) {
.left-panel {
position: relative;
left: 1.5%;
float: none;
}
.right-panel{
left: 0%;
float: none;
}
.right-panel-2{
left: 0%;
}
.profile-info{
left: 0%;
}
}
/* #media (max-width: 900px) {
.left-panel {
position: relative;
left: 1.5%;
}
.right-panel{
left: 0%;
}
.right-panel-2{
left: 0%;
}
.profile-info{
left: 0%;
}
} */
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.