My divs are overlapping, i'm lost - html

Hey I can't figure out why my divs are overlapping and what i should do...
You can watch the site here: http://hersing.dk/job/
I would like for the div carrying the hr to appear underneed the header-info div
Heres is the code from the site:
#font-face {
font-family: hersing;
src: url(lmroman10-regular.otf);
}
html,
body {
font-family: hersing;
height: 100%;
margin: 0px;
}
.container {
width: 90%;
height: 90%;
left: 5%;
top: 5%;
background: green;
position: absolute;
display: block;
clear: both;
}
.info-name {
left: 5%;
top: 10%;
position: absolute;
display: block;
}
.info-picture {
min-width: 250px;
min-height: 250px;
padding: 4px;
position: absolute;
top: 10%;
right: 5%;
background: black;
display: block;
}
.info-picture img {
height: 100%;
width: 100%;
}
#info-header {
font-size: 400%;
}
#info-title {
font-size: 150%;
font-weight: bold;
}
.header-info {
display: block;
padding: 20px;
position: relative;
width: 100%;
}
.stang-1 {
display: block;
width: 100%;
color: blue;
position: relative;
}
#hr-1 {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
background-color: #f1a857;
}
<div class="container">
<div class="header-info">
<div class="info-name" id="info-name">
...
</div>
<div class="info-picture" id="info-picture">
<img src="images/picture.png" />
</div>
</div>
<div class="stang-1" id="stang-1">
<hr id="hr-1">
</div>
</div>
I hope someome can figure this out, cause i'm pretty lost

Both .info-name and .info-picture are absolute positioned and .header-info has no height defined.
You'd rather use relative positioning + float + clear and/or display: inline-block for both .info-* rules and everything will be fine.

<div class="container">
<div class="header-info">
<div class="info-name" id="info-name">
.....
</div>
<div class="info-picture" id="info-picture">
<img src="images/picture.png" />
</div>
</div>
<div class="stang-1" id="stang-1">
<hr id="hr-1">
</div>
</div>
<style>
#font-face {
font-family: hersing;
src: url(lmroman10-regular.otf);
}
html,
body {
font-family: hersing;
height: 100%;
margin: 0px;
}
.container {
width: 90%;
height: 90%;
left: 5%;
top: 5%;
background: green;
position: absolute;
display: block;
clear: both;
}
.info-name {
left: 5%;
top: 10%;
position: absolute;
display: block;
}
.info-picture {
width: 250px;
height: 250px;
padding: 4px;
position: relative;
top: 10%;
left:70%;
background: black;
display: block;
}
.info-picture img {
height: 100%;
width: 100%;
}
#info-header {
font-size: 400%;
}
#info-title {
font-size: 150%;
font-weight: bold;
}
.header-info {
display: block;
padding: 20px;
position: relative;
width: 100%;
}
.stang-1 {
display: block;
width: 100%;
color: blue;
position: absolute;
}
#hr-1 {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
background-color: #f1a857;
}
</style>
I think this will solve your problem...

In this case, although very impractical, the solution would be to add a line break <br> after the .header-info div.
I repeat, this solution is not the best one by far, and you should, as pointed out in the comments by Paulie_D, change your positioning layout method.

Everything inside the absolutely positioned .container would be better positioned relative. Use css float:left; or float:right; to position elements and clear:both; when you want the next element to start below all floated elements. Use padding on the container and margins on the floated elements for positioning.
Also give .container css class of overflow:auto; to wrap around all elements inside without having to set the height every time.

Related

Why div containing img does not stretch his parent's div height

