How to get body below header using relative positioning? - php

I am trying to create a page where the header is centered 70% of the window and a body 85% of the window. The header goes on top of the body, but I can't seem to accomplish this. When I add relative positioning to my #body div; the div seems to be positioned relative to the window (body) of the page instead of the header. How do I make it so the #body div is positioned relatively below the #header div so the body is going in the flow of the page? (I want all the elements inside #header to stay exactly where I positioned them).
HTML/PHP
<?php
$resultSet = $db->query("SELECT * FROM table");
if ($resultSet->num_rows != 0)
{
while ($rows = $resultSet->fetch_assoc())
{
$id = $rows["id"];
$images = $rows["image"];
$title = $rows["title"];
if ($id <= 3)
{
//Front page Div that contains all the header elements
echo "<div id=header>";
if ($id == 1)
{
//The front page div that contains the large image and the title
echo "<div id=largeDiv>";
echo "<img src=$images>";
//Div inside of largeImg div, that creates semi-transparent block for title
echo "<div id=largeTitle>";
//Main title of header
echo "<h2>$title</h2>";
echo "</div>"; //End of largeTitle div
echo "</div>"; //End of largeDiv
}
//Secondary div inside of #header that goes on the right side of #largeDiv
echo "<div id=smallDiv>";
if ($id == 2)
{
//Left image
echo "<img id=leftImg src=$images>";
}
if ($id == 3)
{
$text = $rows["text"];
//Right image
echo "<img id=rightImg src=$images>";
//Secondary div's title
echo "<h2>$title</h2>";
//Secondary div's text
echo "<p>$text</p>";
}
echo "</div>"; //End of smallDiv
echo "</div>"; //End of header
}
else
{
echo "<div id=body>";
if ($id <= 13)
{
echo "<div id=left>";
echo "<img src=$images>";
echo "</div>";
}
echo "</div>";
}
}
}
?>
CSS
/*BODY OF ENTIRE PAGE*/
body{
position: relative;
}
/*HEADER OF PAGE. CONTAINS ALL HEADER ELEMENTS*/
#header{
position: relative;
width: 70%;
height: auto;
margin: 1.5% auto;
}
/*MAIN DIV OF HEADER*/
#largeDiv{
position: absolute;
width: 65%;
}
/*IMAGE OF THE MAIN DIV OF HEADER*/
#largeDiv img{
width: 100%;
}
/*THE DIV INSIDE OF #LARGEDIV THAT IS A SEMI-TRANSPARENT BLOCK*/
#largeTitle{
position: absolute;
width: 100%;
height: 25%;
bottom: 1.5%;
background-color: rgba(0, 0, 100, 0.4);
}
/*THE H2 TAG FOR THE MAIN TITLE OF THE HEADER, THIS IS INSIDE #LARGETITLE*/
#largeTitle h2{
color: white;
text-align: center;
font-family: sans-serif;
font-size: 22px;
}
/*SECONDARY DIV OF HEADER, NEXT TO THE #LARGEDIV*/
#smallDiv{
position: absolute;
right: 0%;
top: 0%;
width: 32%;
height: auto;
}
/*LEFT SMALL IMAGE OF HEADER*/
#leftImg{
width: 45%;
float: left;
}
/*RIGHT SMALL IMAGE OF HEADER*/
#rightImg {
width: 45%;
float: right;
}
/*THE TITLE OF THE SECONDARY DIV OF HEADER*/
#smallDiv h2{
clear: both;
font-size: 24px;
margin-top: 48%;
color: cornflowerblue;
font-family: sans-serif;
}
/*THE TEXT OF THE SECONDARY DIV OF HEADER*/
#smallDiv p{
font-size: 100%;
font-family: sans-serif;
margin-top: -5%;
}
#body{
position: relative;
width: 85%;
}
#left{
width: 28.33%;
}
#left img{
display: block;
width: 100%;
}
Sample dataset:
<div id=header><div id=largeDiv><img `src=http://i2.cdn.turner.com/cnnnext/dam/assets/150429103538-bernie-sanders-gallery-photo-5-super-169.jpg><div id=largeTitle><h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Val hala mo sema serum.</h2></div></div><div id=smallDiv></div></div><div id=header><div id=smallDiv><img id=leftImg src=http://a4.files.biography.com/image/upload/c_fill,cs_srgb,dpr_1.0,g_face,h_300,q_80,w_300/MTE4MDAzNDEwMDU4NTc3NDIy.jpg></div></div><div id=header><div id=smallDiv><img id=rightImg` src=https://pbs.twimg.com/profile_images/602821590582038528/oobPhTxZ_400x400.png><h2>Prima disputando per ne, mea amet</h2><p>Ut usu soleat torquatos, vix iudico singulis constituto ut. In vim consul assueverit, ius no veniam voluptatum. Veritus vivendum</p></div></div><div id=body><div id=left><img src=http://www.planwallpaper.com/static/images/Winter-Tiger-Wild-Cat-Images.jpg></div></div><div id=body><div id=left><img src=http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg></div></div><div id=body><div id=left><img src=http://newflowerwallpaper.com/download/flower-images-to-color-and-wallpapers/flower-images-to-color-and-wallpapers-16.jpg></div></div><div id=body><div id=left><img src=http://eskipaper.com/images/images-4.jpg></div></div>

