CSS #media div class not resizing - html

I am following the tutorial from W3Schools on "How TO - Align Images Side By Side", located at https://www.w3schools.com/howto/howto_css_images_side_by_side.asp
I have the following div class called column, and I am trying to resize it when the width of the screen changes, in order to adapt in different screen sizes on mobile and desktop.
The HTML code is as follows:
<div class="row">
<div class="column">
<img id="firstImage" style="width: 100%">
<figcaption id="firstCaption"></figcaption>
</div>
<div class="column">
<img id="secondImage" style="width: 100%">
<figcaption id="secondCaption"</figcaption>
</div>
<div class="column">
<img id="thirdImage" style="width: 100%">
<figcaption id="thirdCaption"></figcaption>
</div>
</div>
On desktop (default) mode, the three images are listed in a row, like so: https://i.imgur.com/a/zg2j5rv.png
This is defined by the following CSS code:
.column {
float: left;
width: 33.33%;
padding: 5px;
}
.row::after {
content: "";
clear: both;
display: table;
}
But when the width of the screen reaches 768px or less (mobile screen), I intend for the images to be listed vertically, so that the images are listed on above and below one another. I have added the following CSS code to style this change:
#media only screen and (max-width: 768px) {
[class="column"] {
display: block;
width: 100%;
}
}
In the above code, my logic is to make each column div listed in block form, with its width spanning across the entire width of the screen. That way, each div would be pushed to a new line while the div spans the entire width. However, when I do resize the screen, the images remain in a horizontal row, as they are squeezed together as 3 images in a row.
Any ideas on how I can get each column div to move to a new line when the width of the screen decreased? Any help is greatly appreciated!

[class="column"] selector does not override .column selector, even if placed later in code, because it's an attribute selector and has lower specificity than class selector. 1
You should use .column inside the #media query as well. Note [class="stuff"] is a far worse selector than .stuff because it will stop working the moment you add a new class to the same element.
This should work:
.column {
float: left;
width: 33.33%;
padding: 5px;
}
#media only screen and (max-width: 768px) {
.column {
display: block;
width: 100%;
}
}
1 I've just tested (to make sure my answer is correct) and it appears both Chrome and Firefox are smart enough nowadays to recognize the fact that, even if [class="column"] is an attribute type selector, because it refers the class attribute they give it the proper class specificity. However, the second argument (that it stops working as a selector when another class is added to the element) is still valid.

Try this. This is for a three column layout but you should be able to change percentages if needed.
.col-container {
display: table;
width: 100%;
}
.imagegroup {
width: 100%;
background-color: #ffffff;
}
.img-container {
display: table;
float: left;
width: 33.3%;
}
#media only screen and (max-width: 500px) {
.img-container {
display: table;
float: left;
width: 100%;
}
}
<div class="imagegroup">
<div class="col-container">
<div class="img-container">
<p>Image 1 goes here</p>
</div>
<div class="img-container">
<p>Image 2 goes here</p>
</div>
<div class="img-container">
<p>Image 3 goes here</p>
</div>
</div>
</div>
They should now stack.
UPDATE
Just click the full screen link for the code and then resize the window. Anything within those DIVs will stack on top of each other.

Related

How to make image responsive and auto scale down the height

