Center bootstrap button in xs - html
I have spent literally hours on this, I cannot get this button centered when the screen width entered xs mode, it started to position itself based off of the left side. I've tried looking in the bootstrap and cant find any clear indication as to why this happens.
Here is my code, mainly the third main div block with btn-posit class inside and the media queries 461-767px. Thanks
https://codepen.io/fullmetal7777/pen/RgKagp
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-6 col-sm-8 col-xs-10 text-center btn-posit">
<button class="btn btn-primary twit-btn"><i class="fa fa-twitter-square fa-2x" aria-hidden="true"><span id="twit-Text">Tweet it</span></i></button>
<button class="btn btn-default quote-btn"><div id="whole-text">Get Quote</div></button>
</div>
</div>
This will get you close to what you want.
The issues:
The column with the buttons in had a class of col-xs-10 which should be col-xs-12 if you want the buttons to be centered.
The twitter button still had margin right on it for the xs size, which was pushing it to the left, preventing it from centering.
https://codepen.io/anon/pen/xrdPVb
If you just want the menus centered, you don't need to use the col-* classes to wrap them. Remove those and apply .text-center (which you already have), then remove all of the media queries you were using to offset the margin and try to center that column. But then I think you have some display issues from using transform: translateX(-1); so I just reversed the image and removed that transform line. The less work the browser has to do, the better, so if you can change the image, I'd just do that.
$(document).ready(function(){
var quotes = {
Mario: ["So long-a-Bowser!", "Nighty nighty. Ah spaghetti. Ah, ravioli. Ahh, mama mia.", "You know what they say: all toasters toast toast."],
Luigi: ["Let's-a go...", "Oh yeah! Who's number one now?! Luigi!", "Now, THIS is where the real action is"],
Bowser: ["Im HUUUUGE! Even scarier up close, huh?", "GAH HA HA HA! There's no WAY you're ready for a round against ME. Keep practicing, pip-squeak!"],
Peach: ['Oh, did I win?', "Go Peachy, Go Peachy, Go Peachy! Yay! Woohoo!"],
Yoshi: ['Yoshi!'],
Fox: ["This is Fox, returning to base!", "Better luck next time, Falco!"],
Falcon: ["Falcon Kick!", 'Blue Falcon!', 'Show me your moves!'],
Marth: ["Konkaiwa bokuno kachidane! (It's my victory this time!)", "Kyoumo ikinobiru kotoga dekita. (Even today I was able to survive.)",
"Bokuwa makeru wake niwa ikenainda! (There's no way I can lose!)"],
Pit: ["Three Sacred Treasures!", "It's game over for you!", "That all you got?"],
Link: ["....."],
Ike: ["Great... AETHER!", "I fight for my friends.", "You'll get no sympathy from me."],
Lucario: ["Behold, the power of Aura!", "The Aura is with me!", "Max Aura!"],
'Wii Fit Trainer': ["High energy, move that body!", "Salute the sun!", "Work hard to tone that tummy."],
Sheik: ['I\'ve been waiting for you, Hero of Time...', 'The flow of time is always cruel.'],
Ganandorf: ['Hero? ...I\'ve outlived more "heroes" than you can possibly imagine.', 'Behold! The power of the Demon King!',
'I am Ganondorf, the Demon King. Don\'t take that title lightly.'],
Mac: ["Let 'em have it, Mac!", "Way to go, Mac! You're the champ, baby!", "Nice moves, Mac. I can barely keep my eyes on you, son."],
Palutena: ["You shall be purified.", "No one can hide from the light.", "Celestial Fireworks!"],
Robin: ["The key to victory lies within.", "I'm always three steps ahead.", "It seems our fates are joined."],
Shulk: ["Now it's Shulk time!", "I can change the future!", "The future is ours to decide!"],
Sonic: ["That was almost too easy!", "Let's do that again some time!"],
Falco: ["Personally, I prefer the air!", "You aren't worth the trouble."],
Wario: ["Wa-Wa-Wa!", "Time for victory parade."],
'Toon Link': ["....."],
Lucina: ["The future is not written!", "Time to change fate!"]
}
var nameArr = ['Mario', 'Luigi', 'Bowser', 'Peach', 'Yoshi', 'Lucina', 'bowser jr', 'Wario', 'game and watch', 'donkeyk', 'diddyk', 'Link', 'Zelda',
'Sheik', 'Ganandorf', 'Toon Link', 'samus', 'zero suite samus', 'Pit', 'Palutena', 'Marth', 'Ike', 'Robin', 'kirby', 'king deedeedee', 'meta knight',
'Mac', 'placeholder', 'Fox', 'Falco', 'pikachu', 'charizard', 'Lucario', 'jigglypuff', 'Greninja', 'duck hunt', 'Rob', 'ness', 'Falcon', 'villager',
'olimar', 'Wii Fit Trainer', 'dr mario', 'dark pit', 'Lucina', 'Shulk', 'pacman', 'Megaman', 'Sonic'];
var imgurID = '0RQtP';
var key = "cfb3f86a62ab07c";
function randomFxn(){
$.ajax({
type: 'GET',
url: 'https://api.imgur.com/3/album/' + imgurID + '/images',
headers: {'Authorization': 'Client-ID '+ key},
}).done(function(data) {
showZones(data)
});
}
var lastNum = '70';
function showZones(jsonData){
var name = '';
do{
var nameNum = Math.floor(Math.random()*(Object.keys(quotes).length));
// var nameNum = 70;
console.log(nameNum);
} while (nameNum == lastNum)
console.log(lastNum);
lastNum = nameNum;
console.log(lastNum);
name = Object.keys(quotes)[nameNum];
var quoteArrLength = quotes[name].length;
var randQuoteNum = Math.floor(Math.random()*quoteArrLength)
var randQuote = '\"' + quotes[name][randQuoteNum] + '\"';
var indexMult = (nameArr.indexOf(name)*8);
var addToIndex = Math.floor(Math.random()*8);
var url = jsonData.data[(indexMult)+addToIndex].link;
var imgCss = 'url(' + url + ')';
var isReverse = Math.floor(Math.random()*2);
$('h3').text('-' + name);
$('h2').text('Hero? ...I\'ve outlived more "heroes" than you can possibly imagine.');
$('.bg').fadeOut(500, function() {
if(isReverse==1){
$(this).css({'background-image': imgCss, 'transform': 'scaleX(1)'}).fadeIn(700);
}
else{
$(this).css({'background-image': imgCss, 'transform': 'scaleX(-1)'}).fadeIn(700);
}
});
}
var num = 0;
$('.quote-btn').click(function(){
if (num == 0){
num++;
randomFxn();
setTimeout(function(){
num = 0;
}, 1200);
}
});
});
body, html{
height: 100%;
}
.bg,
.quote-btn {
background-repeat: no-repeat;
background-size: cover;
}
.bg{
background-image: url("http://i.imgur.com/sxwO4y3.jpg");
height: 100%;
background-size: 70% 100%;
}
.jumbotron{
margin-left: 16.66666667%;
margin-top: -78vh;
background-color: rgba(100, 100, 100, 0.4);
border-style: solid;
border-color: rgba(0, 0, 0, 0);
}
h2, h3{
color: white;
opacity: 1;
font-weight: 900;
}
h2{
margin-top: -3vh;
margin-left: -1.7vw;
}
h3{
float: right;
}
.quote-btn {
border-color: #5e1111 #5e1111 hsl(0, 69%, 17%);
background-image: url("http://www.wtfgamersonly.com/wp-content/uploads/2015/06/Super-Smash-Bros.-img.2.jpg");
background-position: 50% 60%;
height: 45px;
width: 140px;
}
.twit-btn{
height: 45px;
width: 140px;
margin-right: 35px;
}
#whole-text{
font-weight: 800;
color: #BC1818;
font-size: 22px;
}
.btn.quote-btn:focus,
.btn.quote-btn:active:focus,
.btn.quote-btn.active:focus,
.btn.quote-btn.focus,
.btn.quote-btn:active.focus,
.btn.quote-btn.active.focus,
.btn.twit-btn:focus,
.btn.twit-btn:active:focus,
.btn.twit-btn.active:focus,
.btn.twit-btn.focus,
.btn.twit-btn:active.focus,
.btn.twit-btn.active.focus{
outline-color: none;
outline-style: none;
border-color: #5e1111 #5e1111 hsl(0, 69%, 17%);
}
.btn.quote-btn:hover{
border-style: none;
}
.btn.quote-btn:active{
background-image: url("http://www.wtfgamersonly.com/wp-content/uploads/2015/06/Super-Smash-Bros.-img.2.jpg");
opacity: .8;
}
#media only screen and (max-height: 568px){
.jumbotron{
margin-top:-89vh;
}
}
#media only screen and (min-height: 569px){
.jumbotron{
margin-top:-80vh;
}
.btn-posit {
margin-top: -42vh;
}
}
#media only screen and (min-width: 0px) and (max-width: 1199px){
.bg{
background-size: cover;
background-position: center;
}
}
/*medium*/
#media only screen and (min-width: 992px) and (max-width: 1199px) {
.jumbotron{
margin-left: 8.33333333%;
}
}
/*small*/
#media only screen and (min-width: 768px) and (max-width: 991px){
.jumbotron{
margin-left: 4.15%;
}
}
/*xs*/
#media only screen and (min-width: 461px) and (max-width: 767px){
.jumbotron{
margin-left: 8.33333333%;
}
.btn-posit{
width: auto;
}
}
#media only screen and (min-width: 0px) and (max-width: 460px) {
h2{
font-size: 22px;
}
h3{
font-size: 18px;
}
.btn-posit{
/*padding-left: 78px; */
margin-left: 1%;
}
.jumbotron{
margin-left: 8%;
}
.twit-btn{
margin-right: 55px;
width: auto;
}
#twit-text{
display: none;
}
}
/*#media only screen and (min-width: 0px) and (max-width: 422px) {
h2{
font-size: 22px;
}
h3{
font-size: 18px;
}
.twit-btn{
width: auto;
margin-right: 10px;
}
.btn-posit{
padding-left: 15%;
}
#twit-text{
display: none;
}
}*/
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://use.fontawesome.com/5ad62430a6.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<html>
<head>
<title>AwesomeDesigns Random Quote Generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="bg"></div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 col-sm-11 col-xs-10 jumbotron">
<h2>"Andrews Random Quote Generator. "</h2>
<h3>-Andrew Hickman</h3>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="text-center btn-posit">
<button class="btn btn-primary twit-btn"><i class="fa fa-twitter-square fa-2x" aria-hidden="true"><span id="twit-Text">Tweet it</span></i></button>
<button class="btn btn-default quote-btn"><div id="whole-text">Get Quote</div></button>
</div>
</div>
</div>
</html>
adding text-center class seemed to be the fix!
Related
CSS Image Clipping as Full Screen
I am by no means a CSS expert (as you can see from my code) but I almost got this working the way I want but I was having some slight formatting problems. Basically I am trying to make a page that will go through a ppt deck (exported as .jpgs). It is extremely straight forward with only 2 buttons that go to the next or previous slide and displays the image full screen. The issue I am seeing is the image keeps getting cropped, specifically the top. It will often display fine but when I switch images the top 5ish% of the screen is getting clipped no matter how much I play with the padding. Hopefully this is an easy fix... any help would be greatly appreciated... <html> <head> <style> body, html { height: 100%; } .bg { /* The image used */ background-image: url("Slide1.JPG"); /* Full height */ height: 90%; /* Center and scale the image nicely */ background-position: center; background-repeat: no-repeat; background-size: cover; } .center { position: relative; vertical-align: middle; top: 100%; } .button { background-color: #0033ff; /* Blue */ border: solid; border-width: medium; border-color: black; color: white; padding: 2px 2px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; vertical-align: text-top; height: 5%; width: 40%; font-size: 100%; } </style> <script src="jquery-3.2.1.min.js"></script> <script type="text/javascript"> var refreshIntervalId = setInterval(autoNextSlide, 8000); var clicks = 1; var isPaused = false; var time = 0; function pictureBack() { clicks -= 1; checkImage("Slide" + clicks + ".JPG", function () { }, function () { clicks = 1; }); // alert("slides/Slide" + clicks + ".JPG"); var str_image = 'background-image: url("Slide' + clicks + '.JPG");'; document.getElementById('bkground').style.cssText = str_image isPaused = true; time = 0; } function pictureNext() { clicks += 1; checkImage("Slide" + clicks + ".JPG", function () { }, function () { clicks = 1; }); //alert("slides/Slide" + clicks + ".JPG"); var str_image = 'background-image: url("Slide' + clicks + '.JPG");'; document.getElementById('bkground').style.cssText = str_image isPaused = true; time = 0; } function checkImage(imageSrc, good, bad) { var img = new Image(); img.onload = good; img.onerror = bad; img.src = imageSrc; } function autoNextSlide() { if (isPaused) { time++; if (time > 4) { isPaused = false }; //isPaused = true //alert("is paused") } else { pictureNext(); time = 0; isPaused = false; }; } </script> </head> <body> <div class="bg" id="bkground"> <div class="center"> <p><input type="button" class="button" id="theButton" value="Previous" onclick="pictureBack()" style='float:left;' padding="10%"></p> <p><input type="button" class="button" id="theButton2" value="Next" onclick="pictureNext()" style='float:right;'></p> </div> </div> </body> </html>
Use: .bg { /* The image used */ background-image: url("Slide1.JPG"); /* Full height */ height: 90%; /* Center and scale the image nicely */ background-position: center; background-repeat: no-repeat; background-size: 100% 100%; } Instead of: .bg { /* The image used */ background-image: url("Slide1.JPG"); /* Full height */ height: 90%; /* Center and scale the image nicely */ background-position: center; background-repeat: no-repeat; background-size: cover; } Cover makes the image cover the element in it's entirity but cuts off the image. With 100% 100% it's makes it fit fully no matter what. It may skew the image a tad on some devices but it you aren't worried about mobile use, you should be fine.
Appending Text to Div Extends Div Beyond Initial CSS Grid
I've created a basic CSS Grid and had everything positioned where I wanted it. When I run my JS (appends info from an API call to a div), the div's dimension push beyond the borders of the viewport. Is there a way to prevent the overall body element from changing and just have the div dynamically increase height? pics: https://imgur.com/a/wJAcW I've tried so many different things and can't seem to figure this out. My fallback will be to just overwrite the div rather than append to it. Code is below. //Set initial latitute and longitude variables, to be used later var lat = 0; var long = 0; //Google Geocode API to find the latitude and longitude of the txtAddress $("#submit").on("click", function() { var userInput = $("#txtAddress").val(); //trim the user input to the form needed for the api var userSearchTerm = userInput.split(' ').join('+'); //call the google geocode api var queryURLGeocode = "https://maps.googleapis.com/maps/api/geocode/json?address=" + userSearchTerm + "&key=AIzaSyCSAYHZn9fz13c3bsl_RcS13HJu8wDJXCU" $.ajax({ url: queryURLGeocode, method: "GET" }) .done(function(response) { //Set latitude and longitude from the returned object lat = response.results[0].geometry.location.lat; //limit decimal points to 4 (xx.xxxx) - form needed for hiking api lat = lat.toFixed(4); long = response.results[0].geometry.location.lng; long = long.toFixed(4); //Call the hiking project api var queryURL = "https://www.hikingproject.com/data/get-trails?lat=" + lat + "&lon=" + long + "&maxDistance=10&key=200206461-4fa8ac1aa85295888ce833cca1b5929f" $.ajax({ url: queryURL, method: "GET" }) .done(function(response) { // loop through the response trails and add info to the site for (i = 0; i < response.trails.length; i++) { var contentDivTitle = $("<div> class='newTrailTitle'"); var contentDivMain = $("<div> class='newTrailDescription'"); contentDivTitle.text("Name: " + response.trails[i].name + " Location: " + response.trails[i].location); contentDivMain.text("Summary: " + response.trails[i].summary); $("#search-results").append(contentDivTitle); $("#search-results").append(contentDivMain); } }); }); }); html, body { background-color: black; margin: 10px; } h1, h3 { color: white; text-align: center; padding: 5px; line-height: 1px; } h1 { /* automatically changes lowercase to uppercase text; */ text-transform: uppercase; } sub { color: white; text-align: center; line-height: 1px; font-size: 15px; font-weight: lighter; } .container { display: grid; grid-template-columns: auto; grid-template-rows: 800px 500px 200px 50px 100px; grid-gap: 3px; } .container>div { display: flex; justify-content: center; align-items: center; font-size: 1em; } .container>div:nth-child(1n) { background-color: black; } .container>div:nth-child(2n) { background-color: blue; } .container>div:nth-child(3n) { background-color: red; } .container>div:nth-child(4n) { background-color: yellow; } .container>div:nth-child(5n) { background-color: green; } label { color: white; } #main { background-image: url("assets/images/etienne-bosiger-367964.jpg"); background-size: cover; background-repeat: no-repeat; } #au, #cr { display: block; margin: auto; } #groupPic { padding: 10px; } <html> <head> <link rel="stylesheet" href="test.css"> </head> <body> <div class="container"> <div id="main"> <div id="title"> <h1>kairns<sub>®</sub></h1> <h3>"find your trail"</h3> <div class="search-div"> <label for="txtAddress">Enter Address: </label> <input type="text" name="txtAddress" id="txtAddress"> <button type="button" id="submit">Search</button> </div> </div> </div> <div class="search-results" id="search-results">2</div> <div> <p id="au">About Us</p> <img id="groupPic" src="http://via.placeholder.com/150x150" alt="placeholder image"> <p id="cr">Copyright 2018.</p> </div> <div>4</div> <div> <p>Powered by Google Maps, Open Weather Map, and Hiking Project </p> </div> </div> <!-- JAVASCRIPT --> <!-- jQuery --> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!-- custom javaScript --> <script type='text/javascript' src='assets/javascript/logic.js'></script> </body> </html>
All in-flow children of the #search-results element will align vertically if you apply: #search-results { display: flex; flex-direction: column; }
Youtube Video Header Background
I'm trying to create a few website templates to help me improve my front end development skills, as I'm currently far better at rear end work. I'm trying to somewhat replicate the style of my own website (https://thomas-smyth.co.uk/), which is a simple Bootstrap template. However, instead of using a static photo in the header, I want to replace it with a Youtube video. I began by cutting down the template used in my website and have stripped it down to as little as I think I can get it without breaking the header. I have found a few pieces of code around the place to show how to set a Youtube video as background of the overall page, but not the background for specific sections of the page. How can I do this? Note - It has to be streamed from YouTube as my hosts don't allow me to host video's on their servers. My current code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Tell the browser to be responsive to screen width --> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <title>Group Name | Home</title> <!-- Bootstrap 3.3.6 --> <link rel="stylesheet" href="dist/bootstrap/css/bootstrap.min.css"> <!-- Font Awesome --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css"> <!-- Ionicons --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css"> <!-- Custom --> <link rel="stylesheet" href="dist/css/mainstyle.css"> </head> <body> <header> <div class="header-content"> <div class="header-content-inner"> <h1>This is going once vid is done.</h1> </div> </div> </header> <section class="bg-primary"> <div class="container"> <div class="row"> <div class="col-lg-8 col-lg-offset-2 text-center"> <h2 class="section-heading">Placeholder!</h2> <p>I should have found a witty comment to put here, but I'm just gonna put "Placeholder" instead.</p> </div> </div> </div> </section> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="dist/bootstrap/js/bootstrap.min.js"></script> <script src="dist/js/mainscript.js"></script> </body> </html> CSS html, body { height: 100%; width: 100%; } body { font-family: 'Merriweather', 'Helvetica Neue', Arial, sans-serif; } h1, h2, h3, h4, h5, h6 { font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif; } p { font-size: 16px; line-height: 1.5; margin-bottom: 20px; } .bg-primary { background-color: #F05F40; } section { padding: 100px 0; } .no-padding { padding: 0; } header { position: relative; width: 100%; min-height: auto; background-image: url('../img/header.jpg'); background-position: 0% 80%; -webkit-background-size: cover; -moz-background-size: cover; background-size: cover; -o-background-size: cover; text-align: center; color: white; } header .header-content { position: relative; text-align: center; padding: 100px 15px 100px; width: 100%; } header .header-content .header-content-inner h1 { font-weight: 700; text-transform: uppercase; margin-top: 0; margin-bottom: 0; font-size: 30px; } #media (min-width: 768px) { header { min-height: 100%; } header .header-content { position: absolute; top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); padding: 0 50px; } header .header-content .header-content-inner { max-width: 1000px; margin-left: auto; margin-right: auto; } header .header-content .header-content-inner h1 { font-size: 50px; } } .section-heading { margin-top: 0; } ::-moz-selection { color: white; text-shadow: none; background: #222222; } ::selection { color: white; text-shadow: none; background: #222222; } img::selection { color: white; background: transparent; } img::-moz-selection { color: white; background: transparent; } body { webkit-tap-highlight-color: #222222; } Best I have so far (does whole page's background) <div class="video-background"> <div class="video-foreground"> <iframe src="https://www.youtube.com/embed/W0LHTWG-UmQ?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&playlist=W0LHTWG-UmQ" frameborder="0" allowfullscreen></iframe> </div> </div> CSS * { box-sizing: border-box; } .video-background { background: #000; position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: -99; } .video-foreground, .video-background iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; } #media (min-aspect-ratio: 16/9) { .video-foreground { height: 300%; top: -100%; } } #media (max-aspect-ratio: 16/9) { .video-foreground { width: 300%; left: -100%; } }
I've created a simple example with Youtube video background using direct links to video stream (JS/CSS only solution). Feel free to check it on JSfiddle. Also, you can update public Google Image proxy URL to any public or your own CORS proxy. var vid = "FUUw3zNTXH8", streams, video_tag = document.getElementById("video"); fetch("https://images" + ~~(Math.random() * 33) + "-focus-opensocial.googleusercontent.com/gadgets/proxy?container=none&url=" + encodeURIComponent("https://www.youtube.com/watch?hl=en&v=" + vid)).then(response => response.text()).then(function(data) { if (data) { streams = parse_youtube_meta(data); video_tag.src = streams['hls'] || streams['720pna'] || streams['480pna'] || streams['720p'] || streams['480p'] || streams['360p'] || streams['240p'] || streams['144p']; } else { alert('Youtube API Error'); } }); function parse_youtube_meta(rawdata) { var regex = /(?:ytplayer\.config\s*=\s*|ytInitialPlayerResponse\s?=\s?)(.+?)(?:;var|;\(function|\)?;\s*if|;\s*if|;\s*ytplayer\.|;\s*<\/script)/gmsu; rawdata = rawdata.split('window.getPageData')[0]; rawdata = rawdata.replace('ytInitialPlayerResponse = null', ''); rawdata = rawdata.replace('ytInitialPlayerResponse=window.ytInitialPlayerResponse', ''); rawdata = rawdata.replace('ytplayer.config={args:{raw_player_response:ytInitialPlayerResponse}};', ''); var matches = regex.exec(rawdata); var data = matches && matches.length > 1 ? JSON.parse(matches[1]) : false; console.log(data); var streams = [], result = {}; if (data.streamingData && data.streamingData.adaptiveFormats) { streams = streams.concat(data.streamingData.adaptiveFormats); } if (data.streamingData && data.streamingData.formats) { streams = streams.concat(data.streamingData.formats); } streams.forEach(function(stream, n) { var itag = stream.itag * 1, quality = false, itag_map = { 18: '360p', 22: '720p', 37: '1080p', 38: '3072p', 82: '360p3d', 83: '480p3d', 84: '720p3d', 85: '1080p3d', 133: '240pna', 134: '360pna', 135: '480pna', 136: '720pna', 137: '1080pna', 264: '1440pna', 298: '720p60', 299: '1080p60na', 160: '144pna', 139: "48kbps", 140: "128kbps", 141: "256kbps" }; //if (stream.type.indexOf('o/mp4') > 0) console.log(stream); if (itag_map[itag]) result[itag_map[itag]] = stream.url; }); if (data.streamingData && data.streamingData.hlsManifestUrl) { result['hls'] = data.streamingData.hlsManifestUrl; } return result; }; html, body { height: 100%; min-height: 100%; background: #444; overflow: hidden; } video { width: 100%; height: 100%; object-fit: cover; } <video loop muted autoplay playsinline id="video"></video>
I found here a tutorial that explains how to set a video as a background of your page. This tutorial shows how to make the video as a fullscreen background and a background for only a specific page like you want. You need to set your Html and CSS part to achieve this kind of background. The tutorial page includes some sample code that you can copy. Hope it helps you.
Thanks to the above, I actually came up with a different method when the old one died out. Maybe not as good as the above, but it works for me. This is made into a WP Plugin and the user sets the height and a few other options like Video ID, mute and volume. Also using YouTube API. Can see it here at the top of my website: https://neotropicworks.com/ // Output from plugin onto page using 'wp_add_inline_script' to JS file below var video_id = "qnTsIVYxYkc",video_mute = true,video_volume = 50; // JS file var player; var tag = document.createElement('script'); tag.src = "//www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); function onYouTubeIframeAPIReady() { player = new YT.Player('youtube-header-player', { videoId: video_id, playerVars: { playlist: video_id, loop: 1 }, events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); } function onPlayerReady(event) { event.target.playVideo(); if(video_mute){ player.mute(); } else { player.setVolume(video_volume); } } function onPlayerStateChange(event) { if (event.data === YT.PlayerState.ENDED) { player.playVideo(); } } In a stylesheet .video-wrapper{width: 100%;overflow: hidden;position: relative;} .video-container {position: absolute;width: auto;top: -50%;left: 0;right: 0;bottom: -50%;} .video-bg {background: none;position: absolute;top: 0;right: 0;bottom: 0;left: 0;z-index: 1;} .video-bg .video-fg,.video-bg iframe,.video-bg video {position: absolute;top: 0;left: 0 !important;width: 100% !important;height: 100%;} Below is generated output from user on the height they want. They set sizes for the different devices, window sizes for better control. .video-wrapper{height: 400px;} .video-container {height: 800px;} #media (min-width: 768px) and (max-width: 991px) { .video-wrapper{height: 300px;} .video-container {height: 600px;} } #media (max-width:767px) { .video-wrapper{height: 200px;} .video-container {height: 400px;} } The HTML <div class="video-wrapper"> <div class="video-container"> <div class="video-bg"> <div class="video-fg" id="youtube-header-player"></div> </div> </div> </div>
Just sharing a simple jQuery plugin I've made, to make your lives easier. You only need to select an element with a data-youtube attribute containing a youtube link or ID only. Everything else is done for you by the plugin, including embed api script injection and CSS. Here is a quick usage sample. You can see it in action here. <div id="ytbg" data-youtube="https://www.youtube.com/watch?v=eEpEeyqGlxA"></div> <script type="text/javascript"> jQuery(document).ready(function() { $('[data-youtube]').youtube_background(); }); </script> Code on GitHub.
Why can't I hide my br tag?
I've added a <br> into my h1 tag visible only on xl screens (>1600px). The <br> however is showing all the time, when I want it to respond to the XL class (visible-xl). Live URL: http://185.123.96.102/~kidsdrum/moneynest.co.uk/ CSS: #screen-xl: 1600px; #screen-xl-min: #screen-xl; #screen-xl-desktop: #screen-xl-min; #screen-lg-max: (#screen-xl-min - 1); #container-xl-desktop: ((1560px + #grid-gutter-width)); #container-xl: #container-large-desktop; #media (min-width: #screen-xl-min) { .make-grid(xl); } .container { #media (min-width: #screen-xl-min) { width: #container-xl; } } .make-xl-column(#columns; #gutter: #grid-gutter-width) { position: relative; min-height: 1px; padding-left: (#gutter / 2); padding-right: (#gutter / 2); #media (min-width: #screen-xl-min) { float: left; width: percentage((#columns / #grid-columns)); } } .make-xl-column-offset(#columns) { #media (min-width: #screen-xl-min) { margin-left: percentage((#columns / #grid-columns)); } } .make-xl-column-push(#columns) { #media (min-width: #screen-xl-min) { left: percentage((#columns / #grid-columns)); } } .make-xl-column-pull(#columns) { #media (min-width: #screen-xl-min) { right: percentage((#columns / #grid-columns)); } } .visible-xl { .responsive-invisibility(); #media (min-width: #screen-xl-min) { .responsive-visibility(); } } .hidden-xl { #media (min-width: #screen-xl-min) { .responsive-invisibility(); } } .make-grid-columns() { // Common styles for all sizes of grid columns, widths 1-12 .col(#index) when (#index = 1) { // initial #item: ~".col-xs-#{index}, .col-sm-#{index}, .col-md-#{index}, .col-lg-#{index}, .col-xl-#{index}"; .col((#index + 1), #item); } .col(#index, #list) when (#index =< #grid-columns) { // general; "=<" isn't a typo #item: ~".col-xs-#{index}, .col-sm-#{index}, .col-md-#{index}, .col-lg-#{index}, .col-xl-#{index}"; .col((#index + 1), ~"#{list}, #{item}"); } .col(#index, #list) when (#index > #grid-columns) { // terminal #{list} { position: relative; // Prevent columns from collapsing when empty min-height: 1px; // Inner gutter via padding padding-left: (#grid-gutter-width / 2); padding-right: (#grid-gutter-width / 2); } } .col(1); // kickstart it } HTML: <h1 class="boldme hidden-xs hidden-sm hidden-xl" id="homepage-headline">Wish you were taught personal finance at school?<br class="visible-xl"/>We do too</h1> **Notes:**I'm using Bootstrap
Using two <h1> tags may be harmful for SEO purposes. Both <h1> elements have the same ID, which is invalid markup; each ID in a document must be unique. My solution: HTML <div class="text-center"> <h1 class="boldme hidden-xs hidden-sm hidden-xl" id="homepage-headline">Wish you were taught personal finance at school? We do too</h1> <h1 class="boldme visible-xl" id="homepage-headline2">Wish you were taught personal finance at school?<br>We do too</h1> </div> CSS: .hidden-xs .hidden-sm { display: none; } #media all and (max-width: 1600px) { .hidden-xs .hidden-sm { display: block; } .visible-xl { display: none; } } Note: change your property or value as you want! and think about remove second <h1>
WinJS.BackButton sizes
I have this html tag which reffers to the backButton provided by the WinJS library: <button data-win-control="WinJS.UI.BackButton"></button> I want to change its size. How can I do that? I tried using CSS by adding the ID "backButton" and font-size OR width/height properties, like this: #backButton { font-size: small; } #backButton { height: 30px; width: 30px; } EDIT: Code added and a picture of what happens when changing the values of width/height of the button. // For an introduction to the Page Control template, see the following documentation: // http://go.microsoft.com/fwlink/?LinkId=232511 (function () { "use strict"; WinJS.UI.Pages.define("/pages/anime/anime.html", { // This function is called whenever a user navigates to this page. It // populates the page elements with the app's data. ready: function (element, options) { // TODO: Initialize the page here. this.renderAnimeInfo(Identifier.file); }, unload: function () { // TODO: Respond to navigations away from this page. }, updateLayout: function (element) { /// <param name="element" domElement="true" /> // TODO: Respond to changes in layout. }, renderAnimeInfo: function (id) { // Path for the anime data. var path = "data/animes.json"; // Retrieve the .json. WinJS.xhr({ url: path }).then( function (response) { var json = JSON.parse(response.responseText); for (var i = 0; i < json.length; i++) { if (json[i].file == id) { var animeData = json[i]; break; } } }, function (error) {}, function (progress) {} ); }, }); })(); .right { float: right; } .left { float: left; } .active { background-color: blue; } #animeDetails { background: red; height: 100%; width: 300px; float: left; } #animeInfo { display: -ms-grid; height: 100%; width: calc(100% - 300px); float: right; } #navbar { -ms-grid-row: 1; padding: 20px 25px; } #navbar .right button { margin-right: 4px; } #navbar input { width: 150px; } #details { -ms-grid-row: 2; padding: 0 25px; text-align: justify; white-space: pre-line; } #details h3 { width: 100%; padding: 5px 0; border-bottom: 1px solid #bebebe; margin-bottom: 0; } <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>anime</title> <link href="anime.css" rel="stylesheet" /> <script src="anime.js"></script> </head> <body> <div id="animeDetails"></div> <div id="animeInfo"> <div id="navbar"> <div class="left"> <button class="left" data-win-control="WinJS.UI.BackButton"></button> <h3>Back</h3> </div> <div class="right"> <button type="button" class="active">Details</button> <button type="button">Episodes</button> <button type="button">Characters</button> <button type="button">Staff</button> <input type="search" placeholder="Search" /> </div> </div> <div id="details"> <div id="synopsis"> <h3>Synopsis</h3> <span> </span> </div> </div> </div> </body> When using the width/height properties, what happens is that the button does resize to the specified value, but the icon inside (which is not a background) doesn't. http://i.imgur.com/lMqmL0G.png
Possibly you have to set display: inline-block to button because the width of an element with display: inline (the default for buttons) is exactly the same as its content because it only takes up the space needed to display its contents so try with: With id selector #backButton { height: 30px; width: 30px; display: inline-block; } <button id="backButton" data-win-control="WinJS.UI.BackButton"></button> With style inline <button data-win-control="WinJS.UI.BackButton" style="width: 30px; height: 30px; display: inline-block"></button> Try to set the styles to child element .win-back #backButton .win-back{ /*---styles---*/ }
You haven't given your button an ID. The CSS does not know what tag to link to. <button id="backButton" data-win-control="WinJS.UI.BackButton"></button> edit: you may find the following reference useful CSS Selectors