I wonder why mainCountainerHeadLogo does not stretch parent div mainCountainerHead height?
If I scale the page, both mainCountainerHeadTitle and mainCountainerHeadMenu stretch mainCountainerHead just fine.
Sorry for my english and thanks in advance!
http://jsfiddle.net/gvcs0r6b/
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
.mainCountainer {
min-height: 100%;
width: 70%;
margin: 0 auto;
}
.mainCountainerHead {
background-color: aqua;
height: auto;
}
.mainCountainerHeadLogo {
height: 100px;
width: 20%;
background-color: blue;
float: left;
position: relative;
overflow: hidden;
}
.mainCountainerHeadLogo img {
position: absolute;
width: 100%;
height: auto;
top: -50%;
right: -50%;
bottom: -50%;
left: -50%;
margin: auto
}
.mainCountainerHeadTitle{
margin-left: 20%;
width: 80%;
height: auto;
text-align: center;
padding-top: 3%;
}
.mainCountainerHeadMenu{
margin-left: 20%;
text-align: center;
background-color: orange;
width: 80%;
height: auto;
padding-top: 2%;
text-align: center;
}
.mainLink {
display: inline-block;
padding: 5px;
}
.mainLinkButton {
width: 90px;
height: 30px;
background-color: green;
font-size: 16px;
border: none;
color: white;
padding: 5px;
}
.mainLinkButton:hover {
background-color: darkgreen;
}
.mainLinkDropdown {
position: relative;
display: inline-block;
padding: 5px;
}
.dropdownContent {
display: none;
position: absolute;
min-height: 30px;
min-width: 130px;
text-align: left;
background-color: #f1f1f1;
z-index: 10;
}
.dropdownContent a {
display: block;
color: black;
padding: 12px 16px;
text-decoration: none;
}
.mainLinkDropdown:hover .dropdownContent{
display: block;
}
.dropdownContent a:hover{
background-color: #ddd;
}
<div class="mainCountainer">
<div class="mainCountainerHead">
<div class="mainCountainerHeadLogo">
<img src="https://i.ibb.co/cYzWJFM/logo-Copy.jpg" title="logo" />
</div>
<div class="mainCountainerHeadTitle">
<h4>Welcome aboard!</h4>
</div>
<div class="mainCountainerHeadMenu">
<div class="mainLink">
<button class="mainLinkButton">Main</button>
</div>
<div class="mainLinkDropdown">
<button class="mainLinkButton">Dropdown</button>
<div class="dropdownContent">
Link 1
Link 2
Link 3
</div>
</div>
<div class="mainLink">
<button class="mainLinkButton">Contacts</button>
</div>
</div>
</div>
</div>
In answer to your question:
That's because the float property puts the HTML elements out of the normal page flow, and this causes what you're experiencing. Its effect is similar to position: absolute which is to move the element to "a different layer".
How to solve it?
Well... there are a lot of ways to achieve what you want, and almost all of them requires to refactorize your code. Actually, you have a lot of code that makes it difficult to achieve your goal. You should get rid of float and start using other technics like Flexbox.
I could show you a solution if you provide a sketch of the layout you want.
change the CSS for img to this
.mainCountainerHeadLogo img {
width: 100%;
height: 100%;
margin: auto
}

With CSS, Position a div (B) below (vertically, not z-index) another div (A) based on div A's height and position

