I set up some CSS styles for a HTML page and all was working as expected. I then edited the CSS (minimally) and suddenly the layout breaks. I've got a copy of the original (working) CSS so I could just go with that. But I wanted to sort out what I did wrong.
So, I've spent a few hours going over the faulty CSS but I just cannot find where it is incorrect. Hoping someone can point out the mistake.
In both cases the HTML is the same.
I've created 2 CodePens, one with working HTML/CSS, the other with same HTML and faulty CSS. The problem is in the footer area. With the faulty CSS, the 'bottom bar' rides up into the main footer above. However, I think I've cleared floats correctly.
Below is what I think is the faulty section of CSS (but it will make more sense to view it along with HTML - see CodePen links further below):
footer{
font-family: 'Open Sans', sans-serif;
margin-top:200px;
border-top:6px solid rgba(246, 246, 246, 0.8);
background-repeat:repeat-x;
background-position:left bottom;
background-size:contain;
background-color:#b8b8b8;
}
.footer-column-container{
width:95%;
max-width:1200px;
list-style-type:none;
margin:0 auto;
padding:25px 0;
}
.footer-column-container li{
float:left;
padding:20px 5px;
width:25%;
box-sizing:border-box;
}
.footer-column-container ul {
list-style-type:none;
}
.footer-links{
height:250px;
}
.footer-links li{
float:none;
display:block;
line-height:12px;
padding:8px 0;
width:100%;
}
.footer-column h4{
color:#fff;
font-size:16px;
font-weight:bold;
margin-bottom:10px;
}
.footer-column a:link{
font-size:14px;
text-decoration:none;
color:#fff;
}
#bottom-bar-container{
background-color:#000;
border-top:1px solid #393939;
padding:20px 0;
}
#bottom-bar{
font-size:12px;
margin:0 auto;
width:95%;
text-align:center;
color:#fff;
}
There's a fair bit of code so, rather than place it all here, I'll list links to CodePens:
Link to working HTML/CSS: http://codepen.io/Ben10/pen/VjBgyB
Link to working HTML / Faulty CSS: http://codepen.io/Ben10/pen/pbkYAd
Many thanks if you can help me.
you have a floating issues so use clear:both; on #bottom-bar-container
#bottom-bar-container {
background-color: #000;
border-top: 1px solid #393939;
clear: both;
padding: 20px 0;
}
or
use overflow: hidden; to .footer-column-container
I hope that will be helpful to achieve you goal
Add below overflow:hidden; into your .footer-column-container
.footer-column-container{
width:95%;
max-width:1200px;
list-style-type:none;
margin:0 auto;
padding:25px 0;
overflow:hidden; /*Add this*/
}
Add the <div style="clear:both;"></div> before <div id="bottom-bar-container"></div>
Since you are using floating elements inside footer-column-container, its height won't be set automatically. You need to use overflow:hidden in .footer-column-container CSS.
That is
.footer-column-container{
width:95%;
overflow:hidden; /*This property is missing*/
max-width:1200px;
list-style-type:none;
margin:0 auto;
padding:25px 0;
}
So that the div will accommodate its floating child elements , ie the li elements inside footer-column-container.
You have overflow:hidden property set in your working CSS. In the faulty code, that property is missing. It is simply the reason why it has messed up.
Its only need to clear div. I check your whole code you need to clear your div. Here updated fiddle.
Here I change your code, Have look..
footer{
font-family: 'Open Sans', sans-serif;
margin-top:200px;
border-top:6px solid rgba(246, 246, 246, 0.8);
background-repeat:repeat-x;
background-position:left bottom;
background-size:contain;
background-color:#b8b8b8;
width:100%;
float:left;
clear:both;
}
.footer-column-container{
width:95%;
max-width:1200px;
list-style-type:none;
margin:0 auto;
padding:25px 0;
display:inline-block
}
For more details for clearing div why and how please go here.
learnlayout.com
quirksmode.org
css-tricks.com
I hope it will help you :)
Related
I don`t understand why I have margin from the left:
CSS:
html, body {
font-family:Myriad Pro, sans-serif;
font-size:18px;
color:#000;
margin:0px;
padding:0px;
background: url('./images/background.png');
}
#container {
width:890px;
height:530px;
margin:36px auto;
}
#userList {
width:228px;
height:355px;
float:right;
border:1px solid #cccccc;
}
.users li {
list-style-type:none;
background-color: #f2f2f2;
width:100%;
height:50px;
border-bottom: 1px solid #cccccc;
}
HTML:
<div id="userList"><ul class="users"><li><img src="./pic/none.png">Piet van Meerdijk</li><li><img src="./pic/none.png">Henk v/d Wal</li></ul></div>
When I put margin-left:-40px; in the CSS code the li item will be on the left now, but then have I a margin on the right. Why?
JSfiddle: http://jsfiddle.net/8Cwcy/
The <ul> tag has an automatic padding of 40px so you will need to change that to 0px:
ul {
padding: 0px;
}
This should work across all browsers.
Fiddle: http://jsfiddle.net/8Cwcy/3/
By default a lot of HTML elements have their own CSS rules in many browsers, and <ul> tag has a padding by default. You need to set padding:0px to de <ul> tag:
ul{
padding:0px;
}
http://jsfiddle.net/8Cwcy/1/
If you want to know more about CSS reset rules follow this link.
i'm having a bit of a brain melting problem. I have a master div thats pretty much the body (don't ask me why, i was getting desperate), and within that div is a head div, and within that div is the navigation bar. It's a clear hierarchy. The problem is, whenever i try to use percents to adjust the height and width of the navigation bar or the head div, nothing happens. Zip, zero, nada. I've tried changing the positions to absolute, relative, even static. I've removed the Master Div, i've reordered the hierarchy, but nothing seems to work. Eventually i got to the point where i figured out that when i used pixels, i got the change wanted. (Obviously had to do a bit of conversion). My first thought was hierarchy, but again, it's clear, with no missing ending tags, no weird parents or children.
HTML
<div id="master_div">
<div id="head_div">
<div id="title_div">
<p id="title">A Challenging Sew</p>
<p id="subtitle">A sewing room, Venti Starbucks and a iPod classic....with a weekly Monday update to keep me on task....lets see what happens....</p>
</div>
<div id="nav_bar">
<ul>
<li><a class="nav_bar_links" href="/home">Home</a></li>
<li><a class="nav_bar_links" href="/about">About</a></li>
<li><a class="nav_bar_links" href="/projects/2013">Projects for 2013/2014</a></li>
<li><a class="nav_bar_links" href="http://www.flickr.com/photos/91959855#N02/collections/72157632507621761/">Completed</a></li>
<li><a class="nav_bar_links" href="/archive">Archives</a></li>
<li><a class="nav_bar_links" href="/subscribe">Subscribe</a></li>
<li><a class="nav_bar_links" id="sign_in" href="#">Sign In</a></li>
</ul>
</div>
</div>
</div>
CSS
body
{
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 15px;
padding:0 !important;
}
#master_div
{
position:relative;
width:100%;
height:100%;
margin:0;
padding:0;
}
/* Navigation Page */
#scary_tree
{
position:absolute;
right:40%;
top:25%;
}
/* Home */
/* TODO: Make Responsive Home Page */
#head_div
{
background-color:whitesmoke;
position:absolute;
height:63px;
width:100%;
margin:0;
padding:0;
}
/* A Challenging Sew + A sewing room, Venti Starbucks and a iPod classic..*/
#title_div
{
background-color:white;
opacity: .7;
position:relative;
height:30px;
width:100%;
top:15px;
border-top: solid 1px #e7e7e7;
border-bottom: solid 1px #e7e7e7;
}
#title
{
position:absolute;
left:3%;
top:-9%;
font-size:100%;
margin:0;
padding:0;
}
#subtitle
{
position:absolute;
left:3%;
top:50%;
padding:0;
margin:0;
font-size:40%;
line-height: 1.2;
}
#nav_bar
{
position:absolute;
top:100%;
height:15%;
width:100%;
background-color:whitesmoke;
border-top: solid 1px #e7e7e7;
border-bottom: solid 1px #e7e7e7;
margin:0;
padding:0;
}
#nav_bar ul {
margin:0;
padding:0;
position:relative;
height:20px;
top:-8px;
}
#nav_bar li {
display:inline;
}
#nav_bar a:link,a:visited {
margin:0;
padding-left:5px;
text-decoration: none;
color: black;
font-size:50%;
}
#nav_bar #sign_in
{
position:absolute;
right:2%;
top:3px;
margin:0;
padding:0;
}
Note: I am using a reset file. However, i still have margin and padding :0 in there because it doesn't really seem to be taking hold.
Feel free to critique me on my coding style, still learning!
You might wan to try
min-height: 100%;
min-width: 100%;
position: absolute;
Found the cause, setting my master div's position to relative was the issue. Have no idea why but hey. It works now. Sort of.
I'm bulding a Wordpress site that has a "box" for the main article. This is build using CSS and several Divs around the article. This all works fine, the only problem is that when I need a scroll bar, it apears outside of the right box border.
See for yourself (with awesome perfect red circle around it!).
Basically, I want it to stay IN the article, so in the left side of the last image (the right side border). I read around the internet, and I found that you can reverse the scroll bar using dir="rtl", but that will reverse all the scroll bars, and thats not really what I want.
[EDIT - To make it clear, I don't want it in the left side of the article itself, just inside the box on the right side of the text. This is sort of what I want, but as you see, it messes up the article box. I want it sort of in that position, but without screwing up the article.]
[End edit]
This is the CSS (this comes from a modded template, so excuse me if there are obvious errors):
.article {
margin-bottom:20px;
}
.article-corps-title {
background:url(images/article_sprite.png) no-repeat;
background-position:0 -17px;
min-height:70px;
max-height:142px;
position:relative;
}
.page-corps-title {
display:block;
/*background:url(images/article_sprite.png) no-repeat;
background-position: 13px -65px;*/
background:url(images/articlebox.png) no-repeat;
background-position:15px 0px;
height:80px;
}
.article-top {
position:absolute;
top:13px;
right:25px;
}
.article-top a {
display:block;
font-size:10px;
font-weight:700;
color:#aaa;
text-decoration:none;
padding:4px 12px 0 0;
background:url(images/icons.png) no-repeat;
background-position:top right;
}
.article-date {
position:absolute;
left:11px;
top:26px;
display:block;
width:40px;
text-align:center;
}
.article-date .month {
font-size:13px;
font-weight:700;
line-height:15px;
color:#FFF;
text-transform:uppercase;
}
.article-date .day {
font-size:22px;
font-weight:700;
color:#FFF;
}
h2.page-title {
text-align:center;
font-size:26px;
font-weight:700;
padding-top:10px;
padding-bottom:15px;
color:#000000;
text-shadow:#CCC 0 0 2px;
max-width:565px;
}
h2.article-title {
font-size:26px;
font-weight:700;
margin-left:80px;
padding-top:30px;
color:#ce0709;
text-shadow:#CCC 0 0 2px;
max-width:565px;
}
h2.article-title a, h2.page-title a {
color:#ce0709;
text-decoration:none;
}
h2.article-title a:hover,h2.page-title a:hover {
color:#E00
}
.article-meta-autor {
font-size:11px;
color:#aaaaaa;
margin-left:80px;
background:url(images/icons.png) no-repeat;
background-position:left -15px;
padding:4px 0 4px 20px;
max-height:11px;
line-height:14px;
}
.article-meta-autor a, .article-meta-keywords a, .article-meta-comments a {
color:#aaaaaa;
text-decoration:none;
font-weight:700;
}
.article-meta-autor a:hover, .article-meta-keywords a:hover, .article-meta-comments a:hover {
text-decoration:underline;
}
.article-corps {
position:relative;
/*background:url(images/article_sprite.png) repeat-y;
background-position:-683px 0px;*/
background:url(images/articleboxmiddle.png) repeat-y;
background-position:-5px 0px;
/*min-height: 250px;*/
height:300px;
margin-left:20px;
padding:13px 43px 0px 50px;
line-height:20px;
overflow:auto;/*hidden;*/
}
.article-read-more {
margin:0px auto;
width:164px;
padding-bottom:15px;
}
.article-read-more a {
display:block;
width:156px;
height:26px;
text-align:center;
padding-top:9px;
background:url(images/read_more.png) no-repeat;
background-position:top left;
font-weight:700;
color:#FFF;
text-decoration:none;
text-transform:uppercase;
}
.article-read-more a:hover {
background-position:bottom left;
}
.article-meta-keywords {
position:absolute;
bottom:0;
left:50px;
background:url(images/icons.png) no-repeat;
background-position:0 -34px;
padding-left:20px;
font-size:11px;
color:#aaa;
max-height:20px;
max-width:450px;
overflow:hidden;
}
.article-meta-comments {
position:absolute;
bottom:0;
right:45px;
background:url(images/icons.png) no-repeat;
background-position:0 -54px;
padding-left:20px;
font-size:11px;
color:#aaa;
}
.article-meta-keywords a {
color:#aaa;
font-weight:700;
text-decoration:none;
}
.article-meta-keywords a:hover {
text-decoration:underline;
}
.article-footer {
display:block;
/*background:url(images/article_sprite.png) no-repeat;
background-position:14px -15px;*/
background:url(images/articlebox.png) no-repeat;
background-position:15px -420px;
height:45px;
}
Thank you.
use dir="rtl" to give direction to the text. The scrollbars will appear to the left.
Then use dir="ltr" to the inside elements such as p, div etc to nullify the effect. This way, dir="rtl"
Here is the fiddle - http://jsfiddle.net/ashwyn/dcLQQ/
I works in Firefox though, but in my chrome it doesn't.
[Edit]
Below is the fiddle to shift the scrollbar slightly to the left-
http://jsfiddle.net/ashwyn/fPGy8/1/
I don't think there is any other solution that you can fix apart from the above.
this is not a solution to your problem but just a suggestion:
be aware that you're going against the standard behaviour your users would expect - a scrollbar always appears on the right for left-to-right languages, and this could be bad usability. As you are not creating a site that requires RTL, it would be better to not change the standard browser behaviour.
You haven't given enough code (structure) for me to give a specific answer, but it looks as though you could just narrow the div that contains the article.
My final is to recreate a basic html page with my own css like csszengarden.com.
I made a simple one page deal at http://randallmiller.pcriot.com/72bclass/final72b/index.html.
However a few of my links are not clickable. Here is the css for the site. Any help would be greatly appreciated!
EDIT: I fixed the unclickable part with z-index:1, I think because of the padding on linkblock2. However, now my a:hover to turn them grey is only working for a few.
html{
height:100%;
}
body{
background:#000000;
}
h3{
margin-top:0;
}
h3 span{
color:white;
display:block;
}
.pgtitle1{
word-spacing:10px;
padding-top:25px;
margin-left:125px;
font:1.5em "Trebuchet MS", Arial, Helvetica, sans-serif;
}
.pgtitle2{
padding-top:10px;
margin-left:275px;
font:bold .7em "Comic Sans MS", cursive;
letter-spacing:2px;
}
div#linkblock1{
position:absolute;
top:200px;
padding-left:25%;
}
div#linkblock2{
position:absolute;
top:200px;
padding-left:67.5%;
}
div a{
border-bottom:solid 1px white;
text-decoration:none;
text-align:center;
padding:5px;
display:block;
width:90px;
}
div a:hover{
color:rgb(200,200,200);
}
div a:visited{
color:blue;
}
div#fg_img{
height:323px;
background:url(bg.jpg) no-repeat center;
margin-top:50px;
line-height:999;
overflow:hidden;
}
h2{
font-size:.75em;
color:#FFF;
position:absolute;
top:10px;
left:60px;
}
You've covered up some of your links with #fg_img. Set some z-indexes.
Your divs are overlapping each other in many weird ways, the position:absolute on the div with the right links "linkblock2" is overlapping the links on the left.
You should really remove the position:absolute and use float on the divs, and you wouldn't run into that problem.
Not sure if it's an option or not, but check out a CSS Grid system if you can use it on your assignment.
I'm designing a fairly simple web site but as I don't have much experience I have a very simple question.
I've done the layout in a way that displays all the necessary information without the need of scrolling down. But for some reason it's there.
The site's css is as following:
#charset "utf-8";
/* CSS Document */
html {height:100%;width:100%; margin:0;}
body{
height:65%;
font-size:100%;
font-family:Calibri;
background-image:url(/images/gradient.png);
background-repeat:repeat-x;
background-color:#FFF0;
color:#00080;
margin-left:15%;
margin-top:3%;
margin-right:15%;
width:65%;
}
#banner {
height:40%;
background: url(/images/banner.jpg) right scroll no-repeat;
}
#left_container{
width:20%;
height:80%;
}
#left_container img{
width:100%;
}
a{
text-decoration:none;
color:#FFF;
border:none;
}
#menu{
width:100%;
height:85%;
font-size:120%;
}
#menu td{
background:#999;
color:#FFF;
padding:4%;
}
#menu tr td a:hover{
background:#CCC;
color:#333;
}
#right_container{
width:75%;
height:auto;
position:relative;
left:+26%;
top:-80%;
}
#right_container h2{
font-size:300%;
}
#right_container h3{
font-size:200%;
}
But the web site looks like this (and the scroll appears when I set the right_container h2 title (home) size in the css bigger than 190%....but I need it to be as I set...or it will be to small).How can I remove the scroll bar?
image -> http://i29.tinypic.com/hx3uy8.jpg
You can control the appearance of scrollbars in CSS by using the Overflow property. So you could try adding overflow: hidden to your BODY CSS declaration and see if that helps.