Using background cover image with some transparency making my top navigation menu links text ugly and harder to read. How can I make it correct?
HTML -
<div id="wrapper"> <!-- wrapper starts here -->
<div id="header"> <!-- header starts here -->
<h1>example.com</h1>
</div> <!-- header ends here -->
<div id="top_nav"> <!-- nav starts here -->
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
<li>Menu 5</li>
</ul>
<div class="clr"></div>
</div> <!-- nav ends here -->
<div style="height:1000px;"></div>
</div>
CSS -
html
{
background:url(http://www.designmyprofile.com/images/graphics/backgrounds/background0172.jpg) no-repeat center center fixed;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
}
#wrapper
{
width:980px;
margin:0 auto;
background-color:#FFFFFF;
background-color:rgba(255, 255, 255, 0.7);
}
#top_nav
{
width:100%;
background-color:#3079ED;
position:relative;
}
#top_nav ul
{
margin:0;
padding:0;
list-style-type:none;
}
#top_nav ul li
{
float:left;
}
#top_nav ul li a
{
background-color:#3079ED;
display:block;
text-align:center;
text-decoration:none;
padding:8px 16px;
color:#FFFFFF;
font-size:14px;
border-right:1px solid #6199DF;
}
#top_nav ul li:last-child a
{
border-right:none;
}
#top_nav ul li a:hover
{
background-color:#6199DF;
}
So please tell me how can I make my menu link text clean and more readable as regular text while keeping the background image transparency.
Here is DEMO
Read back again and see your main problems are how you chose to do the background, and that the bar doesn't extend across as the CSS says it should. Try to make these modifications.
In #topnav {}
Below
width: 100%;
add
height: 32px;
The height being 0px is causing the short menu bar error. Also you can remove
position:relative;
It is assumed in this case already.
I would also change the background of wrapper from
background-color:rgba(255, 255, 255, 0.7);
to
background-color:rgba(75, 75, 75, 0.45);
and add
h1
{
color: #fff;
text-shadow: 2px 2px #000;
}
This tends to do better on backgrounds comprised at least half of darker tones.
Should fix your short nav bar problem and make everything easier to read. As well as show off your background better.
DEMO
Related
I'm fairly new to HTML/CSS, and am developing a very simple website with a white menu bar on the top (it looks better than it sounds). However, unfortunately the menu bar background is transparent - text seems to appear within the menu bar as I scroll down in the page. How do I make a white background non-transparent?
Without seeing your code, I will recommend a few things.
set background: white;
set opacity: 1.0;
That should do the trick. Please post your code if you are still having problems.
You can accomplish that by declaring background color as white.
Example:
<style>
#menu-id{
background-color: white;
}
</style>
<style>#menuid{background: rgba(255, 255, 255, 0.3);}</style>
<style>#menuid {
background: rgba(255, 255, 255, 0.3);
}
</style>
Use background color just like following example, change .box background color #fff to get the white color.
.box {
width:100%;
background:#eee; /*background:#fff; use here white background */
}
.box ul {
margin:0px;
padding:0px;
list-style:none;
}
.box ul li {
display:inline-block;
}
.box ul li a {
display:block;
padding:5px;
margin:1px;
text-decoration:none;
}
.box ul li a:hover {
background:#ddd;
}
<div class="box">
<ul>
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
I have this layout that needs to be a bunch of boxes stacked on top of each other, they all have a 1px border.
In order to have the border always be 1px I put a margin-bottom of -1px to all of the boxes, but when I change the border color on hover it doesn't quite work as intended. Here's an example:
How can I make it so it doesn't overlap on hover?
My code:
.main-content ul li a {
margin-bottom:-1px;
padding:15px 23px;
display:block;
border:1px solid #545353;
color:#545353;
}
.main-content ul li a:hover {
border-color:#fff;
color:#fff;
}
I tried giving them all a z-index and then making that higher on hover, but it didn't work either...
Any ideas?
Thanks!
EDIT Adding HTML
<div class="row main-content">
<div class="container">
<div class="col-md-8 col-md-offset-2">
<ul>
<li>Bienvenida</li>
<li>¿Por qué es la decisión correcta?</li>
<li>¿Cómo funciona este servicio?</li>
<li>¿Cuánto cuesta este servicio?</li>
<li>Estoy interesado, ¿qué hago?</li>
<li>Registro</li>
</ul>
</div>
</div>
</div>
You can use the property:
box-sizing: border-box;
so that elements are exactly the width and height you want them to be. The border will be 1px within the element instead of stretching out to other ones.
ewfaeg
To keep the border at 1px, use this css:
.main-content ul li a {
position: relative;
z-index: 30;
margin-bottom:-1px;
padding:15px 23px;
display:block;
border:1px solid #545353;
color:#545353;
}
.main-content ul li a:hover {
border-color:#fff;
color:#fff;
z-index: 99;
}
The changes I made was setting a z-index for both unhovered links and hovered links. The position:relative is added because z-index does not reflect unless there is a position specified.
Try this https://jsfiddle.net/L565nwaL/1/
<div class="main-content">
<ul>
<li>item one</li>
<li>item two</li>
<li>item three large</li>
<li>item four</li>
</ul>
</div>
CSS
.main-content ul li a {
padding:15px 23px;
display:block;
border:1px solid #545353;
border-bottom: transparent;
color:#545353;
}
.main-content ul li a:hover {
border:1px solid #fff;
color:#fff;
}
.main-content {
background: #161616;
box-sizing: border-box;
}
I have some sort of space in between my li tags I don't where it's coming from? How can i remove this?
Also, I'd like to change the color of the font to white on hover of the li
JSFIDDLE http://jsfiddle.net/omarel/tfyxL66c/
CSS
.nav_container {
text-align: center;
width:100%;
}
.nav_container ul {
/* margin-top:15px; */
margin-left:30px;
}
.nav_container ul li {
display: inline-block;
text-align: center;
padding-left:40px;
padding-right:40px;
margin:0px;
height:80px;
cursor:pointer;
}
.nav_container ul li:hover {
background-color:#08298A;
}
.nav_container a:hover {
color:#fff;
}
header {
width:100%;
margin: auto;
box-shadow:0 0 8px rgba(0,0,0,0.1);
min-width:410px;
}
.navlogo {
z-index:99;
}
.navlogo img {
width:100px;
margin:10px 10px 10px 10px;
}
.floatleft {
float:left;
}
.floatright {
float:right;
}
.centerdiv {
margin:0 auto;
}
#media only screen and (min-width:700px) {
header {
max-width:1250px;
}
.container {
max-width:1250px;
}
.box2 {
width:32%;
height:300px;
float:left;
}
.box2left {
width:65%;
height:600px;
float:left;
}
}
div {
border:solid 1px #E6E6E6;
position:relative;
}
ul li {
border:solid 1px #E6E6E6;
}
HTML
<div class="navlogo floatleft">
<img src="images/logo.png" />
</div>
<div class="floatleft">
<div class="nav_container">
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</div>
</div>
<div class="floatright">
<div class="nav_container">
<ul>
<li>Profile</li>
<li>Sign out</li>
</ul>
</div>
</div>
</header>
<div style="clear:both;"></div>
Answering your second question first as the answer is shorter: use the :hover pseudo class.
EXAMPLE
li:hover a{color:#fff;}
More information on pseudo classes
To answer your first question, then; setting an element's display property to inline or inline-block will cause the white space surrounding it to be treated just like the space surrounding any other inline element.
You can workaround it in a number of ways
Remove all line breaks from within your list:
<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>
Use comments to hide the line breaks from the browser:
<ul><!--
--><li>Item 1</li><!--
--><li>Item 2</li><!--
--><li>Item 3</li><!--
--></ul>
Use CSS to set the font-size of the parent element to 0 and then "reset" it for the child elements:
html{font-size:20px;}
ul{font-size:0;}
li{font-size:1rem;}
Alternatively, if you're not 100% set on using display:inline-block, you can use floats or flexbox instead.
To change the color of the links to white, use this css:
.nav_container ul li:hover a {
color:white;
}
However, only the text will be clickable, the li element won't be clickable. Another way to do the same thing is to apply all width/height/background styling to the link, instead of the li.
As Shaggy mentioned, to eliminate extra spacing when using inline-block you should remove all spaces in your html between your menu li items.
As for changing the link color on hover you should add the following to your css code:
.nav_container li:hover a {
color:#FFF;
}
I am using background-color property to my webpage wrapper like this -
background-color:rgba(255, 255, 255, 0.7);
But it is creating problem for me. It is making top navigation menu link text blur and harder to read.
When I remove transparency from wrapper's background-color, then all is fine. Interestingly when I scroll my webpage then all becomes also fine.
Here is my HTML -
<div id="wrapper"> <!-- wrapper starts here -->
<div id="top_nav"> <!-- nav starts here -->
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
<li>Menu 5</li>
</ul>
<div id="search_form">
<form method="get" action="">
<input type="text" name="txtsearch" id="txtsearch" placeholder="Search" />
</form>
</div>
<div class="clr"></div>
</div> <!-- nav ends here -->
</div>
Here is my CSS -
#wrapper
{
width:980px;
margin:0 auto;
background-color:#FFFFFF;
background-color:rgba(255, 255, 255, 0.7);
}
#top_nav
{
width:100%;
background-color:#3079ED;
position:relative;
}
#top_nav ul
{
margin:0;
padding:0;
list-style-type:none;
}
#top_nav ul li
{
float:left;
}
#top_nav ul li a
{
background-color:#3079ED;
display:block;
text-align:center;
text-decoration:none;
padding:8px 16px;
color:#FFFFFF;
font-size:14px;
border-right:1px solid #6199DF;
}
#top_nav ul li:last-child a
{
border-right:none;
}
#top_nav ul li a:hover
{
background-color:#6199DF;
}
So please tell me how can I make my menu link text clean and more readable as regular text while keeping the transparency.
EDIT -
Here is DEMO
I've tried many methods but cannot get this menu centered .. Any ideas?
You can view the page here:
http://jsbin.com/obecig/1/edit
I tried text-align:center in the #nav ul selector but no luck..
<html>
<head>
<style type="text/css">
#nav, .nav, #nav .nav li { margin:0px; padding:0px; }
#nav li {float:left; display:inline; cursor:pointer; list-style:none; padding:0px 10px 0px 10px; border:1px #000 solid; position:relative;}
#nav li ul.first {left:-1px; top:100%;}
li, li a {color:#000;}
#nav .nav li { width:100%; text-indent:10px; line-height:30px; margin-right:10px; border-top:1px #000 solid; border-bottom:1px #000 solid; border-left:none; border-right:none; background:#fff;}
#nav li a {display:block; width:inherit; height:inherit;}
ul.nav { display:none; }
#nav li:hover > a, #nav li:hover { color:#fff; background:#000; }
li:hover > .nav { display:block; position:absolute; width:200px; top:-2px; left:50%; z-index:1000; border:1px #000 solid;}
li:hover { position:relative; z-index:2000; }
</style>
</head>
<body>
<ul id="nav">
<li>Menu 1
<ul class="nav first">
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
<ul>
</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
</body>
</html>
Seeing how everyone answered the same thing and no one bothered to explain why... here we go:
As you all know, centering a block level element can be a pain when you don't know how. First of all, most of us know that margin: 0 auto; works, but not everyone knows why.
A quick breakdown of margin: 0 auto; has to do with the way CSS accepts shorthand notation for certain properties. Saying margin you are of course targeting the margin of the given element and the 0 part is using shorthand notation to say: 0 on the top and 0 on the bottom ... while adding auto at the end you are saying: auto margin on the left and auto margin on the right.
The above will not work if you don't have a defined width for the element in question. In this case the element has an ID attribute of #nav ... this is why the examples that everyone gave in their answers have a fixed width. The logic behind this is that a block level element extends 100% of it's parent container by default unless you specifically define otherwise in your CSS.
So in theory this also works for centering, and while it's more markup and not the best approach for simplicity's sake, I'm only showing it for illustrative purposes.
#nav {
width: 300px;
margin-left: auto;
margin-right: auto;
}
Everyone is more used to looking at it like this... and we use it like this because it's shorter.
#nav {
width: 300px;
margin: 0 auto;
}
The zero is not a must... Remember that it's the top and bottom margin of your element. So with that said, here's an example of the element with a 20 pixel margin on the bottom and centered.
#nav {
width: 300px;
margin: 0 auto 20px auto;
}
Last but not least... The shorthand notation for this property (margin) is the same as for the: border , padding , etc. It stars from Top... going clockwise to Left with Right and Bottom in between the two.
So it's: top, right, bottom, left. Like so: margin: 10px 20px 30px 40px
You need to give it a width, and then set the horizontal margins to auto. That's the quickest way anyways.
add this to your css:
#nav
{
width:100px;
margin: 0 auto;
}
To center something, it needs a width, and margin: 0 auto, so if you add this code:
#nav {
width: 100px;
margin: 0 auto;
}
It should (and did for me) work
#nav{
width:80px;
margin: 0 auto;}