Change the text-align from right to left on extra small screens - html

I have a bit of Razor code like this:
if (providerInfo.ProviderSpecialties.Any()) {
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="row">
<label class="col-xs-12 col-sm-4 control-label specialtiesHeaderLabel">Specialties</label>
<div class="col-sm-8 col-xs-12">
<ul class="control-label resultValueLabel specialtiesValues">
#foreach (var specialty in providerInfo.ProviderSpecialties) { if (!string.IsNullOrWhiteSpace(specialty)) {
<li>
#specialty
</li>
} }
</ul>
</div>
</div>
</div>
</div>
}
and my CSS is like this:
.specialtiesHeaderLabel {
text-align: right !important;
padding-right: 1px;
color: #c1c1c1 !important;
}
I do need the specialtiesHeaderLabel to be right aligned for most of the sizes but when I go to iPhone 5,6 portrait sizes at that point the label is staying still at right side but I want it to now be on LEFT side.
How can I tell it to do that?
bad one:

This should work for you. I also recommend you reading: Using media queries
for further explanation on media queries.
.specialtiesHeaderLabel {
text-align: right;
padding-right: 1px;
color: #c1c1c1;
}
#media (max-width: 768px) {
.specialtiesHeaderLabel {
text-align: left;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="row">
<label class="col-xs-12 col-sm-4 control-label specialtiesHeaderLabel">Specialties</label>
<div class="col-sm-8 col-xs-12">
<ul class="control-label resultValueLabel specialtiesValues">
<li>
Hi I'm a Specialty
</li>
</ul>
</div>
</div>
</div>
</div>

If you consider "extra-small" like bootstrap does, this means you want to affect phones with a width <= 768px. In your case, you may want to use media queries (more on bootstrap) like this :
<style>
media (max-width:768px) {
/*Css in here will only affect devices with a width of <= 768px*/
}
</style>

Use Media Queries as stated by Reddy. Basically you add the media query and type your styling for that specific size. Foe example, I want to style such that my website works on the Ipad Mini, I will use the tag #media screen and (max-width:768px){<styling here>} and start styling accordingly. If you wish to see how it will look like, right click, inspect/inspect element (depends on chrome, im assuming you are using chrome) then you toggle devices and select the device

If you think mobile first, you want the label to be left aligned and for devices larger than mobile phones, you want to be right aligned
So you need
#media (min-width: 768px ) {
.specialtiesHeaderLabel {
text-align: right !important;
}
}
this means that label will be left aligned(default value) and for for devices 768px and up will be right aligned. Note: 768px is bootstrap default small screen breakpoint, it can be any value

Related

Bootstrap pull-right pull-left centering on mobile devices

I am having problem making footer with pull-left and pull-right then center on mobile devices. Currently on desktop it is displaying properly.
Code(fiddle):
<footer >
<div class="container">
<p>
<div class="col-sm-4 pull-left">
<strong>Powered by Google</strong>.
</div>
<div class="col-sm-4 pull-right">
Terms
<span class="">|</span>
Policy
</div>
</p>
<BR>
<p>
<div class="col-sm-4 pull-left">
Please direct all queries to admin#gmail.com
</div>
<div class="col-sm-4 pull-right">
2.1
</div>
</p>
</div>
As you can see when it is on mobile devices it is displayed as this:
I want to be able to display it similar to this on mobile device where it is centered:
Wrap your col-*** divs in the .row div.
I think you don't need pull-left and pull-right classes. Add col-sm-push-4 class to make right div move to the page's right border
Add custom css to center content on mobile devices, like this:
#media (max-width: 767px) {
.col-sm-4 {
text-align: center;
}
}
Or add custom class to these divs, if you don't want other .col-sm-4 divs to have centered content.
https://jsfiddle.net/1gLmb0yy/6/
You need to use query media to do that, because when the result is pull to right in a small resolution. it will responsive and go to bottom. You can use F12 developer tool to see that.
<footer >
<div class="container">
<div class="col-sm-4 row">
<strong>Powered by Google</strong>.
Please direct all queries to admin#gmail.com
</div>
<div class="col-sm-4 row pull-right">
Terms
<span class="">|</span>
Policy
2.1
<div/>
</div>
</div>
<footer>
Developer tool result.
Example Media Query
#media (max-width: 767px) {
.col-sm-6.row.pull-right {
position: relative;
top: -15px;
}
}

