CSS Responsive Design Order of Columns - html

Ok, I have 3 columns floating left. Now when the viewport is less than 600px I want column 2 to appear before column 1 without using position:absolute. Is there a way to do this just by using CSS and HTML?
If not you can also post other variants.
Here's my fiddle

Is this what you are after? http://jsfiddle.net/panchroma/dWJ9g/
You will see I've reordered the col1 and col2 in the HTML and applied margin to the #col1 and #col2
HTML
<div id="wrapper">
<div id="header">HEADER</div>
<div id="main">
<div id="col2" class="cols">COL 2</div>
<div id="col1" class="cols">COL 1</div>
<div id="col3" class="cols">COL 3</div>
<div class="clear"></div>
</div>
<div id="footer" class="clear">FOOTER</div>
</div>
CSS changes
#col1 {float:left; height:100px; width:200px; background:#cc4444;margin-left:-400px;}
#col2 {float:left; height:200px; width:200px; background:#44cc44;margin-left:200px;}
#media only screen and (max-width:600px) {
#wrapper, #header, #main, #footer {width:100%;}
#col1, #col2, #col3 {float:none; width:100%;margin-left:0;}
}
Hope this helps!

If you don't want to change the markup I'd suggest using javascript, to change the html and id.
http://jsfiddle.net/FBAtT/
var col1 = document.getElementById('col1'),
col2 = document.getElementById('col2'),
swapped = false;
window.onresize = function () {
var width = window.innerWidth;
if (width < 600 && swapped === false) {
swapCols();
swapped = true;
} else if (width > 600 && swapped === true) {
swapCols();
swapped = false;
}
};
function swapCols() {
var _col1 = col1.innerHTML,
_col1id = col1.id,
_col2 = col2.innerHTML,
_col2id = col2.id;
col1.innerHTML = _col2;
col1.id = _col2id;
col2.innerHTML = _col1;
col2.id = _col1id;
}

try this
http://jsfiddle.net/mKbnH/2/
CSS
html * {margin:0; padding:0;}
body {background:#000; font-family:helvetica, verdana;}
#wrapper {margin:50px auto;}
#wrapper, #header, #main, #footer {width:600px;}
#header {height:100px; background:#cccc44;}
#main {}
#col1 {float:left; height:100px; width:200px; background:#cc4444;}
#col2 {float:left; height:200px; width:200px; background:#44cc44;}
#col3 {float:left; height:150px; width:200px; background:#4444cc;}
#footer {height:50px; background:#cc44cc;}
.cols {}
.clear {clear:both;}
#media only screen and (max-width:600px) {
#wrapper, #header, #main, #footer {width:100%;}
#col3 {width:100%;}
#col1, #col2 {width:50%}
}

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

flexed div squeezes the height of other div in nested structure

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!! ^_^

div with swf inside and z-index : firefox mac bug

I've got a problem with firefox for mac and z-index.
I've got 3 div: header, wrapper and footer; inside of them i've got 3 swf header.swf, wrapper.swf and footer.swf.
This is the code:
<div id="header">
<div id="navigation">
<script type="text/javascript">
var fo = new FlashObject("fla/head.swf", "top", "960", "118", "7", "#fff", true);
fo.addVariable("quality", "best");
fo.addVariable("scale", "noscale");
fo.addParam("wmode", "transparent");
fo.write("navigation");
</script>
</div>
</div>
<div id="wrapper">
<div id="flashContent" class="home">
<script type="text/javascript">
var fo = new FlashObject("fla/home.swf", "top", "1660", "840", "7", "#fff", true);
fo.addVariable("quality", "best");
fo.addVariable("scale", "noscale");
fo.addParam("wmode", "transparent");
fo.write("flashContent");
</script>
</div>
</div>
<div id="footer" class="fHome">
<div id="news">
<script type="text/javascript">
var fo = new FlashObject("fla/footer.swf", "top", "960", "130", "7", "#292929", true);
fo.addVariable("quality", "best");
fo.addVariable("scale", "noscale");
fo.addParam("wmode", "transparent");
fo.write("news");
</script>
</div>
</div>
and this is the css code:
body {overflow-x:hidden}
#header {position:absolute; top:0px; left:0px; background:url(../img/bkgHeader.jpg) top left repeat-x; width:100%; height:118px; text-align:center; z-index:50}
#navigation {width:960px; height:118px; margin:0 auto;}
#wrapper {background:#fff; position:absolute; top:60px; left:0px; width:100%; height:840px; text-align:center; z-index:1}
#news {width:960px; height:130px; margin:0 auto;}
#flashContent {width:1660px;margin:0 auto;}
.home {height:840px;}
#footer {position:absolute; left:0px; background:url(../img/bkgFooter.jpg) bottom left repeat-x; width:100%; height:130px; text-align:center; z-index:3}
.fHome {top:880px;}
the problem is that wrapper div dont work good with zindex and cant stay below the header.
So rollover and rollout actions doesnt work!
pls help!
for z-index also negative numbers are allowed.... maybe can help? Or give an extremely high z-index value to the other guys!

