I don't understand why the background image of my h1 has a gap at its top and bottom. I've searched around and can't someone else with a similar issue. I've tried a bunch of different properties, but it doesn't change. I have a feeling it has something to do with it being inside an h1, but that's all I got. Any help is appreciated;I'm a beginner.
Here's my code
<h1>K&C Transmission</h1>
<div class="topnav" id="myTopnav">
Home
Contact
Services
☰
</div>
.topnav {
background-color: darkblue;
overflow:hidden;
border:6px solid black;
margin-top:0px;
}
.topnav a {
float:left;
color:yellow;
text-align:center;
padding: 14px 20px;
text-decoration:none;
font-size:17px;
}
h1 {
text-align:inherit;
background-image: url("https://s9.postimg.org/tdjelhj1r/IMG_0090.jpg");
height:280px;
width:100%;
margin:0;
background-position:center;
background-size:cover;
background-repeat:no-repeat;
font-size:50px;
position:relative;
top:0px;
margin-bottom:0px;
vertical-align: top;
}
And here's the jsfiddle:
enter link description here
--Again, the problem does not exist on jsfiddle. I don't know why it does on Atom.
Try this.
* {
box-sizing: border-box;
}
h1 {
margin : 0;
padding: 0;
}
We would need the css applied to your site to get the exact answer, but have you set the following options in your css
body{
margin: 0;
padding: 0;
}
h1{
margin: 0;
padding: 0;
}
Yes, it should just be an image in the tag. The image will display at the top of the page.
Also, no point in displaying H1/Title again over the image, since the picture is descriptive enough.
Definitely give yourself a credit for using a good quality image, since you're a beginner.
<h1>K&C Transmission</h1>
<div class="topnav" id="myTopnav">
Home
Contact
Services
☰
</div>
<style>
.topnav {
background-color: darkblue;
overflow:hidden;
border:6px solid black;
margin-top:0px;
}
.topnav a {
float:left;
color:yellow;
text-align:center;
padding: 14px 20px;
text-decoration:none;
font-size:17px;
}
h1 {
text-align:inherit;
background-image: url("/Volumes/BEAR/KandC Transmission/Media/IMG_0090.jpg");
width:100%;
margin:0;
background-position:center;
background-size:cover;
background-repeat:no-repeat;
font-size:50px;
position:relative;
top:0px;
margin-bottom:0px;
vertical-align: top;
}
</style>
Try this code,it will work.I removed height from h1 tag.
Related
I was wondering if anyone could help me with an issue I'm having. I wanted the text "Liam's Digital Portfolio" to be in the centre of the webpage at the top in line with the navigation bar text. In addition, I then wanted the navigation bar to be on the far right hand corner as shown within the codepen link http://codepen.io/ldocherty1/pen/qRowVK.
I have only started programming and this is my second day and really want to improve, apologies if the code is not in the correct structure.
Below is my HTML code, within the codepen is my CSS if needed.
<div id="Navagationbar">
<ul>
<li><b>HomePage</b></li>
<li><b>Portfolio</b></li>
<li><b>Contact Us</b></li>
<li><b><center>Liam's Digital Portfolio<center></b></li>
</ul>
</div>
</body>
</html>
Thanks,
Liam.
I wish you all the best with your coding journey :) I will give you an easy solution to get the desired effect. First off, cut the padding-top from the body in the css:
padding-top: 180px;
Now from your html, remove
<li><b><center>Liam's Digital Portfolio<center></b></li>
Since this is your page title, it is standard practice to have it inside of h1 tags. Then we can center it with simple css. The html will look like this:
<h1 class="title">Liam's Digital Portfolio</h1>
<div id="Navagationbar">
<ul>
<li><b>HomePage</b></li>
<li><b>Portfolio</b></li>
<li><b>Contact Us</b></li>
</ul>
</div>
And now we can simply add this to the css
.title{text-align:center;}
With the padding-top removed and this added, the title will be in the center of the page inline with the navigation bar. I see you have a lot of issues with your css so I suggest you go through a good tutorial, like this one from w3schools http://www.w3schools.com/css/ . I hope this helps, and good luck!
Make the HTML changes as below
<ul>
<li><b>HomePage</b></li>
<li><b>Portfolio</b></li>
<li><b>Contact Us</b></li>
<li style="position:absolute;right:45%"><b>Liam's Digital Portfolio</b></li>
</ul>
CSS changes as below
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
h1 {
font-family:Arial;
color:white;
font-size:10pt;
text-align:center;
}
li a:hover:not(.active) {
background-color:grey;
}
#Navagationbar {
font-family:Arial;
color:white;
font-size:10pt;
text-align:center;
}
#Navagationbar ul {
list-style:none;
float:right;
margin:0;
padding:0;
}
#Navagationbar ul li {
display:block;
list-style:none;
margin:0;
padding:0;
}
#Navagationbar ul li a {
display:block;
margin:0 0 0 1px;
padding:3px 10px;
color:white;;
text-decoration:none;
line-height:1.3em;
}
#Navagationbar ul li a:hover {
color:white;
}
#Navagationbar ul li a.active,
#Navagationbar ul li a.active:hover {
color:white;
}
body {
margin:0;
}
.page{
min-height:-590px;
background:linear-gradient(45deg, #999, #FFF);
}
#footer{
list-style:none inside none;
margin:0;
padding:0;
position:fixed;
right:0;
bottom:0;
left:0;
height:50px;
background-color:#1f1f1f;
font-size:0;
}
#footer li {
font-family:Arial;
float: right;
color:white;
font-size:10pt;
display:inline-block;
text-align:center;
height:50px;
padding:0 20px;
line-height:3.3;
border-right:1px solid #000;
border-left:1px solid #333;
}
#footer li {
font-family:Arial;
float: left;
color:white;
font-size:10pt;
display:inline-block;
text-align:center;
height:50px;
padding:0 20px;
line-height:3.3;
border-right:1px solid #000;
border-left:1px solid #333;
}
#footer li:last-child {
border-right:0;
}
body {
background:url('https://static.pexels.com/photos/34088/pexels-photo.jpg');
position:static;
height:400px;
background-attachment:fixed;
background-repeat:no-repeat;
background-size:cover;
}
I'm building myself website in a class that I am taking at my school. I had to design what I wanted my site to look like, and now I have to build it.
I've found a stylesheet I really like, "Roboto Slab", and I have a background. I've got most of the main page done, actually.
I keep running into this one error when trying to format my text. I'm trying to make the text in the EXACT center of the web page, and it's a little lower than center. Not only that, but it gives the option to scroll left and right, and there is no reason that I can see for it to be doing that.
Here's the code for the site.
<html>
<head>
<title>MySite</title>
<meta name="description" content="My Site.">
<link rel="stylesheet" href="core.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>html,body,.do-you-even-flexbox{
height:100%;
} body {
margin:0;
font:normal 14px/1.2 "Roboto", Helvetica, Arial, sans-serif;
text-align:center;
background:#111 url('http://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Alpamayo.jpg/1280px-Alpamayo.jpg') center top/ cover;
}::-moz-selection {
background:#2fdd11;
color:#fff;
}::selection {
background:#2fdd11;
color:#fff;
} a {
text-decoration:none;
}a:hover, a:active{
outline:none;
text-decoration:underline;
}a:focus {
outline:thin dotted;
}.do-you-even-flexbox,.container {
position:absolute;
top:50%;
width:100%;
height:1em;
margin-top: -.5em;
}.container {
padding:8px 20px 15px;
}h1, h2 {
font-family:"Roboto Slab",Helvetica,Arial,sans-serif;
margin:0;
color:#000;
font-weight:400;
font-size:96px;
}.social{
margin-top:30px;
}.social a {
background-color:#F5F7FA;
border-radius:35px;
margin:0 3px;
width:26px;
height:26px;
padding:16px;
display:inline-block;
-webkit-transition:background-color .6s ease;
transition:background-color .6s ease;
}.social a:hover,.social a:focus {
outline:none;
background-color:#FC6E51;
}.icon{
width:26px;
height:26px;
}.icon>path{
fill:#111;
}.links{
color:#333;
margin-top:30px;
}.links a{
display:inline-block;
padding:0 5px;
color:#000;
}.links {
color:#000;
}.links a:hover{
color:#000;
} #media (max-width: 660px) {
h1{
font-size:64px;
}h2 {
font-size:24px;
}
} #media (max-width: 460px) {
.do-you-even-flexbox {
display:none;
}.container{
margin:0 auto;
margin-top:4%;
}.links a{
display:block;
}h1{
font-size:48px;
}h2{
font-size:16px;
}
} #media (max-width: 350px) {
h1{
font-size:40px;
}
}
</style>;
</head>
<body>
<i class="do-you-even-flexbox"></i>
<div class="container">
<h1>Hi.</h1>
<h2>This is the website for my independent study.</h2>
<div class="links">
Example Page.
Another Page.
Another page! :D
Blah blah
</div>
</div>
</body>
</html>
What am I doing wrong with this? I've tried using the align: center methods, but none of those have worked for me.
!! EDIT !!
Fixed font size issue. Yay me. Just created a new section in the CSS code for H2.
You need to add a div for that center content, see html
<i class="do-you-even-flexbox"></i>
<div class="container">
<div class="box">
<h1>Hi.</h1>
<h2>This is the website for my independent study.</h2>
</div>
</div>
<div class="links"> Example Page.
Another Page.
Another page! :D
Blah blah
</div>
then you can center that div (I named it "box") with CSS using flex-box model
html, body, .do-you-even-flexbox {
height:100%;
width:100%;
overflow-x:hidden;
}
body {
margin:0;
font:normal 14px/1.2"Roboto", Helvetica, Arial, sans-serif;
text-align:center;
background:#111 url('http://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Alpamayo.jpg/1280px-Alpamayo.jpg') center top/ cover;
}
::-moz-selection {
background:#2fdd11;
color:#fff;
}
::selection {
background:#2fdd11;
color:#fff;
}
a {
text-decoration:none;
}
a:hover, a:active {
outline:none;
text-decoration:underline;
}
a:focus {
outline:thin dotted;
}
.do-you-even-flexbox, .container {
position:relative;
top:0;
width:100%;
height:100%;
}
.container {
padding:8px 20px 15px;
display:flex;
align-content:center;
}
.box {
height:20%;
margin:auto
}
h1, h2 {
font-family:"Roboto Slab", Helvetica, Arial, sans-serif;
margin:0;
color:#000;
font-weight:400;
font-size:24px;
}
.social {
margin-top:30px;
}
.social a {
background-color:#F5F7FA;
border-radius:35px;
margin:0 3px;
width:26px;
height:26px;
padding:16px;
display:inline-block;
-webkit-transition:background-color .6s ease;
transition:background-color .6s ease;
}
.social a:hover, .social a:focus {
outline:none;
background-color:#FC6E51;
}
.icon {
width:26px;
height:26px;
}
.icon>path {
fill:#111;
}
.links {
color:#333;
margin-top:30px;
}
.links a {
display:inline-block;
padding:0 5px;
color:#000;
}
.links {
color:#000;
}
.links a:hover {
color:#000;
}
#media (max-width: 660px) {
h1 {
font-size:64px;
}
h2 {
font-size:24px;
}
}
#media (max-width: 460px) {
.do-you-even-flexbox {
display:none;
}
.container {
margin:0 auto;
margin-top:4%;
}
.links a {
display:block;
}
h1 {
font-size:48px;
}
h2 {
font-size:16px;
}
}
#media (max-width: 350px) {
h1 {
font-size:40px;
}
}
I made your heading tags smalles so you can see the effect, but you will need to adjust that to your needs and also you may need to adjust box height, but you'll get the idea. See fiddle here
h1 and h2 have the same size because your CSS file is included before the <style> tag, which defines h1 and h2 to have font-size: 96px. Just move the line
<link rel="stylesheet" href="core.css">
after <style> ... </style>.
I edited your code in a fiddle. I took out a lot of your, already defined code, but you can simply add that back in there. I think this will give you a good start of what you want to accomplish.
JSFiddle
HTML:
<div id="wrapper">
<div id="container">
<div id="centerText">
<h1>Hi.</h1>
<h1>This is the website for my independent study.</h1>
</div>
</div>
</div>
<footer>
<div class="footer">
Example Page.
Another Page.
Another page! :D
Blah blah
</div>
</footer>
CSS:
html {
background: url('http://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Alpamayo.jpg/1280px-Alpamayo.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
h1 {
padding: 0;
margin: 0;
}
body {
overflow-x: hidden;
}
footer {
bottom: 0;
position: fixed;
width: 100%;
}
.footer {
height: 25px;
margin: auto;
width: 400px;
text-align:center;
padding: 10px;
color:#ffffff;
}
#wrapper {
height: 200px;
width: 500px;
bottom: 50%;
right: 50%;
position: absolute;
font-family: tahoma;
font-size: 8pt;
font-weight: bold;
}
#container {
left: 50%;
padding: 10px;
top: 50%;
margin: 0;
padding: 0;
height: 100%;
height: 100%;
position: relative;
}
#centerText {
position: absolute;
width: 100%;
height: 20px;
top: 50%;
margin-top: -10px;
text-align: center;
}
This is the HTML Can someone please help me? I can't remove the little margin above the navigation.
I've already tried padding:0px and margin-top:0px
<body>
<div id="wrap">
<div class="top_portion">
<img src="img/icbox.png">
</div>
<div id="welcome">
<h1>Welcome to my blog about the married life</h1>
<h3>Ain't much to see here for now!</h3>
</div>
<div id="navigation">
<ul>
<li><a href="#Home">Home</li>
<li><a href="#About">About</li>
<li><a href="#Pictures">Pictures</li>
</ul>
</div>
</div>
</body>
</html>
AND THIS IS THE CSS Sorry it's been a while since I've been back to this website
body {
background-color:white;
font-family: 'Josefin Slab', serif;
}
.top_portion {
width:800px;
height:200px;
background-color:#e2e2e2;
margin:auto;
text-align:center;
border-top:5px;
border-bottom:5px;
border-left:0px;
border-right:0px;
border-style:solid;
border-color:#30474b;
}
.top_portion img {
padding-top:35px;
}
#welcome h1 {
margin-top:0px;
text-align:center;
padding:0px;
margin-bottom:0px;
}
#welcome h3 {
margin-top:0px;
text-align:center;
}
#welcome {
font-family:sans-serif;
margin:auto;
background-color:#e2e2e2;
width:800px;
}
#navigation {
text-align:center;
}
#navigation li {
list-style-type:none;
display:inline;
}
ul {
margin-top:0;
}
ul a {
padding-right:20px;
text-decoration:none;
}
ul a:hover {
text-decoration:underline;
}
It is the h3
Margin:0; does the trick.. Where did you aply the margin:0; earlier?
h3 {margin:0;}
In your case you should change your #welcome h3 to:
#welcome h3 {
margin: 0;
}
DEMO
Try This:
I think its because of the default behavior of Heading.
Style:
html, body
{
padding: 0;
margin: 0;
}
#welcome h3 {
margin-top:0px;
margin-bottom:0px;
text-align: center;
}
/*Or you can try
#welcome h3 {
margin:0;
text-align: center;
}*/
Here is the Demo
I have changed these things in your query
#navigation {
text-align:center;
margin-top:0px;
}
#welcome h1 {
margin-top:0px;
text-align:center;
padding:0px;
margin-bottom:0px;
}
#welcome h3 {
margin-top:0px;
text-align:center;
margin-bottom:0px;
}
workingFiddle
Since you want to remove margin from the top for your navigation bar you could possibly try this:
#navigation {
margin-top: 0px;
border-top: 0px;
}
As, you are including list in your navigation it may eat up some of your space too. Try including this:
#navigation li {
margin-top: 0px;
}
Possibly, you can also try for:
#welcome h3 {
margin: 0px;
margin-bottom: 0px;
}
H3, because this would hold just the line above your navigation bar
*{
margin:0;
padding:0;
border:0;
font-family: Helvetica, sans-serif;
-webkit-text-size-adjust:none;
}
#menubar * { padding: 0; margin: 2; }
body { padding: 5px; font-family: Helvetica, Arial, sans-serif; width:95%; font-size:12px}
#menubar ul{
text-align:center;
}
#menubar ul li { display:inline-block; padding: 2px; position: relative; margin-left:-10px; margin-right:-20px; margin:invisible; }
#menubar ul a { display: table-cell; vertical-align: middle; width: 80px; height: 30px; text-align:center; background: #FFF; color:#000; border-style: solid; border-width:2px; border-color:#1570a6; text-decoration: none; }
#menubar li:after{
border-left:50px solid black;
border-right:60px solid black;
content:"";
position:relative;
left:-12px;
top:-18px;
z-index:-1;
display:block;
height:1px;
}
Ive got this code on the header and ive set the margin and border to 0 but im still getting a blank white space on the sides when i preview the webpage. Any suggestions?
This is the webpage that i have made and its for mobiles so if you want to get the proper user experience you could browse it with your mobile phone http://obdkey.comyr.com/Home.html
this is a temporary domain for the website
Your body still has 5px padding on it, set it to:
body {
padding:0px;
}
You have a
<br />
that's causing the white space at the bottom of the page.
Also your width is set to 95%, which is causing the space on the right.
Unsure as to whether that's intentional or not, but thought it worth a mention in case you were trying to get rid of that white space as well.
body { padding: 5px;
this may be your problem, try removing this attribute.
OK, so if you check out http://www.marioplanet.com you can see that I am trying to mimic the design of apple.com for my menu bar, including my global search bar.
Now, I'm trying to mimic Apple's input field for the global search bar, as close as I possibly can, so I need some help here.
I would like the field to be centered in the middle, which I tried by using maring: auto auto; but that did not work..
I also would like to use the rounded corner technique, from Apple's site, but I'm not sure how to do that. Is that CSS3?
I also need to have a grayed out placeholder string reading Search but I think I may be able to use JS for that. If can use HTML or CSS, please let me know.
The little spotlight / magnifying glass image aligned to the left side of the input field is nice, but not necessary :)
OK, you can check out the site, but here is the code as well:
index.htm:
<div id="globalheader" class="apple">
<!--googleoff: all-->
<ul id="globalnav">
<li id="gn-home">Home</li>
<li id="gn-catalog">Shop!</li>
<li id="gn-about">About</li>
<li id="gn-contact">Contact</li>
<li id="gn-media">Media</li>
</ul>
<div id="globalsearch">
<form id="searchform">
<div>
<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" />
</div>
<div id="suggestions"></div>
</form>
</div>
<!--googleon: all-->
</div>
default.css:
body {
background-color: #666666;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
#header {
background-color: #DDDDDD;
width: 1130px;
margin: 0px auto;
}
#content {
width: 1130px;
margin: 0px auto;
}
#leftcol {
background-color:#EBEBEB;
width: 200px;
height: 550px;
font-size:14px;
clear: both;
float: left;
}
#detail {
background-color:#FFFFFF;
width: 730px;
height: 550px;
font-size:12px;
float: left;
}
#rightcol {
background-color:#EBEBEB;
width: 200px;
height: 550px;
font-size:14px;
float: left;
}
#footer {
background-color:#DDDDDD;
width: 1130px;
height:90px;
font-size:12px;
text-align:center;
clear: both;
margin: 0px auto;
}
h1 {
color: #FF0000;
}
h2 {
color:#FF0000;
}
a:link {
color:#FF0000;
}
a:visited {
color:#FF0000;
}
a:hover {
color:#00FF00;
}
a:active {
color:#FF0000;
}
img {
border:none;
}
#eznetseal {
text-align:center;
}
a.trayIcon {
position: relative;
top: 20px;
}
a.trayIcon:hover {
top: 7px;
}
#twittericon {
left: 0px;
}
#facebookicon {
left: 22.5px;;
}
#youtubeicon {
left: 45px;;
}
#tray {
position:relative;
}
#container {
position:relative;
margin-top: -40px;
}
#nav li
{
display: inline;
}
#features
{
vertical-align: top;
}
globalsearch.css:
/* BASIC RESET */
body, div, img, p { padding:0; margin:0; }
a img { border:0 }
/* HTML ELEMENTS */
body { font-family:"Lucida Grande","Lucida Sans Unicode",Arial,Verdana,sans-serif; }
/* COMMON CLASSES */
.break { clear:both; }
/* SEARCH FORM */
#searchform { margin:auto auto; font-size:18px; }
#searchform div { color:#eeeeee; }
#searchform div input { font-size:18px; width:120px; }
#suggestions{ position: relative; left:235px; width:320px; display:none; }
/* SEARCHRESULTS */
#searchresults { border-width:1px; border-color:#919191; border-style:solid; width:320px; background-color:#a0a0a0; font-size:10px; line-height:14px; }
#searchresults a { display:block; background-color:#e4e4e4; clear:left; height:56px; text-decoration:none; }
#searchresults a:hover { background-color:#b7b7b7; color:#ffffff; }
#searchresults a img { float:left; padding:5px 10px; }
#searchresults a span.searchheading { display:block; font-weight:bold; padding-top:5px; color:#191919; }
#searchresults a:hover span.searchheading { color:#ffffff; }
#searchresults a span { color:#555555; }
#searchresults a:hover span { color:#f1f1f1; }
#searchresults span.category { font-size:11px; margin:5px; display:block; color:#ffffff; }
#searchresults span.seperator { float:right; padding-right:15px; margin-right:5px;
background-image:url(../images/shortcuts_arrow.gif); background-repeat:no-repeat; background-position:right; }
#searchresults span.seperator a { background-color:transparent; display:block; margin:5px; height:auto; color:#ffffff; }
Thanks!
On the div containing the textbox try text-align: center; border-width: 0px; margin-top: 6px; to do the watermark try a jquery watermark plugin
For the rounded corners apple are inserting images into spans either end. I have seen the magnifying glass done this way or by setting the image as a background-image and adding padding to avoid overwriting it.
If I were you id download firebug for firefox so you can explore the markup and css yourself, it's quite easy.
Hope this helps.
I used Firebug and Web Developer extension to find following...
Apple definately use javascript ( and of course css) to make that search box look preety.
if you turn of javascript using noscript you will see a normal square text box.
you can check following javascript and css files to figure out whats going on.
http://images.apple.com/global/scripts/search_decorator.js
http://images.apple.com/global/nav/styles/nav.css
in css files take a look at following rule set
#globalsearch .search-wrapper .left
and
#globalsearch .search-wrapper .right
following are the images used to create the search box
http://images.apple.com/global/nav/images/searchfield_leftcap.png
http://images.apple.com/global/nav/images/searchfield_rightcap.png
I found following interesting things.
They have dedicated script file just to make that search box look pretty
They do not use image sprites.
I tried to smush one of the above images and was able to smush it by 15% ( it might look trivial but when you are looking at website visited by millions this can become a big number )