How to place items exactly where you want to CSS - php

Alright, so this is my HTML right now.
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>GeoVillage - A Community</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id=header>
<img id=logo src="/logo.png" alt="GeoVillage Community" style="width:500px;height:128px;">
<span id=logreg>
<?php
if(isset($_SESSION['loggedon']) && $_SESSION['loggedon'] == true){
echo '<a href=/logout>
<img id=logout src="/logout.png" alt="Logout">
</a>';
} else {
echo '<a href=/login>
<img id=login src="/login.png" alt="Login">
</a>';
echo '<a href=/login/register.php>
<img id=register src="/register.png" alt="Register">
</a>';
}
?>
</span>
</div>
<ul>
<li>FSX/X-P/P3D Vatsim Online Material</li>
<li>Development Page</li>
</ul>
<?php
echo($_SESSION["loggedon"]);
?>
</body>
</html>
And this is my CSS file.
body{
background-color: #33ccff;
margin: 0px;
}
#header{
display:inline;
Right now, the Login and Register buttons are at the top, but aligned essentialy with the bottom of the banner. How would i position it so it would be aligned with the top of the banner?

Try this
#logreg {vertical-align: top;display: inline-block;}

METHOD 1
This makes the width of your header wider, to allow the login / register buttons to fit within the header container. The #logoreg CSS then adds a margin to the top of the login / register button container, which centers it with the logo when the right px amount is specified.
CSS:
#header {
display: block;
width: 105%;
}
#logreg {
float: right;
margin-top: 15px;
}
METHOD 2
Change the width of your banner image.
<img id="logo" src="/logo.png" alt="GeoVillage Community" style="width: 700px;height:96px;">
Then put this in your CSS:
#logreg {
margin-top: 15px;
float: right;
display: inline-block;
}

Related

Image not visible after applying css background color

I can't able to see the image after applying CSS background color.
HTML page:
<html>
<head>
</head>
<body>
<div class="heading">
<h2>
<span>LUMINO</span>ADMIN
<img name ="messageicon" alt="Messages" src="<?php echo base_url(); ?>img/closed-envelope-circle.png">
</h2>
</div>
</body>
</html>
CSS page:
.heading{
background-color: yellow;
width: 100%;
height: 10%;
left: 0;
top: 0;
}
.heading h2{
margin-left: 25px;
padding: 15px;
}
h2{
color: white;
}
span{
color: skyblue;
}
SCREENSHOTS:
The image should be visible after applying the CSS background color.
The images might be having transparent background. In this case it will use the container's background color. Apply a background-color css rule to the img to get a color to your image.
.heading img{
background-color: white;
}
Just in case, base_url(); isn't a valid function (if you haven't written one).
you can use $_SERVER['REQUEST_URI'] it gave you the whole link from your Website back in form of an String. In that case you can use the substr to cut the sting in your form you like.
Here is my Examlpe of your code:
<html>
<head>
</head>
<body>
<div class="heading">
<h2>
<span>LUMINO</span>ADMIN
<img name ="messageicon" alt="Messages" src="<?php echo($_SERVER['REQUEST_URI']); ?>img/closed-envelope-circle.png">
</h2>
</div>
</body>
</html>
If you want to know more about base urls take a look here
Enjoy and have fun ;)
--- EDITS: ---
<html>
<head>
</head>
<body>
<div class="heading">
<h2>
<span>LUMINO</span>ADMIN
</h2>
<img name ="messageicon" alt="Messages" src="<?php echo($_SERVER['REQUEST_URI']); ?>img/closed-envelope-circle.png" style>
</div>
<style>
.heading {
background-color: black;
width: 100%;
height: 10%;
left: 0;
top: 0;
}
.heading h2{
margin-left: 25px;
padding: 15px;
}
h2{
color: white;
float: left;
}
span{
color: skyblue;
}
</style>
</body>
</html>
Perhaps this one is better and you can test it with e sperate file so you don't need to change your original.