Trouble with Div Hide/Show on mouse click

I tried your script but it isn't working right. I have edited my code below to show exactly what I am working with. Thank you so much for being helpful.
Quazi
Hi,
I am very new to JQuery.
I am trying to get a div to fade in after a click event and then hide after click anywhere. I have three divs set up to do this with css set as display:none. The problem is that the script does not work in IE8 and only works in ff/safari if I double click or triple click the menubar links below.
I am using the following code to show/hide these divs on mouse click:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
body,
html {
margin:0;
padding:0;
color:black;
background:black;
color:black;
}
#logo {
margin-top:1%;
width:12%;
margin-left:5%;
padding:1%;
border:2px solid #FF8c00;
}
#showsbanner {
margin-top:1%;
width:60%;
position:absolute;
right:2px;
}
#wrap {
width:90%;
margin:0 auto;
background:black;
color:black;
}
#header {
padding:5px 10px;
background:black;
color:#ef9c00;
}
h1 {
color:#35002c;
font-family:"verdana";
font-size:25px;
}
h2 {
color:#044476;
font-family:"verdana";
font-size:18px;
}
h3 {
color:#044476;
font-family:"verdana";
font-size:15px;
}
#nav {
padding:5px 10px;
width:89%;
margin-left:5%;
background:#ff8c00;
border:2px solid darkblue;
}
#nav ul {
margin:0;
padding:0;
list-style:none;
}
#nav li {
display:inline;
margin:0;
padding:0;
color:white;
}
#menubar {
float:left;
width:40%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#bcity {
float:right;
width:50%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#aicbk {
display:none;
float:right;
width:50%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#pdil{
display:none;
float:right;
width:50%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#footer {
clear:both;
padding:1px, 1px;
background:#ff8c00;
width:100%;
border:2px solid darkblue;
}
#footer p {
color:white;
font-size:12px
}
* html #footer {
height:1px;
}
//The last four lines are an IE bug fix
</style>
<script type="text/javascript" src="homepage_files/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var gLastH = null;
var gLastId = null;
$('.toggleh').hide();
$('.toggle').click(function(e) {
$('.toggleh:visible').fadeOut('slow');
gLastId = $(this).attr('id');
console.log('#' + gLastId + 'h');
gLastH = $('#' + gLastId + 'h');
$(gLastH).fadeIn('slow');
e.stopPropagation();
});
$('*').click(function(e) {
if ($(this).attr('id') != gLastId) {
$(gLastH).fadeOut('slow');
}
e.stopPropagation();
});
});
</script>
stuff...
text here
text here2
text here3
stuff......
<div class="toggleh" id="toggle2h">
<div id="aicbk">
stuff....
</div>
</div>
<div class="toggleh" id="toggle3h">
<div id="pdil">
stuff..
</div>
</div>
<div id="footer">
stuff..
</div>
Here's a working sample, tested under Chrome 8.0.552.0 dev:
<html>
<head>
<title>S.O. 3920865</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var gLastH = null;
var gLastId = null;
$('.toggleh').hide();
$('.toggle').click(function(e) {
$('.toggleh:visible').fadeOut('slow');
gLastId = $(this).attr('id');
console.log('#' + gLastId + 'h');
gLastH = $('#' + gLastId + 'h');
$(gLastH).fadeIn('slow');
e.stopPropagation();
});
$('*').click(function(e) {
if ($(this).attr('id') != gLastId) {
$(gLastH).fadeOut('slow');
}
e.stopPropagation();
});
});
</script>
</head>
<body>
<div id="menubar">
<div class="toggle" id="toggle1">
text here
</div>
<div class="toggleh" id="toggle1h">
some description in here I suppose
</div>
<div class="toggle" id="toggle2">
text here2
</div>
<div class="toggleh" id="toggle2h">
some description in here I suppose 2
</div>
<div class="toggle" id="toggle3">
text here3
</div>
<div class="toggleh" id="toggle3h">
some description in here I suppose 3
</div>
</div>
</body>
</html>
Perhaps you need to check jQuery UI accordion which can be what you really want.
EDIT: following 1st comment.
Use this simple code to hide/show menu (or any div)
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
</script>
Click here to toggle visibility of element #foo
<div id="foo" style="display:block">This is foo</div>