Twitter Bootstrap 3 conditional .text-center - twitter-bootstrap-3

Is it possible to make a col with .text-left change to .text-center ONLY if "XS"?
<div class="row">
<div class="col-xs-12 col-sm-4 text-left text-uppercase">Left Col</div>
<div class="col-xs-12 col-sm-8 text-right">Right Col</div>
</div>
So, the two cols are on the same line, the one on the left with .text-left and the one on the right with .text-right. and when the screen size is XS they will become each in a line and the two with .text-center
Thanks.

Only way I can think of is have a custom class like follows. Seems like it could be refactored somehow, but it's what I can think of now:
<div class="row">
<div class="col-xs-12 col-sm-4 customTextLeft text-uppercase">Left Col</div>
<div class="col-xs-12 col-sm-8 customTextRight">Right Col</div>
</div>
/*CSS*/
/*screen-xs*/
#media (max-width: 768px) {
.customTextLeft{text-align:center;}
}
/*screen-sm*/
#media (min-width: 768px) and (max-width: 992px) {
.customTextLeft{text-align:left;}
}
/*screen-md*/
#media (min-width: 992px) and (max-width: 1200px) {
.customTextLeft{text-align:left;}
}
/*screen-lg corresponds with col-lg*/
#media (min-width: 1200px) {
.customTextLeft{text-align:left}
}
/*screen-xs*/
#media (max-width: 768px) {
.customTextRight{text-align:center;}
}
/*screen-sm*/
#media (min-width: 768px) and (max-width: 992px) {
.customTextRight{text-align:right;}
}
/*screen-md*/
#media (min-width: 992px) and (max-width: 1200px) {
.customTextRight{text-align:right;}
}
/*screen-lg corresponds with col-lg*/
#media (min-width: 1200px) {
.customTextRight{text-align:right}
}

You could hide and show alternate columns using bootstrap's Responsive Utility Classes.
Something like:
<div class="row">
<div class="col-xs-12 col-sm-4 text-left text-uppercase hidden-xs">Left Col</div>
<div class="col-xs-12 col-sm-4 text-center text-uppercase visible-xs">Left Col</div>
<div class="col-xs-12 col-sm-8 text-right hidden-xs">Right Col</div>
<div class="col-xs-12 col-sm-8 text-center visible-xs">Right Col</div>
</div>
Example in Bootply

Here's an extension of cabey77's solution, with support for multiple column sizes, written in less to be able to update with bootstrap's variables. This would need to be included when compiling bootstrap from less.
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
.customTextRight-xs{text-align:right;}
.customTextLeft-xs{text-align:left;}
.customTextRight-sm{text-align:center;}
.customTextLeft-sm{text-align:center;}
.customTextRight-md{text-align:center;}
.customTextLeft-md{text-align:center;}
.customTextRight-lg{text-align:center;}
.customTextLeft-lg{text-align:center;}
/* Small devices (tablets, 768px and up) */
#media (min-width: #screen-sm-min) {
.customTextRight-xs{text-align:right;}
.customTextLeft-xs{text-align:left;}
.customTextRight-sm{text-align:right;}
.customTextLeft-sm{text-align:left;}
.customTextRight-md{text-align:center;}
.customTextLeft-md{text-align:center;}
.customTextRight-lg{text-align:center;}
.customTextLeft-lg{text-align:center;}
}
/* Medium devices (desktops, 992px and up) */
#media (min-width: #screen-md-min) {
.customTextRight-xs{text-align:right;}
.customTextLeft-xs{text-align:left;}
.customTextRight-sm{text-align:right;}
.customTextLeft-sm{text-align:left;}
.customTextRight-md{text-align:right;}
.customTextLeft-md{text-align:left;}
.customTextRight-lg{text-align:center;}
.customTextLeft-lg{text-align:center;}
}
/* Large devices (large desktops, 1200px and up) */
#media (min-width: #screen-lg-min) {
.customTextRight-xs{text-align:right;}
.customTextLeft-xs{text-align:left;}
.customTextRight-sm{text-align:right;}
.customTextLeft-sm{text-align:left;}
.customTextRight-md{text-align:right;}
.customTextLeft-md{text-align:left;}
.customTextRight-lg{text-align:right;}
.customTextLeft-lg{text-align:left;}
}