responsive screen, when I minimize from full screen my right column goes to the bottom. How do I fix this?

I think I know why as soon as I release the screen from full-screen mode my right column goes to the bottom. I'm using Bootstrap and played around with the width as well. currently I have
<div class="col-sm-2">
<div class="col-sm-7">
<div class="col-sm-3">
and in css:
.col-sm-2 {
width:180px;
padding:13px 22px;
}
.col-sm-7 {
background-color: #FFFFFF;
width:970px;
padding:13px 22px;
}
I want my col-sm-3 to stay still even if I'm not in full screen in my desktop. Also in mobile version, if it's possible I want only col-sm-7 to be shown in the middle. And rest of them to be way at the bottom or at the dropbox. Can someone please help me?
I think you should define (or redefine) the width for extra small device too..
<div class="col-sm-2 col-xs-2">
<div class="col-sm-7 col-xs-7">
<div class="col-sm-3 col-xs-3">
and for col-xs-? provide the related width ..

Custom column size on bootstrap (without affect responsive design)

I would like to create on my page a really tiny left menu with bootstrap like this :
<div class="row>
<div class="col-md-1 col-sm-1 leftMenu"></div>
<div class="col-md-7 col-sm-7 main"></div>
<div class="col-md-4 col-sm-4 rightMenu"></div>
</div>
However col-md-1 is too large for my menu. I would like a width equal to 50px;
I don't find a solution to have a menu with a size inferior to the minimal column, without affect the responsive design of my page
Anyone have an answer to my problem ?
If you want to keep using Bootstrap, you could define new columns widths, e.g. 0.5 / 12 and 7.5 / 12:
col-md-0-5 | col-md-7-5 | col-md-4
col-sm-0-5 | col-sm-7-5 | col-sm-4
If you check the bootstrap.css file, you can define the new col-md-0-5 and col-md-7-5 classes as follows:
.col-md-0-5, .col-md-7-5 {
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
#media (min-width: 992px) {
.col-md-0-5, .col-md-7-5 {
float: left;
}
.col-md-0-5 {
width: 4.16666667%;
}
.col-md-7-5 {
width: 62.5%;
}
}
Just follow the same logic to define the new col-xs-0-5 and col-xs-7-5 classes.
.parentdivClass .row .col-md-1.col-sm-1.leftMenu{
/*your style*/
}
this CSS solve your problem but the responsiveness of the bootstrap will get affected for sure.
Assign width to the div
<div class="row">
<div class=" col-md-1 col-sm-1 well leftMenu " style="width:15px;"></div>
<div class="col-md-7 col-sm-7 well main "></div>
<div class="col-md-4 col-sm-4 well rightMenu "></div>
</div>
Demo
i have a solution for this and use it for my project you can make a file in sass directory with own name and add to main bootstrap sass file
first open _bootstrap.scss file and add this to last line
#import "bootstrap/my-responsive";
my-responsive is your file name
and put your custom css to that file (_my-responsive.scss) for any customize responsive size bootstrap screen like this
put your css for col-sm (small screen)
#media screen and (min-width: $screen-sm-min){ your own css }
this css just load in sm size with bootstrap standard size
for example
#media screen and (min-width: $screen-sm-min){ .leftMenu {width:20px} }
#media screen and (min-width: $screen-md-min){ .leftMenu {width:55px} }
in this case finaly you have one class with 20px width in sm screen and 55px in md screen so your responsive is ok and has your specific size

Bootstrap - Placing element B below element A