I have two unequal responsive columns, the smaller one on the right is text and the bigger one on the left is an image. When I resize the browser window to see how the columns fit the page, it works fine until it gets to the max width 700px and the column stack onto of each other. The bottom column is fine however the top one (image) doesn't show the full image only a tiny strip going along the width of the page. how can I get it to auto adjust the height to show the full image?
I have tried setting height on the left column as auto but that didn't work and it continued to only show a small strip.
.column {
float: left;
padding: 10px;
height: 300px;
}
.left {
width: 60%;
background-image: url('http://i.imgur.com/k5gf0zz.jpg');
background-size: cover;
background-position: center;
}
.right {
width: 40%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
#media screen and (max-width: 700px) {
.column {
width: 100%;
}
}
<body>
<div class="row">
<div class="column left";>
</div>
<div class="column right" style="background-color:#FDE4EC;">
<center> <p><font size="8">We Provide Quality Skin Care</font></p>
<p style = "font-family: Verdana, Geneva, sans-serif">Let us help you feel beautiful!</p>
<br>
<button class="button2"><b>BOOK NOW</b></button> </center>
</div>
</div>
</body>
Any help would be very much appreciated :)
img{
max-width:100%;
height:auto;
display:none;
}
.left {
width: 60%;
background:url("http://i.imgur.com/k5gf0zz.jpg") no-repeat center;
background-size:cover;
}
.right {
width: 40%;
padding: 10px 0px;
}
.row{
display:flex;
flex-wrap:wrap;
}
#media screen and (max-width: 700px) {
.column {
width: 100%;
}
img{
display:block;
}
.left {
background:none;
}
}
<div class="row">
<div class="column left";>
<img src="http://i.imgur.com/k5gf0zz.jpg">
</div>
<div class="column right" style="background-color:#FDE4EC;">
<center> <p><font size="8">We Provide Quality Skin Care</font></p>
<p style = "font-family: Verdana, Geneva, sans-serif">Let us help you feel beautiful!</p>
<br>
<button class="button2"><b>BOOK NOW</b></button> </center>
</div>
</div>
try adding img to your html with max-width:100% and height:auto for small screens and div with background for large screens!
Remove height and add min-height
.left {
min-height: auto;
}
Thanks for your topic, I agree with Chris, if we could have more info it'd be easier to know how to help.
you can also use something like this in your html file, two pics with different sizes and to use a specific pic for every page size.
<picture id="pic">
<source media="(min-width: 650px)" srcset="image.jpg">
<img src="image2.jpg" alt="same pic bigger size" style="width:auto;">
</picture>

How do I responsively arrange images in a single line within a div

I'm trying to place links on images in one row so that different images have different links. I'm also having this div to shrink to fit certain media screen sizes. However, the images didn't resize according to the wrapper requirements. Please help.
Here's the HTML:
.box {
width: 100%;
float: left;
margin: 0;
padding: 0;
position: relative;
}
#media screen and (min-width: 768px) and (max-width: 1024px) {
body {
text-align: center;
background: url(image/bg.png) center top;
}
#wrapper {
width: 768px;
margin: 0 auto;
background-color: #fff;
}
}
#media screen and (min-width: 1024px) {
body {
text-align: center;
background: url(image/bg.png) center top;
}
#wrapper {
width: 500px;
margin: 0 auto;
background-color: #fff;
}
<div id="wrapper">
<div class="box">
<img src="image/pea.jpg">
</div>
<div class="box">
<img src="image/pea_01.jpg">
<img src="image/pea_02.jpg">
<img src="image/pea_03.jpg">
<img src="image/pea_04.jpg">
<img src="image/pea_05.jpg">
</div>
<!-- main issue here -->
<div class="box">
<img src="image/pea_footer.jpg">
</div>
</div>
Here's a screenshot of the line up (desktop). Mobile seems to look ok after adding display:inline-block;
width:auto; to .box:
I reckon remove any static widths because you only need to detect when the viewport is a certain size and then change the img width then, as I have done here. I set each image to display block to remove any margin or padding around them. You might prefer to not do this, but I like setting this as default.
This way you can pick different breakpoints that suit you rather than setting static widths at each breakpoint. This is the beauty of responsive development. Stay flexible rather than controlling what happens to containing divs; let the content run things. Run this snippet below in Full Screen mode to see the full desktop styling (each img goes to 20% instead of 50%):
.box {
width: 100%;
float: left;
margin: 0;
padding: 0;
position: relative;
}
img {
display: block;
width: 20%;
float: left;
}
#media screen and (max-width: 767px) {
img {
width: 50%;
}
}
<div id="wrapper">
<div class="box">
<img src="http://placehold.it/100x100">
</div>
<div class="box">
<img src="http://placehold.it/100x100">
<img src="http://placehold.it/100x100">
<img src="http://placehold.it/100x100">
<img src="http://placehold.it/100x100">
<img src="http://placehold.it/100x100">
</div>
<!-- main issue here -->
<div class="box">
<img src="http://placehold.it/100x100">
</div>
</div>
Your .box could be in display:flex
.box {
display: flex;
flex-flow: row nowrap;
justify-content: space-around;
}
Keep in mind that your 5 <img> should be the icons, not containing your background (the clouds).
And I think the following code would be correct for your images:
.box img {
max-width: 20%;
}
I think it's better to not apply an explicit width or height to the image tag.
Please try:
max-width:100%;
max-height:100%;
Just use percentage based layouts rather than pixels or other measurements.
For example:
<img width="50%">: that will fill half of the containing element, at any size
<img width="500px">: that will always fill exactly 500 pixels, if it's too big or if it's too small.