Related

Media query not working, hiding Bootstrap jumbotron when viewed from mobile device

can't get media query to work, trying to hide jumbotron when viewed from mobile device.
url tyrescanner.net
code below
/* Extra Small Devices, Phones */
#media screen and (max-width: 380px) {
.customjumbotron{
background-color: black;
}
}
<div class="row no-container">
<div class="col-md-12">
<div class="jumbotron text-center customjumbotron">
<img class="img-responsive image-center" src="../Images/Nectar-CollectPoints.png" height="130" width="490" style= "margin-bottom: -10px"" />
<h2>Search for tyres and prices in your local area</h2>
<div class="searchbox">
<div class="input-group input-group-lg">
<div class="input-btn-toolbar" style="width:107%; height: 100%;">
<div class="input-btn-toolbar" style=" background-color:#313131; padding-left:5px; padding-top:7px; padding-bottom:3px; padding-right:3px;">
<asp:TextBox style="text-transform: uppercase; width:100%; font-size: 23px; text-align: center;" ID="txtReg" class="form-control" runat="server" placeholder="Enter Registration"></asp:TextBox>
<span class="input-group-btn" >
<asp:LinkButton class ="btn btn-default btn-default1" OnClick="ButtonSearch_Click" height="49" runat="server" type="button" style="color:white" ID="bntSearch"><span aria-hidden="true" class="glyphicon glyphicon-search"></span></asp:LinkButton>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
To make the jumbotron appear as a black background on small screens, add color: black; to your media query. That way, everything in the jumbotron will appear black (though there are probably much more elegant ways to do it).
Working example:
/* Extra Small Devices, Phones */
#media screen and (max-width: 380px) {
.customjumbotron{
background-color: black;
color: black;
}
#imgID {
display: none;
}
#imgHide {
display: block;
}
}
/* Larger Devices */
#media screen and (min-width: 381px) {
#imgHide {
display: none;
}
}
<div class="row no-container">
<div class="col-md-12">
<div class="jumbotron text-center customjumbotron">
<img class="img-responsive image-center" id="imgID" src="../Images/Nectar-CollectPoints.png" height="130" width="490" style="margin-bottom: -10px" />
<img class="img-responsive image-center" id="imgHide" src="" height="130" width="490" style="margin-bottom: -10px"></div>
<h2>Search for tyres and prices in your local area</h2>
<div class="searchbox">
<div class="input-group input-group-lg">
<div class="input-btn-toolbar" style="width:107%; height: 100%;">
<div class="input-btn-toolbar" style=" background-color:#313131; padding-left:5px; padding-top:7px; padding-bottom:3px; padding-right:3px;">
<asp:TextBox style="text-transform: uppercase; width:100%; font-size: 23px; text-align: center;" ID="txtReg" class="form-control" runat="server" placeholder="Enter Registration"></asp:TextBox>
<span class="input-group-btn" >
<asp:LinkButton class ="btn btn-default btn-default1" OnClick="ButtonSearch_Click" height="49" runat="server" type="button" style="color:white" ID="bntSearch"><span aria-hidden="true" class="glyphicon glyphicon-search"></span></asp:LinkButton>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
EDIT: Now hides the image in the jumbotron for small screens.
I fund the problem, I had to add another Media query to the Jumbotrom
#media only screen and (min-width : 992px) {
.customjumbotron {
/*.jumbotron*/
background: url('../Images/Tyre.jpg') no-repeat center center;
background-size: cover;
background-attachment: fixed;
min-height: 410px;
min-width: 100%;
width: 100%;
margin-right: 0px !important;
margin-left: 0px !important;
margin-bottom: 0px;
padding-right: 0px;
padding-left: 0px;
padding-bottom: 0px;
}
}
First identify what kind of iPhone you need to make it hide read iPhone 6 Screen Size and Web Design Tips first. Then use the points of different iPhone versions to add value for max-width or min-width to create changes, you can use either of the two. But take note of other devices breakpoints not only iPhone if you add breakpoints of more than one iPhone version breakpoints. I use in the sample codes below the minimum width of the largest iPhone version in order for your design make changes for all iPhone easily, but it depends:
USING LARGEST iPHONE VERSION MINIMUM POINTS:
<style type="text/css">
/* iPhone 6/7 Plus | 414 x 736 points */
#media only screen and (max-width : 414px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
</style>
USING iPHONE VERSION MAX-WIDTH:
<style type="text/css">
/* iPhone 4 | 320 x 480 points */
#media only screen and (max-width : 480px) {
body{
background-color: gold;
}
.customjumbotron{
display: none;
}
}
/* iPhone 5 | 320 x 568 points */
#media only screen and (max-width : 568px) {
body{
background-color: silver;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 | 375 x 667 points */
#media only screen and (max-width : 667px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 Plus | 414 x 736 points */
#media only screen and (max-width : 736) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
</style>
USING DIFFERENT iPHONE VERSION MIN-WIDTH:
<style type="text/css">
/* iPhone 4 | 320 x 480 points */
#media only screen and (min-width : 320px) {
body{
background-color: gold;
}
.customjumbotron{
display: none;
}
}
/* iPhone 5 | 320 x 568 points */
#media only screen and (min-width : 320px) {
body{
background-color: silver;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 | 375 x 667 points */
#media only screen and (min-width : 375px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
/* iPhone 6/7 Plus | 414 x 736 points */
#media only screen and (min-width : 414px) {
body{
background-color: teal;
}
.customjumbotron{
display: none;
}
}
</style>
DEFAULT BOOTSTRAP MEDIA QUERIES
<style type="text/css">
/*==================================================
Bootstrap 3 Media Queries
==================================================*/
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
/* YOUR CODE HERE|EXAMPLE CODES*/
body{
background-color: black;
}
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
/* YOUR CODE HERE|EXAMPLE CODES*/
body{
background-color: blue;
}
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
/* YOUR CODE HERE|EXAMPLE CODES| SET HERE WHAT YOU NEED TO HIDE OR ANYTHING*/
body{
background-color: green;
}
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
/* YOUR CODE HERE*/
}
</style>

