RoR - Banner Image below navigation not behind - html

Have some basic trouble trying to get the image to sit below the navigation. At the moment it sits behind the navigation.
Each basic page will have a unique image for About Us, Contact Us, Term
Basic page HTML setup:
<header>
<div class="basicbanner">
<%= image_tag("1280x400-about.jpg", style: "background-image", class: "img-responsive", alt: "Diving Image") %>
<div class="container">
<div class="row">
<div class="basicbanner-title center">
<h1>About us</h1>
</div>
</div>
</div>
</div>
</header>
CSS Setup for Banner Postion:
.basicbanner {
min-height: 400px;
position: relative;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
.basicbanner-title {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 620px;
h1 {
text-transform: uppercase;
color: white;
}
}
With this setup it sits behind the nav still and trying to get it to sit below.
Not understanding where the conflict is happening and tried few methods as shown in the styling below.
Navbar CSS
.navbar {
border: 0px solid rgba(0, 0, 0, 0);
background: #70cbce;
//background: transparent;
margin: auto;
min-height: 60px;
padding-top: 10px;
position: fixed;
//top: -60px;
}
.navbar.open {
top: 0;
}
.navbar-inverse .navbar-nav > li > a, .navbar-nav a {
color: #fff;
font-size: 14px;
text-align: center;
vertical-align: middle;
line-height: 60px;
//letter-spacing: 1px;
}
.navbar-inverse .navbar-nav > li > a:hover {
color: #0a4f6f;
opacity: 0.6;
}
.nav > li > a {
position: relative;
display: block;
padding: 10px 10px;
}
.navbar-inverse .navbar-collapse, .navbar-inverse .navbar-form {
border-color: #4ec3cd;
}
.navbar-inverse .navbar-toggle {
border-color: transparent;
}
/* HEADER AND LOGO*/
.header{
padding-top:40px;
padding-bottom:50px;
width: 100%;
font-size:18px;
}
#logo {
float: left;
//margin-right: 10px;
//font-size: 1.7em;
//color: #fff;
//text-transform: uppercase;
//letter-spacing: -1px;
margin-top: -10px;
//font-weight: bold;
}
#logo:hover {
color: #fff;
text-decoration: none;
}
So need to get it to sit below the nav and also work responsively.

sorry, but it is not very clear to me what you are trying to obtain. Why are you keeping the image_tag over the navigation? The navigation html code should be on top, the image below the navigation. Then you can set the following properties:
overflow: hidden;
z-index : a negative or positive number;
z-index will make the different divs, that overflow, stay one over the other to show up. If you want to have the navigation overflow over the image with a trasparent background, the navigation should have
z-index: +1;
So that, when you hover with the mouse on the navigation the hover css style will work. The image should have:
z-index: -1;
Additionally you should position the two divs one over the other, I have used:
position: relative;
margin-top: -70px;
With position relative the div will be positioned relatively to the parent div, if you set this correctly could be the nav div, then with margin-top negative you will bring the image up, to overflow with the navigation div. In my case my navigation div had a 70px height so i used -70px, you should also check if the div has margin and padding.
I hope i did not miss anything and I have sometimes problems with the different windows sizes, so i use mediaqueries. For any additional information you can ask me, still there are tutorials online on how to do this, but I could not find them in my latest search.
Please do not downvote me if i totally misunderstood your requirement, I just though this was what you are trying to achieve.
Thanks
Best Regards
Fabrizio Bertoglio

Related

CSS: How do I get the nav to work if it's positioned inside the image

I'm a CSS novice in need of some help. I need to display a header image and have a working dropdown nav menu sit inside the bottom right of the image. I went ahead and created the nav and used a negative margin to position it so that it appears at the bottom of the background image. The hover effect in the nav is clearly not working. And it has to do with it being inside the image. So how do I get the nav to work if it's positioned inside the image? Or is there a better way to display the nav in the image's bottom right? Thank you for your help!
Here's the code:
.img {
background-image: url("https://raw.githubusercontent.com/bfoley-teamug/misc_images/master/section_header_ip.png");
min-height: 300px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
.container {
float: right;
margin: -40px 0;
}
#topnav {
overflow: hidden;
background: transparent;
font-weight: 600;
text-transform: uppercase;
}
#topnav a {
color: #000;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 18px;
}
#topnav a:hover {
background-color: #ddd;
color: red;
cursor: pointer;
}
<div class="img">
</div>
<div class="container">
<div id="topnav">
Home
Link 2
Link 3
Link 4
Link 5
</div>
</div>