body is a page construct and can't be repositioned, so the position style has no acutal effect.
What would be better is if your header content #header was inside another element such as a HTML5 style header, and perhaps #body inside a main container.
So, for example;
<body>
<header>
<div id="header">
Header Content Here
</div>
</header>
<main>
<div id="body">
<div id="left">
Left Content
</div>
</div>
</main>
</body>
CSS
header {
width: 100%;
}
#header{
position: relative;
width: 70%;
height: auto;
margin: 1.5% auto;
}
main {
width: 100%;
}
#body {
position: relative;
width: 85%;
margin: 0 auto;
}
#left {
width: 28.33%;
}
The above is an incomplete solution, but it's an example of how you look to structure your page.
An altnernative is to have a container (like #container) around all the content with the max width of the inner content.

Related

Footer overlapping only one page

The footer is overlapping one of my webpage. all the others pages are fine but this one its overlapping, i dont really want to edit/update the footer as it is working in other pages, but I would like to see if there is something I can do with the css container for this page.
CSS
#box {
width: 100%;
height: auto;
margin-top: 20px;
position:relative;
padding-right:0.4%;
float:left;
margin-bottom: 10px;
}
.boxChildLeft {
left: 0;
width: 80%;
height: 100px;
border: 1px solid;
margin-bottom: 2px;
position: relative;
float: left;
}
CSS footer/body etc
html,
body {
margin:0 auto;
padding: 0;
max-width: 960px;
height: 100%;
background-color: white;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:white;
padding:10px;
}
#body {
padding:10px;
padding-bottom:40px; /* Height of the footer */
}
#footer {
position: absolute;
bottom:0;
left: 0;
right: 0;
height:40px; /* Height of the footer */
background:#EBEBEB;
border-radius: 5px;
}
PHP/HTML
for($temp = 1; $temp <= $cArray[2]; $temp++)
{
$img .= "<div class='boxChildLeft'>
<div class='img'>
<img src='../ProductImages/$cArray[0].jpg' width='100px' height='100px'>
</div>
<div class='prodInfo'>
<p1>$pName</p1><br>
<span id='sp'><p1>$pPrice<p1>
</span>
</div>
</div>";
}
HTML
<div id="box">
<?php echo $img;?>
</div>
The information you provided is not enough, what I suggest is to use W3school HTML validator it will indicate what's missing from your HTML implementation, it will help you by giving suggestions.

vertical Scrollbar is not working

