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.
Related
I am building a webpage for homework purposes and I am struggling to fit in four photos with different dimensions in a grid layout. To be more specific I have to make that grid layout be responsive as a 4-grid layout on Desktop view, 2-grid layout on Tablet view, and Mobile view. I have tried a lot of advice from different articles but none of them seems to be working.
CSS code:
.services{
float: left;
width: 25%;
height:100vh;
max-width:100%;
object-fit:cover;
}
#media only screen and (max-width: 1180px) {
.services{
width: 50%;
}
}
HTML code:
<div>
<div class="services">
<img src="./Photos/services-1.jpg"></img>
</div>
<div class="services">
<img src="./Photos/services-2.jpg"></img>
</div>
<div class="services">
<img src="./Photos/services-3.jpg"></img>
</div>
<div class="services">
<img src="./Photos/services-4.jpg"></img>
</div>
</div>
Current look:
I want photos to be in a line for each occasion with certain dimensions.
Any thoughts?
Thanks for submitting your question! Instead of using markup for placing your images, I would suggest using with a background-image. Why? With background-image you can use 'background-size: cover' wich make the image cover the whole with a custom height, so the columns are all equal.
Trying to achieve this with regular tags needs a some sort of resizer or the images need to be the same width and height already.
Below my code! Tip: You don't have to close the tag, you can use it without the closing image tag.
HTML
<div>
<div class="services">
<div class="image-box" style="background-image: url('https://source.unsplash.com/random');"></div>
</div>
<div class="services">
<div class="image-box" style="background-image: url('https://source.unsplash.com/random');"></div>
</div>
<div class="services">
<div class="image-box" style="background-image: url('https://source.unsplash.com/random');"></div>
</div>
<div class="services">
<div class="image-box" style="background-image: url('https://source.unsplash.com/random');"></div>
</div>
CSS
.services{
float: left;
width: 25%;
height:100vh;
max-width:100%;
object-fit:cover;
}
.services .image-box {
width: 100%;
height: 400px;
background-size: cover;
}
#media only screen and (max-width: 1180px) {
.services{
width: 50%;
}
}
Try this, for grid you need to define display: grid; in the parent div
.grid{
display: grid;
grid-template-columns: repeat(4,1fr);
}
.services{
height: 100%;
width: 100%;
}
#media only screen and (max-width: 1180px) {
.grid{
display: grid;
grid-template-columns: repeat(2,1fr);
}
}
in HTML , in the place of 'level' add your image code it will work in both responsive
<div class="grid">
<div class="services">
level
</div>
<div class="services">
level
</div>
<div class="services">
level
</div>
<div class="services">
level
</div>
</div>
if you want the image to be cover add this in img class object-fit: cover;
This will work fine .
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;
}
}
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>
Can anyone tell me how to ensure I get white space/margin on the left hand side and right hand side when the page is viewed on a mobile phone?
My CSS is:
#maxCostSlider {
max-width:304px;
width:304px;
padding:0px;
margin-left:-6px;
}
#media (max-width: 480px) {
#maxCostSlider,#sliderScale {
margin-left: 20px;
margin-right: 20px;
}
}
HTML is:
<div class="container-fluid">
<div class="row">
<div class="col-md-offset-4 col-md-4">
<img id="sliderScale" src="/assets/img/price slider 1.png" alt="" class="img-responsive" />
</div>
</div>
<div class="row text-center">
<div class="col-md-offset-4 col-md-4">
<input id="maxCost" data-slider-id='maxCostSlider' type="text" data-slider-min="0" data-slider-max="100" data-slider-step="10" data-slider-value="40" />
</div>
</div>
</div>
This all looks good on a desktop and an iPad but when viewed on an iPhone the bootstrap-slider widget spans the entire width of the device. I would like to ensure there is always a margin of at least 20px either side of the two rows. Ideally the bootstrap-slider would scale to fit.
Hard to tell without know the exact slider component you are using, but adding this to your CSS should work:
#maxCostSlider {
margin-left: 20px;
margin-right: 20px;
}
However if you only want that to happen at mobile width, wrap it in a media query:
#media (max-width: 480px) {
#maxCostSlider {
margin-left: 20px;
margin-right: 20px;
}
}
For small device(sm) and extra small device (xs) you can call them separately.
<div class="col-sm-offset-1 col-xs-offset-1 col-md-offset-4 col-md-4"></div>
And another way you can do this by css.
#media (min-width: 240px) and (max-width: 480px) {
#max-cost {
padding-left: 20px;
padding-right: 20px;
}
}
I'm trying to create a layout with 3 columns when over 1440px, and two columns from 800px to 1440px - the media queries I've got are working fine, however the problem is trying to get the cols to align vertically:
Screen shot http://pichut.eu/x/Screen_Shot_2013-10-13_at_10.png
As you can see the third col when collapsed aligns left, however it sits bellow the end of the first column, but I would prefer if it were aligned with the bottom of the first! (make sense? :L)
Here's the HTML for the cols:
<div class="dyn-col">
<div class="widget">
<div class="widget-title">
Widget Title
</div>
<div class="widget-content">
Widget Contents
</div>
</div>
</div>
<div class="dyn-col">
<div class="widget">
<div class="widget-title">
Widget Title
</div>
<div class="widget-content">
Widget Contents
</div>
</div>
</div>
<div class="dyn-col">
<div class="widget">
<div class="widget-title">
Widget Title
</div>
<div class="widget-content">
Widget Contents
</div>
</div>
</div>
And here's the CSS i've got for the page...
/*=================================================
Dynamic Cols
=================================================*/
.dyn-col {
width: 100%;
display: block;
float: left;
-webkit-box-sizing: border-box;
box-sizing: border-box
-moz-box-sizing: border-box
}
#media screen and (max-width: 800px) {
.dyn-col {
width: 100% !important;
}
}
#media screen and (min-width: 801px) and (max-width: 1439px) {
.dyn-col {
width: 50% !important;
float: left;
}
.dyn-col:last-child {
}
}
#media screen and (min-width: 1440px) {
.dyn-col {
width: 33.3% !important;
}
}
Would recommend using bootstrap 3 makes life easier when doing stuff like that I use it alot.