I have a header div which is absolute so I want to make it fixed, but if I do that the contents inside starts changing position on resizing window. What trick can I use to achieve a fixed header div which do not move contents on window resize ?
Below is my code :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Client </title>
<style type="text/css">
.heading {position:fixed; visibility:show; width:100%; left: 0px; top: 0px; z-index:3;
border-bottom:5px solid #ccc; }
header{
position:absolute;
width: 100%;
height: 60px !important;
z-index:7;
top: 0px;
}
/*My div position*/
.positioning-container{position:relative;
width:1000px; margin:0 auto 0 auto;
black solid; padding:0px;
padding:60px 0 30px 0;
border-bottom:0px; padding:0px;
background:#eee;}
.inner-container{position:relative;
background:#fff; padding:0px;
padding:60px 0 30px 0; }
/*My div position*/
</style>
</head>
<body>
<div class="positioning-container">
<div class="inner-container" align = "center">
<header>
<div class= "heading" style="width:100% ; height:50px; background-color:#00A5C6">
<table id ="headertable" align="left"><tr><td>
<h2 class= "logo">Client Review</h2><td> </td></td><td>
<label>Search</label><input typ= "text"></td>
<td>search</td>
<td>Login</td>
<td>Add Client</td>
<td>Logout</td>
<td align="left" class="profile"><img src="bhubezi/images/logos/nopic.png" width="50"
height="40"></td>
</tr>
</table>
</div>
</header>
<div class="content">
content
</div>
</div>
</div>
you can give your .heading class a minimum width.
so on your css add something like
min-width:700px;
on your .heading styles
Related
I am beginner in this field.I want the logo(image used) to appear on the strip itself but when I use this code it appears below that strip.Basically, I want a strip with background colour black and a heading/title in the centre with a logo at the rightmost corner of that coloured strip.
Here's my code:-
<html>
<head>
<title>MIT PULSE-Home</title>
<style>
.topbar{
color:white;
background-color:black;
height:125px;
width=100%;
text-align: cente
border-bottom:solid 2px red;
}
#Shift{
margin-top:10px;
font-size:100px;
}
body{
margin:0;
padding:0;
}
</style>
</head>
<body>
<div class="topbar">
<p align="center" style="font-size:100px">MIT Pulse</p>
<img src="logo.jpg" align="right" height="75">
</div>
</body>
</html>
Are you looking for something like this? I corrected a few mistakes in your CSS code, added position: relative; to your class .topbar and created a new class .logo which I added to the <img>-Tag.
Also, keep in mind the comment from ThisGuyHasTwoThumbs, you shouldn't use inline CSS
For further reading on relative/absolute positioning, I recommend the MDN articles: https://developer.mozilla.org/en-US/docs/Web/CSS/position
<html>
<head>
<title>MIT PULSE-Home</title>
<style>
.topbar{
color:white;
background-color:black;
height:125px;
width: 100%;
text-align: center;
border-bottom:solid 2px red;
/* Position the element relative */
position: relative;
}
#Shift{
margin-top:10px;
font-size:100px;
}
.logo {
/* Absolute position for this element */
position: absolute;
/* Distance from the right side */
right: 0;
/* Center image vertically */
top: 50%;
transform: translateY(-50%);
}
body{
margin:0;
padding:0;
}
</style>
</head>
<body>
<div class="topbar">
<p align="center" style="font-size:100px">MIT Pulse</p>
<img class="logo" src="http://via.placeholder.com/75x75" align="right" height="75">
</div>
</body>
</html>
The logo is appearing below the title because <p> is a block-level element -- that is, it will force the next element to appear on the next line.
By making the title a span with inline-block display you can achieve something like this snippet. (As with other replies I've fixed some typos and removed unused CSS. Also, I second the comment regarding inline CSS.)
EDIT: more on layouts & block vs. inline at this MDN tutorial
<html>
<head>
<title>MIT PULSE-Home</title>
<style>
.topbar{
color:white;
background-color:black;
height:125px;
width:100%;
text-align: center;
border-bottom:solid 2px red;
}
.right {
float: right;
}
.title {
font-size: 100px;
display:inline-block;
margin: 0 auto;
}
body{
margin:0;
padding:0;
}
</style>
</head>
<body>
<div class="topbar">
<span class="title">MIT Pulse</span>
<img src="logo.jpg" class="right" height="75" >
</div>
</body>
</html>
I need css code for this kind of site:
And with my code I get this:
This is my code of index page:
<html>
<head>
<link type="text/css" rel="stylesheet" href="index.css"/>
<title>
Home Page
</title>
</head>
<body>
<div id=header>
<h1>THIS IS HEADER</h1>
</div>
<div id=account>
THIS IS ACCOUNT<br>
oasdjasdj<br>
asdkasd<br>
asdpasod<br>
</div>
<div id=navigation>
THIS IS NAVIGATION
</div>
<div id=content>
THIS IS CONTENT
</div>
<div id=right_side>
THIS IS RIGHT SIDE
</div>
<div id=footer>
THIS IS FOOTER
</div>
</body>
This is css file:
h1{
font-family: Verdana;
font-weight: bold;
text-align: center;
padding-top: 25px;
padding-bottom: 25px;
color: #acd1b2;
}
#header{
margin : 0px;
position: relative;
width:80%;
background-color: red;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
}
#navigation{
margin : 0px;
width:80%;
background-color:blue;
}
#right_side{
width: 20%;
float: right;
background-color: #green;
}
#footer{
clear: both;
position: relative;
width:80%;
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
background-color: gray;
}
#account{
position: relative;
width: 20%;
float: right;
background-color: #yellow;
}
#content{
width:80%;
float:left;
background-color:#black;
color: white;
}
Please if someone know how to position divs like on my first picture. When I try something I always get strange results. Thanks for help!
Alright, there were a few problems with the way that you wrote your HTML. First, ID tags should always have quotations around the ID name. I would just make a container div, a div for the left, and a div for the right side.
I made a demo that uses floats to control the layout. The divs are contained in a large div that is restricted to 800 pixels.
Here's the demo that I made on JS Bin
HTML:
<body>
<div id="container"> <!-- Make a container to hold everything. Centered in CSS -->
<div id="left-side">
<div id="header">Header</div>
<div id="navigation">Navigation</div>
<div id="content">Content Here</div>
<div id="footer">Footer</div>
</div> <!-- End of the left side div -->
<div id="right-side">
<div id="account">Account</div>
<div id="right_side">Right Side</div>
</div> <!-- End of the right side div -->
</div> <!-- End of the container div -->
</body>
CSS:
*{
font-family:sans-serif;
}
#container{
max-width:800px;
margin: 0 auto;
}
#left-side{
float:left;
width:60%;
}
#right-side{
float:right;
width:37%;
}
#left-side div{
text-align:center;
margin-bottom:10px;
}
#right-side div{
text-align:center;
margin-bottom:10px;
}
#header{
background-color: yellow;
text-align:center;
padding:20px 0px;
}
#navigation{
padding:10px 0px;
border: 1px black solid;
}
#right_side{
background-color: cyan;
padding:50px 0px;
}
#footer{
background-color: gray;
padding:5px 0px;
}
#account{
background-color: green;
padding: 10px 0;
}
#content{
background-color:black;
color: white;
padding:100px 0px;
}
Change HTML as follow because you need container divs:
<head>
<link type="text/css" rel="stylesheet" href="index.css"/>
<title>
Home Page
</title>
</head>
<body>
<div class="left_container">
<div id=header>
<h1>THIS IS HEADER</h1>
</div>
<div id=account>
THIS IS ACCOUNT<br>
oasdjasdj<br>
asdkasd<br>
asdpasod<br>
</div>
<div id=navigation>
THIS IS NAVIGATION
</div>
<div id=content>
THIS IS CONTENT
</div>
<div id=footer>
THIS IS FOOTER
</div>
</div>
<div class="right_container">
<div id=right_side>
THIS IS RIGHT SIDE
</div>
</div>
</body>
in CSS file add also
.left_container{float:left;width:80%;margin:0px}
.right_container{float:left;width:20%;margin:0px}
.clr{clear:both}
Something like this perhaps?, learn about CSS class'es there reusable (incase you might want multiple right side box's and it will shorten the CSS code because you dont need to create a selector for every element.
Copy and paste source - change to suit...
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
* {
margin:0;
padding:0;
}
#wrapper {
width:800px;
height:100%;
margin:0 auto;
}
#wrap-left {
width:75%;
height:100%;
float:left;
}
#wrap-right {
width:25%;
height:100%;
float:right;
}
#header,#navigation,#footer,.right-small {
height:45px;
margin:10px;
}
#content,.right-tall {
height:230px;
margin:10px;
}
.round-corners {
-webkit-border-radius:25px;
-moz-border-radius:25px;
border-radius:25px;
padding:20px;
}
.bg-yellow {
background:#FEF200;
}
.bg-red {
background:#ED1B24;
}
.bg-blueish {
background:#3F47CC;
}
.bg-green {
background:#23B14D;
}
.bg-grey {
background:#C3C3C3;
}
.border {
border:5px solid #000;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="wrap-left">
<div id="header" class="bg-red round-corners">
<h1>THIS IS HEADER</h1>
</div>
<div id="navigation" class="bg-blueish round-corners">
THIS IS NAVIGATION
</div>
<div id="content" class="border round-corners">
THIS IS CONTENT
</div>
<div id="footer" class="bg-grey round-corners">
THIS IS FOOTER
</div>
</div>
<div id="wrap-right">
<div class="right-small bg-yellow round-corners">
ACCOUNT
</div>
<div class="right-tall bg-green round-corners">
left side
</div>
</div>
</div>
</body>
</html>
why no use a table
<body>
<table width="100%" cellspacing=5 cellpadding=5 border =0 >
<tr><td bgcolor=red width="80%" height=200px> header </td> <td bgcolor=yellow>account</td> </tr>
<tr><td bgcolor=blue height=100px> navigation </td> <td bgcolor=green rowspan=2>Left side</td> </tr>
<tr><td bgcolor=cyan height=400px> content </td></tr>
<tr><td bgcolor=grey height=100px> footer </td></tr>
</table>
</body>
you don't need css for that..
I've been trying to add a header to my website, but I cannot get the container to fit the full width of the screen, despite the width being set to 100% or auto. It always has about a ~5px margin on both the left and right, even with margin and padding both set to 0.
HTML:
<div id="header">
<h7>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
</h7>
</div>
CSS:
body div#header{
width: 100%;
margin: 0;
padding: 0;
background-color: #c0c0c0;
}
Add
body, html{
margin:0;
padding:0;
}
to your CSS.
Browsers put default margins and/or paddings when rendering websites. With this you can avoid that.
body, html {
margin: 0;
padding: 0;
}
div { width: 100%;
margin: 0;
padding: 0;
background-color: #c0c0c0;
}
OR
html, body, div {
margin:0;
padding:0;
border:0;
outline:0;
background:transparent;
}
This is because it's being padded by it's parent. Do you have it contained in another div? Or maybe you have a padding/margin property set on the document's body? Please supply your full CSS. If you don't it's because the browser is adding it for you, so explicity set it using:
body {
margin: 0;
padding: 0;
}
put a zero margin on your body/html tags in your CSS. See if that helps.
You'll need to add a reset such as:
html, body, div {
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}
All browsers have a default stylesheet. You need to override it with a reset.
Try this, i hope this helps:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Header & Footer</title>
<style type="text/css">
/* Global */
* {
margin: 0;
}
html, body {
height: 99%;
}
/* Header */
.container{
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
width:100%;
font-family:Segoe UI;
color:#fff;
}
.container-header{
padding-top:5px;
padding-left:20px;
}
/* Footer */
.footer{
background-color:#333030;
width:100%;
font-family:Segoe UI;
color:#fff;
}
.footer img{
padding-left:15px;
}
/* Page Content */
.content{
height: auto !important;
}
.container p{
font-size:12pt;
font-weight:bold;
}
</style>
</head>
<body>
<!-- Header Div -->
<div class="container">
<table width="100%" style="background-color:#333030;color:#FFFFFF;padding:10px">
<tr></tr>
<tr>
<td></td>
<td>
<div style="padding-left:100px;font-size:36px;">Header</div>
</td>
</tr>
<tr></tr>
</table>
<!-- Page Content Div -->
<div class="content">
Blah Blah
</div>
</div>
<!-- Footer Div -->
<div class="footer">
<table width="100%" style="background-color:#333030;color:#FFFFFF;padding:10px">
<tr></tr>
<tr>
<td></td>
<td>
<div style="padding-left:100px;font-size:36px;">Footer</div>
</td>
</tr>
<tr></tr>
</table>
</div>
</body>
</html>
Try out the following code:
<!DOCTYPE html>
<html>
<head>
<style>
body, html{
margin:0;
}
</style>
</head>
I have a image centered on the screen. I need to display some text above the image and I want to set the text coordinates relative to image.
If a user have a different resolution:
The image always located on the top and center of the browser.
The text will be on the same position in the image.
I have tried:
<style type="text/css">
#l1 {
position: relative;
left: 20px;
top: 30px;
color: #03C;
}
</style>
<div align="center">
<div id="l1" align="left">
some
</div>
<img src="some.jpg" width="1024" height="788" />
</div>
But it doesn't work. How can I achieve my goal?
Set the text to be position:absolute and the containing div to be position:relative
And also center the div using margins and not the deprecated align attribute..
<style type="text/css">
.container{
position:relative;
margin-left:auto;
margin-right:auto;
width:1024px;}
#l1 {
position: absolute;
left: 20px;
top: 30px;
color: #03C;
text-align:left;
}
</style>
<div class="container">
<div id="l1">
some
</div>
<img src="some.jpg" width="1024" height="788" />
</div>
I would do it like this:
<!doctype html>
<html>
<head>
<title></title>
<style type="text/css">
/*reset default margins, paddings, set body font*/
html,body,h1,h2,h3,h4,h5,p,ul,li,form,button { margin:0; padding:0 }
body { font:normal 62.5% tahoma }
#my-image {
width:1024px; height:788px;
background:url(some.jpg); /* use image as background */
margin:0 auto; /* this centers the div in the browser horizontally */
position:relative; /* set positioning context for children */
}
#my-text {
position:absolute;
left:0px; top:0px; /* left and top are with respect to the parent div */
}
</style>
</head>
<body>
<div id="my-image">
<div id="my-text">some text</div>
</div>
</body>
</html>
<div>
<h1>Title</h1>
<table>
...
</table>
</div>
Now, the
<h1>
has a margin: 0;
so it is at the top of the div. The height of the div is 300px.
However I'd like the table to be placed at the bottom of the div, eg. valign="bottom" but for the whole table.
Here is what Remy Sharp suggested:
<style type="text/css" media="screen">
#container {
position: relative;
margin: 0;
height:300px;
border:1px solid #000;
}
#container h1 {
margin:0;
}
#tableLayout {
position: absolute;
bottom:0;
border: 1px solid #c00;
}
</style>
<div id="container">
<h1>Title</h1>
<table id="tableLayout">
<tr><td>example cell</td></tr>
</table>
</div>
Looks like it works!
I posted it here so it will always be here.
Try this: http://jsbin.com/emoce
Though it's similar to Darryl's solution. Except I'm not using position:absolute on the wrapping div, but rather position: relative to make the table's position absolute to that.
What about this:
<style type="text/css">
#container {
position: absolute;
margin: 0;
height:300px;
border:1px solid #000; }
#container h1 {
margin:0; }
#tableContainer {
position: absolute;
bottom:0; }
</style>
<div id="container">
<h1>Title</h1>
<div id="tableContainer">
<table id="tableLayout">
<tr><td>...</td></tr>
</table>
</div>
</div>
The only problem is that both the container div and the tableContainer divs need to be absolute positioned. Not sure if this will work for your layout.