Responsive footer with a few images in divs

I have a Wordpress site. I have altered the footer to contain five divs with images in them.
This is the html code for the footer:
<footer class="site-footer">
<div class="table">
<div class="logo-gallery">
<div class="logo">
<img src="image_url">
</div>
<div class="logo">
<img src="image_url">
</div>
<div class="logo">
<img src="image_url">
</div>
<div class="logo">
<img src="image_url">
</div>
<div class="logo">
<img src="image_url">
</div><!-- .logo -->
</div><!-- .logo-gallery -->
</div><!-- .table -->
</footer>
For css I came up with this:
/* Footer */
.site-footer {
background-color: #e8e5ce;
/*min-height: 180px;*/
}
.site-footer .table {
display: table;
width: 80%;
margin: 0 auto;
}
.site-footer .logo-gallery {
display: table-row;
}
.site-footer .logo {
display: table-cell;
}
On a desktop computer the images now show as I would like them to:
1. they take up to 80% of the width (so that they are closer to eachother)
2. they are (as a group) placed at the center of the screen horizontally.
I want to make the images fit a smaller screen (a cell phone or tablet) - right now I get a horizontal scroll bar when I try to downsize the browser window and the images are beyong the right edge of the window (I haven't checked this code with a phone yet).
On the smaller screen I would like them either to get smaller to fit the width (all five) or appear underneath eachother (with the background color stretched underneath).
I also have a second version of css. Here, the problem is that the images clump up when downsizing the browser window (and also on the phone: check here: http://npozp.pl/)
/* Footer */
.site-footer {
background-color: #e8e5ce;
min-height: 180px;
}
.site-footer .logo-gallery {
margin: auto;
width: 70%;
}
.site-footer .logo {
float: left;
width: 20%;
height: auto;
padding: 30px 15px;
}
I am looking for a way to do this, it can be one of the above codes fix or please suggest an approach that I could take.
Thanks for reading! :-)
Please consider using media queries so that you can manipulate your layout using the pixel size of the device.
Your css adjustments should look like:
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {
.site-footer .logo {
width: 100%;
}
}
As you can see the mix and max device width values can be changed and you can add multiple media queries to get the best out of your layout.

Image overlap on css responsive page

This is my first try at responsive design and I can't quite get it right. As seen in the first screenshot the tower image overlaps a div and I'm not sure what I've done wrong. Image here: http://postimg.org/image/l9ax77rhz/
The width of the container is 1170px and I wanted to trigger the scaling of the images and text once the screen size dropped below that point. Image here: http://postimg.org/image/n420djzlj/ Then dropping below 760 the sections begin to overlap. I basically want to fix the overlap and have the images display first on small screens with the title and text below.
Can anyone explain to me how to do that or what I've done wrong? Html and css below
<style>
.lenovo-container {
width: 1170px;
height: 381px;
min-width: 858px;
}
.lenovo-container img {
float: left;
}
#media (max-width:1170px) {
img {
max-width: 100%;
height: auto;
}
.lenovo-container {
max-width: 100%
#media (max-width: 858) {
.lenovo-container p {
display: block;
}
}
</style>
<div class="lenovo-container">
<img class=" wp-image-1498 size-full alignnone" src="wp-content/uploads/2015/06/Rack-server-e1434645252235.jpg" alt="Rack server" width="500" height="381" />
<h2>Rack Servers</h2>
<p>Lenovo ThinkServers and System x Rack Servers are Ideal for small to medium-sized business and feature power-efficient designs, segmented workloads, and fit-for-purpose applications.</p>
<div class="product-button" style="vertical-align: bottom;">
<div class="button-inner-product">Learn more
</div>
</div>
</div>
<br>
<div class="aligncenter" style="width: 1170px; display: block; vertical-align: bottom">
<hr />
</div>
<div class="lenovo-container">
<img class="alignnone size-full wp-image-1565" src="wp-content/uploads/2015/06/Lenovo-server-e1434648963684.jpg" alt="Lenovo server" width="500" height="520" />
<h2>Tower Servers</h2>
<p>Lenovo tower servers provide the performance, reliability, and easy-to-use tools to manage your file/print and point-of-sale workloads.</p>
</div>
The culprit is the float:left. Try this instead:
.lenovo-container {
width: 1170px;
height: 381px; /* If your image is getting cut off, it's too large.
Try auto instead or remove this property altogether. */
min-width: 858px;
overflow: hidden;
}
.lenovo-container img {
float: left;
}
Floats will break the element out of document flow, and float them to the left of ALL elements. This fix forces the container to respect the bounds of the float.
A somewhat cleaner fix is:
.lenovo-container:after {
display: table;
content: '';
clear: both;
}
If you want the image to resize to the container, then try this:
#media (max-width:1170px) {
.lenovo-container img {
max-height: 100%;
}
.lenovo-container {
max-width: 100%
}
}

