I have the following code for my menu:
HTML:
<div class="container wrapper">
<nav>
<ul class="menu">
<li>Home</li>
<li>page1</li>
<li>page2</li>
</ul>
</nav>
And the CSS:
.wrapper{
padding:20px;
background:#d3d3d3;
height:200px;
}
.menu{
background:#7F7979;
}
.menu li{
padding-top: 20px;
padding-bottom: 20px;
padding-left: 15px;
display: inline-block;
}
.menu li a{
color:white;
}
nav ul{
list-style:none;
margin:0
padding:0;
}
What I want to achieve is at the right and left corners to look like it comes from behind the container (like a 3D effect if we can call it this way). Haven't tried anything since I don't have any idea how to achieve this.
I googled a bit but didn't find any website to inspect the code. If someone knows any, please point me out.
And plus, how can I do this by ignoring the container padding? Is it possible to make it with my menu inside this container which has a padding and still forcing the margins to go outside it?
NOTE: I'm not trying to someone do this for me, I'm trying to figure out what CSS properties should I use to achieve what I want.
To better explain what I wanted:
If it helps, my demo:
demo
Thank you so much for pointing me the right direction.
You can use borders on pseudo elements to make the 2 darker triangles on the top left and right of your menu bar.
To make the menu bar wider than it's container, you can use negative left/right margins :
DEMO
header{
width:80%;
margin: 0 auto;
background:#D3D3D3;
padding:100px 0 200px;
}
nav{
position:relative;
height:50px;
background: #7E7979;
margin: 0 -25px;
}
nav:before, nav:after{
content:'';
position:absolute;
top:-10px;
border-bottom:10px dotted #5C5C5B;
}
nav:before{
left:0;
border-left:25px solid transparent;
}
nav:after{
right:0;
border-right:25px solid transparent;
}
<header>
<nav></nav>
</header>
Related
I recently set up a sidebar for my user panel, however it appears that it's being pushed down. I've looked at other problem threads and their solutions all give me no luck. Hoping someone can help me out figuring this out
CSS:
<style>
div.menu
{
width:200px;
height:660px;
background-color:#C0C0C0;
left:0px;
top:0px;
}
.menu ul li
{
margin-bottom:20px;
}
body {width: 800px; margin: 20px auto; /* center */ padding: 20px;
border: 1px solid black;}
</style>
HTML:
<body>
<center><h3>User Panel</h3></center>
<div class="menu">
<ul>
<li>Link1</li>
</ul>
</div>
</body>
I will post any and all things you ask for to help figure this out - hope it's detailed and as full as it needs to be to help you figure it out
Entire code:
<style>
div.menu
{
width:200px;
height:660px;
background-color:#C0C0C0;
left:0px;
top:0px;
}
.menu ul li
{
margin-bottom:20px;
}
body {width: 800px; margin: 20px auto; /* center */ padding: 20px;
border: 1px solid black;}
</style>
<body>
<center><h3>User Panel</h3></center>
<div class="menu">
<ul>
<li>Link1</li>
</ul>
</div>
</body>
you could do something like this, and just change the order in the html so 'center' comes after the sidebar:
div.menu {
width:200px;
background-color:#C0C0C0;
float:left;
}
center {
float:left;
display:inline;
width:400px;
text-align:center;
}
Also you could make it a class in a span or div, instead of using the deprecated center tag.
The problem is caused because the title is technically on top of the sidebar. Remove <center> and you will see what I mean. Let's create a solution without using <center> as it is deprecated and should no longer be used.
Here is a solution using display: table:
Have a jsBin Example!
HTML
<div class="menu">
<ul>
<li>Link1</li>
</ul>
</div>
<div class="content">
<h3>User Panel</h3>
</div>
CSS
* {
margin:0;
padding:0
}
body {
width:800px;
margin:20px auto;
/* center */
padding:20px;
border:1px solid #000;
display:table
}
body > div {
display:table-cell
}
div.menu {
width:200px;
height:660px;
background-color:silver;
padding:10px
}
.menu ul li {
margin-bottom:20px;
list-style:none
}
h3 {
text-align:center
}
The title is an h3 element which is a block level element. It automatically takes some margin by default. Remove margin from h3 to solve the issue.
center h3 {
margin: 0;
}
Note: The ul tag also take some margins by default.
It's hard to tell what you want to achieve exactly without knowing your envisioned layout and content.
But you are using left and top properties with your menu style and those won't do anything without specifying position as absolute, fixed or relative.
Try to do this:
div.menu
{
position:absolute;
width:200px;
height:660px;
background-color:#C0C0C0;
left:0px;
top:0px;
}
The sidebar will no longer be pushed down. But it will also be taken out of the layout flow. So in your example the h3 (and all other content on the page) will now extend underneath the sidebar. That might not be what you want.
If you want to build a multi-column layout you should consider to use a CSS framework, such as for example Twitter Bootstrap (http://getbootstrap.com/).
You have the top and left attributes set, but no position. You need to add
position: absolute;
to your menu css to get it to stay positioned at the top. It will overlap the h3 you have there, but you can play around with z-index and margin to fix that.
I hope this helps, please let me know if you need any further explanation.
:)
Let me please say that I am very new at HTML/CSS so excuse my very sloppy code. Basically, all I want is a header with my name in it and then my nav bar on the top right. But when I resize the window, the nav bar is stuck to the top right and will overlap my heading. I just want it to stay put!
I'm not sure if this is enough information but I'll put my CSS code below. I've been trying for over an hour to get it to resize from the top left. I tried position:fixed / right:0px but nothing happens. If you guys can help I'll be forever grateful.
div#wrapper {
width: 98%;
margin: auto;
}
div.header {
background-color:black;
height: 80px;
width:100%;
position:fixed;
}
div.menu {
width:600px;
height:100px;
position:absolute;
right:0px;
margin-right:10px;
}
div.menu p {
display:inline-block;
float:right;
margin-top:0px;
}
div.menu a {
text-decoration: none;
display:block;
width: 100px;
padding: 30px 10px 29px 10px;
text-align:center;
margin-left: -5px;
color: black;
background-color:white;
font-family: Trajan Pro;
border-left: 1px solid black;
border-right: 1px solid black;
font-size:16px;
}
Thanks so much in advance!!
What I understood is this:
You want to resize the window, but you want your navigation bar not to be resized. If this is what you ask what you should do is simple.
Your current child-parent relation is like this (if I understood correctly)
<div id="wrapper">
<div id="menu"></div>
<div id="navigationbar"></div>
</div>
What you want is this:
<div id="wrapper">
<div id="menu"></div>
</div>
<div id="navigationbar"></div>
This way your navigation bar div won't be resized or won't change position. To make it stuck in top right here is the css code you need:
.navigationbar{position:absolute; top:0px; right:0px;}
If this does not solve your problem please explain how you resize or share a link here so we can understand easier.
I'll start by saying that my css skills are very weak.
Here is the site, and I was trying to add some margins to this background so I can see all the content. I now understand that I am not able to use margins on a background, so what are my options here?
Here is my HTML
<body>
<div id="container">
<nav id="navigation">
<ul>
<li>Homepage</li>
</ul>
</nav>
</div>
</body>
and here is my css
body {
background: url('images/prices.jpg');
min-height: 100%;
height: 100%;
}
#btn {
color: #FAF3BC;
background: #4FB69F url('images/texture.png') no-repeat right bottom;
padding: 15px 30px;
margin: 150px 0px;
border-top: 5px;
border-radius: 25px;
text-decoration: none;
text-transform: uppercase;
}
I am also having issues with the homepage button, I would like some room there as well, but I've tried couple of things like padding and margin and was not able to do it...
I would appreciate any help .... here is the page live, if you like to take a peak http://brewstahs.com/menu.html
I know why your css is not working. The most basic use of CSS is to create a layout, but even though your DOM contains div representing container and footer, the height occupied by each is
equal to the height of its content(because you have not provided any height to the div containers).In short,
margin : 150px 0px does not work because the parent container(nav) does not have that height to provide the margin to it. So provide a height to nav and div and it will work.
Use tools like Firebug to see your layout and see where you're going wrong.
All the best!!
Maybe you should try with background-position attribute:
http://www.w3.org/wiki/CSS/Properties/background-position
What do you want to do?
In case of moving the button, try
margin-top: 50px; for example in the css of btn. This way, the button is moved 50pixels to the bottom. Margin-left moves the button to right, ...
if you are trying to move the button down then you need to first put it in a wrapper
if not try this .
body {
background: url('images/prices.jpg');
min-height: 100%;
height: 100%;
}
#navigation {
position:relative;
display:block;
margin:40px 0px 0px 0px;
padding:0px;
width:auto;
height:auto;
}
#navigation ul {
display:block;
position:relative;
margin:auto;
padding:0px;
}
#navigation ul li {
list-style:none;
}
#btn {
color: #FAF3BC;
background: #4FB69F url('images/texture.png') no-repeat right bottom;
padding: 15px 30px;
margin: 150px 0px;
border-top: 5px;
border-radius: 25px;
text-decoration: none;
text-transform: uppercase;
}
and about your background you can try one thing. Have a looping background texture similar to the one you have right now with background-repeat:repeat; and then put the main background image above it with z-index and centered if required. Just to give you a simple example
body {
background-image:url('images/loop.jpg);
background-repeat:repeat;
}
#backgroundimg {
background-image:url('images/prices.jpg);
background-repeat:no-repeat;
display:block;
position:relative;
width:980px;
height:700px;
margin:auto;
padding:0px;
}
hope this helps :)
I would need some help me! I work on something and I can't get it to work. :) I want the text align to the center. Here is the picture: http://imageshack.us/photo/my-images/266/sn54.jpg/
Can anyone give me some tip please? Thanks.
Here is the code what I use:
HTML:
<div id="container">
<div id="header">
<ul class="nav">
<li>Home</li>
<li>Protfolio</li>
<li>About Me</li>
<li>Contact Me</li>
</ul>
</div><!-- header end -->
</div><!-- container end -->
CSS:
#header{
position: relative;
margin: 60px 0 0 0;
width: 100%;
height: 80px;}
.nav{
background: url(../images/navbar.png) no-repeat 0 0;
width:100%;
height:80px;
text-align:center;
display:block;}
.nav li{
float:left;
list-style: none;
margin: 10px;}
.nav li a{
width:150px;
text-shadow: 0 2px 1px rgba(0,0,0,0.5);
display: block;
text-decoration: none;
color: #f0f0f0;
font-size: 1.6em;
margin: 0 .5em;}
.nav li a:hover {
margin-top: 2px;
background-color: #d0d5d6;}
An easy way of doing this is to add padding to your nav element on the right and left equal to with width of the ribbon sections.
.nav {
padding:0 XXpx; /* XXpx = width of the ribbon ends */
}
.nav li {
width:25%;
text-align:center;
margin:0;
}
As a basis, this should fix your problem. You may have to play around with the exact code to fit your needs based on margins, etc.
Alternatively, check out this tutorial on how to create this type of ribbon with just CSS and not rely on an image at all: http://css-tricks.com/snippets/css/ribbon/
Without knowing the dimensions of the background image its hard to be specific, but try putting the background on the header element rather than the nav. You can then set the width of the nav UL to the width of the inner part of the ribbon image and set a margin 0 auto on it to center it horizontally
I would wrap the ul with a div an this div has the background image. Than you can adjust the ul.
I'm trying to create a fluid element for a site i'm working on, Check out this JS fiddle and make your browser a bit wider, you will see a grey line, a black box, and then a grey line.
When the browser's width is lower the right side line breaks down to the next line, but i want this to stay together no matter how wide the browser is. I generally use float's but have tried a few things, as you can see some css is commented out cause i'm playing with it.
Does anybody have some cool tricks to show me? Any help would be greatly appreciated! Let me know if you need any info.
http://jsfiddle.net/r8Xka/
CSS
header .lower{
overflow:hidden;
width:95%;
margin:40px auto 0 auto;
}
header .lower .line{
/*float:left;*/
display:inline-block;
background:#eaebeb;
width:35%;
height:8px;
/*display:block;*/
position:relative;
top:18px;
}
header .lower a{
/*float:left;*/
display:inline-block;
margin:0 20px;
/*display:block;*/
background: #000;
width: 141px;
height: 42px;
}
HTML
<header data-behavior="randomHeader">
<div class="lower">
<div class="line"></div>
Play Video
<div class="line"></div>
</div>
</header>
You have 3 column: left - fluid, middle - fixed, right - fluid. You would need some js to make it work.
Or some html/css trick like this:
<header data-behavior="randomHeader">
<div class="lower">
<div class="line"></div>
<div class="center">
Play Video
</div>
</div>
</header>
Css:
header .lower{
width:95%;
margin:40px auto 0 auto;
position: relative;
}
header .lower .line{
background:#eaebeb;
height:8px;
}
.center{
text-align: center;
position: absolute;
top: -20px;
left: 0;
width: 100%;
}
header .lower a{
border: 10px solid #FFF;
display:inline-block;
background: #000;
width: 141px;
height: 42px;
}
See working fiddle