Foundation 6 - Use CSS to arrange Header image and Nav properly - html

I am using Foundation 6 to try to create a header image which overlaps part of a navigation bar. It uses the .row class as a responsive div.
HTML
<header class="row text-center">
<a href="//google.com">
<img src="path/to/horizontal banner image">
</a>
</header>
<nav>
<div class="row text-center">
Text here
</div>
</nav>
CSS
header{
background-color: lightgreen;
}
nav{
margin-top: -5%;
font-size: 150%;
background-color: lightblue;
}
http://jsfiddle.net/hvmt2j1j/
As illustrated in the above fiddle, I have an image and a nav bar that includes links. The image itself is a link too.
However I found out that:
when the screen size is large, the text goes upward and does not not
align with the image properly anymore.
In some browsers the image link overlaps the nav bar link. I would like to restrict the clickable area of the image to the green area only.
I am quite new to this, therefore I believe there is probably a better way to structure the <div> tags or CSS to achieve this. Thank you very much.

My proposition:
body {
margin: 0;
}
header {
background-color: #6C6;
background-image: url("http://sweetclipart.com/multisite/sweetclipart/files/imagecache/middle/banner_white.png"), url("https://i.imgur.com/TILTsNC.png");
background-repeat: no-repeat, repeat-x;
background-position: top center, bottom;
height: 189px;
max-width: 100%;
width: 550px;
}
.green {
display: block;
height: 80%;
}
.blue {
display: block;
font-size: 2em;
height: 20%;
text-align: center;
text-decoration: none;
}
<header>
<a class="green" href="https://www.google.com/"></a>
<a class="blue" href="https://www.yahoo.com/">Text here</a>
</header>
You define a header with just two <a> elements that you treat as block (flow in HTML5) content, meaning they will behave just like divs, but will be clickable of course, because they are still links after all. To do so, you got to give them display: block style. Then you need to stack two backgrounds for <header>. First one is your picture and the second one is lightblue color with width of 1px and height of desired blue area height (in this case 20% of 189px). More info on Using CSS multiple backgrounds (MDN).

Related

Why is my button overflowing into another page?

Here is a picture example of what is happening.
I'm trying to build one of those one-page scrolling websites.
The white background indicates one page, the grey background indicates the beginning of another page.
As I start filling my white page with content, I notice that my button slowly starts sliding down and is now encroaching into the grey page. I don't want that to happen but rather for the white page to extend.
Here is my CSS for the pages:
#white-page
{
background-color: white;
height: auto;
min-height: 100vh;
text-align: center;
}
#grey-page
{
background-color: grey;
min-height: 100vh;
}
Here is my CSS for the button.
.download-center
{
text-align: center;
margin-top: 60px;
}
.btn
{
text-decoration: none;
border: 1px solid gray;
padding: 10px 20px 10px 20px;
border-radius: 25px;
color: inherit;
}
Here is the relevant HTML
<section id="white-page">
//page content here
<div class="download-center">
<a class="btn font-r" href="docs/resume.pdf" target="_blank">
<img id="download-pic" src="pic/download.svg" />Download R&eacutesum&eacute
</a>
</div>
</section>
<section id="grey-page">
//page content here
</section>
I tried setting the height to auto for the white page but it doesn't seem to work.
Basically, I just want the page to extend as the content requires but with a minimum of vh so that it takes up the whole of the screen first.
Edit: By removing the margin-top property, here is the result. All it does it pushes the button closer to my content but still encroaches on the page borders.
The reason is you have restricted height and used margin-top:
.download-center {
text-align: center;
margin-top: 60px;
}
Adjusting margin-top to a lesser value, say 30px will make the button stay inside.
Reduce margin from top and add position as like:
.download-center {
text-align: center;
margin-top: 40px;
position: absulote;
}
I'm answering my own post because removing margin-top was not the solution that worked for me. Instead, it was increasing margin-bottom.
margin-bottom: 40px;

Styling html5 navigation bar

I would like to style up my navigation bar, so it would look like this one nav bar on the picture. I have already startet and on the jsfiddle link below you are able to see what I have so far and as you can also see, that there are still a couple of things to fix.
It is important for me to align all elements to the same line, because I will maybe add some more elements to it (e.g. input field and button)
I would also like to have a background in two colors like on the picture. Lets say 30% purple, 70% black.
I have chosen T-Mobile logo image on purpose, because it is originaly very big. I have succeded to resize and fit it to the nav, however I would also like to ask if this is the right/best thing to do.
Thx in advance
https://jsfiddle.net/amsalk/y6km93gm/
body {
background: #EEE;
}
div#wrapper{
margin: auto;
background: white;
width: 800px;
height:2000px;
}
#horizNav {
display: block;
padding: 10px 10px 10px 10px;
background: black;
}
img {
max-height: 50px;
vertical-align: middle;
}
h3 {
color: white;
display: inline-block;
float: right;
}
<body>
<div id="wrapper">
<nav id="horizNav">
<img id="pageLogo" src="http://intranet.t-mobile.at/intranet/arbeitsplatz/T_Logo_magenta_schwarz_Brandneu_RGB.jpg" />
<h3>Title</h3>
</nav>
</div>
</body>
I am not writing whole html and css for you but follow these examples
http://fortawesome.github.io/Font-Awesome/examples/

