Heading 1 causing DIVs to part [duplicate] - html

This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
Why does this CSS margin-top style not work?
(14 answers)
Closed 4 years ago.
I have an issue with my page its making a gap appear between the H1 and main page DIV section. After 2 hours I cant seem to fix it. Can anyone advise where its going wrong. I want the top banner and the #mainarea to be on top of each other. There is a small gap between the 2 at the moment.
body {
font-size: 15px;
font-family: 'Open Sans', sans-serif;
background-color: #f6f6f6;
padding: 0;
margin: 0;
border: 0;
}
#logo {
width: 100%;
height: 50px;
background-color: #000;
}
#mainarea {
width: 60%;
height: auto;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
background-color: #E70A0E;
height: 250px;
}
h1 {
font-size: 1.5em;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-weight: bolder;
font-style: normal;
padding-left: 15px;
}
<div id="logo">
</div>
<div style="clear: both;"></div>
<div id="mainarea">
<h1>This is a test </h1>
</div>

Set overflow:auto; in #mainarea and add margin:auto toh1 Tag.
See, what happens when you put div inside div: https://stackoverflow.com/a/8529773/9947640
body {
font-size: 15px;
font-family: 'Open Sans', sans-serif;
background-color: #f6f6f6;
padding: 0;
margin: 0;
border: 0;
}
#logo {
width: 100%;
height: 50px;
background-color: #000;
}
#mainarea {
width: 60%;
height: auto;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
background-color: #E70A0E;
height: 250px;
overflow:auto;
}
h1 {
font-size: 1.5em;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-weight: bolder;
font-style: normal;
padding-left: 15px;
margin:auto;
}
<div id="logo">
</div>
<div style="clear: both;"></div>
<div id="mainarea">
<h1>This is a test </h1>
</div>

Related

How do I prevent padding from throwing off my DIV widths?

I have two DIVs, which I would like to stack vertically …
<div id="searchContainer”>…</div>
<div id="searchResultsContainer”>…</div>
I have the following styles assigned to them …
#searchContainer {
padding: 10px;
font-family: "Calibre", "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
background-color: tan;
width: 100%;
}
#searchResultsContainer {
background-color:cyan;
font-family: "Calibre", "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
padding: 5px 0px 5px 0px;
width: 100%;
}
However it seems that adding padding to my top DIV causes it to be wider than the DIV below it. I would like both DIVs to be the same width, but I would like the top DIV to have the padding so that the elements don’t scrunch up to the border. How do I do that? Here is the Fiddle that illustrates my problem — https://jsfiddle.net/1zb5mqmo/ .
Use box-sizing: border-box; on the padded div:
#searchContainer {
padding: 10px;
font-family: "Calibre", "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
background-color: tan;
/* max-width: 1000px; */
width: 100%;
box-sizing: border-box;
}
box-sizing: border-box The width and height properties include the content padding and border
box-sizing: content-box The width and height properties include only content
Updated JSFiddle
In this case, simply remove the width and you can combine both padding and border without throwing it off
#searchContainer {
padding: 10px;
font-family: "Calibre", "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
background-color: tan;
}
#searchResultsContainer {
background-color:cyan;
font-family: "Calibre", "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
padding: 5px 0px 5px 0px;
border: 5px solid steelblue
}
<div id="searchContainer">...</div>
<div id="searchResultsContainer">...</div>

How do I put a piece of text above another? (Using div)

I am creating a website, but the top of the website with the name and what page you are on is too far spaced out. ATM it looks like this;
Website Name
Page you're on
But I want there to not be the spaces between. I have tried using div tags to position it but whatever I do they dont move.
My code is
<!DOCTYPE html>
<html>
<title>Website name -Home</title>
<style>
body {
background-color: #3399FF;
}
h2 {
text-align: center;
font-family: 'Arial Narrow', Arial, sans-serif;
}
h4 {
text-align: center;
font-family: 'Arial Narrow', Arial, sans-serif;
}
p{
font-family: 'Arial Rounded MT Bold', 'Helvetica Rounded', Arial, sans- serif;
}
hr {
width: 100%
}
#pageTop {
position: absolute;
top: 80px;
right: 0;
width: 200px;
height: 100px;
border: 3px solid #8AC007;
}
#titleDivide{
position: relative;
}
</style>
<body>
<div #id="pageTop">
<h2>Website Name</h2>
<h4>Home</h4>
</div>
<div #id="titleDivide">
<hr />
</div>
</body>
</html>
Remove the margin from h2 and h4:
h2, h4
{
margin: 0;
}
Demo:
body
{
background-color: #3399FF;
}
h2, h4
{
text-align: center;
font-family: 'Arial Narrow', Arial, sans-serif;
margin: 0;
}
p
{
font-family: 'Arial Rounded MT Bold', 'Helvetica Rounded', Arial, sans-serif;
}
hr
{
width: 100%
}
#pageTop
{
position: absolute;
top: 80px;
right: 0;
width: 200px;
height: 100px;
border: 3px solid #8AC007;
}
#titleDivide
{
position: relative;
}
<!DOCTYPE html>
<html>
<title>Website name -Home</title>
<body>
<div #id="pageTop">
<h2>Website Name</h2>
<h4>Home</h4>
</div>
<div #id="titleDivide">
<hr />
</div>
</body>
</html>

