flexed div squeezes the height of other div in nested structure - html

I am new to this forum. I encountered some issues when I was programming a file list display for my education portal.
Here are the codes (part of the whole page):
HTML
<div id = "mcMid">
<div id = "mcMidContainer" class = "tpWhite6">
<div id = "path">
Folder: ROOT
</div>
<div id = "top">
<div id = "name" class = "block1">Name</div>
<div id = "owner" class = "block2">Owner</div>
<div id = "date" class = "block3">Date</div>
<div id = "Delete" class = "block4">X</div>
</div>
<div id = "files">
<div id = "file1" class = "rollOverFBlueFile">
<div id = "name1" class = "block1">Determination of p value</div>
<div id = "owner1" class = "block2">Nguyen Chan</div>
<div id = "date1" class = "block3">2014-05-03</div>
<div id = "Delete1" class = "block4">X</div>
</div>
<div id = "file2" class = "rollOverFBlueFile">
<div id = "name2" class = "block1">Econ Module 1</div>
<div id = "owner2" class = "block2">Joyce</div>
<div id = "date2"class = "block3">2014-05-03</div>
<div id = "Delet2" class = "block4">X</div>
</div>
<?php for ($i=3;$i<$_GET['times'];$i++) { ?>
<div id = "file<?php echo $i; ?>" class = "rollOverFBlueFile">
<div id = "name<?php echo $i; ?>" class = "block1"">Econ Module 2</div>
<div id = "owner<?php echo $i; ?>" class = "block2">Joyce</div>
<div id = "date<?php echo $i; ?>" class = "block3">2014-05-03</div>
<div id = "Delet<?php echo $i; ?>" class = "block4">X</div>
</div>
<?php } ?>
</div>
</div>
</div>
CSS
#mcMid {
float:left;
display:flex;
flex:1;
flex-direction:column;
border-width:1px;
border-left-color:#666;
border-right-color:#666;
border-left-style:solid;
border-right-style:solid;
}
#mcMidContainer {
width:100%;
flex:1;
padding:0px 0px;
}
#path {
width:calc(100% - 20px);
height:auto;
padding:10px 10px;
background-color:#CCC;
}
#top {
width:100%;
height:auto;
padding:5px 0px;
background-color:#EEE;
font-size:12px;
overflow:auto;
}
#files {
width:100%;
flex:1;
overflow:auto;
}
.block1 {
width:calc(50% - 10px);
padding:5px 5px;
height:auto;
float:left;
}
.block2 {
width:calc(20% - 10px);
padding:5px 5px;
height:auto;
float:left;
}
.block3 {
width:calc(20% - 10px);
padding:5px 5px;
height:auto;
float:left;
}
.block4 {
width:5%;
padding:5px 0px;
height:auto;
float:left;
}
.rollOverFBlueFile {
background-color:#FFF;
border-width:1px;
border-bottom-style:solid;
border-color:#999;
width:100%;
height:auto;
padding:5px 0px;
font-size:12px;
overflow:auto;
}
.rollOverFBlueFile:hover {
background-color:#5BADFF;
}
.tpWhite6 {
background-color:rgba(255,255,255,0.5);
}
When this block of code is run with different values of the "times" variable, there were different results. The problem arises when I get the value of "times" to over a certain value when the div's inside start to exceed the allocated height of the "files" div. The "files" div start to stretch and squeezed the "top" and "path" div's.
Is there any other methods, other than fixing the height of "files", to stop this problem? Many thanks!! ^_^

Related

ionic 3 mobile app video auto play and pause on scroll like facebook videos

