I have two divs centred side-by-side using bootstrap. One div is text-right aligned and the other text-left. I'm trying to get it so that these become centred on top of each other when the page becomes to small to view them side by side. I have tried using #media rule in CSS to deal with this but with no luck. Any suggestions? The HTML so far looks like this:
<div class="container-fluid">
<div class="col-md-3 col-md-offset-3 text-right">
<p class="summary">Some summary text</p>
</div>
<div class="col-md-3 text-left">
<p class="description">An extended description</p>
</div>
</div>
UPDATE!
The CSS relating to the two divs:
/* Summary text */
.summary {
font-family: 'Stint Ultra Expanded', cursive;
font-size: 1.5em;
color: #ffffff;
text-transform: uppercase;
opacity: 0.8;
}
/* Description text */
.description {
font-family: 'Slabo 13px', serif;
font-size: 1.1em;
color: #ffffff;
opacity: 0.8;
}
#media screen and (max-width: 300px) {
.summary,
.description {
text-align: center;
}
}
300px max width is far too smaller to trigger. If you're using .col-md-3 then the two columns will occupy the full screen width starting at 992px and lower. See the Bootstrap Docs on Media Queries
#media (max-width: 992px) {
.summary,
.description {
text-align: center;
}
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container-fluid">
<div class="col-md-3 col-md-offset-3 text-right">
<p class="summary">Some summary text</p>
</div>
<div class="col-md-3 text-left">
<p class="description">An extended description</p>
</div>
</div>
If you want to go even smaller than 992px, you can use .col-sm-3 or .col-xs-3 or even come up with your own custom column widths by wrapping them in a media query.
Give an id to your columns as this will be more specific in your css and overwrite the Bootstrap css.
<div class="container-fluid">
<div id="column-one" class="col-md-3 col-md-offset-3 text-right">
<p>Some summary text</p>
</div>
<div id="column-two class="col-md-3 text-left">
<p>An extended description</p>
</div>
</div>
CSS:
#media screen and (max-width: 300px) {
#column-one, #column-two {
text-align: center;
}
}
Related
I am trying different things to adjust the margin left for mobile (different)screen size. I am setting margin according to medium screen size using margin-left. And want to adjust for small screen size. Generally which method is useful and papular. Nothing is working in my case.What is wrong?
Can someone explain it with example. I am able to adjust screen size for column grid. But heading and header and footer is the issue. If I give heading and make it horizontal-align using margin left. How to change it for different size screen? What is wrong?
1)Do I need to add different style tags for each of them(mobile and medium size using media query. It is not working.)
2)I trying to add class visible-xs and add mobile-margin (h1 view on mobile)
3)Add bootstrap utility class (h1 Utility class)
<script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- font awsome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- font awsome -->
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
</script>
<style>
.read{
width:300px;
height:70px;
border-radius: 40px;
background-color: darkgoldenrod;
padding-left: 50px;
padding-top: 8px;
margin-left: 400px;
margin-top: 100px;
}
.learn{
width:300px;
height:70px;
border-radius: 40px;
background-color: darkgoldenrod;
padding-left: 50px;
padding-top: 8px;
/* margin-left: 400px;*/
/* margin-top: 300px;*/
}
.mobile{
width:400px;
height:70px;
border-radius: 40px;
background-color: darkgoldenrod;
padding-left: 100px;
}
.mobile-margin{
margin-left: 50px;;
}
#media only screen and (min-width : 320px) {
margin-left: 50px;
}
#media only screen and (min-width : 768px) {
margin-left: 400px;
}
</style>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="read">Read more</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12 ml-md-4 ml-sm-1">
<h1 class="learn">Utility Class</h1>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="mobile-margin visible-xs">
<h1 class="mobile">view on mobile</h1>
</div>
</div>
</div>
</body>
You can try Bootstrap classes to adjust according to the screen sizes. First set a default (mobile) and then change using md or lg:
<div class="row">
<div class="col-md-3 ml-0 ml-lg-5">Margin Test</div>
<div class="col-md-3 ml-0 ml-lg-3">Margin Test</div>
</div>
margin-left is set to 0 for mobile screens and margin-left is set to 5 for large screens
I give you an example of a heading H1 element.
First make sure to add bootstrap css link correctly to your page.
In bootstrap you can use the m class for margin and the p class for padding. In addition you can optionally set the side on which you want to apply margin or padding. Use ml for example to set margin left. You can give it a value between 0 and 5. For example, ml-3. You can also specify multiple values for multiple screen sizes as shown in the below example:
<h1 class="ml-5 ml-md-3 ml-lg-0">Header Text</h1>
In this example, the heading element will have a margin of 5, it will change to 3 when screen size reaches medium and it will change to 0 when screen size reaches large.
All you have to do is give the class name in the media screens.You haven't given your class name and just given margin-left
#media only screen and (min-width : 768px) {
margin-left: 400px;
}
You can specify the name like this
#media only screen and (min-width: 320px) {
.read {
margin-left: 50px;
}
}
#media only screen and (min-width: 768px) {
.read {
margin-left: 400px;
}
}
You can center the heading through
<h4 class="text-center">
<h4 class="text-lg-center">h4: centered in large screen and centered in med/smaller</h4>
<h4 class="text-md-center">h4: centered in medium/large screen and centered in smaller</h4>
<h4 class="text-sm-center">h4: centered in small/medium/large except extra small</h4>
and for buttons centering
<div class="col text-center">
<button class="btn btn-default">Centered button</button>
</div>
I am trying to build my UI using Bootstrap. I am trying to set 3 divs in one row next to each other for medium and large screens. And for
under 768px I would like to place them one under another.
file.html
<section className="about" id="about">
<div className="container-fluid">
<div className="row boxes justify-content-md-center">
<div className="col-sm-12 col-md-4 box">
<div className="innerBox">
<div className="icons">
<img src={iconEducation} className="img-responsive" />
</div>
<div className="box-body">
<h3 className="box-title">Title </h3>
<div className="box-list">
<div className="box-list-items">
<div className="item-ul"><img src={dot} className="img-responsive" /></div>
<div>
<p>Text</p>
</div>
</div>
<div className="box-list-items">
<div><img src={dot} className="img-responsive" /></div>
<div className="item-ul">
<p>Text</p>
</div>
</div>
</div>
</div>
</div>
</div>
The HTML code is the same for all three divs.
Problem
On large and medium screens I have two divs in one row and a third underneath in new row. For tablet screens the divs do not flow one under another but are still in the same row. The layout I want is two in one row and the third underneath.
file.css
.about{
padding: 127px 0 196px 0;
}
.about .row.boxes >div{
margin: 0 20px 0 20px;
}
.about .box{
height: 550px;
width: 100%;
background-image: linear-gradient(144deg, #fdfdfd, #f9f9f9);
}
.about .innerBox{
margin: auto;
color: black;
width: 100%;
overflow: hidden;
}
.box-list-items > div {
display: inline-block;
}
.box-list-items img {
height: 35%;
width: 35%;
}
.icons {
height: 95px;
width: 95px;
float: right;
margin: 7% 5% 5% 0;
}
.icons img {
width: 100%;
height: 100%;
}
h3.box-title{
font-size: 2.7em;
}
As I was going through the Bootstrap docs I thought that naming the class as .col-md-4 would align my divs for above 768px in same row one next to each other and underneath would place them in kind of display: box view.
theres is no use of #media only screen and all ,this will work:
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">abc</div>
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">xyz</div>
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">123</div>
</div>
</div>
you can check:
https://jsfiddle.net/bfos8ttd/
you need to put all the code in file.html in side a div with class row and test it again.
Go to this Link for bootstrap columns (col-lg-4, col-md-4, col-sm-6, col-xs-12)
And follow these media query as per your device.
#media only screen and (min-width:1024px) and (max-width: 1200px) {
}
#media only screen and (min-width:992px) and (max-width: 1023px) {
}
#media only screen and (min-width:768px) and (max-width: 991px) {
}
#media only screen and ( max-width: 767px ) {
}
#media only screen and ( max-width: 479px ) {
}
#user9347049 This wouldn't fit in the comments, so I'm putting it here for clarity.
Your container-fluid lets you use the entire width of the screen, but it's still just a container, that contains your rows and columns. You create rows, then, you add columns. As in:
<div class="container"> <!-- you can change this class to container-fluid class if you like -->
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
</div>
</div>
You can only have one container class. The row div contains all your cols divs for that row. You can have as many rows of columns as you need. If you adapt you code, you should start getting some of the results you're looking for before you look at the media query side of it.
h1 {
font-size: 36px;
}
h3 {
font-size: 24px;
}
.container {
max-width: 1115px;
margin: 0 auto;
}
.profile-pic {
margin-top: 3vh;
}
<header>
<div class="container">
<div class="row">
<div class="col-sm-6 profile-pic"><img class="img-responsive img-circle" src="image/setu.png" alt="Setu Shubham">
</div>
<h1 class="col-sm-6 text-right middle"> Abhi</h1>
<h3 class="profession text-right">FRONT-END</h3>
</div>
</header>
Hi everyone, I am using bootstrap, I want my image and h1 to be at at same row, image to be at extreme left and heading to be at extreme right when browser gets resized. When I am resizing image comes at top, and my heading goes down, which is not looking good.
problem i m facing is shown in image
If you want name and profession in a column on the right, you should put them in some container (not .container, just a new parent element) with the class .col-**-6.
In following example, I'm switching to -xs- for resolutions lesser than 768px. I also removed centering of .container because it's already done by BS afaik.
EDIT: working example in Bootply
Relevant documentation: Bootstrap 3.x Grid
.col-xs-6 {
outline: 1px dashed darkred;
}
h1 {
font-size: 36px;
}
h3 {
font-size: 24px;
}
.container {
max-width: 1115px;
/*margin: 0 auto; already applied by BS afaik*/
}
.profile-pic {
margin-top: 3vh;
}
<header>
<div class="container">
<div class="row">
<div class="col-xs-6 profile-pic"><img class="img-responsive img-circle" src="image/setu.png" alt="Setu Shubham">
</div>
<div class="col-xs-6">
<h1 class="text-right middle"> Abhi</h1>
<h3 class="profession text-right">FRONT-END</h3>
</div>
</div>
</header>
My code is from bootstrap, but what I am trying to do is add a fig caption below an image that is center aligned for only smaller screens. When I check on my computer and shrink the window, the fig caption appears and is center aligned, when i check the code on a phone simulator (for example iphone5), it is also center aligned, but when I then upload the file to the server and check my phone (which is an iphone5), the text is not center aligned like on the simulator, but is instead left aligned. So my question is what is causing this error, and how do I fix it to be center aligned.
Also, I have the footer coded in a way to disappear on smaller screens. It is the same issue as above. It disappears when i shrink the window or when I check on the phone simulator, but it doesn't disappear on the actual phone.
Thanks for the help.
HTML:
<div class="col-xs-12 col-sm-9" style="padding: 0px;">
<img src="example.jpg" style="max-width:100%; margin-top: 48px;" alt="example"></img>
<figcaption>Details</figcaption>
</div>
<footer class="footer" style="background-color: #ffffff;">
<div class="container">
<p class="text-muted">Details</p>
</div>
</footer>
CSS:
#media screen and (min-device-width : 768px) {
figcaption {
display: none;
}
#media screen and (max-width: 767px) {
figcaption {
display: block;
text-align: center;
}
#media screen and (max-width: 767px) {
.footer {
display: none;
}
It looks like you're missing the closing brackets around your #media queries.
Should be:
#media screen and (min-device-width : 768px) {
figcaption {
display: none;
}
}
#media screen and (max-width: 767px) {
figcaption {
display: block;
text-align: center;
}
}
#media screen and (max-width: 767px) {
.footer {
display: none;
}
}
But, instead of doing it manually, you could use the Bootstrap responsive utility classes. To do what you're looking for:
<div class="col-xs-12 col-sm-9" style="padding: 0px;">
<img src="example.jpg" style="max-width:100%; margin-top: 48px;" alt="example"></img>
<figcaption class="visible-xs-block text-center">Details</figcaption>
</div>
<footer class="footer hidden-xs" style="background-color: #ffffff;">
<div class="container">
<p class="text-muted">Details</p>
</div>
</footer>
i have add bootstrap class text-center in figcaption below plz refer it
<div class="col-xs-12 col-sm-9" style="padding: 0px;">
<img src="example.jpg" style="max-width:100%; margin-top: 48px;" alt="example"></img>
<figcaption class="visible-xs-block text-center">Details</figcaption>
</div>
<footer class="footer hidden-xs" style="background-color: #ffffff;">
<div class="container">
<p class="text-muted">Details</p>
</div>
</footer>
Please see this JSFiddle.
I'm using Twitter-Bootstrap. What I'm trying to accomplish here is on md+ devices, have a row of 4 diamonds/thumbnails with a second row of 3, all fairly close but not touching. When the user is on a smaller device, the diamonds switch from a row of 2, then a row of 3, then a row of 2. I have the code working fine for this now as you can see on the JS Fiddle, but if you have a cleaner way of doing this without JS please share. :)
My problem arises when I try to make the images clickable, since these are going to be thumbnails I want to use Featherlight (a lightbox alternative as you probably know) so that when the user clicks on a thumbnail I can have a box pop up with a larger image and information about it. I left this out of the JSFiddle and instead used "regular" links for demo purposes. The transparency from these diamond images is the problem. Because the images are so close together, the transparent section of one of these diamonds always overlaps another, making a section of each diamond link to an unintended diamond.
I have tried image mapping and altering the z-index. The overlapping transparency problem persists. Would creating this shape out of CSS work instead (how would I do that)? What solution is there to this? Thank you so much for any help!
HTML:
<section class="container-fluid diamonds">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="xsrow1">
<div class="col-md-3 col-xs-6 xsright no-padding"><img src="http://i57.tinypic.com/o5565j.png">
</div>
<div class="col-md-3 col-xs-6 no-padding"><img src="http://i57.tinypic.com/o5565j.png">
</div>
</div>
<div class="col-md-3 col-xs-4 xsRow2Margin no-padding"><img src="http://i57.tinypic.com/o5565j.png">
</div>
<div class="col-md-3 col-xs-4 xsRow2Margin no-padding"><img src="http://i57.tinypic.com/o5565j.png">
</div>
</div>
<div class="col-md-8 col-md-offset-2 mdrow2">
<div class="col-md-4 col-xs-4 xsRow2Margin no-padding"><img src="http://i57.tinypic.com/o5565j.png">
</div>
<div class="xsrow3">
<div class="col-md-4 col-xs-6 xsright no-padding"><img src="http://i57.tinypic.com/o5565j.png">
</div>
<div class="col-md-4 col-xs-6 no-padding"><img src="http://i57.tinypic.com/o5565j.png">
</div>
</div>
</div>
</div>
</section>
CSS:
.no-padding {
padding: 0!important;
padding-right: 3px!important;
padding-left: 3px!important;
margin: 0!important;
}
.diamonds {
position: relative;
}
.diamonds img {
width: 100%;
height: auto;
}
#media (max-width: 479px) {
.xsRow2Margin {
margin-top:-15.2%!important;
margin-bottom:-15.2%!important;
}
.no-padding {
padding-right: 2px!important;
padding-left: 2px!important;
}
}
#media (max-width: 991px) {
.xsrow1 img, .xsrow3 img {
width: 66%!important;
height: auto;
}
.xsright {
text-align: right;
}
}
#media (min-width: 480px) and (max-width: 991px) {
.diamonds {
margin-left: 1%;
margin-right: 1%;
}
.xsRow2Margin {
margin-top:-15.9%!important;
margin-bottom:-15.9%!important;
}
}
#media (min-width: 992px) {
.mdrow2 {
position: absolute;
top: 51%;
left:0%;
padding-left: 3%;
padding-right: 3%;
}
}
I've got a solution . I've placed the anchor tag on top of the image at the center and rotated it by 45degrees. Give highest z-index for the anchor. I've done only one diamond so you might have to do some tweaks with your css.
.img{
height:168px;
width:168px;
}
.link{
transform: rotate(45deg);
position: absolute;
height: 118px;
width: 118px;
left: 25px;
top: 25px;
}
<div class="col-md-3 col-xs-4 xsRow2Margin no-padding"><img class="img" src="http://i57.tinypic.com/o5565j.png" style="
position: absolute;
">
</div>