Three images side by side, responsive without scaling - html

I cannot find the exact answer to my question, so hopefully someone can help me.
I have three images. I want them side by side on a large screen.
On a smaller screen (tablet) I want two of them to be in rows.
And on small phone screen I want them all to be in rows above each other, centered.
The code that I have so far is:
<div align="center">
<div style="width: 371px; float: left;"><img src="{{media url="wysiwyg/magenthemes2/images/review1.png"}}" alt="" width="371" height="270" /></div>
<div style="width: 371px; float: left;"><img src="{{media url="wysiwyg/magenthemes2/images/review2.png"}}" alt="" width="371" height="139" /></div>
<div style="width: 371px; float: left;"><img src="{{media url="wysiwyg/magenthemes2/images/review3.png"}}" alt="" width="371" height="139" /></div>
</div>
But this doesn't work right. It is also not centered. I'd like it to render like this:
Responsive example on different screen sizes

The best way to do this is to give the parent <div> a class name, and then apply different styles to it in different #media queries. More can be read about #media at MDN. you could use this site, or this site for a simpler but less complete overview, as a cheatsheet for which media queries you could use.
An example of some code that would work for a selection of devices is:
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
.imagebox > img {
float:left;
}
}
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
.imagebox > img:first-child {
float:left;
}
}
<div align="center" class="imagebox">
<div style="width: 371px; float: left;"><img src="https://placekitten.com/250/300" alt="" width="371" height="270" /></div>
<div style="width: 371px; float: left;"><img src="https://placekitten.com/250/150" alt="" width="371" height="139" /></div>
<div style="width: 371px; float: left;"><img src="https://placekitten.com/250/150" alt="" width="371" height="139" /></div>
</div>

Instead of float you can also work with the text-align attribute. In the following example you can see how I used it for boxes on a front-page. They automatically adjust to different screen-sizes (click on "Run code snippet" and then on "Full page").
.entries-box {
/* Style for box containing Frontpage boxes */
text-align: center;
padding: 0;
}
.entry {
/* Style for a Frontpage box */
display: inline-block;
text-align: left;
padding: 0.4em 0.8em 0.4em 0.8em;
border: 1px solid black;
margin: 0 1em 0.4em 0;
border-radius: 10px;
background: #007f59;
}
<div class="entries-box">
<div class="entry newest-e">
<b>Title of Storie</b> - Genre (Lang icon)
<br>'Excerpt of newest entry, max. 2 lines
<br>Second line of excerpt...'
<br>_User_
</div>
<div class="entry newest-e">
<b>Title of Storie</b> - Genre (Lang icon)
<br>'Excerpt of newest entry, max. 2 lines
<br>Second line of excerpt...'
<br>_User_
</div>
<div class="entry newest-e">
<b>Title of Storie</b> - Genre (Lang icon)
<br>'Excerpt of newest entry, max. 2 lines
<br>Second line of excerpt...'
<br>_User_
</div>
</div>

Related

Set uniform box height in CSS image gallery

