left indent in children div - html

how do I remove the indent in 1 px left of the blue div? I tried to reset border, no effect
body
{margin: 0; padding: 0; width: 100%; height: 100%; background: #222222;}
.container
{background: red; width: 1600px; height: 100px; margin: 0 auto;}
.header
{background: blue; width: 100%; height: 64px; box-sizing: border-box;}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<div class="container">
<div class="header"></div>
</div>
</body>
</html>

Judging your example, there seems to be some margin on the body element. You can remove it like this:
.container {
background: red;
width: 1600px;
height: 100px;
margin: 0 auto;
}
.header {
background: blue;
width: 100%;
height: 64px;
box-sizing: border-box;
}
body {
margin: 0;
}
<div class="container">
<div class="header"></div>
</div>

Related

Adding Footer at the end of Div having Position: Absolute

I have a webpage with following structure:
div: (app)
div: (navbar)
div: (wrapper) {position: relative}
div: (intro)
div: (content) {position: absolute}
div: (footer)
where div-content is dynamic that means it should extend if the data inside this div extends from its minimum height.
I am trying to add the footer at the end of the content but since content has absolute position, footer is being placed at the end of Intro.
I am beginner at front-end designing so pardon me if I am missing something basic. Please refer me some reading articles as well related to concepts about positioning divs.
This is my code:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.App {
text-align: center;
}
.navbar {
height: 60px;
background-color: #333;
}
.wrapper {;
position: relative;
border: 4px solid yellow;
}
.intro {
height: 450px;
background-color: blue;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
margin: 0 auto;
padding-top: 70px;
/* align-items: center;
justify-content: center;
display: flex;*/
}
.content {
position: absolute;
top: 250px;
width: 94%;
right: 3%;
left: 3%;
background-color: white;
border-radius: 6px;
box-shadow: 0 2px 15px 0 rgba(61,61,61,.15);
max-width: 960px;
margin: auto;
min-height: 800px;
background-color: gray;
}
.footer {
bottom: 0;
width: 100%;
height: 2.5rem; /* Footer height */
background-color: red;
}
</style>
</head>
<body>
<div class="app">
<div class="navbar">Navbar</div>
<div class="wrapper">
<div class="intro">Intro</div>
<div class="content">Content</div>
</div>
<div class="footer">Footer</div>
</div>
</body>
</html>
NOTE: .content is overlapped with .intro intentionally. and that is why i am using position absolute for .content
Remove position: absolute; from .content. This will fix the overlapping with the footer. The width will need to be adjusted accordingly (make width: 100%).
Updated: .contentto span width
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.App {
text-align: center;
}
.navbar {
height: 60px;
background-color: #333;
}
.wrapper {;
border: 4px solid yellow;
}
.intro {
height: 450px;
background-color: blue;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
margin: 0 auto;
padding-top: 70px;
}
.content {
margin: -250px auto auto;
width: 94%;
background-color: white;
border-radius: 6px;
box-shadow: 0 2px 15px 0 rgba(61,61,61,.15);
max-width: 906px;
min-height: 800px;
background-color: gray;
}
.footer {
width: 100%;
height: 2.5rem; /* Footer height */
background-color: red;
}
</style>
</head>
<body>
<div class="app">
<div class="navbar">Navbar</div>
<div class="wrapper">
<div class="intro">Intro</div>
<div class="content">Content</div>
</div>
<div class="footer">Footer</div>
</div>
</body>
</html>
delete your content min-height. is that what you need?

Can't scroll when child height: 100% and overflow:hidden

I'm trying to create a responsive web page. I have a header div that's 60px, and a landing div right below it that I want to take up the rest of the screen (height 100%). However, it overflows. I can't use overflow:hidden because when I zoom in, I can't scroll down anymore.
**************CSS***************
#home{
margin: 0;
height: 100%;
min-height: 100%;
width: 100%;
}
.header {
width: 100%;
height: 60px;
background-color: none;
}
.landing{
margin: 0 auto;
height: auto;
min-height: 100%;
width: 100%;
background-color: yellow;
}
*************HTML*************
<div id="home">
<div class="header"></div>
<div class="landing"></div>
</div>
How do I fix this so that my landing page doesn't overflow?
Use calc:
.landing {
min-height: calc(100%-60px;);
[...etc...]
}
html,
body {
height: 100%;
margin: 0;
}
#home {
margin: 0;
height: 100%;
height: 100%;
min-width: 100%;
}
.header {
width: 100%;
height: 60px;
background-color: blue;
}
.landing {
margin: 0 auto;
height: auto;
min-height: calc(100% - 60px);
min-width: 100%;
background-color: yellow;
}
<div id="home">
<div class="header"></div>
<div class="landing"></div>
</div>
here is a full working example for a page with a 60px tall header, with the rest of the page being filled by a div. It uses flexbox (display: flex), I changed a few things from an answer here. You may have a to change a few things (classes, ids, etc.) to get it to work for you but this should work:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
html,body {
height: 100%;
margin: 0
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.box .row {
border: 1px dotted grey;
}
.box .row.header {
flex: 0 1 60px;
}
.box .row.content {
flex: 1 1 auto;
background-color: yellow;
}
</style>
</head>
<body>
<div class="box">
<div class="row header">
<p><b>header (60 px tall)</b>
</div>
<div class="row content">
<p>
<b>content</b>
(fills remaining space)
</p>
</div>
</div>
</body>
</html>

Vertical scrollbar appears for unknown reason

What causes vertical scrollbar to appear here? http://codepen.io/anon/pen/QGByOQ?editors=1100
As I suggest, .container is 100% height of body, body inherits html, html is 100% of the viewport, hence every .chart should fit perfectly as it's height is half of the .container's. Nevertheless a y-scrollbar appears. What's the behavior behind this?
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div class="container">
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
</div>
</body>
</html>
css:
.container {
width: 100%;
height: 100%;
border: 5px dashed black;
box-sizing: border-box;
font-size: 0;
overflow: auto;
}
html, body {
height: 100%;
}
body {
margin: 0;
}
.chart1 {
display: inline-block;
width: 50%;
height: 50%;
border: 1px solid red;
box-sizing: border-box;
}
This is due to the red border of the container. Use CSS calc() function, like:
.chart1 {
height: calc(100% - 1px); /* 1px for the extra border */
}
Have a look at the snippet below:
.container {
width: 100%;
height: 100%;
border: 5px dashed black;
box-sizing: border-box;
font-size: 0;
overflow: auto;
}
html, body {
height: 100%;
}
body {
margin: 0;
}
.chart1 {
display: inline-block;
width: 50%;
height: calc(50% - 1px);
border: 1px solid red;
box-sizing: border-box;
}
<div class="container">
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
<div class="chart1"></div>
</div>
Hope this helps!

How to position element as fixed in relatively positioned container?

I want to make .side-menu element's position fixed, but I have no success with the code below. .side-menu element moves with .child-container content.
Why it doesn't work and how to make it work? :)
HTML:
<div class="pageWrapper">
<div class="container">
<div class="side-menu">
Menu content
</div>
<div class="child-container">
Large Content
</div>
</div>
</div>
CSS:
body, html {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.pageWrapper {
overflow-x: hidden;
min-width: 1200px;
height: 100%;
}
.container {
position: relative;
width: 1170px;
margin: 0 auto;
height: 100%;
}
.side-menu {
position: fixed;
width: 80px;
height: 300px;
}
.child-container {
position: relative;
margin: 40px auto 0 auto;
width: 900px;
}
I have updated the code with the html of the question:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style type="text/css">
*
{
margin: 0;
}
.container
{
position: static;
padding: 0px;
width: 1200px;
margin: 0 auto 0 auto;
}
.side-menu
{
position: fixed;
background: red;
width: 200px;
}
.child-container
{
background: orange;
float: left;
width: 1000px;
margin-left: 200px;
}
</style>
<body>
<div class="pageWrapper">
<div class="container">
<div class="side-menu">
Menu content
</div>
<div class="child-container">
Large Content
</div>
</div>
</div>
</body>
</html>

How does one make div's align correctly to start the layout of a page? (header, left panel and main section)

Description:
I am trying to learn to align elements such as divs and headers.
Here's what I have so far > http://jsfiddle.net/QxV6p/
Below are the issues:
The "Main section - in red" is not aligned with the blue header on the right hand side.
I have set the width of the body and the header to the same value of 1000px. And I have set the left div (black) to have a width of 20% and the main div to have a width of 79% (both inside the body) leaving a margin of 10px between the two divs.
I believe I have positioned the div correctly using the "position: relative" feature.
Please suggest what is wrong with the code? Also is there a better way of making the divs (in this case the left/black div and the main/red div) align as if they were inline?
I've tried "display: inline" but for some reason it makes the divs disappear. Any help is appreciated.
Code:
<!DOCTYPE html>
<head>
<style>
header {
max-width: 1000px;
height: 100px;
background: blue;
}
body {
max-width: 1000px;
}
.left {
width: 20%;
height: 2000px;
background: black;
margin-top: 10px;
}
.main {
width: 79%;
height: 2000px;
margin-top: 10px;
background: red;
position: relative;
top: -2010px;
left: 210px;
}
</style>
</head>
<html>
<header>
</header>
<body>
<div class="left"></div>
<div class="main"></div>
</body>
</html>
firstly you need a valid html code
<html>
<body>
<div class="wrapper">
<header>
</header>
<div class="left"></div>
<div class="main"></div>
</div>
</body>
</html>
CSS
header {
max-width: 1000px;
height: 100px;
background: blue;
}
.wrapper {
max-width: 960px;
margin:0 auto;
}
.left, .main {
display:inline-block;
margin-top:10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.left {
width: 20%;
height: 2000px;
background: black;
}
.main {
width: 79%;
height: 2000px;
background: red;
margin-left:4px;
}
DEMO
My recommendations:
Avoid positioning using pixels.
Avoid floats for layout.
KISS: if you want your main content to be 80%, set it to 80%. Manually manouvering it into position will take more time and scales poorly.
Demo (I changed some of the sizes for easier viewing in the fiddle)
HTML
<header></header>
<body>
<div class="left"></div><div class="main"></div>
</body>
CSS
header {
height: 100px;
background: blue;
}
.left {
display: inline-block;
width: 20%;
height: 100px;
background: black;
}
.main {
display: inline-block;
width: 80%;
height: 100px;
background: red;
}
use float:left on each element
see it here
<!DOCTYPE html>
<head>
<style>
header {
max-width: 1000px;
margin: 0 auto;
height: 100px;
background: blue;
}
body {
margin:0;
padding:0;
}
.left {
width: 20%;
height: 2000px;
background: black;
margin-top: 10px;
}
.main {
width: 79%;
height: 2000px;
margin-top: 10px;
background: red;
position: relative;
top: -2010px;
left: 210px;
}
.wrapper{
margin:0 auto;
}
.container{
margin: 0 auto;
width: 1200px;
}
</style>
</head>
<html>
<body>
<header>
</header>
<div class="wrapper">
<div class="container">
<div class="left"></div>
<div class="main"></div>
</div>
</div>
</body>
</html>
You can use float:left instead of using "top and left position"
Here is the updated Code:
HTML
<body>
<header></header>
<div class="left"></div>
<div class="main"></div>
</body>
CSS
header {
max-width: 1000px;
height: 100px;
background: blue;
}
body {
max-width: 1000px;
}
.left {
width: 20%;
height: 2000px;
background: black;
margin-top: 10px;
float:left;
}
.main {
width: 78%;
height: 2000px;
margin-top: 10px;
background: red;
float:left;
margin-left:2%;
}
And Working Demo for the same
Hope this helps!!!