Bootstrap - Use of different classes depending on the screen size

<input type="submit" class="form-control">
I want to add the form-control class only when the screensize is xs. Right now form-control gets added in all screensizes. How can I make it so that form-control class only gets added when screen size is xs?
You could use two different inputs like so:
<input type="submit" class="form-control hidden-lg hidden-md hidden-sm">
<input type="submit" class="hidden-xs">
This will hide the form-control when its anything but xs.
You can use #media
http://www.w3schools.com/cssref/css3_pr_mediaquery.asp
For example, to do hide sidebar id tagged div when size screen is less than 768:
#media (here is some true value...)
#media (max-width: 768px) {
#sidebar {
display: none;
}
}
jQuery is another way to do this by adding/removing the class based on the window width. See Docs.
*See working example at Full Screen, then re-size to view the change.
function checkWidth(init) {
if ($(window).width() < 480) {
$('input').addClass('form-control');
} else {
if (!init) {
$('input').removeClass('form-control');
}
}
}
$(document).ready(function() {
checkWidth(true);
$(window).resize(function() {
checkWidth(false);
});
});
body,
html {
padding-top: 40px;
padding-bottom: 40px;
}
#loginForm {
max-width: 500px;
padding: 15px;
margin: 0 auto;
background: #ddd;
}
#media (max-width: 480px) {
#loginForm {
background-color: red;
color: white;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form id="loginForm">
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" placeholder="Email address" />
</div>
<div class="form-group">
<label for="pw">Password</label>
<input type="password" id="pw" name="pw" placeholder="Password" />
</div>
<div class="form-group">
<input type="submit">
</div>
</form>
</div>
<!-- /container -->
Responsive text alignment has been added in Bootstrap V4:
https://v4-alpha.getbootstrap.com/utilities/typography/#text-alignment
For left, right, and center alignment, responsive classes are available that use the same viewport width breakpoints as the grid system.
<p class="text-xs-center">Center aligned text on all viewport sizes.</p>
Copied.
You should use both .xs and .form-control classes together as below:
.form-control.xs {/*Write your declerations.*/}