How to display the full content of a database on clicking on 'Read More' button

I have created a database named Magazine and it has a table social_media. The table has 5 columns namely ID, Headline, Author, Content Short, Content. The Content Short column contains the shorter version of the entire article(which will be displayed in the following code) and the Content column contains the entire article(which will be displayed on clicking the Read More button). I have created a homepage where all the articles from the social_media are displayed in the Content_Left div(NOTE: The Content Short column is displayed and not Content). At the end of each entry from the database there is a 'Read More' button. On clicking on that read more button I want the user to be redirected to a new page 'article.php' where the Headline, Author and Content of the corresponding article will be displayed(The Longer version of the content and not the Content Short). How do I do it? I have created the following webpage:
<?php require_once('connections/connection.php'); ?>
<?php
session_start();
$stmt = $con->query("SELECT * FROM social_media");
?>
<!doctype html>
<html>
<head>
<link href="CSS/Layout.css" rel="stylesheet" type="text/css" />
<link href="CSS/menu.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
<meta charset="utf-8">
<title>Home</title>
</head>
<body style="background-color:#E0DDDD">
<div id="Container">
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li>Home</li>
<li>Social Media</li>
<li>Tech</li>
<li>Tips & Tricks</li>
</ul>
</nav>
</div>
<div id="Content">
<div id="Content_Left">
<h1><center>Social Media</center></h1>
<table>
<?php
while($records=$stmt->fetch_assoc()) {
$_SESSION["ID"] = $records['ID'];
echo "<tr>";
echo "<th><h3>".$records['Headline']."</h3></th>";
echo "</tr>";
echo "<tr>";
echo "<td>By <strong>".$records['Author']."</strong></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".$records['Content_short']." Read More...</td>";
echo "</tr>";
}
?>
</table>
</div>
<div id="Content_Center">
<h1>Header Here </h1>
<p>Text Goes Here!</p>
</div>
<div id="Content_Right">
<h1>Header Here </h1>
<p>Text Goes Here!</p>
</div>
</div>
<div id="Footer">
<center>Your Copyright Message</center>
</div>
</div>
</body>
</html>
And here is the CSS file(Layout.css):
body{
margin:0;
padding: 0;
}
#Container {
width: 980px;
height:auto;
margin-left:auto;
margin-right:auto;
margin-top:20px;
margin-bottom:21px;
}
#Header {
height:120px;
background-image:url(../Assets/Untitled-1.png);
background-repeat:no-repeat;
margin-bottom:21px;
}
#NavBar {
height:60px;
background-color:#000000;
}
#Content {
background-color:#FFFFFF;
margin-top: 20px;
padding: 5px;
overflow:hidden;
}
#Content_Left {
height: auto;
width: 210px;
padding:5px;
float:left;
background-color: lightblue
}
#Content_Center {
height: auto;
padding:5px;
width: 500px;
float:left;
margin-left: 10px;
margin-right: 10px;
background-color: lightblue
}
#Content_Right {
height: auto;
padding:5px;
width: 210px;
float: right;
background-color: lightblue
}
#Container #Content h1 {
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-style: normal;
font-variant: normal;
font-weight: bolder;
text-shadow: 0px 0px;
}
#Footer {
padding-top: 10px;
height: 100px;
}
And here is the CSS file(menu.css):
nav ul {
margin:0;
padding:0;
}
nav ul li {
list-style-type:none;
display:block;
width:150px;
height:60px;
float:left;
text-align:center;
line-height:55px;
font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
font-size:17px;
}
nav ul li a {
text-decoration:none;
color:#FFF;
}
nav ul li:hover {
background-color:#BBB5B5;
}
nav ul li:hover a {
display:block;
color:Black;
}
I want to display that article in the new page but with the same background theme. Or is there any other way to display the entire article? I hope this much detail is enough. In case any more information is needed please ask.
EDIT: As per the suggestions of the fellow members I have edited the code. My article.php file now looks like this:
<?php require_once('connections/connection.php');?>
<?php
$articleId = $_GET['articleId'];
// you need to fetch only one record this time for showing only the article that wanted to be read. so use `where` condition
$stmt = $con->query("SELECT * FROM social_media WHERE id = $articleId ");
?>
<!doctype html>
<html>
<head>
<link href="CSS/Layout.css" rel="stylesheet" type="text/css" />
<link href="CSS/menu.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
<meta charset="utf-8">
<title>Home</title>
</head>
<body style="background-color:#E0DDDD">
<div id="Container">
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li>Home</li>
<li>Social Media</li>
<li>Tech</li>
<li>Tips & Tricks</li>
</ul>
</nav>
</div>
<div id="Content">
<div id="Content_Full">
<table>
<?php
while($records=$stmt->fetch_assoc()) {
echo "<tr>";
echo "<th><h1>".$records['Headline']."</h1></th>";
echo "</tr>";
echo "<tr>";
echo "<td>By <strong>".$records['Author']."</strong></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".$records['Content']."</td>";
echo "</tr>";
}
?>
</table>
</div>
</div>
<div id="Footer">
<center>Your Copyright Message</center>
</div>
</div>
</body>
</html>
However, I am getting the following error:
Fatal error: Call to a member function fetch_assoc() on a non-object
How do I resolve this problem?
Change few thing
in php file
echo "<td>".$records['Content_short']." <a href='article.php'>Read More...</a></td>";
to
echo "<td>".$records['Content_short']." <a href='article.php?articleId= " . $records['ID']. "'>Read More...</a></td>";
then in your article.php
<?php
if(isset($_GET['articleId'])){
$articleId = $_GET['articleId'];
}else{
echo "Invalid access"; die;
}
// you need to fetch only one record this time for showing only the article that wanted to be read. so use `where` condition
$stmt = $con->query("SELECT * FROM social_media WHERE id = $articleId ");
Follow same html code of your article listing page on article.php
Change your below line
echo "<td>".$records['Content_short']." <a href='article.php'>Read More...</a></td>";
To:
echo "<td>".$records['Content_short']." Read More...</td>";
Now you've to get details by ID and display data accordingly.