I want to autoplay the video when it comes in the viewport and should stop playing the video when it goes out of the viewport with ionic 3, can anyone please suggest how to do that?
Yes you can do it.
$(window).scroll(function(){
var trackerOffset = $('.tracker').offset().top; // offset in document
var trackerPosition = trackerOffset - $(window).scrollTop(); // offset in viewport
$('.debug-status').html('video status: ' + checkTrackerPos(trackerPosition));
}).trigger('scroll');
function checkTrackerPos(trackerPosition){
var triggerTop = $('.trigger-top').position();
var triggerBottom = $('.trigger-bottom').position();
if (trackerPosition >= triggerTop.top && trackerPosition <= triggerBottom.top ) {
return 'playing!';
}
return 'paused';
}
* {
margin:0;
padding:0;
box-sizing:border-box;
}
body {
text-align:center;
font-family:Arial,sans-serif;
}
.debug {
font-size:20px;
position:fixed;
left:50%;
top:50%;
width:30vw;
margin-left:-15vw;
margin-top:-35px;
padding:15px;
background:rgba(0,0,0,0.05);
}
.viewport {
position:relative;
width:100vw;
height:200vh;
border:2px dashed red;
display:flex;
justify-content:center;
flex-direction:column
}
/* Position these two as you please */
.trigger-top,
.trigger-bottom {
width:100%;
text-indent:-50%;
position:fixed;
top:25%;
border-top:1px dotted #000;
}
.trigger-bottom {
top:auto;
bottom:25%;
}
.video-wrapper {
position:relative;
color:blue;
border:1px solid blue;
width:400px;
height:300px;
margin:0 auto;
}
.video-wrapper .tracker {
position:absolute;
top:50%;
left:50%;
width:1px;
height:1px;
padding:1px; /* these 3 attributes are here just for the show */
border:1px solid red;
color:red;
line-height:1px;
text-indent:5px; /* again, just for the show */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="viewport">
<div class="debug">
<div class="debug-trigger"></div>
<div class="debug-pos"></div>
<div class="debug-status"></div>
</div>
<div class="trigger-top">top trigger</div>
<div class="trigger-bottom">bottom trigger</div>
<div class="video-wrapper">
video
<div class="tracker">tracker</div>
</div>
</div>
Refer this answer: https://stackoverflow.com/a/50479802/10971575
Could just call a JS -function when you scroll.
<div onscroll="myFunction()">
And the JS-function would roughly look like this:
if (end of viewport > document.body.scrollTop > start of viewpoint || end of viewport > document.documentElement.scrollTop > start of viewpoint) {
vid.play();
}else{vid.pause();}

Css div gets messed up

Hey I am making a website and have recently seen some problems With css. My header div Works great maybe because I have styled it With Width 100%. But my main and side div seems to have some problems with the size. I have a Width of 1288px on my main id and when I checked it it is way less. I want my side div to be 30% of the Width of the page and the main div to be 70% of the page. How can I do this?
Here is my php code:
<?php
$tjener = "localhost";
$brukernavn = "root";
$passord = "";
$database = "searchengine";
$connection = mysqli_connect($tjener,$brukernavn,$passord,$database) or die("could not connect");
$connection->set_charset("utf8");
$output = "";
//collect
if(isset($_POST["q"])) {
$searchq = $_POST["q"];
$searchq = mysqli_real_escape_string($connection,$searchq);
$searchq = htmlspecialchars($searchq);
$query = mysqli_query($connection,"SELECT * FROM products WHERE vareNavn LIKE '%$searchq%' OR desci LIKE '%$searchq%'");
$count = mysqli_num_rows($query);
if($count == 0) {
$output = "There was no search results.";
} else {
while ($row = mysqli_fetch_array($query)) {
$id = $row['vareNr'];
$vareNavn = $row['vareNavn'];
$desci = $row['desci'];
$output .= "<h1>" . $vareNavn . "</h1><p> " . $desci . "</p><br/>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<script>
function active(){
var Search = document.getElementById("search");
if(search.value == "Search..."){
search.value = "";
search.placeholder = "Search...";
}
}
function inactive(){
var Search = document.getElementById("search");
if(search.value == ""){
search.value = "Search...";
search.placeholder = "";
}
}
</script>
</head>
<body>
<div id="header">
<div id ="searchBar">
<form action="main.php" method= "post">
<input type="text" id="search" name="q" placeholder="" value="Search..." autocomplete="off" onMouseDown="active();" onBlur="inactive();"/><input type="submit" id="searchButton" value="Search"/>
</form>
</div>
</div>
<div id="main">
<div id="oppstart">
<h1>Newly commenced webstore</h1>
</div>
<div id="klokkeMer">
<h2>Watches</h2>
</div>
<div id="div1">
</div>
<div id="div2">
</div>
<div id="div3">
</div>
<?php
print($output);
?>
</div>
<div id="side">
</div>
</body>
</html>
and here is my css code:
body {
font-family: arial;
}
h1 {
margin: 20px 0px 0px 0px;
padding:0;
}
p {
margin: 0;
padding:0;
}
#header {
width:100%; /* Full lengde*/
background-color:#1F2A40;
height:100px; /* 150px */
position:absolute;
top:0px;
left:0px;
}
#search {
border: 1px solid #1F2A40;
border-right:none;
font-size:16px;
padding:10px;
outline:none;
width:700px;
-webkit-border-top-left-radius:10px;
-webkit-border-bottom-left-radius:10px;
-moz-border-radius-topleft:10px;
-moz-border-radius-bottomleft:10px;
border-top-left-radius:10px;
border-bottom-left-radius:10px;
}
#searchButton {
border: 1px solid #1F2A40;
padding:10px;
font-size:16px;
background-color:#ff9933;
font-weight:bold;
color:#1F2A40;
cursor:pointer;
outline:none;
-webkit-border-top-right-radius:10px;
-webkit-border-bottom-right-radius:10px;
-moz-border-radius-topright:10px;
-moz-border-radius-bottomright:10px;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
}
#searchButton:hover {
background-color:#F5870A;
}
#main {
position:absolute;
top:100px;
background-color:red; // change to white when website is done
width:1288px;
height:800px;
left:300px;
}
#side {
position:absolute;
top:100px;
background-color:orange; // change to white when website is done
width:300px;
left:0px;
height:800px;
}
#searchBar {
position:absolute;
width:800px;
top:8px;
left:250px;
/* border:1px solid red; */
}
#div1 {
position:absolute;
width:100px;
top:200px;
left:300px;
border:1px solid black;
height:100px;
background-color:purple;
}
#div2 {
}
#div3 {
}
Try using percentages for your main and side widths instead of pixels
#side{
width: 30%;
}
#main{
width: 70%;
}
So what I would do is to scrap most of this css, and use Bootstrap
This way you get a clean and easy set of tools to use troughout your webpage.
You include the following in your header:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
After this, then you use this code:
<div id="side" class="col-md-3">
Sidebar
</div>
<div id="main" class="col-md-9 col-md-offset-3">
<div id="oppstart">
<h1>Newly commenced webstore</h1>
</div>
<div id="klokkeMer">
<h2>Watches</h2>
</div>
<div id="div1">
</div>
<div id="div2">
</div>
<div id="div3">
</div>
<?php
print($output);
?>
</div>
See it in action here on jsfiddle
It might not have your exact dimentions, however this gives you a structered set of rules for your CSS you can use troughout your website