This seems like a simple problem, but I can't crack it. I'm trying to set up a responsive image gallery much like the one demonstrated at W3Schools. That gallery looks fine--until you change the length of the captions. Then the height of the boxes starts to vary, and the arrangement of the gallery gets all screwed up. How can I set the height of those boxes so they line up neatly, even when the captions range from, say, 2-4 lines long?
One thing that you can do is, you can give a min-height and make it fixed height.
div.desc {
padding: 15px;
text-align: center;
min-height: 50px;
}
Snippet:
div.img {
border: 1px solid #ccc;
}
div.img:hover {
border: 1px solid #777;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
min-height: 50px;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
#media only screen and (max-width: 700px){
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px){
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<h2>Responsive Image Gallery</h2>
<h4>Resize the browser window to see the effect.</h4>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_fjords.jpg">
<img src="img_fjords.jpg" alt="Trolltunga Norway" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_forest.jpg">
<img src="img_forest.jpg" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_lights.jpg">
<img src="img_lights.jpg" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_mountains.jpg">
<img src="img_mountains.jpg" alt="Mountains" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="clearfix"></div>
<div style="padding:6px;">
<p>This example use media queries to re-arrange the images on different screen sizes: for screens larger than 700px wide, it will show four images side by side, for screens smaller than 700px, it will show two images side by side. For screens smaller than 500px, the images will stack vertically (100%).</p>
<p>You will learn more about media queries and responsive web design later in our CSS Tutorial.</p>
</div>
You can do 2 things. Put both of these on the class applied to each block.
overflow-y: hidden; //Or scroll if you want...
max-height: 400px;

Bigcartel mobile only

I'm trying to get my bigcartel page to show
<div style="margin-top: 0px; img align: middle">
<img width="420" height="42" style="vertical-align:middle;" src="https://i.imgsafe.org/52c5068376.png" alt="PAF ENTRY">
</div>
on mobile devices only while trying to show an exact copy of the code for browsers only
here is the page
http://pafclub.bigcartel.com/entry
And this is what I have so far:
<div class="mobileHide">
<div style="margin-top: 0px; img align: middle">
<img width="420" height="42" style="vertical- align:middle;" src="https://i.imgsafe.org/52c5068376.png" alt="PAF ENTRY"> </div>
<style type="text/css">
.mobileHide { display: inline;}
/* Smartphone Portrait and Landscape */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px){ .mobileHide { display: none;}}
</style>
<div class="mobileShow">
<div style="margin-top: 120px; margin-bottom: 10px; text-align: center;">
<img width="420" height="42" style="vertical-align:middle;" src="https://i.imgsafe.org/52c5068376.png" alt="PAF ENTRY">
</div>
<style type="text/css">
.mobileShow { display: none;}
/* Smartphone Portrait and Landscape */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px){ .mobileShow { display: inline;}}
</style>
it shows one version of the image but when I check on a mobile device there is no image at all.
The theme has code that adds a margin to custom page bodies that you'll need to override. Add this to the bottom of Customize Design > Advanced > CSS to remove it:
#entry .page {
margin: 0 auto;
}
Then for your entry page, all you'll need is the following code to have the image display centered properly (on desktop and mobile)
<a href="/products">
<img style="width:100%;margin:0 auto;max-width: 427px;display:block" src="https://i.imgsafe.org/7da3920e19.png" alt="ENTRY">
</a>
i have worked on your problem, and got solution for this. Please check the code.
.mobileHide { display:table; height:100%; text-align:center; vertical-align:center; width:100%;}
.middle{ display:table-cell; height:100%; vertical-align:middle; width:100%;}
.middle a{ max-width:80%; display:inline-block;}
.middle a img{ max-width:100%;}
html, body {
height: 100%;
margin: 0px;
}
<div class="mobileHide">
<div class="middle">
<a href="/products">
<img width="420" height="" src="https://i.imgsafe.org/52c5068376.png" alt="PAF ENTRY">
</a>
</div>
<div style="clear:both;"></div>
</div>

Text is centre aligned on computer and phone simulator, but not on actual phone?

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>

HTML: Stop pictures from overlap on mobile view (responsive design)

