Change position of Images HTML when Window changes - css

This is probably much easier than I'm making it sound.
Basically I have 6 Images, each with a button underneath...
This is what it looks like:
I just place them like this:
<img src="Image.png" width="350" height="208" style="margin: 0px 16px">
<img src="Image.png.png" width="350" height="208" style="margin: 0px 16px">
<img src="Button.png" width="282" height="84" style="margin: 0px 16px">
<img src="Button.png" width="282" height="84" style="margin: 0px 16px">
It looks great on a typical browser window. But when I make the window narrower, it goes like this:
Which makes sense give how I list my images/buttons.
But I want them to look like this when the window is narrowed:
What can I add to my very basic HTML to keep this in a nice and format no matter how wide the window is?
Ideally I'd like to go from a 2 by x grid as max, down to a 1 by x grid as seen in the first and final images.
A push in the right direction would be amazing.
I did look HERE on Stackoverflow, but it's far more complex as only works with squares.
I look forward to your help :D
UPDATE
https://jsfiddle.net/du6Lu4ge/
looks like this:
when resized, looks like this:
:(

I would do something like this:
https://jsfiddle.net/du6Lu4ge/3/
Hope it helps you out!
What I did was to wrap the image and the button in a div .img-wrapper styled with display: inline-block

this example is working full responsive, you can simply edit the css and add viewports.
html:
<div class="imageContainer">
<div class="imageBlock">
<!--<img class="image" src="image.png">-->
<div class="image">
your image
</div>
</div>
<div class="buttonBlock">
<!--<img class="button" srck="button.png">-->
<div class="button">
your button
</div>
</div>
</div>
<div class="imageContainer">
<div class="imageBlock">
<!--<img class="image" src="image.png">-->
<div class="image">
your image
</div>
</div>
<div class="buttonBlock">
<!--<img class="button" srck="button.png">-->
<div class="button">
your button
</div>
</div>
</div>
<div class="imageContainer">
<div class="imageBlock">
<!--<img class="image" src="image.png">-->
<div class="image">
your image
</div>
</div>
<div class="buttonBlock">
<!--<img class="button" srck="button.png">-->
<div class="button">
your button
</div>
</div>
</div>
<div class="imageContainer">
<div class="imageBlock">
<!--<img class="image" src="image.png">-->
<div class="image">
your image
</div>
</div>
<div class="buttonBlock">
<!--<img class="button" srck="button.png">-->
<div class="button">
your button
</div>
</div>
</div>
css:
.imageContainer {
width: 400px;
display: inline-block;
}
.imageContainer .imageBlock {
display: inline-block;
}
.imageContainer .imageBlock .image {
display: inline-block;
width: 400px;
height: 300px;
background-color: darkred;
}
.imageContainer .buttonBlock {
display: inline-block;
text-align: center;
}
.imageContainer .buttonBlock .button {
display: inline-block;
width: 300px;
margin: 10px 50px; /* simple way to center it */
height: 100px;
background-color: cyan;
}
you can test it on https://jsfiddle.net/q10fbesm/
edit: if you need a 2 line grid, simply put a container arround this html, style it with max-widht: 801px;

Related

positioning two images in an overlay format

I have two images that I need to be layered side-by-side.
This is what image 1 looks like now, utilizing the following code:
<section id="4" class="pt-sm-3 pt-md-5 pb-2">
<div class="row text-center">
<div class="col-md-1">
</div>
<div class="col-md-3">
<img class="lazyload img-responsive product-images"
style="max-width: 100%; height: auto; margin: 0 auto;"
data-src="#Url.Content("./redImage.png")"
src="#Url.Content("~/Themes/21Rocs/Content/Images/loading(2).gif")" />
</div>
<div class="col-md-3">
<img class="lazyload img-responsive product-images"
style="max-width: 100%; height: auto; margin: 0 auto;"
data-src="#Url.Content("./blueImage.png")"
src="#Url.Content("~/Themes/21Rocs/Content/Images/loading(2).gif")" />
</div>
</div>
</section>
I would like to have the images overlay on top of each other like the following:
How would I go about setting that up in CSS? I tried to use this approach but can't get the layer to fit properly. Please help. Thank You!
You should use negative margins to make these thing
I set a class to col-md-3 called overlay and i styled this on style.css
Hope this works
.overlay {
margin-right: -100px;
}
<link rel = "stylesheet" href="style.css">
<section id="4" class="pt-sm-3 pt-md-5 pb-2">
<div class="row text-center">
<div class="col-md-1">
</div>
<div class="col-md-3 overlay">
<img class="lazyload img-responsive product-images"
style="max-width: 100%; height: auto; ;"
data-src="#Url.Content("./redImage.png")"
src="https://wallpapercave.com/wp/wp3260204.jpg" />
</div>
<div class="col-md-3">
<img class="lazyload img-responsive product-images"
style="max-width: 100%; height: auto; ;"
data-src="#Url.Content("./blueImage.png")"
src="https://cdn.wallpapersafari.com/44/96/ow6U0D.jpeg" />
</div>
</div>
</section>
</section>
Something like adding position: relative; transform: translateX(-50px) translateY(-50px); z-index: -1; as styling to the second image could be a quick fix. (You would probably need to amend the translateX/translateY values to get them where you need them - no other elements on the page will be affected by this transform)

achieve 3 images exact size CSS

So I´m having trouble fitting 3 images in the same row ,
The thing is, that this images are not always the same so when I upload an image that its has a diferrent size everything moves., Any advise to achieve this ? thanks
HTML:
<div class="first-slot">
<div class="masonry-box post-media">
<img src="upload/'.$row['fotos'].'" alt="" class="img-fluid">
<div class="shadoweffect">
<div class="shadow-desc">
<div class="blog-meta">
<span class="bg-orange">'.$row['categoria'].'</span>
<h4>'.$row['titulo'].'</h4>
<small>'.$row['fecha'].'</small>
<small>'.$row['autor'].'</small>
</div>
</div>
</div>
</div>
</div>
CSS:
.first-slot {
float: left;
width: 65%;
height: 35%;
}
.last-slot,
.second-slot {
float: left;
width: 35%;
height: 28%;
}
Bootstrap
.img-fluid {
max-width: 100%;
height: auto;
}
I think this will solve your problem. You can use these class names and css in you code. Change image src locations according to your requirements. And change margin attribute in css according to your need.
PS: dnt forget to include bootstrap link in your project file
.imgItem{
display: inline-block;
margin: 10px;
}
.imgContainer{
display: flex;
}
<div class="row">
<div class="col imgContainer" >
<div class="col imgItem">
<img src="http://placehold.it/150x100" class="img-responsive
" alt="Responsive image" />
</div>
<div class="col imgItem">
<img src="http://placehold.it/150x100" class="img-responsive
" alt="Responsive image" />
</div>
<div class="col imgItem">
<img src="http://placehold.it/150x100" class="img-responsive
" alt="Responsive image" />
</div>
</div>
</div>

How to make inline images responsive in smaller screens

I'm looping through some images in my rails app"
<% #attachments.each do |attachment| %>
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; width: 120px;">
<%=image_tag attachment.images_url(:thumb).to_s %>
<div class="desc">
<%= link_to "Remove", remove_image_path(attachment), data: { confirm: "Are you sure you want to delete this image?" }, :method => :delete, :style => "text-decoration: none !important" %>
</div>
</div>
<% end %>
The images appear inline and they start from the left side which is exactly what I wanted. Now I'm wondering if there is a way I can make the image take up the 100% width only when the screen is smaller?
I created a dummy snippet for help.
.form-border {
padding-bottom: 20px;
padding-top: 20px;
border: 1px solid lightgrey;
border-radius: 8px;
background-color: white;
}
div.desc {
padding: 15px;
text-align: center;
}
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="container form-border">
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; width: 120px;">
<img src="pic_trulli.jpg" alt="Italian Trulli">
<div class="desc">Remove</div>
<img src="pic_trulli.jpg" alt="Italian Trulli">
<div class="desc">Remove</div
</div>
</div>
</div>
</div>
</div>
Update A
I followed #agustin answer by doing the doing:
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; width: 120px;">
<div class="img-fluid">
<%=image_tag attachment.images_url(:thumb).to_s %>
</div>
</div
or
<div class="img-thumbnail" style="display:inline-block; margin:auto; text-align: center; padding-top: 15px; max-width: 100%;;">
<div class="img-fluid">
<%=image_tag attachment.images_url(:thumb).to_s %>
</div>
</div
but I still get the same result:
You have errors in your layout.
Remember that you shouldn't create another .container element inside a col or row element. The correct way is .container > .row> .col, and if you want columns inside a column, then you have to create another .row with .cols inside, but not another container.
The img-fluid class has to be applied to the img element. You will probably want to define the width of the image though.
Check the following snippet. I created two columns with the class col-md-6, which means that, on medium screens (≥768px), those columns will take 50% of the width of the row each. As I didn't define any class with col-sm or col-xs, those columns will take 100% of the width of the row on small screens.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="row">
<div class="col-md-6">
<div class="img-thumbnail">
<img src="https://placehold.it/400x300/" class="img-fluid" alt="Italian Trulli">
<div class="desc">Remove</div>
</div>
</div>
<div class="col-md-6">
<div class="img-thumbnail">
<img src="https://placehold.it/400x300/" class="img-fluid" alt="Italian Trulli">
<div class="desc">Remove</div>
</div>
</div>
</div>
</div>
</div>
</div>

Input field should take the remaining width

I am trying to build a form to add new users to some kind of entity. The idea is to have user avatars in a line and on the end of the line there is a input-field with a typeahead to insert new users.
I tried this some years ago and ended up using javascript as I was not able to do this in plain css (2).
The big question: is this somehow possible in css3?
Basic idea of code:
<div class="availableWidth">
<div class="list">
<ul>
<li><div class="avatar">...</div></li>
...
</ul>
</div>
<div class="form">
<div class="typeaheadField">
<input ...>
</div>
<button>+</button>
</div>
</div>
CSS:
.list ul li {
list-style-type:none;
display:inline-block;
}
button {
width:50px;
}
Basic Idea is that the box .availableWidth has some width (100%) the box .list grows in width (when new li items are added) as the box .form should shrink in width. Right to the input is a some pixels wide button. The input should take the remaining space.
Is that possible in css3 or will I need Javascript?
You can use flexbox, or you can use display table attributes in CSS. Take a look:
.container {
display: table;
width: 100%;
position:relative;
}
.avatar {
width: 50px;
height: 50px;
display: table-cell;
}
.input {
height: 50px;
display:table-cell;
vertical-align: middle;
}
.input input {
width: 100%;
box-sizing: border-box;
padding: 5px;
}
<div class="container">
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="input">
<input type="text"/>
</div>
</div>
<div class="container">
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="avatar">
<img src="http://dummyimage.com/50x50/000/fff&text=Avatar"/>
</div>
<div class="input">
<input type="text"/>
</div>
</div>
You can add all the avatars that you want at left side and the input rearrange automatically.
You want to make input 100% width relative to some container from avatars to button. You can get it by using table, flexboxes or formatting contexts and floats.
Here is last one http://jsfiddle.net/53f0yzeL/
Notice overflow:hidden rule for .avatars-wrapper, it make container to fit exactly between floated elements and .avatars side so you can make input 100% wide.

Twitter Bootstrap Banner - How to render

This is probably a pretty basic question, but I have a banner with an image on the left and text on the right. Under the banner is just a block of color. When the page gets smaller, my expectation is that the bits in the banner would stack (maintaining the background color for both) and the block of color (class="blue-line") would fall beneath them.
Here is the mark-up:
<section>
<div class="row header">
<div class="col-sm-6">
<img src="../images/logo.png" height="100px" />
</div>
<div class="col-sm-6 title">
<h2>Some Title Text</h2>
</div>
</div>
<div class="row">
<div class="col-sm-12 blue-line"></div>
</div>
</section>
and the css
.header {
background-color: #F2EBCC;
border: 10px solid #F2EBCC;
height: 120px;
}
.row > .title {
text-align: right;
top: 45%;
}
Thanks in advance!
JSFiddle: http://jsfiddle.net/3n6Kd/
try this:
<section>
<div class="row header">
<div class="col-sm-6">
<img src="../images/logo.png" height="100px" />
</div>
<div class="col-sm-6 title">
<h2>Some Title Text</h2>
</div>
</div>
<div class="row">
<div class="col-sm-12 blue-line"></div>
</div>
and:
.header {
background-color: #F2EBCC;
height: 120px;
}
.title {
text-align: right;
display: block;
padding: 10px;
}
.blue-line {
margin-top:10px;
height: 15px;
background-color: blue;
}
the text go under the first column not the blue-line, but it seems to appear above the blue-line so try it in your computer because some time jsfiddle.net don't show code correctly.
hope it will help you.

Resources