Placing text in a background header

I have a bigger HTML header containing a menu and a large picture.
I would like to place text on the image somewhere as a "title" to the page.
Whenever I try to add my <h1> tag somewhere, it positions the text above the menu and it's not what I want.
I would like to be able to position any form of tags somewhere in the picture and I am struggling to find a solution as my code is not efficient to do this.
I am starting to understand what my problem is but I cannot find a solution.
Here is a template of what's going on. I want to place the text somewhere next to my face (as weird as it sounds lol), anyone?
body {
font: 15px/1.5 Gravity, Arial;
padding: 0;
margin: 0;
}
header {
width: 100%;
height: 800px;
background: url('../img/web_bg.jpg');
background-size: cover;
}
.logo {
line-height: 60px;
position: fixed;
float: left;
margin: 16px 46px;
color: #000;
font-weight: bold;
font-size: 20px;
letter-spacing: 2px;
}
nav {
z-index: 100;
position: fixed;
width: 100%;
line-height: 60px;
}
nav ul {
line-height: 60px;
list-style: none;
background: rgba(0, 0, 0, 0);
overflow: hidden;
color: #fff;
padding: 0;
text-align: right;
margin: 0;
padding-right: 40px;
transition: 1s;
}
nav.black ul {
background: #fff;
z-index: 100;
}
nav ul li {
display: inline-block;
padding: 16px 40px;
;
}
nav ul li a {
text-decoration: none;
color: #000;
font-size: 16px;
}
nav ul li a:hover {
background-color: #white;
border: none;
color: #000;
text-align: center;
opacity: 0.6;
}
.menu-icon {
line-height: 60px;
width: 100%;
background: #000;
text-align: right;
box-sizing: border-box;
padding: 15px 24px;
cursor: pointer;
color: #fff;
display: none;
}
<header id="home">
<h1>MOHANAD ARAFE</h1>
<nav>
<div class="menu-icon">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo">MOHANAD ARAFE</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
</nav>
</header>
You are going good, cheers for that. For the problem you are facing I would suggest you to play with z-index. It is a CSS property, and defines the elements as layers. Element with greater z-index will be the top most layers, followed by the elements with lesser z-index. I would suggest you to set z-indec of image to lowest, and make the content above in another container, and set the z-index of this container to a higher range, this should solve your problem.
Here's more reference on z-index
Happy Coding.
I would suggest using grid in these kind of situations where you have to deal with position of elements. A crash course on grid will be the best option. I personally use it a lot and don't have to care about anything other than z index.
You can use position: absolute; for the h1 tag and use top value in %, and left value in %
h1{
position:absolute;
top: value in %;
left: value in %;
}
header{
position:relative;
}
Note: apply a class name for h1 and apply css for that class or else it might affect h1 tag in sub pages.

CSS: background image opacity in ul-li menu