Internet explorer auto height with position absolute

I'm trying to make my columns same height, it works for columns without problems, but I have div inside and it has position: absolute, in every browsers it works, but in explorer there is a problem, can you help me?
http://days.cz.uvds268.active24.cz/new/
SCREEN: https://www.dropbox.com/s/rqld6xrwb3wc2m4/Bez%20n%C3%A1zvu-1.jpg?dl=0
enter code here*
row-full-height {
height: 100%;
}
.col-full-height {
height: 100%;
vertical-align: middle;
}
.row-same-height {
display: table;
width: 100%;
/* fix overflow */
table-layout: fixed;
}
.col-xs-height {
display: table-cell;
float: none !important;
}
#media (min-width: 768px) {
.col-sm-height {
display: table-cell;
float: none !important;
}
}
#media (min-width: 992px) {
.col-md-height {
display: table-cell;
float: none !important;
}
}
#media (min-width: 1200px) {
.col-lg-height {
display: table-cell;
float: none !important;
}
}
/* vertical alignment styles */
.col-top {
vertical-align: top;
}
.col-middle {
vertical-align: middle;
}
.col-bottom {
vertical-align: bottom;
}
/* CSS of box */
#third .row-same-height >div:first-of-type .box{ position: absolute;}`
<div class="row">
<div class="row-same-height ">
<div class="col-sm-6 col-sm-height col-top">
<div class="box">
<h2>DAYS MENU s.r.o.</h2>
<p>Naše společnost zahájila výrobu v lednu 1998. Díky vysoké kvalitě a příznivé ceně svých výrobků si brzy vybudovala pevnou pozici mezi konkurencí.</p>
<p>Důkazem toho je i neustále se zvyšující počet spokojených zákazníků a pravidelných odběratelů. Snažíme se jim maximálně vyjít vstříc a podle jejich přání a požadavků pravidelně rozšiřujeme a obměňujeme naši nabídku hotových i mražených jídel.</p><br>
<div class="row display-flex">
<div class="col-sm-6 vertical-align">
<strong class="certifikace">Jsme držitelem certifikátů</strong><br><br>
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-xs-6">
<img src="image/certificate_haccp.png" alt="HACCP certifikát systému kvality" class="img-responsive">
</div>
<div class="col-xs-6">
<img src="image/certificate_bisnode.png" alt="AA certifikát vysoké důvěryhodnosti" class="img-responsive">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-sm-height ">
<div class="box">
<h3>AKTUALITY</h3>
<blockquote>
<strong>4.3.2015 | HOTOVÁ TEPLÁ JÍDLA</strong>
<p>Vážení zákazníci. Z důvodu plné kapacity vozidel pro rozvoz hotových teplých jídel již bohužel nepřijímáme nové drobné odběratele (obědy pro jednotlivce). Děkujeme za pochopení.</p>
</blockquote>
<blockquote>
<strong>4.3.2015 | HOTOVÁ TEPLÁ JÍDLA</strong>
<p>Vážení zákazníci, informace o složení našich jídel a alergenech v nich obsažených dle nařízení EU č.1169/2011 - O označování potravin - Vám na vyžádání zodpovíme na tel. č. 466 951 571 nebo jsou tyto informace k dispozici na našich stránkách v nabídce jídelníčků a v nabídce mražených jídel.</p>
</blockquote>
<a class="more-news" href="vsechny-aktuality.php"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>VŠECHNY AKTUALITY</a>
</div>
</div>
</div>
</div>