Consider the following jsfiddle:
https://jsfiddle.net/0fwhmhLe/
html markup:
<div class="city-losangeles-bg">
<div class="user-container user-container-losangeles">
<div class="user-pic user-pic-losangeles"></div>
<div class="user-name-container">
<p class="user-name">User Name</p>
<div class="user-name-mask"></div>
</div>
<hr class="underline">
<div class="ellipse-container">
<div class="ellipse ellipse-losangeles-1"></div>
<div class="ellipse ellipse-losangeles-2 ellipse-with-left-margin"></div>
<div class="ellipse ellipse-losangeles-3 ellipse-with-left-margin"></div>
</div>
</div>
<p class="user-text user-text-losangeles">Some text that needs to be below the user-container div, based on the position and height of user-container</p>
</div>
css:
.city-losangeles-bg
{
width: 100%;
height: 1230px;
top: 0px;
background-color: orange;
position: relative;
}
.user-container
{
position: relative;
width: 206px;
height: 192px;
background-color: green;
}
.user-container-losangeles
{
left: 41%;
top: 25px;
}
.user-pic
{
position: relative;
width: 73px;
height: 73px;
left: -36.5px;
margin-left: 50%;
border-radius: 50%;
border: none;
}
.user-pic-losangeles
{
background-color: red;
}
.user-name-mask
{
position: relative;
width: inherit;
height: inherit;
top: 0;
}
.user-name
{
position: relative;
font-family: Ariel;
font-size: 28px;
text-align: center;
width: 100%;
/*top: -6px;*/ /*so text hides properly under color bar reveal animation */
}
.underline
{
position: absolute;
width: 178px;
top: 138px;
left: 14px;
margin-top: 0;
margin-bottom: 0;
}
.ellipse-container
{
position: absolute;
width: 126px;
height: 30px;
top: 162px;
left: 40px;
}
.ellipse
{
position: relative;
width: 30px;
height: 30px;
float: left;
border-radius: 50%;
border: none;
}
.ellipse-with-left-margin
{
margin-left: 18px;
}
.ellipse-losangeles-1
{
background-color: #4574b4;
}
.ellipse-losangeles-2
{
background-color: #71c8ca;
}
.ellipse-losangeles-3
{
background-color: #e6dddd;
}
.user-text
{
position: relative;
margin-top: 0; /* 100 */
font-family: Ariel;
font-size: 26px;
text-align: center;
line-height: 50px;
color: #848484;
}
.user-text-losangeles
{
margin-left: 29%;
width: 50%;
}
I can't figure out how to make the paragraph tag user-text user-text-losangeles always be below the div user-container user-container-losangeles. I thought they should automatically stack and if I changed user-container-losangeles's top property that user-text-losangeles would get bumped down as well.
Someone tell me what obvious mistake I am making please!!
You can use padding-top: 25px; on the container (.city-losangeles-bg) instead of the top:25px; of .user-container-losangeles
https://jsfiddle.net/y8pocwsn/1/
The reason: With position:relative and a topsetting an element is simply moved down from its original position, but the subsequent elements are NOT moved. The space reserved for the element is still the space it would occupy with top: 0 , which is the same as if that element would have position: static

Firefox and IE border-box not working properly?

