I'm currently reading Headfirst CSS/HTML and I'm having an issue with an example.
I'm attempting to float the body to the left of the sidebar using float:left; however it's not floating properly. I've been over the HTML and CSS an I can't quite see what's wrong.
This is what I want it to look like:
And the fiddle: https://jsfiddle.net/Taubin/7Lhz4wtd/
#main {
background: #efe5d0 url(images/background.gif) top left;
font-size: 105%;
padding: 15px;
margin: 0px 10px 10px 10px;
width: 420px;
float: left;
}
<div id="allcontent">
<div id="header">
</div>
<div id="sidebar">
<p class="beanheading">
Sidebar text
</p>
<p>
Sidebar text
</p>
</div>
<div id="main">
<h1>QUALITY COFFEE, QUALITY CAFFEINE</h1>
<p>
Main text
</p>
</div>
</div>
Any suggestions would be greatly appreciated.
First, it might be the issue that you are adding margin and paddings, which add size to the box even though the box has a width of 420px, you have to calculate margins and paddings to, or use * { box-sizing: border-box; }, which will calculate the width of that element as a sum of all the sizes (padding, margin, width) and not exceed the width.
Second, the order of the elements are important when floating, put main always on top of the sidebar, since elements start as top to bottom, when you float a top element, the bottom element if its wider, will collapse and align with the main box.
Screenshot for reference:
Here is the https://jsfiddle.net/bg2v0dqn/.
You shouldn't add a large gap with margin.
Here's what I changed:
#main {
background: #efe5d0 url(images/background.gif) top left;
font-size: 105%;
padding: 15px;
margin: 0px 10px 10px 10px;
width: 420px;
float: left;
}
#sidebar {
background: #efe5d0 url(images/background.gif) bottom right;
font-size: 105%;
padding: 15px;
margin: 0px 10px 10px 0;
width: 290px;
float: right;
}
#sidebar {
background: #efe5d0 url(images/background.gif) bottom right;
font-size: 105%;
padding: 15px;
margin: 0px 10px 10px 0px;
float: right;
width: 290px;
}
Try this CSS code
body {
background-color: #b5a789;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: small;
margin: 0px;
display: table;
}
#header {
background-color: #675c47;
margin: 10px;
height: 108px;
}
#main {
background: #efe5d0 url(images/background.gif) top left;
font-size: 105%;
padding: 15px;
margin: 0px 10px 10px 10px;
width: 420px;
display: table-cell;
}
#sidebar {
background: #efe5d0 url(images/background.gif) bottom right;
font-size: 105%;
padding: 15px;
margin: 0px 10px 10px 10px;
width: 300px;
display: table-cell;
float: right;
}
#footer {
background-color: #675c47;
color: #efe5d0;
text-align: center;
padding: 15px;
margin: 10px;
font-size: 90%;
clear: left;
}
h1 {
font-size: 120%;
color: #954b4b;
}
.slogan { color: #954b4b; }
.beanheading {
text-align: center;
line-height: 1.8em;
}
a:link {
color: #b76666;
text-decoration: none;
border-bottom: thin dotted #b76666;
}
a:visited {
color: #675c47;
text-decoration: none;
border-bottom: thin dotted #675c47;
}
#allcontent {
width: 800px;
padding-top: 5px;
padding-bottom: 5px;
background-color: #675c47;
}
Related
I am unable to get my aside element to align properly with the rest of my page. It sits above the main element and spills into the header. How do I fix that?
Here's what it looks like on the page:
Here's the CSS Style code I'm using:
* {
margin:0;
padding:0;
}
body {
font-size:1.1em;
font-family: Arial, Helvetica, sans-serif;
background-color:darkseagreen;
}
header {
padding: 1%;
margin-bottom: 3%;
text-align: center;
font-size:2em;
font-family: Arial, Helvetica, sans-serif;
text: white;
background-color: #4EEE94;
}
aside {
width: 25%;
padding: 0.5%;
margin: 0 5px 5px 0;
background-color: #1C86EE;
float: right;
border-radius: 20px;
position: relative;
min-height: 100%;
display: block;
}
#main {
width: 446px;
margin-right: 27%;
padding: 0.5%;
background-color: #EE6363;
text: white;
position: relative;
border-radius: 4%;
}
.map {
padding: 2em;
margin: 3em auto 3em auto;
position: relative;
display: block;
text-align: center;
width: 95%;
.image {
padding: 5%;
margin: 4em;
float: left;
position: relative;
left: 10px;
top: 15px;
}
}
div {
box-shadow: 10px 10px 5px #888888;
border: 2px solid;
border-radius: 25px;
}
nav ul li {
margin-right: 1em;
display: inline;
list-style-type: none;
}
nav li a {
padding: 1em;
color: white;
text-decoration: none;
}
nav li a:hover {
color: yellow;
text-decoration: underline;
}
footer {
margin: 0.5% 27% 0 0;
border-top: solid thick teal;
padding: 0.5%;
background-color: lime;
}
first issue with your css remove the braces after .image class.
.image {
padding: 5%;
margin: 4em;
float: left;
position: relative;
left: 10px;
top: 15px;
}
}
second thing use px or % or em do not use all (recommended) .
Third use id something like this
<div id="xyz"></div>
Not <div id="#xyz"></div> # is the css selector
also do not use multiple id like <div id="abc xyz"></div> u cannot use multiple id's use class instead of <div class="abc xyz"></div>
How to centering that download button? I tested many times but it's wrong codes.
.col {
width: 100%;
height: auto;
float: left;
}
.download {
width: auto;
font-weight: 600;
font-size: 14px;
color: #000;
border: 2px solid #000;
padding: 17px 37px;
margin-top: 30px;
float: left;
}
<div class="col">
<span class="download">Download</span>
</div>
Just add text-align: center; to .col and replace float:left with display:inline-block; in the button element. jsfiddle
Remove float:left; from .download (because it forces the element to be floated to the left).
Give display:inline-block; (It acts like inline element, it means you can center it by giving text-align:center; to its parent.)
JSFiddle
.col {
width: 100%;
height: auto;
float: left;
text-align: center;
}
.download {
font-weight: 600;
font-size: 14px;
color: #000;
border: 2px solid #000;
padding: 17px 37px;
margin-top: 30px;
display: inline-block;
}
When opening the site in IE, there's unwanted 1px space under the footer. Chrome and Firefox shows correctly like I want (that means margin-bottom: 0).
The same bug appears while hovering the navigation items. There's 1px visible space. Again, only IE.
I would like to know why this is happening.
* {
padding: 0;
margin: 0;
}
header {
background: brown;
height: 100px;
width: auto;
min-width: 1200px;
margin-left: 0;
margin-right: 0;
padding-left: 0;
padding-right: 0;
}
h1 {
color: white;
font-family: calibri;
text-align: center;
padding-top: 25px;;
padding-left: 10px;
}
nav {
min-width: 1200px;
}
nav ul {
background: grey;
text-align: center;
-webkit-box-shadow: -1px 3px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: -1px 3px 5px 0px rgba(0,0,0,0.75);
box-shadow: -1px 3px 5px 0px rgba(0,0,0,0.75);
}
nav ul li {
list-style-type: none;
display: inline-block;
padding: 20px;
}
nav ul li a {
text-decoration: none;
color: white;
padding: 20px;
font-family: verdana;
}
nav ul li:hover {
background: black;
cursor: pointer;
}
section {
background: darkblue;
height: 200px;
width: 500px;
margin-top: 20px;
margin-left: 15px;
}
article {
background: gold;
height: 800px;
width: 500px;
margin-top: 10px;
margin-left: 15px;
}
aside {
background: orange;
height: 1010px;
width: 600px;
float: right;
margin-top: -1010px;
margin-right: 20px;
}
div#content {
background: none;
width: 1200px;
margin: auto;
}
p {
text-align: center;
}
p#sider, #article, #section {
padding-top: 20px;
padding-left: 20px;
}
footer {
background: brown;
height: 40px;
width: auto;
margin-top: 20px;
margin-bottom: 0;
}
p#credits {
font-size: 15px;
font-family: verdana;
float: left;
margin-top: 10px;
margin-left: 15px;
}
p#logo {
font-size: 15px;
font-family: verdana;
float: right;
margin-top: 10px;
margin-right: 15px;
font-weight: bold;
}
#logoname {
heigh: 200px;
width: 200px;
margin: auto;
position: relative;
left: -40px;
top: -40px;
}
article, section, aside {
font-family: verdana;
font-size: 20px;
text-align: left;
}
<header>
<h1>Logo Picture</h1>
<div id="logoname">
<img src="http://www.ssbwiki.com/images/thumb/9/9a/DKSymbol%28preBrawl%29.png/50px-DKSymbol%28preBrawl%29.png">
</div>
</header>
<nav>
<ul>
<li>Home</li>
<li>News</li>
<li>Reference</li>
<li>Contact</li>
</ul>
</nav>
<div id="content">
<section>
<p> Hello there! This is a section and here it will be some pretty content about something pretty nice. </p>
</section>
<article>
<p> Hello again. This is an article about something new. What happened lately. You see?</p>
</article>
<aside>
<p id="sider">This is a sider. It is onn the left side of the website.
This is a sider. It is onn the left side of the website
This is a sider. It is onn the left side of the website
This is a sider. It is onn the left side of the website
This is a sider. It is onn the left side of the website
This is a sider. It is onn the left side of the website
This is a sider. It is onn the left side of the website
This is a sider. It is onn the left side of the website</p>
</aside>
</div>
<footer>
<p id="credits">Copyright 2015 | All rights reserved</p>
<p id="logo">Logo Name</p>
</footer>
Make sure you set properties for the body as well. so
body{margin:0;padding:0;width:100vw;height:100vh;}
IE is that annoying browser that unfortunately lots of people still use, but the body in every browser usually needs to be set like this.
I'm kind of new to HTML and CSS. I have a nav bar that I want (the logo and links) aligned to being above the sidebar on my page. It's in different positions on different screens (and when browser is resized) and I don't know how to fix it. I made a fiddle thing and I'll link to the site so that you will know what I mean.
This is the fiddle: The Fiddle
This is the page: The page
#header {
width: 100%;
height: 91px;
margin: 0;
top: 0;
}
#menu {
float: right;
width: 100%;
height: 54px;
margin-top: 0;
background: #ffffff url(http://i1378.photobucket.com/albums/ah105/WinPhanNick/menu_bar_zps6212d723.jpg) repeat-x left top;
position: fixed;
}
#menu ul {
margin: 0;
padding: 0px 0 0;
list-style: none;
line-height: normal;
margin-left: 28%;
}
#menu li {
display: inline;
text-align: center;
}
#menu a {
display: block;
float: left;
height: 36px;
padding: 18px 20px 0px 20px;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
color: #ffffff;
}
li#logo {
height: 52px;
width: 52px;
background: url(http://i1378.photobucket.com/albums/ah105/WinPhanNick/cb_logo_zpsd1b14443.png) no-repeat;
margin-top: 1px;
margin-right: 1px;
margin-left: 1px;
}
#menu a:hover,
#menu .active a {
background: #1687ef;
color: #FFFFFF;
}
#logo {
float: left;
width: 270px;
height: 76px;
margin: 0px;
padding: 15px 0px 0px;
margin-left: 27%;
}
Make your link wrapper (which is the ul) the same width as your page container (which is 892px) and set it to margin: auto to center it. You can remove the margin-left: 28% as well. That's not needed. You also have a float issue so your ul is collapsed. You need to clear your floated elements. You can add overflow:hidden.
#menu ul{
overflow: hidden; //clear float issue
width: 892px; // same width as #page
margin: 0 auto; //will center
padding: 0px 30px; //add to keep the same padding as #page-bgtop
}
FIDDLE
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I cant for the life of me find out whats wrong with the CSS code, I cant get the font in main <p> to be 20px and can't properly center the address in the footer. I am only allowed to edit css file.
Html file:
http://www.mediafire.com/view/68bcokhw6tb086g/redball.htm
CSS file:
http://www.mediafire.com/view/9rk9dracsz47sn7/pizza.css
CSS code:
/*
New Perspectives on HTML and CSS
Tutorial 4
Case Problem 2
Pizza Style Sheet
Author: Joesph Aguilar
Date: 01/31/2014
Filename: pizza.css
Supporting Files:
*/
/* Display Block Elements */
header, section, aside, footer, nav{
display: block;
}
/* Padding and Margin Style */
*{
padding: 0px;
margin: 0px;
}
/* Body Style */
body{
background-color: red;
font-family: Verdana, Geneva, sans-serif;
}
/* Container Style */
#container{
width: 1000px;
margin-top: 0px;
margin-bottom: 0px;
margin-left: auto;
margin-right: auto;
border-left: 1px solid black;
border-right: 1px solid black;
background: white url('redbar.png') repeat-y left top;
}
/*Header Style */
header{
background-color: white;
height: 100px;
}
/* Horizontal Nav Style */
nav.horizontal{
background-color: white;
height: 70px;
width: 100%;
}
nav.horizontal li{
background-color: white;
font-size: 16px;
height: 50px;
line-height: 50px;
width: 180px;
display: block;
float: left;
margin-left: 5px;
margin-right: 5px;
text-align: center;
}
nav.horizontal li a{
display: block;
background-color: red;
color: white;
border-radius: 30px / 25px;
-moz-border-radius: 30px / 25px;
-webkit-border-radius: 30px / 25px;
text-decoration: none;
}
nav.horizontal li a:hover{
background-color: (255, 101, 101);
color: black;
}
/* Vertical Nav Style */
nav.vertical{
clear: left;
float: left;
width: 200px;
}
nav.vertical li{
list-style-type: none;
text-indent: 20px;
margin-top: 20px;
margin-bottom: 20px;
}
nav.vertical li a{
color: white;
text-decoration: none;
}
nav.vertical li a:hover{
color: black;
}
/* Section Style */
#main{
background-color: rgb(255, 211, 211);
float: left;
width: 600px;
}
#main > p {
font-size: 20px;
margin: 15px;
}
#main img{
float: right;
margin: 15px;
width: 350px;
border-bottom-left-radius: 350px;
-moz-border-radius-bottomleft: 350px;
-webkit-bottom-left-radius: 350px;
}
/* Coupon Style */
#main div.coupon{
border: 5px;
border-style: dashed;
float: left;
width: 170px;
height: 150px;
margin-top: 20px;
margin-bottom: 20px;
margin-left: 10px;
margin-right: 10px;
background: white url('slice.png') no-repeat right bottom;
}
#main div.coupon h1{
color: white;
background: rgb(192, 0, 0);
font-size: 16px;
letter-spacing: 2px;
text-align: center;
height: 25px;
font-variant: small-caps;
}
#main div.coupon p{
font-size: 14px;
text-align: center;
margin: 5px;
}
/* Aside Style */
aside{
float: left;
width: 200px;
}
aside h1{
color: rgb(192, 0, 0);
font-size: 20px;
letter-spacing: 2px;
font-weight: normal;
text-align: center;
}
aside li{
background-color: rgb(255, 135, 135);
border-radius: 5px;
list-style-type: none;
margin: 10px;
padding: 5px;
}
/*Footer Style*/
footer{
clear: left;
margin-left: 200px;
}
footer address{
border-top-style: 1px solid red top;
color: red;
font-size: 10px;
font-style: normal;
text-align: center;
margin-top: 25px;
padding-bottom: 20px;
}
The address is centered in the footer. Your problem is that you want the address centered on section#main, and the footer isn't in the section#main, it's in div#container, resulting in an address centered to the whole container.
However, since your aside has a static width of 200px, we can add that as a margin into footer>address, so that it centers the content accordingly.
So, we want on footer address is:
margin-right:200px;
but since we already have
margin-top:25px;
we can just delete that margin-top line and say both with:
margin:25px 200px 0 0;
which is shorthand for margin top 25px right 200px bottom 0 left 0.
Finally, the correct way to post this would be on JSFiddle, it's super easy to figure out, and I put my solution for your problem here:
http://jsfiddle.net/R8Hsv/
All about your font size seems fine, at least I can change it. How do you expect 20px to be?
Had to set a width for your footer, to the same as the main.
footer address{
border-top-style: 1px solid red top;
color: red;
font-size: 10px;
font-style: normal;
text-align: center;
margin-top: 25px;
padding-bottom: 20px;
width:600px;
}
JSFIDDLE: http://jsfiddle.net/42h96/1/