aligning an image horizontally to the right of text in CSS within a larger Div

I need images for the Top , Middle and Bottom to be on the right hand side of the text within these divs. at the moment even though the images go right and text left the image sits below the paragraphs position. I have applyed a reset.css already as well.
Here is the relevent HTML and CSS
Index.html extract:
<Div id="background">
<div id="Space">
</div><!--spacing between divs-->
<article id="Top">
<h2>Flower arrangement</h2>
<p>Our team of professional designers will make your event memorable and stress free. We will design to your theme, colour, budget and needs with attention to detail given high priority.</p>
<img src="Images/Top_Image.gif" alt="" width="207" height="195">
<a href="#" >Read More </a>
</article>
<div id="Top_box">
</div><!--spacing between divs-->
<article id="Middle">
<h2>Seed Library</h2>
<p>Don't be afraid to try growing your own plants, you will be surprised how easy seed germination really is. A large variety of native seed mixes are offered, ideal for creating sustainable wildflower gardens.</p>
<a href="#" >Read More </a>
<img src="Images/Middle_picture.gif" alt="" width="208" height="216">
</article>
<div id="Middle_box">
</div><!--spacing between divs-->
<article id="Review">
<h2>Ran Dome said:</h2>
<p>'I have never had such an outstanding experience with such a wonderful group of people who understood my needs'</p>
<img src="Images/Review_picture.gif" alt="" width="93" height="120">
</article>
<div id="Review_box">
</div><!--spacing between divs-->
<article id="Bottom">
<h2>Sustainability</h2>
<p>Belinda Aspect founded Aspect in April 1985 and is a leading expert on green floral design. Belinda's dual passions for floral design and sustainability were merged when she decided that The Aspect would 'go green'.</p>
<a href="#" >Read More </a>
<img src="Images/Bottom_picture.gif" alt="" width="208" height="216">
</article>
<div id="Bottom_box">
</div><!--spacing between divs-->
</Div><!--background picture Div-->
style.css extract:
#background {
background-image: url(Images/background.jpg);
background-repeat: no-repeat;
width:100%;
}
#catch_line{
color: #7f6e99;
height: 50%px;
width: 57%;
margin-left: 6%;
margin-top:132px;
background-color: #000000;
border-radius: 5px;
}
#catch_line h1{
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 3.4em;
padding-top: 10px;
padding-left: 10px;
padding-bottom: 10px;
paddingtop: 50px;
color: #7f6e99;
}
article#Top, article#Review {
width: 100%;
height: 200px;
border-radius: 5px;
background-color: #7a9c52;
}
article#Middle, article#Bottom {
width: 100%;
height: 200px;
border-radius: 5px;
background-color: #2d6d18;
}
article#Top h2, article#Middle h2, article#Bottom h2 {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 1.6em;
color: #0c1306;
padding-bottom: 2%;
word-spacing: 2px;
padding-top: 3%;
padding-left: 6%;
margin right: 0px;
}
article#Top p, article#Middle p, article#Bottom p{
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 1em;
color: #0c1306;
width: 70%;
clear: none;
display:block;
padding-left: 6%;
padding-bottom: 2%;
margin right: 0px;
}
article#Top a, article#Middle a, article#Bottom a {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 0.7em;
color: #dc3646;
text-decoration: none;
clear: none;
float: left;
padding-left: 6%;
margin right: 0px;
}
article#Top img, article#Middle img, article#Bottom img{
float: right;
margin-right: 20px;
clear: none;
width: 140px;
height: 140px;
display:block;
margin left: 0px;
}
article#Review h2 {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 1.6em;
color: #0c1306;
padding-bottom: 2%;
word-spacing: 2px;
padding-top: 2.5%;
text-align: center;
}
article#Review p {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-style: italic;
font-size: 1em;
color: #0c1306;
text-align:center;
padding-left: 10%;
padding-right: 10%;
padding-bottom: 0.5%;
}
article#Review img{
margin-left: auto;
margin-right: auto;
display:block;
height: 78px;
width:62px;
}
#Space, #Top_box, #Middle_box, #Review_box, #Bottom_box{
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
height: 80px;
clear: both;
}
I am also aware that I could change it so that the articles have margins instead and get rid of the spacing divs to get the same effect as what I want from them but I'm not concerned with that at the moment.