So I have been trying to figure this out for a day or so without any luck, and figured I would turn to the CSS masters of the universe here.
Anyway, in Chrome my page looks fine (like always), but Firefox and IE both seem to have issues w/resizing images. I basically have 2 parts, a 'left div' and a 'right div', and the on the left just has right-padding to make it be the entire width, minus the width of the 'right div'.
Inside 'left div', there is an image who's size is set to be 100% of the width and height of the containing element, which in Chrome, works out wonderfully, and leaves the image in the center and looking good. FF and IE don't resize it at all, and worse, they don't respect the padding set on 'left div' so it looks even more weird.
The simplified HTML:
<div>
<div class="dialog-bg"></div>
<div id="view-larger-dialog" class="mc_report_dialog dialog-container">
<div class="details-container staticimage">
<span id="openPostModal">
<span class="modal-body cardDetails">
<div class="closeOpenModal">×</div>
<div class="cardContent">
<div class="cardBody">
<div id="card-content" class="card-content-staticimage">
<span class="image">
<img class="annotatable" src="https://s-media-cache-ak0.pinimg.com/originals/5a/28/22/5a282241e64e41d605384bb261ea581f.jpg">
</span>
</div>
</div>
</div>
</span>
</span>
<span class="detailBox">
<div class="cardContent cardDetails">
<div class="content">
<p>
blank white space
</p>
</div>
</div>
</span>
</div>
</div>
</div>
The CSS:
.dialog-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: black;
opacity: 0.6;
z-index: 1001;
}
.mc_report_dialog .details-container {
padding: 0px;
}
span#openPostModal {
position: fixed;
top: 0;
left: 0;
height: 800px;
margin-top: 0px;
margin-left: 0px;
display: table;
z-index: 5000;
height: 100%;
background: none;
width: 100%;
box-sizing: border-box;
padding-right: 24rem;
border: none;
}
span.detailBox, span.shareNewBox {
width: 24rem;
height: 100%;
padding: 0;
position: fixed;
top: 0px;
right: 0px;
background-color: white;
z-index: 5005;
}
span#openPostModal .modal-body {
border: 0px solid #ffffff;
padding: .6rem 1rem;
display: table-cell;
vertical-align: middle;
width: 100%;
max-height: 50%;
background: none;
overflow-y: visible;
}
.closeOpenModal {
font-size: 2rem;
color: #fff;
float: right;
position: absolute;
right: 1rem;
top: 1rem;
font-weight: 700;
cursor: pointer;
padding-right: 24rem;
opacity: 0.8;
}
span#openPostModal .cardContent {
background: none;
border: none;
position: relative;
width: 90%;
margin: auto;
}
span#openPostModal .cardContent .cardBody {
padding: 0;
}
span#openPostModal .cardContent .cardBody #card-content {
height: 100%;
padding: 0;
}
#card-content.card-content-staticimage .image {
position: relative;
display: inline-block;
width: 100%;
height: 100%;
}
#card-content.card-content-staticimage .image img {
max-height: 100%;
max-width: 100%;
}
You can see the result of that here on my jsFiddle
Any help would be greatly appeciated.
Apparently the whole display: table; and display: table-cell were messing it up. Just changing those to display as block worked. Sorry for the question.
Your problem isn't box-sizing:border-box, it's display:table.
Just add table-layout:fixed; right after the display:table declaration and you should be ok.

HTML CSS strange gaps between divs

Please see the below code and screenshot. Can anyone please explain why there are white gaps between the divs and how to remove them? I would like the divs sit next to one another without any margin between them
![
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #b3b3b3;
font-family: arial;
font-size: 14pt;
}
#containerdiv {
width: 1184px;
height: 626px;
position: absolute;
margin-top: -338px;
margin-left: -552px;
top: 50%;
left: 50%;
}
#centerdiv {
display: inline-block;
width: 1024px;
height: 576px;
background-color: #fff;
}
#lowercenterdiv {
background-color: #ff00ff;
width: 1024px;
height: 50px;
text-align: center;
line-height: 50px;
display: inline-block;
}
#lowerleftdiv {
background-color: #00ff00;
width: 80px;
height: 50px;
line-height: 50px;
position: absolute;
}
#leftdiv {
position: absolute;
background-color: #ff000f;
width: 80px;
height: 576px;
display: inline-block;
line-height: 576px;
}
#rightdiv {
position: absolute;
background-color: #000fff;
width: 80px;
height: 576px;
display: inline-block;
line-height: 576px;
text-align: right;
}
#lowerrightdiv {
position: absolute;
background-color: #fff000;
width: 80px;
height: 50px;
text-align: right;
display: inline-block;
line-height: 50px;
}
.arrowimg img {
vertical-align: middle;
}
</style>
</head>
<body>
<div id="containerdiv">
<div id="leftdiv"><img class="arrowimg" src="leftarrow.png"></div>
<div id="centerdiv">
</div>
<div id="rightdiv"><img class="arrowimg" src="rightarrow.png"></div>
<div id="lowerleftdiv">?</div>
<div id="lowercenterdiv">?</div>
<div id="lowerrightdiv">?</div>
</div>
</body>
</html>
You could try to remove all your position: absolutes, as they make things complicated. What you want is: three boxes next to each other, then three boxes next to each other below it. If you float them to the left, you solve this problem. I have amended your CSS, just copy and paste and you can see the gaps disappear because floating elements don't care about whitespaces. There are other difficulties involved with floating, but it does solve your problem.
I have also removed everything I didn't need to get my point across.
#containerdiv {
width: 1184px;
height: 626px;
position: absolute;
margin-top:-338px;
margin-left:-552px;
top:50%;
left:50%;
}
// I added this to float all the divs inside your container to float
#containerdiv div {
float: left;
}
#centerdiv {
// I removed position: absolute from every box, as well as line-heights, align and display
width: 1024px;
height: 576px;
background-color: #fff;
}
#lowercenterdiv {
background-color: #ff00ff;
width: 1024px;
height: 50px;
text-align:center;
}
#lowerleftdiv {
background-color: #00ff00;
width: 80px;
height: 50px;
}
#leftdiv {
background-color: #ff000f;
width: 80px;
height: 576px;
}
#rightdiv {
background-color: #000fff;
width: 80px;
height: 576px;
}
#lowerrightdiv {
background-color: #fff000;
width: 80px;
height: 50px;
}
Add this to your css:
* {
margin: 0;
padding: 0;
}
This is a weird thing in how html is interpreted. The whitespace between the divs is rendered as a space. There are many ways to solve this, and none of them are very pretty.
One way is like this:
<div id="leftdiv">
<img class="arrowimg" src="leftarrow.png">
</div>
<div id="centerdiv">
</div>
<div id="rightdiv">
<img class="arrowimg" src="rightarrow.png">
</div>
<div id="lowerleftdiv">
?
</div>
<div id="lowercenterdiv">
?
</div>
<div id="lowerrightdiv">
?
</div>
Hope its fix
{
margin: 0;
padding: 0;
border-sizing: border-box;
}