Laravel PHP: Container not floating left

I'm currently working on a homepage using the Laravel PHP Framework and I'm running into CSS issues. I'm trying to accomplish a simple task of having two things in my 'header' tag,
1) An image of a logo on the left
2) A container to the right of the logo displaying a user's information
The logo is positioned fine on the left but when I try to position the container to the right of it, it is being positioned underneath the logo instead. I know my CSS is good unless I'm overlooking something entirely but I have a feeling that the Larevel Blade Templating is having an effect in how 'div' elements are being handled.
CSS(style.css):
body {
background:linear-gradient(#3C5D79, #2E4253) no-repeat;
color:white;
}
.container {
width:100%;
}
.header_container {
width:960px;
}
.main_logo_container {
width:313px;
margin:0 170px;
position:relative;
}
.admin_container {
display:inline-block;
float:left;
width:600px;
margin:5px 5px;
position:relative;
}
#extends ('layouts.default')
Admin View after user logs in (admin_index.blade.php):
#section('content')
<header>
<div class="header_container">
<div class="main_logo_container">
<img src="../images/logo.png" width="300" height="97" alt="Company Logo" />
<div class="admin_container">
<b> You have reach the admin page!</b>
</div>
</div>
</div>
</header>
#stop
layouts.default.blade.php(Main Blade Template):
<!doctype html>
<html>
<head>
<meta charset ="utf-8">
<link rel="stylesheet" href=" <?php echo asset('css/style.css')?>" type="text/css">
<style>.flash { padding: 1em; border: 1px dotted black; } </style>
</head>
<body>
#if (Session::get('flash_message'))
<div class="flash">
{{ Session::get('flash_message') }}
</div>
#endif
<div class="container">
#yield('content')
</div>
</body>
</html>
Any help is greatly appreciated since I'm trying to become more familiar with Laravel PHP.
Your logo container was too small because according to your DOM it also carries your text which is 600px wide for a 313px wide container hence the split on two separate lines.
I suggest you change your CSS to fix this and also remove the float: left directive. The display: inline-block here will be more efficient.
Therefore you will get this following CSS:
body {
background:linear-gradient(#3C5D79, #2E4253) no-repeat;
color:white;
}
.header_container {
width:960px;
}
.main_logo_container {
width: 100%;
}
.main_logo_container img {
display: inline-block;
}
.admin_container {
display: inline-block;
margin-left: 5px;
position:relative;
top: -40px;
}
And here is a demo to show you the working result:
http://jsfiddle.net/w7wqaw9L/

Couple of page layout problems

I'm having some trouble getting my page laid out the way I want. I have a gap that's showing up between two divs on my page, and a css menu that I can't figure out how to center. Any help would be appreciated...
FYI, template_header.php is the only template with any content in it at this point.
Here is the code...
* index.php *
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body >
<?php include './templates/template_header.php'; ?>
<div id="pageBody">
<?php
include './templates/template_contextmenu.php';
include './templates/template_content.php';
include './templates/template_sidebar.php';
?>
</div>
<div id="pageFooter">
<?php include './templates/template_footer.php'; ?>
</div>
</body>
</html>
* template_header.php *
<div class="banner" >
<img class="bannerImage" src="./graphics/FullLogo2.png" height="216" />
</div>
<div id="menu">
<ul>
<li></li>
<li>Home</li>
<li>Products</li>
<li>Information</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
* style.css *
header, footer, aside, nav, article, section {
display: block;}
body {
margin: 0px;
padding: 0px;}
div.banner {
background-image:url("./graphics/BannerBG_220.png") ;
background-repeat:repeat-x;
height:13.5em;
border:solid;
border-width:thin;
margin: 0;
padding: 0;}
.bannerImage {
display: block;
margin-left: auto;
margin-right: auto;}
#menu{
position:relative;
display:block;
margin-left:auto;
margin-right:auto;
height:2.25em;
font-size:1.25em;
font-weight: 500;
background:transparent url(./graphics/navbackground2.png) repeat-x ;
font-family:Arial,Verdana,Helvitica,sans-serif;}
#menu ul {
padding:0;
list-style-type:none;
width:auto;}
#menu ul li {
display:block;}
#menu ul li a {
display:block;
float:left;
color:#e5e5e5;
text-shadow: 2px 2px 2px #3d3d3d;
text-decoration:none;
padding: .4em 1.5em .2em 1.5em;
height: 2.25em;
background:transparent url(./graphics/MenuDivider.png) no-repeat top right;}
#menu ul li a:hover, #menu ul li a.current {
background: url(./graphics/NavBackgroundOn.png) repeat-x;}
You won't be able to center #menu using margin: 0 auto without a width. You can measure the width of the links with javascript and then set the sum of all link widths as the width of #menu. You'll see a short delay but it'll work.
As for the white gap, an inspection with Firebug will show you where the unwanted margin or padding is coming from.
Get rid of the whitespace around your php tags.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body >
<?php include './templates/template_header.php'; ?>
<div id="pageBody"><?php
include './templates/template_contextmenu.php';
include './templates/template_content.php';
include './templates/template_sidebar.php';
?></div>
<div id="pageFooter"><?php include './templates/template_footer.php'; ?></div>
</body>
</html>
To center it, try this in the css:
#pageFooter { margin-left:auto; margin-right:auto; }