I've got a website, based on wordpress and the responsive design "Mystile".
I use the following html code to display three pictures side by side:
<div style="position: absolute;"><img src="myimgsrc" alt="" /></div>
<div style="position: absolute; margin-left: 250px;"><img src="myimgsrc" alt="" /></div>
<div style="position: absolute; margin-left: 500px;"><img src="myimgsrc" alt="" /></div>
This works flawlessly on the computer.
As you can see on the picture.
But on a mobile device it looks terrible.
Like this:
What can should I do?
Thank you very much.
The easiest is just to display the images inline. They will then wrap under each other if there isn't enough space to fit beside one another:
html, body {margin:0;}
.hmm a {display:inline-block; margin:10px 0 0 10px;}
.hmm a img {display:block; margin:0;}
<div class="hmm"><img src="http://www.placehold.it/240x50" alt="placeholder" /><img src="http://www.placehold.it/240x50" alt="placeholder" /><img src="http://www.placehold.it/240x50" alt="placeholder" /></div>
If you want to get a little more advanced you can use media-queries to change the style for different sized viewports:
html, body {margin:0;}
.hmm a {display:inline-block; margin:10px 0 0 10px;}
.hmm a img {display:block; margin:0;}
#media all and (max-width: 750px) {
.hmm a:first-of-type img {width:490px;}
}
#media all and (max-width: 510px) {
.hmm a {
display: block;
margin:10px;
}
.hmm a img {
width:100%!important;
}
}
<div class="hmm"><img src="http://www.placehold.it/240x50" alt="placeholder" /><img src="http://www.placehold.it/240x50" alt="placeholder" /><img src="http://www.placehold.it/240x50" alt="placeholder" /></div>
^ Go 'full-page' and resize to see this one working.

How do I get these social icons to be straight centered on the page on all browsers?

Link to website: foxweb.marist.edu/users/kf79g/contact.php
This is it. The last step I have to fix before deploying my website and finally finishing it. But I do not know how to resolve this issue. On medium and small screens, I am having a lot of trouble with my social icons. I want the whole thing on medium and small devices to be centered and 100% responsive. I have tried making a container to make them responsive, but no matter what I do, it always looks messy in IE 7-10. The icons are moving to the next line instead of staying on one line evenly as the page width gets smaller and smaller. I tried adjusting the margins, but that didn't helps since that ruined my center attribute for the whole page. I simply do not know what to do or how to fix this issue. If anybody can help me I would really appreciate it.
Visual representation of problem (IE):
http://tinypic.com/r/nla7eq/5
What I want it to look like (modern browsers):
http://tinypic.com/view.php?pic=vp9gg7&s=5
HTML:
<h2> Social networks </h2><br/>
<div id = "center_icons">
<img src="images/facebook.png" alt="facebook" style="margin:1px;">
<img src="images/google-plus.png" alt="google plus" style="margin:1px;">
<img src="images/linkedin.png" alt="linkedin" style="margin:1px;">
<img src="images/github.png" alt="github" style="margin:1px;">
</div>
<br/>
</div>
</section>
Main CSS:
#details_section {
max-width:100%;
float:left;
margin-right:20px;
}
Large screens:
#details_section {
width:320px;
}
Medium screens:
#center{
width: 450px;
display: block;
margin-left: auto;
margin-right: auto;
}
#center_icons{
width: 213px; /*this value is changing for IE and chrome*/
display: block;
margin-left: auto;
margin-right: auto;
}
Small screens:
#center{
width: 220px;
display: block;
margin-left: auto;
margin-right: auto;
max-width:100%;
}
#center_icons{
width: 214px; /*this value is changing for IE and chrome*/
display: block;
margin-left: auto;
margin-right: auto;
max-width:100%;
}
You could also remove spaces between "=", and use " instead of '.
<div id = "center">
<div id='details_section'>
should be
<div id="center">
<div id="details_section">
You should also indicate the image size somewhere.
<div id="container">
<div id="center_icons">
<img src="images/facebook.png" alt="facebook" width="40" height="40">
<img src="images/google-plus.png" alt="google plus" width="40" height="40">
<img src="images/linkedin.png" alt="linkedin" width="40" height="40">
<img src="images/github.png" alt="github" width="40" height="40">
</div>
</div>
And a simpler CSS would be:
div {border: 1px red solid;padding: 5px} /*this is only for us to see it when testing*/
#container {
text-align:center;
}
#center_icons{
width: 214px; /*this value is changing for IE and chrome*/
display: block;
margin-left: auto;
margin-right: auto;
max-width:100%;
}
Check it working here: http://codepen.io/anon/pen/mAjzo
Just use <center> </center> in code instead of Div id "center".
you need to change your CSS properties just measure your screen co-ordinates and put it in margin or you can use HTML5 to solve this problem.