Trying to make my portfolio, and new to webdesign. I am trying to add navigation links but the last link goes to next line. Don't know why is it so?
I want in single line, and if even there is some different method to represent this pl. help me/guide me for that too.
Thank You!
My Demo
CSS & HTML
html,
body {
margin: 0%;
top: 0%;
}
body {
background: #2f233d;
overflow: hidden;
}
header {
position: fixed;
top: 0%;
left: 0%;
width: 100%;
height: 12%;
background: #333;
font-family: Agenda Medium, Sans-Serif, Arial;
font-size: 20px;
}
header img {
display: inline;
width: 227px;
height: 100px;
margin-left: 2%;
}
header .links {
display: inline-block;
position: absolute;
bottom: 10%;
}
header a {
border: 1px solid #ddd;
padding: 1%;
text-decoration: none;
color: #ccc;
}
footer {
position: fixed;
bottom: 0%;
left: 0%;
width: 100%;
height: 10%;
background: #ccc;
}
aside {
position: fixed;
top: 12%;
left: 0%;
width: 20%;
height: 78%;
background: #f2f1f1;
overflow-y: auto;
}
section {
position: fixed;
top: 12%;
left: 20%;
width: 82%;
height: 78%;
background: #fff;
overflow-y: scroll;
}
<header>
<img src="Logo.png" alt="logo" />
<span class="links">
Home
About
Gallery
Work
Contact
</span>
</header>
<footer></footer>
<aside></aside>
<section></section>
You need to define your widths. Currently width is dependent on the length of the word.
Here is one of many solutions, this one being very straightforward.
header img {
width: 15%;
}
.links {
width: 80%;
}
I shaved a bit off to account for margins and paddings. The important thing here is I'm defining the image's width in percent instead of pixels, and I'm defining the width of .links, and not just the children of it.
In honesty, your solution is going to need to be more complex. It needs to account for mobile devices, because a small screen will cause the words to overflow their border. This, however, should answer your immediate question.
fiddle
For header a and header .links to changes in CSS..
demo:
html,
body {
margin: 0%;
top: 0%;
}
body {
background: #2f233d;
overflow: hidden;
}
header {
position: fixed;
top: 0%;
left: 0%;
width: 100%;
height: 12%;
background: #333;
font-family: Agenda Medium, Sans-Serif, Arial;
font-size: 20px;
}
header img {
display: inline;
width: 227px;
height: 100px;
margin-left: 2%;
}
header .links {
display: inline-block;
position: absolute;
bottom: 10%;
width:100%
}
header a {
border: 1px solid #ddd;
padding: 1%;
text-decoration: none;
color: #ccc;
display:inline-block
}
footer {
position: fixed;
bottom: 0%;
left: 0%;
width: 100%;
height: 10%;
background: #ccc;
}
aside {
position: fixed;
top: 12%;
left: 0%;
width: 20%;
height: 78%;
background: #f2f1f1;
overflow-y: auto;
}
section {
position: fixed;
top: 12%;
left: 20%;
width: 82%;
height: 78%;
background: #fff;
overflow-y: scroll;
}
<header>
<img src="Logo.png" alt="logo" />
<span class="links">
Home
About
Gallery
Work
Contact
</span>
</header>
<footer></footer>
<aside></aside>
<section></section>
Just replace your header .links class
header .links
{
display:inline-block;
position:absolute;
bottom:10%;
width:100%
}
It will work for you.
Related
So as the title say I put a color on top of an image and I then tried to put some text on top of it, but then all the div got moved to the bottom and the text got moved to the top of the div and when I inspect the heading, it shows a space colored in yellow. I'm trying to understand CSS position and I'm starting to understand it, but right now I don't understand haha. I think it's something with a margin, but I reinitialized it at the beginning of the CSS.
(Also sorry! If you feel the need to tell me that my CSS is bad don't hesitate to tell me off i want to learn from my mistake!)
The HTML
<div id="section3">
<div id="layer">
<h1>Parmi les premiers de classe !</h1>
</div>
</div>
And CSS
#section3 img {
width: 1903px;
margin-left: 0px;
margin-top: -645px;
z-index: 100;
}
#section3 h1 {
margin-top: 260px;
margin-left: 420px;
font-size: 80px;
}
#section3 p {
margin-top: 10px;
margin-left: 590px;
font-size: 30px;
}
.img4{
position: relative;
top: 641px;
}
#section3{
background: url('../Images/CF3.jpg');
position: relative;
bottom:4px;
width: 1903px;
height: 930px;
}
#layer{
background-color: #4c96eb75;
width: 100%;
height: 100%;
}
#layer h1{
display: block;
}
The reset at the start of CSS
* {
margin: 0;
padding: 0;
font-family: Segoe UI;
}
You used up higher values of height and width that's why it happened. I changed that:
#section3 h1 {
/* margin-top: 260px;
margin-left: 420px; */
font-size: 80px;
}
#section3 p {
margin-top: 10px;
margin-left: 590px;
font-size: 30px;
}
.img4{
position: relative;
top: 641px;
}
#section3{
background: url('../Images/CF3.jpg');
position: relative;
bottom:4px;
width: 390px;
height: 300px;
}
#layer{
background-color: #4c96eb75;
width: 100%;
height: 100%;
}
#layer h1{
display: block;
margin: 0;
}
<div id="section3">
<div id="layer">
<h1>Parmi les premiers de classe !</h1>
</div>
</div>
Change the css to this:
#section3 img {
width: 1903px;
margin-left: 0px;
margin-top: -645px;
z-index: 100;
}
#section3 h1 {
/* margin-top: 260px;
margin-left: 420px; */
font-size: 80px;
}
#section3 p {
margin-top: 10px;
margin-left: 590px;
font-size: 30px;
}
.img4{
position: relative;
top: 641px;
}
#section3{
background: url('../Images/CF3.jpg');
position: relative;
bottom:4px;
width: 1903px;
height: 930px;
}
#layer{
background-color: #4c96eb75;
width: 100%;
height: 100%;
}
#layer h1{
display: block;
margin: 0;
}
I have added a margin:0, to the header and removed other styles margin for #section3 h1, that was the reason div was placed at the bottom and
I know this is a common issue but I just can't work this out. No matter how many combinations of settings I try, the footer won't stay on the bottom of the page. It will just sit under whatever else is above it.
body {
margin: 0;
background-color: #ACFAB7;
}
# container {
margin: 0 auto;
padding: 40px;
}
#header {
z-index: 0;
height: 78px;
background-color: #2ecc71;
}
#footer {
z-index: 2;
height: 40px;
width: 100%;
padding: 0px;
position: relative;
background-color: #2ecc71;
/*display required to center text*/
display: table;
text-align: center;
margin-left: auto;
margin-right: auto;
}
#image {
z-index: 1;
margin: 20px auto;
padding: 50px;
}
/*Centers text within the header*/
span {
display: table-cell;
vertical-align: middle;
}
You have a lot of problems. This solution is for:
Fixing your footer at the end of the page.
Centering the contents (both vertically and horizontally).
Fixes
Get rid of display: table.
Get rid of width: 100%.
Change relative to fixed.
#footer {
z-index: 2;
line-height: 40px;
padding: 0px;
position: fixed;
background-color: #2ecc71;
text-align: center;
left: 0; right: 0;
bottom: 0;
}
<div id="footer">Copyrights.</div>
position: fixed; and bottom: 0; should do the trick. Add width and height as neccessary.
.footer {
position: fixed;
bottom: 0;
width: 100%;
height: 30px;
background-color: aquamarine;
}
<div style="background-color: lightgrey;height: 800px">
Page content
</div>
<div class="footer">
this is the footer
</div>
You can use position: fixed; bottom: 0;
#footer {
z-index: 2;
height: 40px;
width: 100%;
padding: 0px;
background-color: #2ecc71;
text-align: center;
margin-left: auto;
margin-right: auto;
position:fixed;
bottom:0;
left: 0;
}
<div>
<footer id="footer">Footer</footer>
</div>
I'm try to do a special navigation-bar.
I will show it in pictures:
this on scrollbar on top
and this on scrollbar down:
So I tried to do header with position: fixed and z-index: 1.
inside nav with z-index high(1000) and
the right block with z-index high(1000)
and the content have z-index: 2 and position: relative.
and it didn't worked :/
**and important thing is that I need the upload div will be in the header
and will be higher (in z-index) from content
I will try to show you in code:
header {
display: block;
position: fixed;
width: 100%;
top: 0;
right: 0;
left: 0;
z-index: 1;
background-color: blue;
}
nav {
width: 100%;
height: 40px;
background-color: green;
z-index: 1000;
}
#upload {
background-color: green;
height: 40px;
width: 40px;
float: right;
margin-right: 0;
z-index: 1000;
}
#content {
position: realative;
display: block;
border: 2px solid #000;
margin-left: auto;
margin-right: auto;
height: 200px;
width: 80%;
background-color: #cacaca;
z-index: 2;
}
<header>
<nav></nav>
<div id="upload">
</div>
</header>
<div id="content">
</div>
thank you,and I'm sorry about my english !!
you will need to move the nav out of the header for the #content z-index to work and need to align nav with fixed positioning or by giving margin
header {
display: block;
position: fixed;
width: 100%;
top: 0;
right: 0;
left: 0;
height: 80px;
background-color: blue;
z-index: 1;
}
nav {
width: 100%;
height: 40px;
z-index: 3;
background-color: green;
position: fixed;
top: 0;
right: 0;
left: 0;
}
#upload {
background-color: green;
height: 40px;
width: 40px;
float: right;
margin-right: 0;
margin-top: 40px;
}
#content {
position: relative;
display: block;
border: 2px solid #000;
margin-left: auto;
margin-right: auto;
height: 200px;
width: 80%;
background-color: #cacaca;
z-index: 2;
}
<header></header>
<nav>
<div id="upload"></div>
</nav>
<div id="content"></div>
I am trying to create a header for my website, with a logo contained. I wish for the logo to have a 5 pixel margin from the top of the header div that it is contained inside, however when I add "margin-top: 5px" to the div containing the logo, the header div is push 5 pixels down instead.
<div id="background">
<div id="HeaderGrey">
<div id="HeaderLogo">
<img src="CHBadgeLogo.png" />
</div>
</div>
<div id="HeaderShaderTop"></div>
<div id="HeaderShaderBottom"></div>
</div>
CSS
body {
margin: 0;
padding: 0;
}
#background {
left: 0px;
top: 0px;
position: relative;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 600px;
overflow: hidden;
z-index:0;
background-color: #303030;
}
#HeaderGrey {
background-color: #676767;
height: 94px;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin-top: 0px;
}
#HeaderShaderTop {
background-color: #0e453d;
height: 2px;
width: 100%;
}
#HeaderShaderBottom {
background-color: #009d89;
height: 2px;
width: 100%;
}
#HeaderLogo{
margin-top: 5px;
margin-left: 28px;
height: 85px;
width: 86px;
}
I'm assuming this would have a pretty easy fix, I'm just new to html/css, sorry.
The positioning works only when you put the parent (containing) element as non-static, like relative. Then you can position the element with relative or absolute (taking it out of the flow).
Like so:
body {
margin: 0;
padding: 0;
position:relative;
}
#background {
left: 0px;
top: 0px;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 600px;
overflow: hidden;
z-index:0;
background-color: #303030;
position:relative;
}
#HeaderGrey {
background-color: #676767;
height: 94px;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin-top: 0px;
position: relative;
}
#HeaderShaderTop {
background-color: #0e453d;
height: 2px;
width: 100%;
}
#HeaderShaderBottom {
background-color: #009d89;
height: 2px;
width: 100%;
}
#HeaderLogo{
margin-top: 5px;
margin-left: 28px;
height: 85px;
width: 86px;
position: absolute;
}
Very nice Question,
I see that you know how to use padding which is good. If just simply add a padding-top: 5px; to the image div it should just move the image down 5px from the top of the navbar!
I need to create two full-width headers but I can't seem to find a way to do them without using position absolute because if i use position:absolute, I can't use margin-bottom, which I need. What can I do?
This is what I have tried:
<div class="header1">
</div>
<div class="header2">
</div>
.header1 {
background-color: red;
margin-top: 110px;
color: #FFFFFF;
height: 35px;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.header2 {
background-color: blue;
margin-top: 150px;
color: #FFFFFF;
height: 35px;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
Not sure if I'm understanding the problem correctly, but
body {
margin:0
}
.header1 {
background-color: red;
color: #FFFFFF;
height: 35px;
width: 100%;
}
.header2 {
background-color: blue;
color: #FFFFFF;
height: 35px;
width: 100%;
}
Will give you 2 full width headers
DEMO