Create a Footer Block in css

I am creating a footer block for my website. I am not an expert with css. I am looking to create a block with padding on both left and right side.
Attached is the example of the footer block, I wish to create:
However, the footer block, that I created is spanning over the entire screen. Any idea what could be wrong ?
Here is my css code :
#footer-row1{
margin-top: 80px;
padding: 1.2em 0;
background: #000;
bottom: 0;
margin-right: -33px;
font-family: "Fjalla One", Verdana, Geneva, sans-serif;
font-size: 0.95em;
text-transform: uppercase;
}
Here is the footer.html code
<div id="footer-row1">
<div id="footer-bg">
<div id="footer" class="container_24">
<div class="copyright">
#COPYRIGHT#&COPY;{var name='copyright_year'} {var name='sitename'}. {var name='footer_menu'}
</div>
</div>
</div>
</div>
Thanks
check this FIDDLE
#footer-row1{
margin-top: 80px;
padding: 1.2em 0;
background: #000;
bottom: 0;
margin-right: -33px;
font-family: "Fjalla One", Verdana, Geneva, sans-serif;
font-size: 0.95em;
text-transform: uppercase;
}
.copyright{
text-align: center;
color: #FFF;
}
Based on my understanding of the above, you can reduce a lot and get the footer from the image. All you really need is below:
CSS
footer {
padding: 1.2em 0;
background: #000;
font-family: "Fjalla One", Verdana, Geneva, sans-serif;
font-size: 0.95em;
text-transform: uppercase;
text-align:center;
/* you probably need to add some extra styles here */
}
HTML
<div class="footer">
#COPYRIGHT#&COPY;{var name='copyright_year'} {var name='sitename'}. {var name='footer_menu'}
</div>
This would place something like the image at the bottom of your content.
The css :
#footer-row1{
margin-top: 80px;
padding: 1.2em 0;
background: #000;
bottom: 0;
margin-right: -33px;
font-family: "Fjalla One", Verdana, Geneva, sans-serif;
font-size: 0.95em;
text-transform: uppercase;
//add
text-align: center;
display: block;
width: 100%;
clear: both; //because you have some float on the previous "row"
}
And add :
#footer-row1 a{ //for you link
font-family: "Fjalla One", Verdana, Geneva, sans-serif;
font-size: 0.95em;
text-transform: uppercase;
color: #3399FF; //blue for example
}
#footer-previousRow{ //the previous row with list items
display: block;
width: 100%;
height: 260px;
}
#footer-previousRow ul.listItem{
list-style: none;
list-style-type: none;
min-height: 36px;
margin: 0;
overflow: hidden;
display: block;
float: right;
}
ul.listItem li{
color: #CCCCCC;
}
And your html code for the previousRow :
<div class="footer-previousRow">
<ul class="listItem">
<li>Contact</li>
<li>Social</li>
</ul>
</div>
<div id="footer-row1"> // your actual code
<div id="footer-bg">
<div id="footer" class="container_24">
<div class="copyright">
#COPYRIGHT#&COPY;{var name='copyright_year'} {var name='sitename'}. {var name='footer_menu'}
</div>
</div>
</div>
</div>

how to stretch the header background color across the web browser?

I am having a hard time to create make the background color stretch across the browser
here is some code
body {
font-size: 1.1em;
font-family: "Myriad Pro", "Gill Sans", "Gill Sans MT", "Calibri", sans-serif;
margin: 0px auto;
padding-bottom: 25px;
width: 980px;
}
div#black_bar{
background-color: #000000;
}
div#header {
height: 66px;
font-family: arial;
margin: 0 auto;
color: #FFFFFF;
margin-top: 5px;
}
of course as you can see i have specified the width to be 980px in the body and this apply to the header of course, any ideas how to solve this
and by the way this black bar is actually a div containing the header in it
Thanks in advance.
You will need the header wrapper to be inside the body with width 100%, and to specify width=980px both on the header and content below, like this :
CSS
body, html{
width:100%;
}
div#black_bar{
background-color: #000000;
width:100%;
}
div#header {
height: 66px;
font-family: arial;
color: #FFFFFF;
margin-top: 5px;
width:980px;
margin:0 auto;
}
#content{
font-size: 1.1em;
font-family: "Myriad Pro", "Gill Sans", "Gill Sans MT", "Calibri", sans-serif;
padding-bottom: 25px;
margin: 0 auto;
width: 980px;
}
HTML
<body>
<div id="black_bar">
<div id="header">
</div>
</div>
<div id="content">
</div>
</body>