So, i'm super new to HTML/CSS. For my class I have to make a portfolio webiste.
I want to be very simple. So, I'm starting off with my name centered in the middle of the page, and then underneath I want it to look like this:
About Graphic Design Studio Art (but, spaced out a little obviously)
Here is my html:
<!-- BEGIN: Sticky Header -->
<div id="header_container">
<div id="header">
</div>
<div id="indexheader"><a rel="title">THIS IS MY NAME</a>
</div>
<div id="links">
<a rel="#about">About</a>
</div>
<div id="links">
<a rel="#design">Graphic Design</a>
</div>
<div id="links">
<a rel="#art">Studio Art</a>
</div>
</div>
</div>
<!-- END: Sticky Header -->
Here is my CSS:
/* Make Header Sticky */
#header_container {
background:transparent;
height:60px;
left:0;
position:fixed;
width:100%;
top: 40px;
text-align: center;
}
#header {
left: 0;
position: fixed;
right: 0;
text-align: center;
top: 160px;
z-index: 999;
float: right;
}
body.top-navigation-position-below-banner #navigation-bottom {
position: fixed;
top: 0;
border-bottom: none;
z-index: 999;
}
#page-header-wrapper {
margin-top: 180px;
}
#links {
height: auto;
width: 100%;
margin-top:30px;
background-color:transparent;
text-align: center;
margin-top: 10px;
margin-left:0%;
padding: 0px;
}
http://jsfiddle.net/r7K26/
I also tried to make it a sticky-header. Not sure if that's right either. IM A HUGE NOOB. Forgive me.
You are closing your div with id #header immediately, so the elements beneath is are not receiving any styling. That might be what you want, but then you have an extra at the end of your html.
You can center your div a lot of ways, but the following should work fine:
#indexheader {display:block;width:100%;text-align:center;}
Good luck!
Well, you don't need that many divs first of all. Look at this, for example:
Html:
<div class="myInfo">
<h1>Your Name</h1>
<ul class="myLinks">
<li>link</li>
<li>link</li>
<li>link</li>
</ul>
</div>
And actually, you don't even need a div in this case but regardless, having the class on one div you can style with selectors such as:
.myInfo H1 {....}
.myInfo UL {..}
etc
or just
.myLinks {} for the url and then:
.myLinks li {} for the list items.
I know this is a fast answer but as you are learning, I think it might be better to 'sort of' give you some pointers instead of just doing it all, right?
:)
You're very close, and here's one solution using your code as a base. Try this styled JSFiddle and see if its what you need. Please feel free to play around with the code, and hit the Run button when you are ready to see the results. http://jsfiddle.net/TalkingRock/MAuzN/
The structure:
The html code is simplified by using "header_container" to wrap the entire header (title and menu). The "indexheader" is placed in its own div. A new menu div now contains/wraps only the menu items.
<div id="header_container">
<div id="indexheader">THIS IS MY NAME</div>
<div id="menu">
<div class="links">About</div>
<div class="links">Graphic Design</div>
<div class="links">Studio Art</div>
</div> <!-- end menu -->
</div> <!-- end header_container -->
The CSS
Inline-block is used to shrink wrap, center, and display the menu items in a single line. Inline-block has a natural 4px margin around each item, and that can be removed by removing the white space in-between each inline-block item in the html code. You'll also need to add "vertical-align:top". Inline-block is a good style to learn, has good browser support, and comes in handy.
#header_container {
margin:0px;
padding:0px;
border:0px;
min-height:80px; /* use min-height so the div will expand around the contents, regardless of height. */
width:100%;
background-color:transparent;
position:fixed;
top:40px;
}
#indexheader {
text-align:center;
padding:10px;
}
#menu {
text-align:center; /* text-align center works because of the inline-block */
}
.links {
display:inline-block;
vertical-align: top
}
Good article on lnline-block: http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/
Inline-block support: http://caniuse.com/#feat=inline-block
Here are a few other articles you'll find useful. CSS Fixed Menus:http://www.w3.org/Style/Examples/007/menus.en.html
The Z Index: http://coding.smashingmagazine.com/2009/09/15/the-z-index-css-property-a-comprehensive-look/
Note: The div that holds your contents needs a top padding or margin tall enough to make sure it isn't covered up by the fixed menu. Position fixed will be buggy in touch devices, especially handheld phones. In your original code there is an extra div in your html, id's can only be used once per page, use href for your links, and "backgound-color:transparent" (transparent is the default style).
Related
I'd like to create a full-width header div that links to the top of the page and inside this div, there is the 'page title' that links to the home page.
Doing so, doesn't seem to work: https://jsfiddle.net/9wscc5yy/
<a href="www.example.com">
<div id="header" style="width:100%; background-color: #fff">
<a href="www.google.com">www.google.com
</a>
</div>
</a>
So I tried to create three divs next to each other with the middle div containing the 'page title' and the remaining two divs floating left and right. The result: https://jsfiddle.net/vef0tt07/
<div id="header">
<a href="www.example.com">
<div style="float: left; width: 40%; background-color:#fff">
</div>
</a>
<a href="www.example.com">
<div style="float: right; width: 40%; background-color:#fff">
</div>
</a>
<a href="www.google.com">
<div style="overflow:hidden; text-align: center;">
<strong>Title</strong>
</div>
</a>
</div>
The new issue is that I don't know how to let the side divs change width so that they always reach to the text of the 'page title'.
Is there a better way to create a linked title inside a linked div?
Thanks in advance for your time to help me.
Try this:
HTML
<header>
<h1>
link to top of page
</h1>
<h2>
link to home page
</h2>
</header>
CSS
header {
position: relative;
background-color: red;
height: 50px;
}
h1 {
margin: 0;
}
h1 > a {
display: block;
color: red;
}
h2 {
margin: 0;
background-color: yellow;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
DEMO
The background section (red) links to one place. The title in the middle (yellow) links to another place.
With absolute positioning, the h2 is set to remain perfectly centered in the header.
Update (based on comments)
In order to make the header fully responsive, with no artificial heights, and all links equal height regardless of content size, use flexbox.
It's actually very simple and requires minimal code.
HTML
<header>
</header>
CSS
header { display: flex; } /* establish flex container */
header > a { flex: 1; } /* make all flex items equal width */
DEMO
To learn more about flexbox visit:
Using CSS flexible boxes ~ MDN
A Complete Guide to Flexbox ~ CSS-Tricks
Note that flexbox is supported by all major browsers, except IE 8 & 9. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add all the prefixes you need, post your CSS in the left panel here: Autoprefixer.
I try to redesign my website with device compatibility.
I use this code for min-width768px which means desktop or laptop devices.
<div style="width:100%;">
<div style="width:20%; height:60px; margin-top:10px; float:left;">
<img src="images/logo.png" width="155" height="60" alt="Logo">
</div>
<div class="menu" style="width:70%; height:50px; margin-top:25px; font-size:12px; float:left;">
<ul class="yatay_menu">
<li>
<a href="#" title="Anasayfa">/a>
</li>
<li>
</li>
<li>
</ul>
</div>
<div class="menu" style="width:10%; height:80px; margin-top:20px; float:left;">
<img src="images/telefon.png" width="147" height="40">
</div>
<div class="responsive_menu"><i class="fa fa-bars" style="color:#b0063a; font-size:28px;"></i></div>
<div style="clear:both;"></div>
</div>
In compatibility version of this code I hide menu and phone number divs. Instead of them until 480px I show another div which is a contains bars icon.
.menu { display:none; }
.responsive_menu { display:block; width:80%; margin-top:25px; }
What i want is this icon has to align right side of div. However it isn't work. I use float right but it isn't displayed beacause dimension of page. Image is exactly explain the issue.
There are many ways to remedy this.
using divs with percentage widths on devices that scale is asking for problems, especially if there is content overflow on them.
The safest way to do this, is to use absolute positioning for the menu button.
Something like this :
#menuButton
{
position:absolute;
top:15px;
right:10px;
}
This makes the element titled 'menuButton' positioned from the right, ensuring it's always on the right side of your view.
Based on your fixed edit: i'd propose just giving your menu icon a position: fixed; when displayed. The draw back is that you'd need the title bar fixed as well....
#menu_icon{
position: fixed;
right: 15px;
}
OR you can give the parent containing div width: 100%; and then give the icon absolute right: 15px; like, this is better overall, imo:
.responsive_menu{
position: relative;
width: 100%;
}
#menu_icon{
position: absolute;
right: 5px;
}
I suggest you to use the most popular HTML, CSS, JS Framework which provides responsive containers applicable for your mobile. http://getbootstrap.com/
I am having some issue trying to implement sticky footer, that is to make the footer stay at the most bottom of the page, I think this problem is due to the fact that I use 2 divs to render rounded corners for my page, I have searched for all possible solution and tried them, nothing works.
So basically, this is my design:
<div class="global">
<div class="wrapper">
<div class="banner"></div>
<div class="content"></div>
<div class='footer'>
<div class='footercontent'>COPYRIGHT INFO</div></div>
</div>
</div>
This is my CSS:
body {
font-family: Verdana, Geneva, sans-serif;
}
#global {
margin: 0 auto;
width: 85%;
min-width: 1020px;
}
.wrapper {
background: #FFFFFF;
}
.footer {
background: url('../Images/roundedcornerRIGHT.gif') no-repeat bottom right;
}
.footer div {
height: 40px;
background: url('../Images/roundedcornerLEFT.gif') no-repeat bottom left;
}
.footercontent {
text-align: center;
font-size: small;
}
No matter what solution I try posted by other people on Stackoverflow, nothing works, it will either not move the footer down to the bottom of the page, or it just messes up with the footer's layout of the rounded corners.
Try this:
.footer {
background: url('../Images/roundedcornerRIGHT.gif') no-repeat bottom right;
position: absolute;
bottom: 0;
}
If you want footer at the bottom give a minimum height to your content.
min-height: 800px;
Change your markup to this:
<body>
<div class="wrapper">
<div class="banner"></div>
<div class="content"></div>
</div>
<div class='footer'>
<div class='footercontent'>COPYRIGHT INFO</div></div>
</div>
</body>
And then add these styles:
.footer {
position:fixed;
left:0px;
bottom:0px;
width:100%;
}
Okay, so assuming you want to keep everything you are currently doing.. I have a quick fix for you. Now, a few things to note.. I did add in a height variable to your 'wrapper' class because I needed to gauge it as if there were space inside of the wrapper itself. I also went ahead and put in a few colors to let me know exactly where I am. Either way, the simplest fix is to take your footer div and put it outside of the wrapper. The way this all works is, the footer is showing up inside of the wrapper class, the only problem is that nothing else is showing up in that class, which causes the footer to be the only thing.. creating the problem of having this footer at the top. However, if you would like to stay current with every page, moving the footer down to the bottom of the global div should be your fix, the code below:
<div class="global">
<div class="wrapper">
<div class="banner"></div>
<div class="content"></div>
</div>
<div class='footer'>
<div class='footercontent'>COPYRIGHT INFO</div>
</div>
</div>
So the problem really was in the HTML, not the CSS. You can keep your CSS or play with it as you please but to better describe what I am saying, I have been fiddling (haha) with a JsFiddle for you :) Comment below if I need to make more sense of what I am saying!
I try to use the
position:fixed;
width:10in;
but when resize the browser, the contents go out of boundary(there's no way to reach those elements).
i need an alternative because i want the nav bar to be at top at all times.
edit: i also want the contents to be inline which is not served by using
width:100%;
display:inline or inline-block
check here - http://jsfiddle.net/dF4Bx/1/
In simple language -
I need that the browser should provide a horizontal bar if the width is not fullfilled by the resized window.
Making your top bar sticky with CSS
#header{
position:fixed;
left:0px;
top:0px;
height:30px;
width:100%;
background:#999;
}
I see what's your problem.
Use this HTML instead of yours:
<div class="back">
<div id="header" class="front">
<ul>
<li>Home</li>
<li style="float: right;">Login</li>
<li style="float: right;">Register</li>
<li style="float: right;">Search: <input type="text" class="textbox" name="sr"></li>
</ul>
</div>
</div>
And put this rule into your CSS:
#header ul li {
margin-right: 7px;
}
And too, change this width 8in to 95%:
div.back div.front {
background-color: #0072C6 !important;
margin: auto;
width: 95%;
}
Note that i removed the inline style padding of search element.
Try with below CSS,
position:fixed;
top:0;
width:100%;
z-index:99;
8In is such a big value and moreover it is fixed width that's why it keeps going beyond browser. Use % values for responsive designs.
So change width like this
div.back div.front {
width:100%;
}
then about keeping the elements inline,
Use something like margin-left:20% instead of 24In in padding:24px 20px 24px 2in!important;.
Even it will break the line when it reaches a limited browser window. You can reduce this range by avoiding larger fixed values of padding and width in your code.
Check Fiddle: FIddle
to arrive to your purpose you can try this code :
.divClass{
position:fixed;
top: 0px;
z-index: 99;
width: 80% /*for responsible width*/
}
I've used Blueprint to prototype a very simple page layout...but after reading up on absolute vs. relative positioning and a number of online tutorials regarding vertical positioning, I'm not able to get things working the way I think they should.
Here's my html:
<div class="container" id="header">
<div class="span-4" id="logo">
<img src="logo.png" width="150" height="194" />
</div>
<div class="span-20 last" id="title">
<h1 class="big">TITLE</h1>
</div>
</div>
The document does include the blueprint screen.css file.
I want TITLE aligned with the bottom of the logo, which in practical terms means the bottom of #header.
This was my first try:
#header {
position: relative;
}
#title {
font-size: 36pt;
position: absolute;
bottom: 0;
}
Not unexpectedly, in retrospect, this puts TITLE flush left with the left edge of #header...but it failed to affect the vertical positioning of the title. So I got exactly the opposite of what I was looking for.
So I tried this:
#title {
position: relative;
}
#title h1 {
font-size: 36pt;
position: absolute;
bottom: 0;
}
My theory was that this would allign the h1 element with the bottom of the containing div element...but instead it made TITLE disappear, completely. I guess this means that it's rendering off the visible screen somewhere.
At this point I'm baffled. I'm hoping someone here can point me in the right direction. Thanks!
don't go changing positioning or floating of the blueprint classes. That will mess up the framework.
What you are trying to do is going to be difficult, because what you are trying to do (I assume) is align the baseline of the type with the bottom of the image. There is no easy way to determine the baseline of type via CSS. So getting them aligned is going to be entirely dependent on the particular font that loads for your user. If your image is 50px high, you could start by setting the line height of your h1 to 50px and then tweak from there. But understand that there will be variance from browser to browser, font to font.
You're probably better off making your headline part of the image then use some image replacement techniques to hide the text.
Give this a go and let me know if it is what you are trying to achieve?
HTML:
<div id="container">
<div class="logo">Logo here</div>
<h1>TITLE</h1>
</div>
CSS:
#container{
background-color:#ccc;
position:relative;
width:300px;
height:200px;
}
.logo{
width:110px;
height:40px;
background-color:#ff0000;
margin: 0 auto;
}
#container h1{
font-size:120%;
font-weight:bold;
text-align:center;
}
Here's a live demo: http://jsfiddle.net/jrLL2/