I have a menu using ul/li items, and they have a background image.
All over the Internet, and in stackoverflow, there is information on how to hack background image opacity. For example: https://scotch.io/tutorials/how-to-change-a-css-background-images-opacity
But not for my particular use case when using menus. It seems particularly tricky. From everything I have tried, one of the solutions in the aforementioned website seems to work the best.
But still, the image is not vertically aligned. I cannot seem to be able to center the image in the menu...
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {float: left;}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {background-color: #4CAF50;}
.my-container {
position: relative;
overflow: hidden;
}
.my-container a {
position: relative;
z-index: 2;
}
.my-container img {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: auto;
opacity: 0.2;
}
<ul>
<li><div class="my-container">Aaaa <img src="http://www.joaobidu.com.br/jb/content/uploads/2012/03/cancer3.png"></img></div></li>
<li><div>Bbbb</div></li>
<li><div>Cccc</div></li>
<li><div>Dddd</div></li>
<li><div>Eeee</div></li>
</ul>
Hi,Please try this one.
If we will use top:-14px,It will affecting the modern browser like chrome and safari which is not accepting negative values.So we can use below format for background images.
.my-container {
background-image:url("http://www.joaobidu.com.br/jb/content/uploads/2012/03/cancer3.png");
background-size:cover;
background-repeat:no-repeat;
background-position:center;
}

Moving my nav bar?

I need to move my top horizontal navbar all the way to the right beside my header that says "Best TV Ever" I've floated it to the right, now it has to move up to the top of the page.
How do I do this?
Here is the jsfiddle: https://jsfiddle.net/qkLgqmfh/
As well as the code.
h1{
background-color: black;
background-image: url(logo.png);
background-repeat: no-repeat;
font-family: Peralta;
color: white;
height: 100px;
padding-top: 25px;
padding-left: 150px;}
h2{
font-family: Peralta;
text-align: center;
height: 25px;
background-color: white;
padding-top: 0;
height: 50px;
}
p{
border-bottom: 1px solid black;
padding-bottom: 3em;
display: block;
overflow: hidden;
height:130px;
}
img{
float: left;
margin-right: 1em;
width: 150px;
height: 100px;
padding-left: 10px;
border-radius: 20px;}
ul li {
display: inline-block;
float: right;
padding-top: 0;
}
.topnav ul li a:link{
text-decoration: none;
color: black;
background-color: white;
border-radius: 50%;
margin: 15px;}
<body>
<div class="wrapper">
<div id="masthead">
<h1>Best TV Ever</h1>
</div>
[insert menu toggle here]
[insert menu checkbox here]
<div class="topnav">
<ul>
<li>50s</li>
<li>60s</li>
<li>70s</li>
<li>80s</li>
<li>90s</li>
</ul>
</div>
I've been staring at this computer screen for 6 hours now and feel like my mind has just given up. I'm sure it's simple... but for the life of me I cant figure it out!
I see that you have your float: right; on the li instead of on the .topnav. That is your main issue.
I changed that and removed a lot of cluster and this is what I got: https://jsfiddle.net/qkLgqmfh/3/
I think that is what you wanted to achieve.
Edit: If you want the black background on the whole width, put the topnav and h1 together in a new div and set background-color: black;. And since the div only contains floated elements, it will render with 0 height and width, so you need to set overflow: hidden; as well (unless you want to give it a specific height).
Regarding the size of the links, you can just change the font-size.
Have a look: https://jsfiddle.net/qkLgqmfh/5/

Navigation Bar for Website [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need help.
I have been at this for a good couple of hours. I am new to html and css. I have been googling the hell out of this question and the only thing that seems to work is the follow: http://codepen.io/wolfcry911/pen/HyLdg.
Here is what I am trying to accomplish:
create a navigation with 4 links (Home, About Me, Contact, Resume) with a logo in the middle that can adjust to any screen size (tablets, laptops, smartphones). I have tried an unordered list with the logo as the 3rd item (didn't really like this way. Seemed very sloppy and couldn't get the logo to be in the center of the screen since the text lengths were different) and I have tried using the logo as a background image but I cannot seem to center the logo in the middle of the page or when I do, the text never adjusts around the logo, always through the logo. With the link above, I was able to understand about 50% of the css and when I tried to tweak it, I couldn't get the text aligned in the center of the navigation and I can not get the logo to fit into the navigation. Here is my code:
body {
background: #f5f5f5;
font-family: arial;
font-size: 11px;
margin: 0;
}
#header {
height: 56px;
position: relative;
margin: auto;
background: #fff;
box-shadow: 0px 2px 2px #ebebeb;
text-align: center;
padding: 20px 10px;
}
#header ul {
margin: 0 auto;
width: 800px;
padding: 0;
list-style: none;
}
#header ul li {
float: left;
width: 97px;
}
#header ul li:nth-of-type(4) {
margin-left: 217px;
}
#header ul li a {
text-transform: uppercase;
text-decoration: none;
display: block;
text-align: center;
padding: 12px 0 0 0;
height: 28px;
}
#header ul li a:hover {
background: rgb(235, 200, 35);
}
.logo {
position: absolute;
left: 50%;
margin: -48px 0 0 -108px;
background: url(img/logo.jpg) 50% 0 no-repeat;
background-size: 125px 56px;
width: 125px;
height: 56px;
top: 20px;
}
#media screen and (max-width: 800px) {
.logo {
bottom: 100%;
}
#header ul li:nth-of-type(4) {
margin-left: 0;
}
#header ul {
width: 600px;
position: relative;
}
}
<html>
<head>
<title>Template</title>
<link rel="stylesheet" href="navigation.css">
</head>
<body>
<div id="header">
<a class="logo" href="index.html">
<img src="img/logo.jpg" alt="Michigan State" width="215" height="140" />
</a>
<ul>
<li>Home
</li>
<li>About Me
</li>
<li>Contact
</li>
<li>Resume
</li>
</ul>
</div>
</body>
</html>
I am able to understand about 50% of the css code. So if someone could help explain what is going on with the ul, li, logo, and the #media format, that would be greatly appreciated.
Thank you for the help.
ul is an unordered list which will show bullet points instead of numbers as with and ordered list, ol. They have the list-style set to none so the bullet points will not show and set the width of each element to a set width of 97px.
ul li:nth-of-type(4) is a CSS selector that was implemented in CSS3. It basically tells the browser for the 4th item of the unordered list, use these set styles. http://css-tricks.com/almanac/selectors/n/nth-of-type/
ul li a:hover is just what styles happen when the user hovers over the item of an unordered list.
.logo is a class. These styles handle the position, size, image used, and other styles to format the picture.
#mediadetects the size of the browser and depending on that size uses a different set of styles that are indicated. http://css-tricks.com/css-media-queries/
Check out that site, css-tricks.com. It has a lot of information which has helped me out a lot in the past, especially getting up to speed on all the new tricks and properties with CSS3.
I'll give you a brief explanation of what's going on but you should really read up on CSS. There are some great tutorials for beginners out there as well(codeacademy for example)
#header ul {
margin: 0 auto; /* Centers the UL. */
width: 800px;
padding: 0;
list-style: none; /* Remove list bullets */
}
#header ul li {
float: left; /*Floats the LI's meaning it will place them next to eachother instead of stacking them underneath eachother*/
width: 97px;
}
#header ul li:nth-of-type(4) {
margin-left: 217px; /* Adds a left-margin to your fourth LI-itme(Resume). This is here so to prevent the link from overlapping the image. The left-margin should be the same width as you image. This needs to be added because your logo has position:absolute. */
}
.logo {
position: absolute; /* This means that the image is taken out of the flow and can be placed anywhere on the page.
Position absolute elements are relative to parent elements containing the position:relative style. In your case that's #header*/
left: 50%;/* places the left edge of the imaget 50% from the left*/
margin: -48px 0 0 -108px; /* adds a negative top/bottom margin to center the image. */
width: 125px;
height: 56px;
top: 20px; /* places the image 20px from the top.
}
The media queries is there to define what will happen to the menu when the window size is less than 800px
Here is a basic markup/layout for you. (BTW it's very basic). It's using positioning, and allows you to easily customize bits and pieces.
.nav {
margin-top: 50px;
height: 40px;
width: 100%;
background-color: blue;
position: relative;
border-bottom: 5px solid gold;
border-top: 5px solid gold;
}
.link {
position: absolute;
width: 20%;
height: 100%;
background: red;
}
.link2 {
left: 20%;
background: green;
}
.logo {
left: 40%;
background: orange;
}
.link3 {
left: 60%;
background: purple;
}
.link4 {
left: 80%;
background: pink;
}
#media screen and (max-width: 800px) {
.link {
position: absolute;
width: 25%;
height: 100%;
background: red;
}
.link2 {
left: 25%;
background: green;
}
.logo {
display:none;
}
.link3 {
left: 50%;
background: purple;
}
.link4 {
left: 75%;
background: pink;
}
}
<div class="nav">
<div class="link link1">Link1</div>
<div class="link link2">Link2</div>
<div class="link logo">logo</div>
<div class="link link3">Link3</div>
<div class="link link4">Link4</div>
</div>
You can use media queries to add styling for different sized screens. For example, when my snippet gets smaller than a width of 800px, the 'logo' div will disappear, and yet when it gets wider, the logo div will reappear. (best viewed in full screen mode to see this effect)
It's just something simple, but i think you could work with this.