In-line tables with CSS

I am having a major problem trying to create in-line tables with divs instead of tables and CSS. My issue is that I have 3 types of rows that aren't really in sync, so expectedly, do not line up. I am wondering if there is a solution or a better approach.
As you'll see in the fiddle, I am trying to get the header, row, and child row to line up. All columns and headers have the same width %, but their overall widths will be different. Also, the child row should be indented to appear under the parent.
Fiddle
http://jsfiddle.net/b6ptag0b/15/
HTML
<div id = "wrapper">
<div id = "headers">
<div class = "col header_name">Name</div>
<div class = "col header_id">ID</div>
<div class = "col header_country">Country</div>
</div>
<div id = "table">
<div class = "row" data-id = "1">
<div class = "col button">+</div>
<div class = "col name">Bob Dolle</div>
<div class = "col id">1234</div>
<div class = "col country">America</div>
</div>
<div class = "row_child" data-parent = "1">
<div class = "col name">Joe Dolle</div>
<div class = "col id">67788</div>
<div class = "col country">America</div>
</div>
</div>
CSS
#headers{
background-color:#ccc;
}
.row{
background-color:#ddd;
}
.row_child{
background-color:#AAA8A8;
margin-left:40px;
}
.col{
display:inline-block;
}
#table{
padding:5px;
}
.header_name, .name{
width:30%
}
.header_id, .id{
width:10%;
}
.header_country, .country{
width:25%;
}
.button{
padding:0 10px;
}
well, despite the "use tables" argument (I can see why you want to use DIVS), what you want to do is incredibly easy with CSS, but you're using a really convoluted logic. You can use a columns approach instead of rows, or using your rows approach, just give each columns the same width and include the .button class in the same div as the name , then simply add some table logic to your divs
#table, #headers {
display:table;
width:100%;
}
.row {
display:table-row;
width:100%;
}
.col {
display:table-cell;
width:30%;
}
#headers {
background-color:#ccc;
}
.row {
background-color:#ddd;
}
.row_child {
background-color:#AAA8A8;
margin-left:40px;
}
.header_id, .id {
width:10%;
}
.header_country, .country {
width:25%;
}
.button {
padding:0 10px;
float:left;
}
.row_child .name {
padding-left:50px;
}
See fiddle here
Modern browsers will allow you to use new CSS Table Layouts, for example:
Fiddle
http://jsfiddle.net/b6ptag0b/30/
HTML
<div id = "wrapper">
<div id = "headers">
<div class = "col header_name">Name</div>
<div class = "col header_id">ID</div>
<div class = "col header_country">Country</div>
</div>
<div class = "row" data-id = "1">
<div class = "col name">Bob Dolle</div>
<div class = "col id">1234</div>
<div class = "col country">America</div>
</div>
<div class = "row_child" data-parent = "1">
<div class = "col name">Joe Dolle</div>
<div class = "col id">67788</div>
<div class = "col country">America</div>
</div>
</div>
CSS
#wrapper{
display: table;
}
#headers{
background-color:#ccc;
display: table-row;
}
.row{
background-color:#ddd;
display: table-row;
}
.row_child{
background-color:#AAA8A8;
display: table-row;
}
.col{
display: table-cell;
padding: 2px;
}