so confused at the moment I am trying to place a social icon below a h3 tag that is in the same bootstrap row however having a nightmare doing it.
I am trying to create this effect:
However I cant seem to get those icons below the phone number element when they are in the same row, they just sit on the same line.
The logo is also in the same row as the phone number element so if I created another row and placed the icons in that row they appear to far down the page.
Here is an example of my code:
HTML
<div class="container hidden-sm hidden-xs">
<div class="row">
<div class="brand col-md-6 col-sm-6"><img src="media/img/logo.png" alt="Driven Car Sales" class="img-rounded logo-custom"></div>
<div class="phone-div col-md-6 col-sm-6">
<h3 class="phone-number"><i class="glyphicon glyphicon-phone"></i> 01429 7654287</h3>
<img src="media/img/facebook-icon.png" alt="Facebook" class="facebook-icon">
</div>
</div>
</div>
CSS
.phone-number {
color: #fff;
margin-top: 20px;
display: inline-block;
font: 600 2em 'Open Sans', sans-serif;
float: right;
}
.facebook-icon {
display: block;
height: 30px;
float: right;
}
/* main logo */
.logo-custom {
height: 75px;
}
#media only screen and (max-width : 1199px) {
.logo-custom {
height: 61px;
}
}
Any tips on what I might be able to do to create this effect?
Thanks, Nick :)
Try this Code:
<div class="container hidden-sm hidden-xs">
<div class="row">
<div class="brand col-md-6 col-sm-6"><img src="media/img/logo.png" alt="Driven Car Sales" class="img-rounded logo-custom"></div>
<div class="phone-div col-md-6 col-sm-6">
<div class="col-md-12 col-sm-12">
<h3 class="phone-number"><i class="glyphicon glyphicon-phone"></i>01429 7654287</h3>
</div>
<div class="col-md-12 col-sm-12">
<img src="media/img/facebook-icon.png" alt="Facebook" class="facebook-icon">
</div>
</div>
</div>
</div>
Hope this may useful
I think you might be just over-complicating things in your own mind. Forget about Bootstrap for a minute, if you wanted to just make a page that has two elements stacked one on top of the other, then you'd make sure to use block elements (which means that they will take up 100% the width of the container they are in by default).
The thing is that your custom css is actually overriding this normal behavior because you are expressly setting the phone number to be display: inline-block; and making both elements use float:right. Just remove those from your css rules and you'll get your desired effect:
.phone-number {
color: #fff;
margin-top: 20px;
font: 600 2em sans-serif;
}
.facebook-icon {
display: block;
height: 30px;
}
If you want the items to align to the right, just add the Bootstrap helper class: text-right to the column div or add text-align: right to your css rules.
EDIT: Just a suggestion
Also, you can streamline your markup. If you want the entire container to be hidden on sm and xs devices, then all you have to have in your col classes is col-md-6. And, if you didn't want your container to be hidden at the xs and sm breakpoints, then all you would need is col-sm-6, because that alone would set the columns to be 50% for ALL viewports that are larger than 767px. Remember, col classes are additive. When you add a col class, it's like saying: "make this column this width from this viewport size and up until I tell you otherwise".

Reordering divs in Twitter Bootstrap 3.1 not working as intended

I am trying to reorder div tags with Bootstraps push/pull classes. This stackoverflow answers it to an extent:
Reordering divs responsively with Twitter Bootstrap?
But I don't think the answer is complete. Yes, it moves the divs to the correct spot, but as soon as you add content to the the div labled "B", it pushes down the div labeled "C".
How do you keep "C" directly under "A" without having "B" push it down?
Example: http://www.bootply.com/WYZUhmD0Ft
I was able to use "pull-right" and "pull-left" instead and they work. However, they are not responsive and require additional css to work at different breakpoints.
http://www.bootply.com/PILUCrxwYa
Take a look at this answer to a similar question.
The layout that you want can be achieved using floats.
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-3 pull-right">Content of A</div>
<div class="col-xs-12 col-md-9 pull-left">
<p>Content</p>
<p>of</p>
<p>B</p>
</div>
<div class="col-xs-12 col-md-3 pull-right">Content of C</div>
</div>
Edit:
If you need this behavior only on some screens you could create your own classes:
Add these custom styles in your LESS file: (variables taken from grid.less)
#media (min-width: #screen-sm-min) {
.pull-right-sm {
float: right;
}
}
#media (min-width: #screen-md-min) {
.pull-right-md {
float: right;
}
}
#media (min-width: #screen-lg-min) {
.pull-right-lg {
float: right;
}
}
So you now have the classes pull-right-sm pull-right-md pull-right-lg.