Here is my problem i want to use scrollbar but it is only showing scrollbar but that scrollbar is not working. I am using CSS to style the scrollbar and other layouts and Html to use that styling.
here is my Styling Code
#sub_menu, #content{
display: inline-block;
}
#sub_menu{
width:23%;
height: 10%;
background-color: #999999;
padding: 1%;
vertical-align: top;
border: 1px solid;
}
#content{
width: 73%;
margin-right: 1%;
}
#media screen and (max-width: 600px), sreen\0{
#sub_menu{
height: initial;
font-size: 15px;
margin-bottom: 2%;
}
#content, #sub_menu{
display: block;
width: 95%
} }
.contentt {
height: 100%;
overflow-y: scroll;
margin-bottom: 1%;
}
.contentt::-webkit-scrollbar {
display: none;
}
And Here is my HTML CODE
<div id="sub_menu">
<h3 style="border-bottom: 3px solid rgb(135, 31, 139);">Related Videos</h3>
<div class="contentt" style="width:100%;height:40%; margin-bottom:3%;padding:2%" >
<?php
$con = new mysqli('localhost','','','');
$sql = "SELECT ID, Title, Link FROM that where Category like 'this'";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$url = $row["Link"];
$title = $row["Title"];
$id = $row["ID"];
$path="http://domain/Song.php";
echo "<h5>$title'</h5>";
echo '<img src="http://domain/images/' . $id .'.jpg" alt="HTML tutorial" style="width:75%;height:95%;border:0;"class="btnn songpicc">';
echo '<hr>';
}
} else {
echo "0 results";
}
$con->close();
?>
</div>
</div>
Thanks in Advance
You need to fix the height of the container (not in %, but in px or em for example) with overflow-y: scroll;
your scrollbar is not working or it is hidden ?
remove below css and it should work for you
.contentt::-webkit-scrollbar {
display: none;
}
and instead
.contentt {
overflow-y: scroll;
}
just apply below code and check
.contentt {
height: 400px;
overflow-y: auto;
}
Just remove below code of css
.contentt::-webkit-scrollbar {
display: none;
}
Add below code of css
.contentt {
overflow-y:auto;
height:/* give here height in px as you need */
}
if you use webkit-scrollbar it will hide the scroll bar in chrome. But Firefox still alive with default scrollbar.

dompdf - set page margin only after first page

I am converting an HTML to pdf file using dompdf. It is working fine. But the problem is that I need to have page margin for all the pages except the first page. The first page should have an image covering the whole page. But now the margin is coming for all pages including the first one.
I am not able to disable margin for the first page. Any help is greatly appreciated. Thanks in advance.
Below is my css
<style type="text/css">
body { margin: 0px; }
#page { margin: 50px; }
#header {
position: fixed;
left: 0px;
top: -52px;
height: 50px;
border-bottom: 2px solid #797979;
margin: 0;
}
#footer {
position: fixed;
left: 0px;
bottom: -52px;
height: 50px;
border-top: 2px solid #797979;
margin: 0;
}
#footer .page:after { content: counter(page); }
.firstpage {
position: absolute;
page-break-after: always;
top: -50px;
width: 100%;
margin: 0;
}
.otherpages{ margin: 0; }
</style>
And here's my html
<div class="firstpage">
<img src="pdf-bg.jpg" style="width:100%; height:auto;/>
</div>
<div id="header">
<p><?php echo date("F j, Y"); ?></p>
</div>
<div id="footer">
<p class="page">Page <?php $PAGE_NUM ?></p>
</div>
<div class="otherpages">
some content
</div>
Try this,
#page { margin: 50px 0; }
.firstpage {
position: absolute;
page-break-after: always;
top: -50px; // compensating for #page top margin
width: 100%;
margin: 0;
}
.otherpages{ margin: 0 50px; }

Grid using calc() show extra pixels

