I'm trying to build an image gallery with description below the image. Every thing run well except when i added in a longer description, the second row goes misorder.
How to overcome this issue?
my testing site is : http://osakaairport.com/airlines/index.htm
below is the sample code: (short code due to limited by stack overflow)
<style>
#media only screen and (max-width: 500px) {
.responsive-main {
width: 100%;
}
}
*{
box-sizing: border-box;
}
.responsive1 {
padding: 0 6px;
float: left;
width: 19.99999%;
}
#media only screen and (max-width: 500px) {
.responsive1 {
width: 32%;
}
div.desc1 {
padding-top:3px;
padding-bottom:10px;
text-align: center;
font-size: 12px;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
</style>
<div class="responsive1">
<div class="gallery1">
<a href="china_airlines/index.htm">
<img src="../images/airlines/china_airlines_logo.png" alt="China Airlines"></a>
<div class="desc1">Japan Airlines Japan Airlines</div>
</div>
</div>
<div class="responsive1">
<div class="gallery1">
<a target="_blank" href="../facilities/wifi.htm">
<img src="../images/airlines/airasia_indonesia.png" alt="airasia indonesia"> </a>
<a target="_blank" href="../facilities/wifi.htm">
<div class="desc1">All Nippon Airways</a></div>
</div></div>
<div class="responsive1">
<div class="gallery1">
<a target="_blank" href="../facilities/wifi.htm">
<img src="../images/airlines/cebu_pacific.png" alt="cebu pacific">
</a>
<div class="desc1">Peach</div>
</div>
</div>
<div class="responsive1">
<div class="gallery1">
<a target="_blank" href="../facilities/wifi.htm">
<img src="../images/airlines/china_airlines_logo.png" alt="china airlines">
</a>
<div class="desc1">9 Air</div>
</div>
</div>
<div class="responsive1">
<div class="gallery1">
<a target="_blank" href="../facilities/wifi.htm">
<img src="../images/airlines/china_eastern_airlines.png" alt="China Eastern Airlines">
</a>
<div class="desc1">AirAsiaX</div>
</div>
</div>
<div class="clearfix"></div>
One way to tackle this is to set the following to class responsive1.
<style>
.responsive1{
padding: 0 6px;
width: 19.6%; // adjust your width accordingly base on your demand
display: inline-block; // behave as block elements inside, but inline elements outside, just like the behavior of characters
// no need to use float:left in this case
vertical-align: top;
}
</style>
Related
I'm having some trouble with this not running properly. It won't align the text correctly and it also won't distribute the cells across the available space. Not sure what I'm doing wrong here, so any help would be appreciated.
While we're at it, I'm also trying to figure out how to get it to show 2 columns instead of 1 when it switches to mobile sized. The way it's setup now, it just transitions to 1 column.
This is for a website on Shopify that uses an html block to insert custom code. I have other blocks that I've inserted into it and they all seem to be working fine, it's just this one that's giving me issues.
.table2 {
display: table;
}
.table-row2 {
display: table-row;
}
.table-cell2 {
display: table-cell;
vertical-align: top;
width: 20%;
padding: 2.5%;
}
.icontext {
display: text;
vertical-align: middle;
width: 20%;
padding: 2.5%;
float: middle;
}
#media screen and (max-width: 768px) {
.table2,
.table-row2,
.table-cell2 {
display: block;
width: 100%;
float: middle;
}
}
<h1><center>Materials</center></h1>
<div class="table2">
<div class="table-row2">
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/0ce94db3-8b05-4d84-a64c-dc6de006151c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Durable
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/b6ff1bd5-4c2e-4db0-bacc-3aa76678e92c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Quick Dry
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/e09a4c7e-c262-415f-b491-599bd0bc3a66/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Lightweight
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/03df04db-7851-4f80-ad8f-0438cc7e0397/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Breathable
</div>
</div>
<div class="table-cell2" width="20%" align="center">
<img src="https://ucarecdn.com/8034c6ad-6c30-406d-8865-a4bdb4060bca/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Moisture Wicking
</div>
</div>
</div>
</div>
I would recommend using flex something like below will fix your issue. There was a few issues with your previous code being out of date. This will also flex on mobiles to show 2 columns as you stated.
.table-row2 {
width: 100%;
height:auto ;
display: flex;
flex-direction: row;
flex-wrap:wrap;
justify-content:space-around;
}
.table-cell2 {
vertical-align: top;
padding: 2.5%;
}
.icontext {
padding: 2.5%;
text-align: center;
}
#media screen and (max-width: 768px) {
.table2,
.table-row2,
.table-cell2 {
// removed all
}
}
<meta name="viewport" content="width=device-width" />
<h1><center>Materials</center></h1>
<div class="table2">
<div class="table-row2">
<div class="table-cell2">
<img src="https://ucarecdn.com/0ce94db3-8b05-4d84-a64c-dc6de006151c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Durable
</div>
</div>
<div class="table-cell2" >
<img src="https://ucarecdn.com/b6ff1bd5-4c2e-4db0-bacc-3aa76678e92c/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Quick Dry
</div>
</div>
<div class="table-cell2" >
<img src="https://ucarecdn.com/e09a4c7e-c262-415f-b491-599bd0bc3a66/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Lightweight
</div>
</div>
<div class="table-cell2" >
<img src="https://ucarecdn.com/03df04db-7851-4f80-ad8f-0438cc7e0397/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Breathable
</div>
</div>
<div class="table-cell2">
<img src="https://ucarecdn.com/8034c6ad-6c30-406d-8865-a4bdb4060bca/-/format/auto/-/preview/3000x3000/-/quality/lighter/">
<div class="icontext">
Moisture Wicking
</div>
</div>
</div></div>
Hi community and thanks in advance for your help.
My problem is following, I would like to display some images while on computer screen but switch those images to only one composite image on mobile devices. Here is the code I have:
#media screen and (max-width:480px) {
.hidden_mobile {
display:none;
background-image: url("http://julienleveau.com/wp-content/uploads/2018/04/Mobile-version.jpg");
background-repeat: no-repeat;
background-size: contain;
}
}
<div class="col-sm-1">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/top100.jpg" style="display: block; width: 100%; height: auto; margin: 0 auto 15px" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/WW-1.jpg" style="display: block; width: 100%; height: auto; margin: 0 auto 15px" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/fearless.jpg" style="display: block; width: 100%; height: auto; margin: 0 auto 15px" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/bowp-300-1.jpg" style="display: block; width: 100%; height: auto; margin: 0 auto 15px" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/ispwp.jpg" style="display: block; width: 100%; height: auto; margin: 0 auto 15px" alt="">
</div>
</div>
<div class="col-sm-1">
</div>
So far it works on computer but on mobile it doesn't. It just displays the images on top of each others.
Thank you
You have 2 problems here:
1) The elements that you are trying to hide in mobile have an inline display:block that overrides the display:none in your stylesheet. That's why you keep seeing the images in mobile. In the running snippet below, I removed all the inline styles, and moved the margins to a class in the stylesheet.
You can read more about CSS rule specificity here: https://www.smashingmagazine.com/2007/07/css-specificity-things-you-should-know/
2) Even if you delete the inline styles, you wouldn't see the background image you want, because you added it to an element that had display:none. You need to add that background image to a different element, which I created in the div with class .mobile_only.
With these 2 changes, applied in the snippet below, you can see the different images depending on the resolution of your screen.
.hidden_mobile {
height: auto; width: 100%; margin: 0 auto 15px;
}
#media screen and (max-width:480px) {
.hidden_mobile {
display: none;
}
.mobile_only {
height: 250px;
background-image: url("http://julienleveau.com/wp-content/uploads/2018/04/Mobile-version.jpg");
background-repeat: no-repeat;
background-size: contain;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-sm-1">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/top100.jpg" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/WW-1.jpg" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/fearless.jpg" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/bowp-300-1.jpg" alt="">
</div>
<div class="col-sm-2">
<img class="hidden_mobile" src="http://julienleveau.com/wp-content/uploads/2018/04/ispwp.jpg" alt="">
</div>
</div>
<div class="col-sm-1">
</div>
<div class="mobile_only"></div>
</div>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to place my banner divs one below the other. I tried using different combinations of display and position properties but it doesnt work. They are displaying on top of each other.I want my output as firstly the banner,then below it the row of images and below the row the second banner.
.row div:first-child {
margin-left: 0;
}
.row div {
display: inline-block;
margin-left: 5%;
}
.row div img {
max-width: 100%;
max-height: 100%;
}
.row div a {
word-wrap: break-word;
text-decoration: none;
color: #515150;
}
.row div a:hover,
.row div img:hover {
color: black;
}
.img-container {
display: inline-block;
float: left;
padding-top: 40px;
padding-bottom: 20px;
text-align: center;
width: 150px;
}
.banner {
padding-top: 20px;
border-bottom: 2px solid black;
margin-left: 5%;
color: black;
font-size: 20px;
}
<div class="banner">
<h3>TOP SELLING</h3>
<div class="row">
<div class="img-container">
<a href="#">
<img src="martial.png">
</a>
</div>
<div class="img-container">
<a href="#">
<img src="bvb.png">
</a>
</div>
<div class="img-container">
<a href="#">
<img src="ars.png">
</a>
</div>
<div class="img-container">
<a href="#">
<img src="lewandowski1.png">
</a>
</div>
</div>
</div>
<div class="banner">
<h3>TOP SELLING</h3>
<div class="row">
<div class="img-container">
<a href="#">
<img src="martial.png">
</a>
</div>
<div class="img-container">
<a href="#">
<img src="bvb.png">
</a>
</div>
<div class="img-container">
<a href="#">
<img src="ars.png">
</a>
</div>
<div class="img-container">
<a href="#">
<img src="lewandowski1.png">
</a>
</div>
</div>
</div>
PS: I also tried using different ids for the banners but it doesnt work.
Either add .banner {clear:both} or remove the unnecessary float from .img-container (the display:inline-block already does that job.)
What I want to do is have the images on this site change in width and height (they should be equal) between 50-60px. However between them they all need to have a minimum padding of 5px. This can vary depending on the size of the images, this is the case as the two end images need to fit to the edges of the parent div, to align with an image about it. The height/width/padding should all change to ensure the images are still properly aligned when then screen size changes.
If you look at this page you will be able to see what I mean. The images that need to change are the grey squares at the bottom.
http://media.gaigo.org/work2.html
This is my html:
<div class="smallImages">
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
</div>
and my css is as follows:
smallImages div {
display: inline-block;
padding: 5px;
}
.smallImages div img {
max-width: 60px;
min-width: 50px;
max-height: 60px;
min-height: 50px;
}
Sorry if this seems confusing. Just ask if you need me to explain more.
One option is to set percentage widths, however that number percentage is dependent upon the number of images in your row. See this example:
* {
box-sizing:border-box; /* You need this so that heights and widths are inclusive of padding and border */
}
.container {
width:400px; /* set this to whatever you like, it should work still */
padding:5px;
border:1px solid;
}
.row {
width:100%;
padding:0 5px;
}
.row img {
padding:5px;
}
.row.one img {
width:100%;
}
.row.two img {
width:50%;
}
.row.three img {
width:33.33%;
}
.row.four img {
width:25%;
}
<div class="container">
<div class="row one">
<img src="http://placehold.it/150x150">
</div>
<div class="row two">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
<div class="row three">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
<div class="row four">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
</div>
Putting HTML comments between lines means there's no white space between the images.
This is what you are after.
Display inline-block wont let the images behave in that manner you need to use table.
You should just check the source code of the site you are working from..
.row {
display: table-row;
}
.smallImages {
padding-left: 0px;
margin-bottom: 0px;
display: table;
text-align: center;
}
.smallImages .row div {
display: table-cell;
padding: 5px;
}
.smallImages .row div:first-child {
padding-left: 0;
}
.smallImages .row div img {
max-width: 100%;
}
img {
border: 0;
}
<div class="smallImages">
<div class="row">
<div>
<a href="#item-1">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-2">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-3">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-4">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-5">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-6">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-7">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-8">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-9">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-10">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-11">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-12">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
</div>
</div>
I'm using Bones theme from Themble, which includes a grid system in it's style. I have tried to implement it in the header for my menu items so that they will size down into icons in mobile size and show the full menu in desktop screens.
The problem is that I can't get the grid to work, all the menu items float next to each other, on all screen sizes. The divs 'menubar' is only as big as the icon.
The grid is working on other areas, such as the sidebars and content areas. I'm not really familiar with responsive columns so hopefully it's obvious to some of the pros here.
Also, so you know, I'm working locally with koala, a processor for the Sass.
Header
<body <?php body_class(); ?>>
<div id="container">
<header class="header" role="banner">
<div id="inner-header" class="wrap ">
<div id="logo" class="menubar m1of5 t1of5 d2of6 cf">
<img src="/home_icon.png">homepage
</div>
<div id="menu-icon" class="menubar m1of5 t1of5 d1of6 cf">
<img src="/icon.png"/>
</div>
<div id="menu-icon" class="menubar m1of5 t1of5 d1of6 cf">
<img src="/icon.png"/>
</div>
<div id="menu-icon" class="menubar m1of5 t1of5 d1of6 cf">
<img src="/icon.png"/>
</div>
<div id="menu-icon" class="menubar m1of5 t1of5 d1of6 last-col cf">
<img src="/icon.png"/>
</div>
</div>
</header>
Grid
#mixin grid-col {
float: left;
padding-right: 0.75em;
}
// the last column
.last-col {
float: right;
padding-right: 0 !important;
}
#media (max-width: 767px) {
.m-all {
#include grid-col;
width: 100%;
padding-right: 0;
}
.m-1of5 {
#include grid-col;
width: 20%;
}
}
And on and on for other sizes and screens.
Style
This is the mobile styling....
.header {
width:100%;
position: fixed;
background-color: $white;
border-bottom: 2px solid $border-color;
}
.menubar {
float: left;
}
#logo {
font-size: 0px;
a {
text-decoration: none;
}
}
#menu-icon {
background-color: $light;
border-radius: 4px;
}
<div id="logo" class="menubar m1of5 t1of5 d2of6 cf">
<img src="/home_icon.png">homepage
</div>
Your class names should be hyphenated:
<div id="logo" class="menubar m-1of5 t-1of5 d-2of6 cf">
<img src="/home_icon.png">homepage
</div>