Cannot change column/row heights of a table in a div

I am generating a table using my Vertical_Table function. When I remove the table from the div I can adjust the dimensions of the rows and columns but when it is inside the div I cannot change them. Any ideas why? Here is some jfiddle so you can see what I am talking about http://jsfiddle.net/6XAHR/
CSS CODE
> #Pallate
{
border: 1px solid black;
position:relative;
top:40px;
margin:0 auto;
width:1200px;
height:360px;
background-color: #C8C8C8;
}
#Scroll_Table_Border
{
Position:relative;
top:40px;
Left:320px;
border: 1px solid black;
height:275px;
max-width: 850px;
background-color: #C8C8C8;
}
#Scroll_Table {
left:25px;
top:25px;
white-space: nowrap;
Position:Absolute;
height:225px;
max-width: 800px;
width: 100% !important;
overflow:auto;
background-color: #C8C8C8;
}
#Button_Group_Title
{
Position:Absolute;
padding-right:5px;
padding-left:5px;
background-color: #C8C8C8;
top:30px;
Left:35px;
z-index:2;
}
#Scroll_Table_Title
{
Position:Absolute;
padding-right:5px;
padding-left:5px;
background-color: #C8C8C8;
z-index:2;
top:30px;
Left:335px;
}
#Button_Group {
text-align:center;
padding-top:30px;
padding-bottom:15px;
padding-right:25px;
padding-left:25px;
border: 1px solid black;
position:Absolute;
top:40px;
left:20px;
height:230px;
width:200px;
vertical-align: middle;
background-color: #C8C8C8;
}
HTML CODE
<div ID = "Pallate" >
<div ID = "Scroll_Table_Title">Trial Information</div>
<div ID = "Button_Group_Title">View Results</div>
<div ID = "Button_Group">
<input type="button" ID = "Paper_Information" onclick="changeContent(this.id)" value="Paper Information" class = "Class_Button">
<input type="button" ID = "Trial_Information" onclick="changeContent(this.id)" value="Trial Setting" class = "Class_Button">
<input type="button" ID = "Results" onclick="changeContent(this.id)" value="Trial Results" class = "Class_Button">
<input type="button" ID = "Control_Law" onclick="changeContent(this.id)" value="Control Algorithm" class = "Class_Button">
<input type="button" ID = "Exercise" onclick="changeContent(this.id)" value="Exercise" class = "Class_Button">
<input type="button" ID = "Actuator" onclick="changeContent(this.id)" value="Pump Properties" class = "Class_Button">
<input type="button" ID = "Sensor" onclick="changeContent(this.id)" value="Glucose Sensor" class = "Class_Button">
<input type="button" ID = "Blood_Glucose_Safety" onclick="changeContent(this.id)" value="Blood Glucose Safety" class = "Class_Button">
<input type="button" ID = "Reference_Glucose" onclick="changeContent(this.id)" value="Reference Measurements" class = "Class_Button">
</div>
PHP CODE
<div ID = "Scroll_Table_Border">
<div ID = "Scroll_Table">
<?php
$Columns = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_NAME = \'Control_Law\'';
$Columns = sqlsrv_query($dbhandle,$Columns);
$Sets = array(sqlsrv_query($dbhandle, 'SELECT * FROM Control_Law WHERE [Paper ID] = ' . $ID));
$i = 0;
while ($Row = sqlsrv_fetch_array($Columns))
{
$Column_Vector[$i] = $Row[0]; $i++;
}
$Table_ID = 'Advanced_Table';
$Columns_Vector = array($Column_Vector);
Vertical_Table($Columns_Vector,$Sets,'40px','',$Table_ID);
?>
</div>
</div>
#Scroll_Table {
left:25px;
top:25px;
white-space: nowrap; //REMOVE THIS
Position:Absolute;
height:225px;
max-width: 800px;
width: 100% !important;
overflow:auto;
background-color: #C8C8C8;
}
This will get it to drop down then you can set the max width. The problem with the text you have in there now is it is all 1 string with no spaces. Remove the spaces and it will drop down normally. Hope this helps!

Why is my first image not clickable?