I created a grid using the Pods plugin. For some reason, there are extra pixels at the bottom of each div (see the white space). I've gone through the code multiple times and cannot find a reason for this. Below is the css for the grid. Would anyone know where the white space is coming from?
link: http://test.mpluczenik.com/#work
Thank you!
Functions.php:
// Add Image size for Portfolio List
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
// additional image sizes
add_image_size('portfolio-thumb', 300, 300, true ); // (cropped)
}
Pods template:
<div class="portfolio-list">
<a href="{#permalink}">
<div class="overlay">
<a href="{#permalink}">{#post_thumbnail.portfolio-thumb}
</a>
<p>
<a href="{#permalink}">{#post_title}
</a>
</p>
</div>
</a>
CSS:
div .portfolio-list{
border: 0px;
padding: 0px;
width: calc(20%);
overflow: hidden;
position: relative;
display: inline-block;
float:left;
}
img.attachment-portfolio-thumb{
width:100% !important;
height:100%!important;
}
div .portfolio-list p{
display: none;
color:#000;
}
div .overlay:hover:after {
content: ' ';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(234,79,38,.75);
width: 100%;
height: 100%;
border:none;
margin:0;
padding:0;
}
div .portfolio-list:hover p {
display:block;
z-index: 9999;
position:absolute;
bottom:50px;
left:0px;
text-align: center;
width:100%;
overflow:hidden;
color:#fff;
margin: 0px;
}
div .portfolio-list:hover a{
color:#fff;
font-weight: bold;
opacity: 50%;
}
Thank you!
An inline block has a line height and that is where the extra space is coming from. You can remove the line hight by adding line-height: 0 to your css selector div .portfolio-list. More info here.

Image DIV Covering Child DIV

I have a simple program that echoes images out to a page from a database. I want to have a child element, just a simple slightly transparent box shown on top of the images.
I know child elements always has a higher z-index than it's parent but the image always covers over the box I want on top. When the page is loading I can see the box in the position I want but then when the images load and the box it disappears.
Here is a jsFiddle: http://jsfiddle.net/EBvCZ/
PHP
echo '<div id="wrapper">';
while ($data = mysql_fetch_array($query_run)) {
echo '<div id="picback"><div id="centerpic"><'.'img src="resizeimage.php?photo_id='.$data['photo_id'].'">';
echo '<br style="clear:both;" />';
echo '<div id="titlepic">This is an image</div>';
echo '</div></div>';
}
echo '</div>
CSS
#wrapper {
overflow:auto;
width:1000px;
height:1000px;
margin: 20px auto;
}
#titlepic {
background-color:rgba(0, 0, 0, 0.5);
top:100px;
width:200px;
height:35px;
position:relative;
}
#centerpic {
position:relative;
margin:auto;
width: 200px;
height: 150px;
top:18.75px;
overflow:hidden;
}
#picback {
position:relative;
margin:10px 23px;
top:75px;
float:left;
width:250px;
height:187.5px;
overflow:hidden;
}
#picback:hover {
background-color:rgb(190,190,190);
-webkit-border-radius:0.4em;
-webkit-transition: background-color 0.5s;
}
Here is a working js fiddle:
http://jsfiddle.net/XKHZv/3/
I did some .css changes and also moved one div before the titlepic.
Here is your new .css:
#wrapper {
overflow:auto;
width:1000px;
height:1000px;
margin: 20px auto;
}
#titlepic {
margin-left:auto;
margin-right:auto;
background-color:rgba(0, 0, 0, 0.5);
width:200px;
height:35px;
position:relative;
clear: both;
}
#centerpic {
position:relative;
margin:auto;
width: 200px;
height: 150px;
top:18.75px;
overflow:hidden;
}
#picback {
position:relative;
margin:10px 23px;
top:75px;
float:left;
width:250px;
height: 203.75px;
overflow:hidden;
}
#picback:hover {
background-color:rgb(190, 190, 190);
-webkit-border-radius:0.4em;
-webkit-transition: background-color 0.5s;
}
Then you also have to move a div closing to before the title pic.

Categories