I'm new to HTML and CSS, I don't know where is the mistake in my code.
So I have a class header-text to show "Welcome to MOK VPS" with h1.
I used float:left; on my CSS code but it stills show the text on the center. But if I use float:right; it moves to the right.
I'm just messing around with HTML and CSS after learning it a few hours and reviewing what I learned.
* {
margin: 0;
padding: 0;
border: none;
font-family: Arial, sans-serif;
}
.header-home {
height: 75px;
background-color: rgba(23, 32, 42, 0.7);
color: #CCD1D1;
}
.header-logo {
float: left;
padding: 20px;
margin-right: 20%;
}
.header-list li {
list-style: none;
float: left;
padding: 25px;
}
.header-login {
padding-top: 25px;
padding-right: 45px;
float: right;
}
.body-text {
float: left;
}
<div class=header-home>
<div class=header-logo>
<h1>MOK VPS</h1>
</div>
<div class=header-list>
<ul>
<li>Home</li>
<li>Features</li>
<li>Contact</li>
</ul>
</div>
<div class=header-login>
<p>LOGIN</p>
</div>
</div>
<div class=body>
<div class=body-text>
<h1>Welcome to MOK VPS</h1>
</div>
</div>
I've added borders around the elements to illustrate what is happening here. Click Run code snippet to see.
* {
margin: 0;
padding: 0;
border: none;
font-family: Arial, sans-serif;
/* adding for demonstration */
border: 1px solid;
}
.header-home {
height: 75px;
background-color: rgba(23, 32, 42, 0.7);
color: #CCD1D1;
}
.header-logo {
float: left;
padding: 20px;
margin-right: 20%;
}
.header-list li {
list-style: none;
float: left;
padding: 25px;
}
.header-login {
padding-top: 25px;
padding-right: 45px;
float: right;
}
.body-text {
border-color: lime;
float: left;
}
<div class=header-home>
<div class=header-logo>
<h1>MOK VPS</h1>
</div>
<div class=header-list>
<ul>
<li>Home</li>
<li>Features</li>
<li>Contact</li>
</ul>
</div>
<div class=header-login>
<p>LOGIN</p>
</div>
</div>
<div class=body>
<div class=body-text>
<h1>Welcome to MOK VPS</h1>
</div>
</div>
If you look closely, you'll see that the body-text div is actually caught on the header-home div. To prevent that, use clear to cause your div to go to the next line, after any previously floated elements.
* {
margin: 0;
padding: 0;
border: none;
font-family: Arial, sans-serif;
/* adding for demonstration */
border: 1px solid;
}
.header-home {
height: 75px;
background-color: rgba(23, 32, 42, 0.7);
color: #CCD1D1;
}
.header-logo {
float: left;
padding: 20px;
margin-right: 20%;
}
.header-list li {
list-style: none;
float: left;
padding: 25px;
}
.header-login {
padding-top: 25px;
padding-right: 45px;
float: right;
}
.body-text {
border-color: lime;
float: left;
clear: left;
}
<div class=header-home>
<div class=header-logo>
<h1>MOK VPS</h1>
</div>
<div class=header-list>
<ul>
<li>Home</li>
<li>Features</li>
<li>Contact</li>
</ul>
</div>
<div class=header-login>
<p>LOGIN</p>
</div>
</div>
<div class=body>
<div class=body-text>
<h1>Welcome to MOK VPS</h1>
</div>
</div>
Just change in your CSS for class body-text. "Absolute positioned" element has no positioned ancestors, it uses the document body, and moves along with page scrolling.:
.body-text {
position:absolute;
}
You can simple add the position:absolute on your class body-text. Just add that get you problem fixed. But you also can make this:
.body-text {
position: absolute;
left: ***** Here you define how much you wanna move the tag, for example 20px***
}
You need to style <h1>. Like text-align: left;.
h1{
float: left;
text-align: left;
display: inline-block; /*use this code if needed. It can be replaced with text-align*/
}
Related
I have tried this. But it doesn't work. I don't know why it makes the parent div appear like that. I want the divisionContainer to contain them. But it doesn't appear like that.
* {
box-sizing: border-box;
}
body {
font-family: arial;
}
.mainContainer {
border: 1px solid #000;
width: 65%;
}
.header {
width: 100%;
height: 85px;
background: #19578c;
}
.header .container {
padding: 5px;
float: right;
}
.header .headerTitle {
color: #4e94d0;
;
font-family: monospace;
margin: 0;
font-size: 300%;
}
.header .navBar li {
display: inline;
padding: 5px;
}
/* here's the problem */
.divisionContainer {
border: 1px solid #000;
margin-top: 2px;
}
.sidebarContainer {
width: 30%;
float: left;
}
.contentContainer {
width: 70%;
float: right;
}
/* here's the problem */
.navBar {
list-style: none;
padding: 0;
margin: 5px 0 0 0;
color: white;
}
<html>
<head>
<title>thepoopstation</title>
</head>
<body>
<div class="mainContainer">
<div class="header">
<div class="container">
<h1 class="headerTitle">[thepoopstation]</h1>
<ul class="navBar">
<li>home</li>
<li>search</li>
<li>global</li>
</ul>
</div>
</div>
<div class="divisionContainer">
<div class="sidebarContainer">
<div class="container">
<ul class="navBar">
<li>my profile</li>
<li>my friends</li>
</ul>
</div>
</div>
<div class="contentContainer">
<div class="container">
<div class="containerHeading">about thepoopstation</div>
<div>
</div>
</div>
</div>
</body>
</html>
It appears as if the parent divisionContainer is not containing them at all. I wanna fix it.
It because how float works...floated elements are out of flow..so you will need to put a in-flow elements below that div to enforce the parent div to take all the inner element space using :after pseudo element
Stack Snippet
* {
box-sizing: border-box;
}
body {
font-family: arial;
}
.mainContainer {
border: 1px solid #000;
width: 65%;
}
.header {
width: 100%;
height: 85px;
background: #19578c;
}
.header .container {
padding: 5px;
float: right;
}
.header .headerTitle {
color: #4e94d0;
;
font-family: monospace;
margin: 0;
font-size: 300%;
}
.header .navBar li {
display: inline;
padding: 5px;
}
/* here's the problem */
.divisionContainer {
border: 1px solid #000;
margin-top: 2px;
}
.sidebarContainer {
width: 30%;
float: left;
}
.contentContainer {
width: 70%;
float: right;
}
/* here's the problem */
.navBar {
list-style: none;
padding: 0;
margin: 5px 0 0 0;
color: white;
}
.divisionContainer:after {
content: "";
display: table;
clear: both;
}
<div class="mainContainer">
<div class="header">
<div class="container">
<h1 class="headerTitle">[thepoopstation]</h1>
<ul class="navBar">
<li>home</li>
<li>search</li>
<li>global</li>
</ul>
</div>
</div>
<div class="divisionContainer">
<div class="sidebarContainer">
<div class="container">
<ul class="navBar">
<li>my profile</li>
<li>my friends</li>
</ul>
</div>
</div>
<div class="contentContainer">
<div class="container">
<div class="containerHeading">about thepoopstation</div>
<div>
</div>
</div>
</div>
</div>
</div>
i want to make my logo and navigation list on the same nav-bar. At first, before i put the logo the nav-list worked well inline-but after i put the logo it started to make a new line (the nav-list).
i would be so glad if you all can help me. You can help to check my code on codepen here
or i will post it here. Thank You. I really appreciate your help.
body{
margin: 0;
font-family: arial;
}
#background-img{
width: 100%;
border: 1px solid black;
height: 198px;
background: url('http://auxanograhicdesigns.com/media/wysiwyg/auxano/digital-marketing-services/web-designing-services/photoshop-banner-template-beautifull-web-banner-designs.jpg')
}
#nav-bar{
top: 0;
position:absolute;
width: 100%;
height: 63px;
background-color: rgba(42, 34, 41, 0.6);
}
.logo{
width: 86px;
height:63px;;
background-color: purple;
margin-left: 30px;
float:left;
display: inline-block;
color: white;
}
.logo p{
text-align:center;
padding-bottom: px;
font-size: 30px;
}
#nav-bar ul{
list-style-type: none;
float: right;
}
#nav-bar li{
display: inline-block;
padding: 1%;
}
#nav-bar a {
text-decoration: none;
color: white;
}
<body>
<div id = "wrapper">
<div id = "background-img">
<div id = "nav-bar">
<a class = "logo" href = "#"><p>Ps</p></a>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Portofolio</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</div>
</body>
Ajust the width of nav ul as you wish. Your error was working with float (is very annoying and difficult to rely on that) and to add a div as nav container: poorly to SEO and just useless content, with more code into HTML. Check CodePen
<body>
<div id = "wrapper">
<div id = "background-img">
<nav>
<a class = "logo" href = "#"><p>Ps</p></a>
<ul>
<li>Home</li>
<li>About</li>
<li>Portofolio</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</body>
<!-- https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAANSAAAAJGRhYzRlMjllLTNlZTMtNDA1OS1iN2M2LTQ5NDI4YmFjZjJhOA.png --!>
body{
margin: 0;
font-family: arial;
}
#background-img{
width: 100%;
border: 1px solid black;
height: 198px;
background: url('http://auxanograhicdesigns.com/media/wysiwyg/auxano/digital-marketing-services/web-designing-services/photoshop-banner-template-beautifull-web-banner-designs.jpg')
}
nav{
top: 0;
position:absolute;
width: 100%;
height: 63px;
background-color: rgba(42, 34, 41, 0.6);
}
.logo{
width: 86px;
height:63px;;
background-color: purple;
margin-left: 30px;
display: inline-block;
color: white;
}
.logo p{
text-align:center;
padding-bottom: px;
font-size: 30px;
}
nav ul{
text-align: right;
list-style-type: none;
display: inline-block;
width: 90%;
}
nav li{
display: inline;
padding: 1%;
}
nav a {
text-decoration: none;
color: white;
}
Please help, I need the white space on the right bar gone and the position of the main content placed at the middle of the page.
What should I do? Any suggestion?
This is my site : http://www.plebonline.co.uk
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 18px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #ea730b;
}
.clock {
color: white;
text-align: center;
padding: 16px 18px;
display: block;
}
.leftbar {
float: left;
background-color: #333;
width: 10%;
margin: 0;
padding: 1em;
margin-bottom: -5000px;
padding-bottom: 5000px;
overflow: hidden;
}
.rightbar {
float: right;
background-color: #333;
width: 10%;
margin: 0;
padding: 1em;
margin-bottom: -5000px;
padding-bottom: 5000px;
overflow: hidden;
}
.maincontent {
padding: 0;
float:left;
margin-left: 10%;
margin-right: 10%;
background-color: #ff00ff;
width: 80%;
}
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li>Projects</li>
<li>Notes</li>
<li>About</li>
<li>Contact</li>
<li style="float:right" class="clock" id="clock"></li>
<script>
var today = new Date();
document.getElementById('clock').innerHTML=today;
</script>
</ul>
<div class="leftbar"></div>
<div class="maincontent"></div>
<div class="rightbar"></div>
There is a div tag close without opening that may be causing the problem.
Change:
<div class="leftbar"></div>
<div class="maincontent"></div>
</div>
<div class="rightbar"></div>
To:
<div class="leftbar"></div>
<div class="maincontent"></div>
<div class="rightbar"></div>
I notice that you didn't put your rightbar and leftbar in any div. In my code here, I remove the right and left bar. You can adjust the code if you want them back.
It's better to add some container to hold all of your element. As you notice the header and the maincontent is inside the div class .container.
Hope this help.
html,body {
margin:0;
padding:0;
height: 100%;
/*
* The container which hold the header and the main content
*/
.container {
width:100%;
position: absolute;
height:1200px;
background:#333;
}
/*
* Header which contain your menu and date
*/
.header {
width:100%;
}
/*
* The main content of your site
*/
.maincontent {
width:80%;
max-width:1000px;
background-color: #fff;
float:left;
left:50%;
height:100%;
margin-left:-500px;
position: absolute;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 18px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #ea730b;
}
.clock {
color: white;
text-align: center;
padding: 16px 18px;
display: block;
}
</style>
<body>
<div class="container">
<div class="header">
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li>Projects</li>
<li>Notes</li>
<li>About</li>
<li>Contact</li>
<li style="float:right" class="clock" id="clock"></li>
<script>
var today = new Date();
document.getElementById('clock').innerHTML=today;
</script>
</ul>
</div>
<div class="container">
<div class="maincontent">
<h1>This is the content</h1>
</div>
</div>
</body>
I've never seen anything stupid like that, or may be it's 2:30 am and I am hallucinating. I've made simple anchor links within the header and I am completely unable to click on them. They are just plain text and are completely non-clickable.
I'll be thankful if you can give me a hint as what/where I am not obeying the HTML/CSS daemon.
HTML
<header>
<div class="confine">
<div class="complete-head-content">
<div class="left-width-less logo-width">
<img src="./imgs/twit-logo.png" />
</div>
<div class="right-width-less">
<div class="top-header-content">
<h1 class="pres-title">Defining Twisted Strategy</h1>
</div>
<div class="lower-header-content">
<div id="navcontainer">
<ul>
<li>Meet the Hobos</li>
<li>Why me?</li>
<li>Our Work in Oblivion</li>
<li>Our Perspective</li>
<li>Our Approach</li>
</ul>
</div>
</div>
</div>
<div class="c"> </div>
</div>
</div>
</header>
<div id="contend">
... ... ...
CSS
a {
color: #EA2E49;
text-decoration: none;
}
a:hover {
text-decoration: underline;
color: #EA2E49;
cursor: pointer;
}
header {
height: 50px;
position: absolute;
top: 0;
left: 0;
width: 100%;
display: block;
z-index: 1;
}
.complete-head-content {
width: 100%;
background-color: #a0c654;
height: 130px;
}
.left-width-less {
float: left;
background-color: #fff;
width: 15%;
text-align: center;
height: 130px;
vertical-align: middle;
}
.left-width-less img {
width : 76px;
height: 100px;
margin-top: 10px;
}
.right-width-less {
float: right;
width: 85%;
}
.top-header-content {
width: 100%;
height: 70px;
background: #437b3c url("../imgs/presentation-title-bg.jpg") no-repeat right;
}
.lower-header-content {
width: 100%;
height: 70px;
}
.logo {
cursor: pointer;
}
/* Navigation */
#navcontainer {
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
text-transform: uppercase;
margin-top: 19px;
}
#navcontainer ul
{
margin: 0;
padding: 0;
list-style-type: none;
text-align: left;
}
#navcontainer ul li { display: inline; }
#navcontainer ul li a
{
text-decoration: none;
padding: .2em 1.7em;
color: #fff;
}
#navcontainer ul li a:hover
{
color: #fff;
background-color: #369;
}
EDIT
Thanks to Nikhil, the had a Z-index:1 which when removed fixed the bug.
Thanks.
Unless you left something out. it is working for me with and without css.
Tested in IE 8
How did you include the CSS btw?
The <div id="contend"> right next to tag had a z-index:1. This made every link in <header> tag non-clickable.
The solution was to remove the z-index property.
Hope it helps someone.
This might be a really basic css question but I tried to create my fluid layout following instructions from a book, so far my header and nav bar seems to be in the place but the content div isn't, also I'd like to make my content height flexible because it's for a dynamic web app so the footer should be positioned below it accordingly. Ok so here's the mockup of what id like to achieve
<body>
<div id="header">
<h1>LOGO</h1>
<ul>
<li> Home </li>
<li> Logout </li>
</ul>
</div>
<div id="navigation">
<ul>
<li>Home</li>
<li>My account</li>
<li>Help</li>
<li>Contact Us </li>
</ul>
</div>
<div id="personalised">
<p>Hey there</p>
</div>
<div id="content">
</div>
<div id="footer">
<p>© TEST</p>
</div>
</body>
</html>
here's my css code:
body{
width: 90%;
margin: 0 auto;}
#content {
overflow: auto;
height: 29em;}
#header{
height: 60px;
overflow: hidden;
}
#header h1 {
float: left;
}
#header ul {
float: right;
}
#header li {
display: inline;
padding: 0.5em;
}
#personalised p {
float: left;
width: 20%;
margin-top:5%;}
#navigation{
margin: 1%;}
#navigation ul {
font-family: Arial, Verdana;
font-size: 14px;
padding: 0px;
list-style: none;
}
div#navigation {
float:right;
position: absolute;
top: 10%;
right: 5%;
}
#navigation ul li {
display: block;
position: relative;
float: left;
}
#navigation li ul { display: none; }
#header, #footer, #navigation, #personalised {
margin: 1%;
}
#footer {
padding: 0.5em 0;
font-family: Arial, Verdana;
font-size: 10px;
text-align: center;}
I know this is long, but I'd really appreciate your help. Thanks in advance
Try working on your formatting first. (It's not too bad, but can use improvement.) That's one of the biggest benefits to you is code that you can read. You can look through what I've done here and play with what you like. http://jsfiddle.net/mPH8X/
<head>
<style>
div {
border: 1px dashed #FF0000;
}
body {
margin: 0px;
padding: 0px;
}
.clear {
clear: both;
}
#header {
min-height: 60px;
overflow: hidden;
margin: 1%;
}
#header h1 {
float: left;
}
#header ul {
float: right;
}
#header li {
display: inline;
padding: 0.5em;
}
#navigation{
margin: 1%;
float: right;
}
#navigation ul {
font-family: Arial, Verdana;
font-size: 14px;
padding: 0px;
margin: 0px;
list-style: none;
}
#navigation ul li {
margin: 0px;
padding: 0px;
display: block;
position: relative;
float: left;
}
#navigation li ul {
display: none;
}
.body {
clear: both;
}
#personalised {
margin: 1%;
float: left;
width: 20%;
}
#content {
margin: 1%;
float; right;
min-height: 29em;
}
#personalised p {
margin: 0px;
padding: 0px;
}
#header, #footer, #navigation, #personalised {
}
#footer {
padding: 0.5em 0;
font-family: Arial, Verdana;
font-size: 10px;
text-align: center;
}
</style>
<body>
<div id="header">
<h1>LOGO</h1>
<ul>
<li> Home </li>
<li> Logout </li>
</ul>
<div class="clear"></div>
</div>
<div id="navigation">
<ul>
<li>Home</li>
<li>My account</li>
<li>Help</li>
<li>Contact Us </li>
</ul>
<div class="clear"></div>
</div>
<div class="body">
<div id="personalised">
<p>Hey there</p>
<div class="clear"></div>
</div>
<div id="content">
</div>
</div>
<div id="footer">
<p>© TEST</p>
</div>
</body>
</html>
Edit: Looking at your content statement, you are looking for CSS's min-height. Min-height will set it to a minimum height and grow when necessary. overflow: auto; says if your content stretches past the maximum height, add a scrollbar.
I think the culprit is this:
#content {
overflow: auto;
height: 29em;}
You are explicitly setting the height of the content div. Try setting it to inherit.
Here is a fiddle where the container grows according to the number of elements in it:
http://jsfiddle.net/pUb6q/2/
Uses your layout. The changes are
#content {
border:1px solid black;
float: right;
overflow: auto;
height: inherit;
}