How to center [image + text] of unknown width?

This is the header of my page:
--------------------------------
Logo | fixed | Title with
Image | margin | unknown width
--------------------------------
I want to horizontally center the whole header in my page. Currently I set the logo image as the background image of a container and wrap the title in the container.
HTML is:
<header role="banner">
<div class="logo">
<h1>Title</h1>
</div>
</header>
CSS is:
header[role="banner"] .logo{
height: 76px;
background: url(/images/logo.png) no-repeat;
}
.logo h1{
line-height: 76px;
text-indent: 96px;
}
Before you answer please notice that the hard parts of this problem are:
The width of title is unknown.
There is a logo image to the left of the title. Only centering the title is what I already know how to do but not what I want. Centering the image is just wrong — [logo + title] is to be centered, logo should not be centered in the header.
I'm not sure if your HTML is the best way of having a logo and page title. I'd personally go with an <img> for the logo.
You can use the display: table and display: table cell for centering without knowing the width.
Here's how I'd do it with the image for a logo:
HTML
<header role="banner">
<div class="extra-container">
<div class="logo">
<img src="http://placehold.it/100x76" alt="Logo Image" />
</div>
<h1>Title</h1>
</div>
</header>
CSS
header[role="banner"] {
display: table;
margin: 0 auto;
}
header[role="banner"] .extra-container {
display: table-cell;
}
header[role="banner"] .logo {
margin-right: 40px;
float: left;
}
header[role="banner"] .logo img {
display: block;
}
h1{
line-height: 76px;
display: inline-block;
}
http://jsbin.com/UhIqUXe/1/edit
You don't need the <div> to be honest. Make the background of the <header> your background image like this:
header[role="banner"] {
background: url(/images/logo.png) center top no-repeat;
width: 100%;
height: 76px;
}
And to center your title put text-align: center;
The header will need to have a width specified in order for the margin trick to work. If you don't know the exact width you could use a percentage for the header tag.
Have a look at this source CSS-Trick
The best way should be set margin..
margin:0px auto 0px auto;
this will set margin of top and bottom to 0px and right and left to auto,
this will trick the wrapperDiv in center( the container of image or text)

Repeat image to extend header to fill screen

I have a Header (2300x328px) and another image (456x328px). Now I want this second image to extend this header to the left and right, that the header fills the whole width availiable.It needs to connect without overlapping, because there is a pattern.
Here is an image of what I mean: http://imgur.com/0ji3Hae
The circles are the pattern (why it should not overlap) And the Images to extend the header can be repeated infinitely.
For the pattern to align exactly you need to align the background pattern according to the header image (ex. center, left etc) and then make sure the pattern starts at the right place.
I made a fiddle to explain what I mean - http://jsfiddle.net/taneleero/g99xa/
.header {
background:url(http://i.imgur.com/BzVtzl4.jpg) repeat-x center;
}
.header img {
display:block;
margin:0px auto;
}
You have to add div bot sides with repeat-x.
I make an example for you on jsFiddle.
Html:
<div id="header">
<div class="extend"></div>
<div id="logo"></div>
<div class="extend"></div>
</div>
css
#header {
display: inline-block;
border: 1px solid black;
}
#header div {
display: inline-block;
}
.extend {
background-image: url('http://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Google_Chrome_icon_(2011).svg/64px-Google_Chrome_icon_(2011).svg.png');
height: 60px;
width: 100px;
}
#logo {
background-image: url('http://upload.wikimedia.org/wikipedia/he/3/3f/Microsoft_Outlook_Icon.png');
width: 64px;
height: 64px;
}
jsFiddle
// markup
<div id="header" style="height: 200px;"></div>
// css
#header {
background: url(images/preloader-w8-cycle-black.gif) repeat-x;
}

How to center logo background img and text in header?

I'm stumped by something that feels like it should be simple!
I'm trying to center a logo in the centre of a <header>. The logo is made up of an <a> with a background image which is the logo icon and the anchor text is the logo name. I have the logo icon centred using margin: 0 auto; on the <h1> but can't find a good solution to centering the icon and the text together as one unit.
<header>
<h1>
Logo Name
</h1>
</header>
CSS:
header h1 {
height: 54px;
width: 54px;
background: url('../img/logo.png') no-repeat left;
margin: 0 auto;
}
a.logo {
font-size: 33px;
margin: 0 auto;
display: block;
padding-top: 20px;
}
Any ideas?
I usually do it like this:
<style>
.logo{
margin: 0px auto;
padding-left: 120px; /* the space between the start of your logo and your text */
padding-top: 30px; /* the vertical space between the top and your text, to center the logo*/
display: block; /* very important since normally anchors are inline */
background: url(path/to/logo.png) top left no-repeat; /* obviously :) */
}
</style>
It really don't need to be inside an h1.
When you see results, yo may not see it centered, well, measure your unit, and specify a width and a height inside the .logo rules above.
you can position the background using css.
background-position:center;
you can also define it by pixels or percent
background-position:20px 50px;
background-position:50% 50%;
you have put background url left it should be center
try this
background: url('../img/logo.png') no-repeat center;
This might work.
<header style="align:center">