firefox , IE6 and opera have different things to show

my code which I am going to paste here shows different results in FF, IE6 and Opera.
The difference between results from FF and Opera is the amount of space shown above (in sky color) and below (in white color) the horizontal menu. In the case of IE6, the difference from the result of FF is the amount of space (white color) shown below the horizontal menu. How can I get all 3 browsers to show the same result i.e the current result from FF ?
Html code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title>fffffff</title>
<link rel="stylesheet" href="css/main.css" type="text/css"/>
</head>
<body>
<div id="header">
<div class="header_inside">
<div class="logo">
<img src="img/img_flwr.png" width="224px" height="162px" >
</div> <!-- end of class logo-->
<div class="chat">
<img src="img/img_flwr.png" width="124px" height="62px">
</div>
<div class="clear">
</div>
<div class="name">
<marquee behavior="scroll" direction="RIGHT" scrollamount='5' scrolldelay='25' >
CODE ARROW
</marquee>
</div> -->
<div id="slides">
<img src="img/img_1.jpg" alt="Img 1" width="815px" height="268px" />
</div>
<div class="clear">
</div>
<br>
</div> <!-- end of class header_inside-->
</div> <!-- end of header-->
<div class="menu_h">
<div class="menu_h_inside">
<br>
<ul>
<li><a href="index.php" id="home_nav" >Home</a></li>
<li>About</li>
<li>Products</li>
<li>News</li>
<li>Photo Gallery</li>
<li>Video Gallery</li>
<li>Career</li>
<li>Contact</li>
</ul>
<br style="clear:left"/>
</div> <!-- end of class menu_h_inside-->
</div>
</body>
</html>
and the css is:
/* CSS Document */
*{
padding:0;
margin:0;
}
body{
width: 1160px;
/*background:#BFFDC4 !important;*/
margin-left: 20px;
/*border:4px solid red;*/
}
#frame {
/*width: 710px;*/
width: 1125px;
/*BORDER:12PX SOLID RED;*/
/*border:7px solid green;*/
}
#header{
position:relative:
display:block;
/*border:10px solid green;*/
width:1160px;
background:#9DD4FF;
}
.header_inside{
}
body#home a#home_nav,
body#image_gallery a#image_gallery_nav
{
background-color:#0b75b2 !important;
}
.logo{
position:relative;
left:3px;
top:3px;
float:left;
/*border: 8px solid #F2AC4E;*/
}
.chat{
position:relative;
float:left;
display:inline-block;
margin-left:100px;
margin-top:15px;
/*border:13px solid red;*/
}
.chat img:hover{
}
.clear{
clear:both;
}
.name{
position:relative;
display:block
clear:both;
width:300px;
height:50px;
MARGIN-TOP:75PX;
background-color:#000000;
color:#FFFF80;
font-size:40px;
}
#slides{
position:relative;
left:300px;
MARGIN-top:-180px;
FLOAT:LEFT;
}
/* horizontal menu_h css begins*/
.menu_h{
position:relative;
margin-top:20px;
width: 1145px;
/*border:5px solid yellow;*/
}
.menu_h ul{
margin: 0; padding: 0;
float: left;}
.menu_h ul li{
display: inline;
}
.menu_h ul li a{
float: left; text-decoration: none;
color: white;
padding: 10.5px 44.6px;
/*background-color: #333; EDITED BY ME */
background-color:#C7A781;
border-right: 1px solid #FFFFFF;
}
.menu_h ul li a:visited{
color: white;}
.menu_h ul li a:hover, .menu_h ul li .current{
color: #fff;
background-color:#0b75b2;}
/* horizontal menu_h css ended */
.menu_h_inside{
margin-left:1px;
/*margin-top:7px;*/
}
IMAGES should be used in appropriate places.
Thanks in advance.
Istiaque Ahmed
Bangladesh
Your problem is most likely caused by the browser default stylesheets being all over the place. You should consider adding in a good CSS reset before spending a lot of time trying to debug the problem. This one is from the guy that came up with the first universal reset. It works pretty well.
http://meyerweb.com/eric/tools/css/reset/
Your doctype is incorrect and you are in quirks mode. Change your doctype to this <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> and see where we stand.
Make sure you follow Firefox or Opera first. Then look to see how IE screws things up before you try and "fix" anything. Never, ever trust IE to do anything right.

Categories