A friend and I are working on a website, but for some reason there is still white space when I use 100% width. How can I fix this? These are the main css elements
#info_container{
height:100%;
width:100%;
display:inline-block;
padding-top:3%;
background-color:#D3D3D3;
}
#main_header {
background: -webkit-linear-gradient(#2a2a2a, #545454);
text-align: center;
align-items: center;
vertical-align: middle;
position: absolute;
width:100%;
height:8%;
margin:-1em;
position:fixed;
display: table;
width: 100%;
table-layout: fixed;
/* For cells of equal size */
}
JSFiddle
First best practice is to put universal selector * { padding: 0; margin: 0;}
to avoid the margins and paddings overflow.
I updated your fiddle
Changes to your CSS
* { padding: 0; margin: 0; }
#main_header {
background: -webkit-linear-gradient(#2a2a2a, #545454);
text-align: center;
align-items: center;
vertical-align: middle;
position: absolute;
width:100%;
position:fixed;
display: table;
width: 100%;
table-layout: fixed;
/* For cells of equal size */
}
#main_header a {
display:inline-block;
text-decoration:none;
color:#567aa9;
display: table-cell;
vertical-align: middle;
padding:.5%;
}
a span {
text-decoration:none;
color:#878787;
font-size:55px;
top: 10%;
overflow: hidden;
left:50%;
}
.a1:hover {
color:#bababa;
}
.a2:hover{
color:#bababa;
}
.a3:hover{
color:#bababa;
}
.a4:hover{
color:#bababa;
}
#info_container{
height:100%;
width:100%;
display:inline-block;
padding-top:7%;
}
html {
font-size: 62.5%;
}
body {
font-size: 1em;
}
#media (max-width: 300px) {
html {
font-size: 70%;
}
}
#media (min-width: 500px) {
html {
font-size: 80%;
}
}
#media (min-width: 700px) {
html {
font-size: 120%;
}
}
#media (min-width: 1200px) {
html {
font-size: 200%;
}
}
#info_container{
height: 100px; // changed this from 100%;
width:100%;
padding-top: 3%; // removed
display:inline-block;
background-color:#D3D3D3;
}
EDIT: UPDATED THE FIDDLE
There is a very simple fix to this. You have a background color on your text which goes on the whole line, so to make it only on the text area in your info container, simply put that text into a span class. Now just remove that background color from the original class and put it into your span! You can give a class to the span if you will put it into another css file, but I have just put it directly into the html here.
<p><span style="background-color:red;">Hello World</span></p>
Related
I am creating a responsive header. I got two columns and want the button in the right column to be vertical centered.
I know I can center items using top: 50%; margin-top: -xy px, and my button although got a fixed height: 40px.
To use this method I wrapped my button inside a div {position: relative}. This does not work, as the div does not stretch its own height.
How can I solve this with css? First I thought about Flexbox, but it has quite some lack of browser compatibility.
JSFIDDLE DEMO
You can greatly simplify your code - remove floats, (use display: inline-block instead), remove the .relative div, etc.
Working Fiddle
html, body {
margin: 0;
padding: 0;
font-size: 16px;
}
header {
background: red;
color: #fff;
padding: 0.5em;
}
header h1 {
font-size: 2em;
margin: 0 0 0.2em;
}
header p {
margin: 0;
}
header button {
height: 40px;
width: 70px;
}
.column-left {
display:inline-block;
width: 70%;
vertical-align: middle;
}
.column-right {
width: 29%;
text-align: right;
display: inline-block;
vertical-align: middle;
height: 100%;
}
/* responsive */
#media (min-width: 200px) {
header {
padding: 1em;
}
}
#media (min-width: 300px) {
header {
padding: 1.5em;
}
}
#media (min-width: 400px) {
header {
padding: 2em;
}
}
#media (min-width: 500px) {
header {
padding: 2.5em;
}
}
#media (min-width: 600px) {
header {
padding: 3em;
}
}
/* helpers */
.clearfix:after {
content: ".";
clear: both;
display: block;
visibility: hidden;
height: 0px;
}
Remove this div with position: relative and add position: relative to your header tag. You can even delete your column-right div.
Another solution:
header button {
top: 50%;
transform: translateY(-50%); // instead of negative margin-top (it is useful when your button has dynamic height, supports IE9+ with -ms- prefix)
}
JSFIDDLE
I'm using display:flex ,
I'm working with a ul list of elements. Don't know Why i get 2 different Result :
Problem issue with chrome :
Browsers_Pic
This is what I'm trying to do:
http://jsfiddle.net/0fbdgfcq/26/
ul {
max-width:800px;
display: flex;
flex-direction: row-reverse;
background-color: blue;
height: 100px;
max-width: 500px;
min-width: 100px;
padding:0;
}
.box{
/* Clean */
}
.g p{
white-space:nowrap;
text-align:center;
color:white;
text-decoration:none;
font-size:3vw;
}
.g li {
flex: 1 0;
width: 15%;
height: auto;
color:white;
font-size:3vw;
list-style-type: none;
word-wrap: break-word;
}
.g img {
width: 100%;
height: 100%;
max-width:100px;
max-height:100px;
}
Off-hand I'd say the problem is the width:15% you have applied which is overriding the flexing of the list items.
Try
.g li {
flex: 1 0 15%;
}
JSfiddle
Try adding the following:
ul {
Position: relative;
}
.g p {
Position: relative
}
This is to prevent your paragraph from overflowing.
That might fix the issue.
If not try adding it to your li as well.
So I have some wierd spacing at the bottom of the footer and im not sure whats causing it. the code is as follows:
scss:
html,
body {
margin:0;
padding:0;
height:100%;
}
#wrapper {
min-height:100%;
position:relative;
}
header {
padding:10px;
background:#EFDECD; //#5ee;
// text-align: center;
}
#content {
padding:10px;
// padding-bottom:80px; /* Height of the footer element */
}
footer {
display: block;
width:100%;
height:5em;
position:absolute;
bottom:0;
left:0;
background:#EFDECD; //#EFDECD
text-align: center;
overflow: hidden;
a{
padding: .75rem;
// position:relative;
top: 1.5em;
display: inline-block;
font-size: .72rem;
}
p{
font-size: .72rem;
}
}
video{
width: 100%;
height:auto;
}
.label{
margin-left: .5em;
margin-right: .5em;
}
table{
font-size: .75em;
}
.panel.callout a:not(.button):hover{
color: $anchor-font-color-hover;
}
.headtext{
display:inline-block;
font-size:3em;
margin-left: 1.5em;
text-align: center;
font-family:"Courier New";
font-weight: bold;
margin-left: 6em;
margin-right: 7em;
}
.img2{
// max-height: 20%;
max-width: 25%;
float:right;
display:inline-block;
}
.accorborder{
border: black dotted 1px;
}
h6{font-weight: bold;}
The site is in development and is at www.new.omegadesignla.com please inspect element to view and can also view source code there.
The problem comes from the <br> which is between <div id="wrapper">...</div> and <footer>...</footer>.
If you eliminate position:absolute from your footer rule, the white space below footer will disappear. Is there a specific reason you are using position:absolute?
So im fully aware of the amount of questions asked about "Sticky Footers", and have also referenced many, MANY different questions on here and websites about sticky footers. I've created a fresh template away from this project that work and have examples of how sticky footers operate, be it inside the wrapper or out...
However, i just cant seem to get it operate correctly within my solution.
Currently the footer appears to be "sticky", however on one of my main pages, the content (images and text) seem to overlap the footer, due to the footer not being pushed to the bottom correctly. It seems to sit just below the screen (Meaning you have to scroll slightly to see the footer) - But on this page it sits in that location, doesnt get pushed down and then the content overlaps.
I've tried everything, Removing 100% on HTML, BODY, WRAPPER, contentDiv, but basically, one thing works, which breaks another.
What im after is, ContentDiv = 100% (pushing down the footer). So i should be able to create a blank page, the footer be glued to the bottom, and if content increases it pushed it down... Simple right? But tearing out my hair with this :/
So, any help would be massively appreciated, as i have a short deadline to get this sorted.
Fiddle Demo
CSS
html
{ margin: 0px; padding: 0px; height:100%; }
body
{ margin: 0px; padding: 0px; height: 100%; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 12px; }
/* { margin: 0px; padding: 0px; height: 100%; font-family: 'Montserrat', sans-serif; font-size: 12px; } */
p { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 12px; }
h1 { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size:24px; }
h2 { margin:0px; padding:0px; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; }
/* PAGE FORMATTING - START*/
span:hover { /* text-decoration: underline; */ }
a:link, a:visted { }
ahover, a:active { }
.link_nav_header{
padding:0px;
font-size:20px;
font-weight:bold;
color:#333333;
cursor:pointer;
}
.but_default
{
padding: 2px;
border: 1px solid #009900;
background-color: #33FF00;
/* background-color: #dddbdb; */ /* TWO COLOURS? */
}
.but_events-buybutton
{
padding:3px;
min-width:90%;
margin-bottom:5px;
color:#ffffff;
background-color:#378ec8;
}
.but_all
{
min-width:90%;
cursor: pointer;
margin: 2px;
}
/* HEADER - START */
.hdr_container
{
width:100%;
height:110px;
padding:0px;
margin:0px;
position:relative;
background-color:#0099ff;
color: #ffffff;
overflow: hidden;
}
#hdr_profile-icon {
margin-top: 1%;
margin-right: 1%;
float: right;
background-color: inherit;
}
/* NEW NAVIGATION */
#nav {
width: 100%;
padding: 0;
margin: 0 auto;
background-color: #333333;
position: absolute;
bottom: 0%;
}
#nav ul {
list-style: none;
/* width: 800px;*/ /* REMOVE TO STRETCH NAV TO FULL WIDTH */
width: 100%;
margin: 0 auto;
padding: 0;
}
#nav li {
float: left;
text-align: center;
}
#nav ul li{
width: 11%; /* STRETCHES NAV TO FULL WIDTH */
}
#nav li a {
padding: 8px 15px;
display: block;
text-decoration: none;
font-weight: bold;
color: white;
text-transform:uppercase
}
#nav li:first-child a {
background: red;
width: 10px;
font-weight: normal;
}
#nav li a:hover {
/* color: #c00; */
background-color: #0099ff;
}
#nav a:hover a:focus {
/* color: #c00; */
background-color: red;
}
/* MAIN CONTENT - START */
#wrapper {
clear: both;
/* margin: 0 auto; */
width: 100%;
height:100%;
min-height: 100%;
/* margin-bottom: -75px; */
z-index:10;
}
.contentDiv
{
clear: both;
width:65%;
min-width: 800px;
height:90%;
background-color:#ffffff;
margin-left:auto;
margin-right:auto;
/* z-index: -9999; */
}
/* TABLE - START */
.tbl_container-centered
{
width:100%;
height:100%;
min-height:100%;
/* padding-bottom: 20px; */
margin-left:auto;
margin-right:auto;
display:table;
overflow:auto;
/* margin-bottom: 75px; */
display: inline-table;
vertical-align: middle;
}
.tbl_containerpaneltext-centered
{
width:95%;
min-height:35%;
margin-left:auto;
margin-right:auto;
background-color:red;
}
.tbl_head-genericthread
{
min-height:3%;
max-height:3%;
text-align:center;
color:#ffffff;
background-color:#0099ff;
}
.tbl_events-head {
width: 100%;
height: 100%;
min-height: 100%;
border: 1px solid;
text-align: left;
border-collapse: collapse;
}
.tbl_grid-events
{
background-color: #ffffff;
}
.tbl_pickseats-famtable
{
width:100%;
background-color:#e1e1e1;
}
table#tbl_events{
height:100%;
min-height:100%;
border-collapse: collapse;
border-right: 1px solid #333333;
border-left: 1px solid #333333;
}
.link_moreinfo{
padding:0px;
font-size:14px;
font-weight:bold;
color:#0099ff;
cursor:pointer;
}
#event_row {
height: 140px;
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}
#basket2 {
background: red;
}
/* FOOTER CSS - START */
.footer_container
{
clear: both;
width:100%;
height:75px;
bottom:0;
background-color:#0099ff;
/* position:absolute; */
}
.footer_container, .wrapper:after {
/* .push must be the same height as footer */
height: 75px;
}
.wrapper:after {
content: "";
display: block;
}
.footer_global-bottom {
width: 100%;
margin: auto;
padding-top: 20px;
text-align: center;
color: white;
background: #333333;
}
.footer_global-bottom a {
color: white;
text-decoration: none;
}
/* ERROR HANDELING */
.error {
background: #ef7474;
border: 1px solid #f5aca6;
text-align: center;
}
.success
{
background: #74e963;
border: 1px solid #59e836;
text-align: center;
}
.alerts_box {
padding: 10px;
width: 250px;
position: absolute;
visibility: hidden;
font-size: 10px;
color:black;
}
.alerts {
width: 275px;
z-index: 2;
padding-bottom: 40px;
}
have you considered using this piece of code:
.footer_container {
position: fixed;
bottom: 0;
z-index: 100;
}
If you want full content being visible you can add to wrapper something like this:
margin-bottom: (footer-height)px;
Or use padding-bottom instead of margin-bottom.
in your #wrapper rule-set change height:100% to height:auto and remove min-height:100%.
jsFiddle
#wrapper {
clear: both;
width: 100%;
height:auto;
z-index:10;
}
I believe that setting the height to 100% is setting it to 100% of the browser window, not 100% of the content. I could be wrong about that though.
This will place the footer at the end of the content. On pages where the content is less than the height of the window, you can wrap the footer and give the footer wrapper a class like this:
.minContentFooter {
position: absolute;
bottom: 0;
}
If the case is that the content is loaded dynamically and you don't know if it will fill a browser window, then you will need a bit of javascript to have it both ways - either at the bottom of the content or the bottom of the window when there is minimal content.
Problem was solved, not by CSS, but by Javascript.
The problem was due to the page loading dynamic content from a table, it never knew how big the contentDiv was, so didnt know where to but the footer.
The sticky footer is achieved by setting CSS % heights, and also using javascript to help correct for pages with no content or those with dynamically loaded content.
The code below explains the active javascript:
var totalHeight = $('#header').height() + $(id).height();
var contentDivHeight = $('#content').height();
var wrap = $('#wrapper');
if (totalHeight >= contentDivHeight) {
wrap.removeClass('wrapper-height');
wrap.addClass('wrapper-minHeight');
} else {
wrap.addClass('wrapper-height');
wrap.removeClass('wrapper-minHeight');
}
The code checks the height of the header and the content contained within the content and if its over the footer switches to a css class enforcing min-heights rather than heights to allow the footer to flow to the end of the content.
Many Thanks for everyone's help.
Here is the code:
<header>
<h1>Title</h1>
<h2>Subtitle</h2>
</header>
Is there a way to align h1 to the left and h2 to the right with only using inlines, no floats, no absolute positioning? I have tried:
header {
width: 100%;
}
header h1 {
display: inline-block;
text-align:left;
}
header h2 {
display: inline-block;
text-align: right;
}
got no luck: http://codepen.io/Gasimzada/pen/qFolb
Give em some width dimensions! Without, inline-block elements will default to the exact width of the contents.
header {
width: 100%;
}
header h1 {
display: inline-block;
width: 49%; /* 50% might be suitable; codepen bumped to next line at 50-50 */
text-align:left;
}
header h2 {
display: inline-block;
width: 50%;
text-align: right;
}
http://codepen.io/anon/pen/tBfHm
you can as well either use text-align:justify, display:table or display:flex; http://codepen.io/anon/pen/IwbBs
* {
margin: 0px;
padding: 0px;
font-size: 100%;
font-weight: inherit;
font-family: inherit;
}
body {
font-weight: 300;
font-family: 'Open Sans', sans-serif;
color: white;
}
header {
width: 100%;
padding: 10px;
background: black;
}
header h1 {
display: inline-block;
text-align:left;
}
header h2 {
display: inline-block;
text-align:right;
}
/* justify */
.justify {
text-align:justify;
line-height:0px;
}
.justify * {
line-height:1.2em;
}
.justify:after {
content:'';
width:99%;/* add an extra line to trigger justify on .. first-line */
display:inline-block;
vertical-align:top;
}
/* flex */
.flex {
display:flex;
justify-content:space-between;
}
/* table */
.table {
display:table;
}
.table h1, .table h2 {
display:table-cell;
}
... Float has already been told :)