I have a square that contains pictures and each picture is supposed to be clickable to take you to that person's profile, but my top left picture is not clickable. I'm not sure what I'm doing wrong.
Here is my jsfiddle so you can see the problem.
<div id = 'crew_div'>
<div class = 'my_crew'><div id = 'jason'><a href = 'http://www.startingtofeelit.com/author/musicmakesmelosectrl/'><img src='http://www.startingtofeelit.com/profile/jason.jpg' title = 'View Posts by Jason'></a></div></div>
<div class = 'my_crew'><div id = 'dharam'><a href = 'http://www.startingtofeelit.com/author/4everevolution/'><img src='http://www.startingtofeelit.com/profile/dharam.png' title = 'View Posts by Dharam'></a></div></div>
<div class = 'my_crew'><div id = 'james'><a href='http://www.startingtofeelit.com/author/jjstiles/'><img src='http://www.startingtofeelit.com/profile/james.png' title = 'View Posts by James'></a></div></div>
<div class = 'my_crew'><div id = 'cody'><a href='http://www.startingtofeelit.com/author/codecray/'><img src='http://www.startingtofeelit.com/profile/Cody.jpg' title = 'View Posts by Cody'></a></div></div>
</div>
#crew_div {
position:relative;
width: 312px;
height:312px;
}
.my_crew {
position:absolute;
}
.my_crew img {
width:156px;
display:block;
}
.my_crew #jason {
top:0px;
left:0px;
position:relative;
}
.my_crew #dharam {
top:0px;
left:156px;
position:relative;
}
.my_crew #james {
top: 156px;
left: 0px;
position:relative;
}
.my_crew #cody {
top:156px;
left:156px;
position:relative;
}
Add a z-index to your image like this :
.my_crew #jason {
top:0px;
left:0px;
position:relative;
z-index: 1;
}
You haven't specified width/height dimensions or top/left positioning for your <div class="my_crew">. They are each positioned at the top-left, and their child <div> is then positioned relative to the absolutely positioned parent. That's why the top-left isn't clickable, because it's really stacked under 3 other <div>s.
A better solution would be to combine the two <div>s into one.
See the fiddle here: http://jsfiddle.net/R4HJb/8/
<div id = 'crew_div'>
<div class = 'my_crew jason'><a href = 'http://www.startingtofeelit.com/author/musicmakesmelosectrl/'><img src='http://www.startingtofeelit.com/profile/jason.jpg' title = 'View Posts by Jason'></a></div>
<div class = 'my_crew dharam'><a href = 'http://www.startingtofeelit.com/author/4everevolution/'><img src='http://www.startingtofeelit.com/profile/dharam.png' title = 'View Posts by Dharam'></a></div>
<div class = 'my_crew james'><a href='http://www.startingtofeelit.com/author/jjstiles/'><img src='http://www.startingtofeelit.com/profile/james.png' title = 'View Posts by James'></a></div>
<div class = 'my_crew cody'><a href='http://www.startingtofeelit.com/author/codecray/'><img src='http://www.startingtofeelit.com/profile/Cody.jpg' title = 'View Posts by Cody'></a></div>
</div>
#crew_div {
position:relative;
width: 312px;
height:312px;
}
.my_crew {
position:absolute;
width: 156px;
height: 156px;
}
.my_crew img {
width:156px;
display:block;
}
.my_crew.jason {
top:0px;
left:0px;
}
.my_crew.dharam {
top:0px;
left:156px;
}
.my_crew.james {
top: 156px;
left: 0px;
}
.my_crew.cody {
top:156px;
left:156px;
}
Here is what you need, I reorganized your HTML a bit :)
New Fiddle
<div id = 'crew_div'>
<a href = 'http://www.startingtofeelit.com/author/musicmakesmelosectrl/'><div class = 'my_crew'><div id = 'jason'><img src='http://www.startingtofeelit.com/profile/jason.jpg' title = 'View Posts by Jason'></div></div></a>
<a href = 'http://www.startingtofeelit.com/author/4everevolution/'><div class = 'my_crew'><div id = 'dharam'><img src='http://www.startingtofeelit.com/profile/dharam.png' title = 'View Posts by Dharam'></div></div></a>
<a href='http://www.startingtofeelit.com/author/jjstiles/'><div class = 'my_crew'><div id = 'james'><img src='http://www.startingtofeelit.com/profile/james.png' title = 'View Posts by James'></div></div></a>
<a href='http://www.startingtofeelit.com/author/codecray/'><div class = 'my_crew'><div id = 'cody'><img src='http://www.startingtofeelit.com/profile/Cody.jpg' title = 'View Posts by Cody'></div></div></a>
Why don't you just float them next to each other? That will also save some lines of CSS.
.my_crew {
float:left;
}
Example: http://jsfiddle.net/T5LCm/