Bootstrap 3 mixin multiple make-*-column

I'm using an specific mixin trying to make my code more clear. So instead of using:
<div class="col-lg-3 col-md-5 col-sm-6 col-xs-12">
I'm using:
<div class="stackOverflowRocksIt">
and in my mixins.less:
.stackOverflowRocksIt{
.make-lg-column(3);
.make-md-column(4);
.make-sm-column(6);
.make-xs-column(12);
}
It works properly with XS and SM viewports, but not when I resize to MD or LG (then is taking the SM size). Is this the proper way to create columns for different viewports sizes? Any idea?
You should re-order your mixin calls:
.stackOverflowRocksIt {
.make-xs-column(12);
.make-sm-column(6);
.make-md-column(4);
.make-lg-column(3);
}
#seven-phases-max is right. Bootstrap's code is mobile first, which mean you should start your code for the smallest screen widths and features and properties when the screen size become wider.
Bootstrap use CSS media queries to make the CSS code responsive. In your situation the .make-lg-column(3); compiles into the CSS code that shown below:
#media (min-width: 1200px) {
.stackOverflowRocksIt {
float: left;
width: 25%;
}
}
If you write .make-md-column(4); after the .make-lg-column(3); the #media (min-width: 992px) will came #media (min-width: 1200px) and also evaluates true for screens wider than 1200px and so overwrites your large columns code.

Bootply: offcanvas row hight 100%

I'm trying to use the offcanvas row to create a slide-in side menu for a mobile device.
I would like the menu to have a fixed position so that it will occupy the entire length of the screen in both small and larger screens. It's a bit tricky to play with position:fixed because the whole structure seems to fall apart when I do so. I use the following structure
<div class="container">
<div class="row row-offcanvas row-offcanvas-left">
<!-- sidebar -->
<div class="col-sm-3 col-lg-2 col-xs-6 sidebar-offcanvas" id="sidebar" role="navigation">
<!-- menu left content -->
</div>
<!-- main right col -->
<div class="col-sm-9 col-lg-10 col-xs-12" id="main">
<div class="navbar navbar-inverse navbar-main navbar-static-top collapse-group" role="navigation" id="mobile-main-nav">
<div class="collapse in no-ani">
<div class="nav-buttons">
<button type="button" class="btn btn-success icn-only visible-xs pull-left offcanvas-toggle" data-toggle="offcanvas"><i class="icon-th"></i></button>
<!--- top menu content --->
</div>
</div>
</div>
<div class="row navbar-top-padding">
<div class="col-md-12 page" id="col3">
<!--- main content --->
</div>
</div>
</div>
</div>
</div>
With the following LESS styles
#media screen and (max-width: #screen-xs-max) {
/*
* Off Canvas
* --------------------------------------------------
*/
.row-offcanvas {
position: relative;
-webkit-transition: all .2s ease-out;
-moz-transition: all .2s ease-out;
transition: all .2s ease-out;
left:0;//necessary to make the animation work
}
.row-offcanvas-right .sidebar-offcanvas {
right: -87%; /* 6 columns */
}
.row-offcanvas-left .sidebar-offcanvas {
left: -87%; /* 6 columns */
}
.row-offcanvas-right.active {
right: 87%; /* 6 columns */
}
.row-offcanvas-left.active {
left: 87%; /* 6 columns */
}
.sidebar-offcanvas {
position: absolute;
top: 0;
width: 87%; /* 6 columns */
}
}