creating a product score value

im new to css and html i wanna cr8 a product box value like this
http://i.imgur.com/kMogtMz.png
I tried with these but didn't get any result.
I want .fill class to be dynamically modifiable.
Anyone can help me ?
.box {
width: 250px;
height: 30px;
background: grey;
color: white
}
.box .fill {
float: left;
width: 78%;
background: orange;
height: 100%;
}
.box .empty {
position: absolute;
white-space: nowrap;
right: 10px
}
.box .fill-badge {
position: absolute;
padding-left: 10px;
line-height: 30px
}
.box .empty-badge {
padding-right: 10px;
line-height: 30px;
}
<div class="box">
<div class="fill"><div class="fill-badge">Radeon 7870</div></div>
<div class="empty"><div class="empty-badge">125.6 GB/S</div></div>
</div>
You just need to look at your absolute and relative positioning. Make sure that all elements that are absolutely positioned are inside an element with relative defined as a position. So in this case you just need to add position: relative; to the .box.
.box {
width: 250px;
height: 30px;
background: grey;
color: white;
position: relative;
}
.box .fill {
float: left;
background: orange;
height: 100%;
}
.box .empty {
float: right;
white-space: nowrap;
right: 10px
}
.box .fill-badge {
position: absolute;
left: 0;
padding-left: 10px;
line-height: 30px
}
.box .empty-badge {
position: absolute;
right: 0;
padding-right: 10px;
line-height: 30px;
}
<div class="box">
<div class="fill" style="width:60%;">
<div class="fill-badge">Radeon 7870</div>
</div>
<div class="empty">
<div class="empty-badge">125.6 GB/S</div>
</div>
</div>
Edited to show inline style.
You must set the .box position to relative. http://jsfiddle.net/Lzmop76a/
.box {
width: 250px;
height: 30px;
background: grey;
color: white
position: relative;
}
I would do it using a background color and a background image for the same element like:
.box {
width: 240px;
padding: 0 5px;
height: 30px;
line-height: 30px;
background: #fa0 url(http://placehold.it/250x300/aaa) 200px 0 no-repeat;
color: white;
}
.box span{
float:right;
}
<div class="box">
Radeon 7870 <span>125.6 GB/S</span>
</div>