Trouble positioning elements using float in a responsive design

I'm working on a responsive website, and I ran into some trouble doing the layout. I broke the problem down to the fewest lines possible.
When the window is larger then 909px I want to place my second content (content2) just below the title. When there is less space availible I want it to be placed below the image.
Currently it always gets placed below the image.
Here's a visual.
I need to find a solution without using absolute positioning, because the title does not have a fixed height. In fact none of my html elements have a fixed height, I do have fixed widths though.
I have been trying to come up with a simple solution for a few hours now. Here's hoping someone can point me in the right direction :)
Thanks for reading!
HTML code:
<div class="wrapper">
<h1> some title </h1>
<div class="image"> some img</div>
<div class="content1"> some content </div>
<div class="content2"> some other content </div>
</div>
CSS styles:
.content1{
float: left;
}
.image{
width: 600px;
}
.content2{
width: 300px;
float: right;
}
#screen and (min-width: 768px) and (max-width: 909px){
.wrapper {
width: 700px;
}
.content1 {
width: 300px;
}
}
#screen and (min-width: 909px){
.wrapper {
width: 900px;
}
.content1{
width: 600px;
}
}
Here is one way of doing it for the case of min-width: 909px
The CSS is:
#media screen and (min-width: 909px) {
.wrapper {
width: 900px;
outline: 1px dotted blue; /* optional for demo */
}
.image {
width: 600px;
float: left;
outline: 1px dotted blue; /* optional for demo */
}
.content1 {
float: left;
width: 600px;
outline: 1px dotted blue; /* optional for demo */
}
.content2 {
width: 300px;
margin-left: 600px;
outline: 1px dotted blue; /* optional for demo */
}
}
and the demo fiddle is: http://jsfiddle.net/audetwebdesign/WfyJL/
I did not see anything about heights, so I assume that the content will take determine the various heights of the elements.
How This Works
In your previous example, content2 is floated so its top edge is placed next to the bottom edge of the nearest, adjacent block level element, which is image.
To get the desired layout for the 900px format, float image to the left, and keep content2 in the flow but with a 600px left margin to allow the left floated elements to flow down the left hand side of content2.
maybe you need use some like this, with offsets, hope your help
<div id="wrapper">
<div class="row-fluid">
<div class="span4">
<h1> some title </h1>
</div>
<div class="span4">
<div id="image"> some img</div>
<div id="content1"> some content </div>
</div>
</div>
<div class="span8 offset5">
<div id="content2"> some other content </div>
</div>
</div>