I'm making an image view thing, and am having some trouble with aligning the images. When I have two of the same image in a row, it will be aligned, but when the images are different, the second image will go lower than the first. Here is screenshot screenshot. Here is my html and css
html
<div id="wrapper">
<div id="images">
<div class="image" onClick="showimage('users/images/username/battlefield4_maars.png','battlefield4_maars.png','3.91MB','png');">
<img src="users/images/username/battlefield4_maars.png">
<div class="normaltext">battlefield4_maars.png</div>
</div>
<div class="image" onClick="showimage('users/images/username/dark_souls_2.jpg','dark_souls_2.jpg','363KB','jpg');">
<img src="users/images/username/dark_souls_2.jpg">
<div class="normaltext">dark_souls_2.jpg</div>
</div>
<div class="image" onClick="showimage('users/images/username/thief.jpg','thief.jpg','393KB','jpg');">
<img src="users/images/username/thief.jpg">
<div class="normaltext">thief.jpg</div>
</div>
</div>
</div>
css
#images {
margin-top: 20px;
display: inline-block;
}
.image {
height: 200px;
width: 140px;
border: 1px solid #cccccc;
border-radius: 3px;
background: #fff;
display: inline-block;
word-wrap:break-word;
padding: 10px;
cursor: pointer;
}
.image img {
width: 140px;
height: 140px;
}
Anyone know what's wrong here?
add this:
#images {display:block;}
.image {
vertical-align: top;
}
Related
What i would like to achieve is that i want to change the way my boxes appear only on the mobile version of the website. I experimented with display: and flex: rules but had no luck. I want them stick to each other but Couldn't find the right CSS rule. Help.
Thanks.
Example picture of how i want them:
The way they appear on desktop version of the website:
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img /></div>
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
#media only screen and (max-width: 1000px) {
.main {
display: flex;
gap: 10px;
}
.m-image {
border: solid black 3px;
}
}
<div class = "main">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" />
</div>
</div>
Couple of things to think about when it comes to mobile view. When wanting certain items to display a certain way on mobile view you want to use #media only screen and (max-width: /* width of the device */. Place all the CSS rules inside of here. These rules will change the rules set above or run new rules that you have define below.
Also, when it comes to display: flex; you want to make sure you wrap it into another div. This "wrapper" or "container" will provide the structure to the way you want the images to display.
add a main container to compress the class m-image then add display flex
Ex:
<div id="main-container">
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
.main-container {
display: flex;
}
then add padding left and right to your m-image class
what you should do in this case is put your images in a single container and apply flex property in the css.
basically manipulate your html and css like this.
HTML:
<div class="image-container">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img />
</div>
</div>
CSS:
.image-container{
display:flex;
gap: 8px;
flex-wrap: nowrap;
}
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
This should give you your desired result for the desktop and for the mobile version you will have to apply media query into your CSS code.
hope this answers your question!
I couldn't really understand your code, So I wrote one for you suiting your needs
I hope it will fix your problem!
#content{
display: flex;
justify-content: space-around;
width: 100%;
}
.imagecontainer{
overflow: hidden;
width: 30%;
}
img{
width: 100%;
}
<div id="content">
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg"></div>
</div>
in my HTML code, I have some rows and div, but one div is shown before another, even if in the code is after. Div with class "contact" is shown before div with class "photos"
Photo: https://imgur.com/a/Y8BGQIM
<div class="photos">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8 section-heading">Galerie Foto</div>
</div>
<div class="gallery">
<img src="background1.jpeg" alt="Cinque Terre">
</div>
<div class="gallery">
<img src="galerie1.jfif" alt="Forest">
</div>
<div class="gallery">
<img src="galerie2.jfif" alt="Northern Lights">
</div>
<div class="gallery">
<img src="galerie3.jfif" alt="Mountains">
</div>
</div>
<div class="contact">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8 section-heading">Contact</div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-6 section-subheading">
<h1><br>
<br>
</h1>
</div>
</div>
</div>
And the css code that I applied to the divs:
.photos{
width: 100%;
position: absolute;
background-color: black;
}
div.gallery {
border: 1px solid #ccc;
float: left;
}
.section-subheading:hover {
border: 5px solid #d3ae87;
}
div.gallery img {
width: 400px;
height: 400px;}
.contact{
width: 100%;
position: absolute;
background-color: black;
}
Hope deleting or commenting position: absolute in both the places will give you expected result.
Give a try. to below CSS
.photos{
width: 100%;
background-color: black;
}
div.gallery {
border: 1px solid #ccc;
float: left;
}
.section-subheading:hover {
border: 5px solid #d3ae87;
}
div.gallery img {
width: 400px;
height: 400px;}
.contact{
width: 100%;
background-color: black;
}
Position absolute will position both divs on top of one another at the top of the page if no other styling positions then differently. Remove the position absolute it is not needed here and add a float left to your photos class and your contact class so that the divs fall in order under one another because your gallery has a float left set.
.photos{
width: 100%;
float:left;
background-color: green;
}
div.gallery {
border: 1px solid #ccc;
float: left;
}
.section-subheading:hover {
border: 5px solid #d3ae87;
}
div.gallery img {
width: 400px;
height: 400px;}
.contact{
width: 100%;
background-color: black;
float:left;
}
I try to display a left and right area but it's not working actually with the cotes "right" and "left"
I tried the position :absolute but it's display me something strange
Maybe I'm doing something wrong with my conteneur div or my div element1
Someone knows how I can achieve that?
#conteneur {
padding-top: -25px;
display: flex;
border: 2px solid black;
padding-bottom: 10px;
}
#element1 {
display: block;
width: 350px;
border: 1px solid black;
}
.right {
float: left;
width: 100%;
}
.left {
float: right;
width: 100%;
}
<div id="conteneur">
<div id="element1">
<img src="{{ public_path('../public/uploads/logo-FFRXIII-2017-01.png')}}" style="max-width: 300px;">
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
</div>
</div>
you are using flexbox, so stick with flexbox and forget floats
#conteneur {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
border: 1px solid black;
padding-bottom: 10px;
}
.img {
flex: 0 100%;
}
img {
max-width: 300px;
}
<div id="conteneur">
<div class="img">
<img src="http://placehold.it/300x200">
</div>
<div class="right">
adresse_right
</div>
<div class="left">
adresse_left
</div>
</div>
First of all your
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
Won't react to your CSS since these are ID's and in your CSS you are trying to find classes with the . selector. So change the . to a # or change your ID tags to Classes.
Secondly i've created a jsfiddle and edited your code hope this helps!
I have a very simple HTML/CSS webpage.
I have three images arranged horizontally on the page, like so:
I'd like to center them on the page, like so:
What's the fix?
Here's the (not-working) code I'm currently using:
.sketches {
align-content: center;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="sketches">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>
Since <div> by default is a block element and <img> is an inline-block element, if you wanna center images horizontally, it's enough to set text-align: center; to div container:
.sketches {
text-align: center;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="sketches">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>
Here's the solution:
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.sketches {
align-content: center;
margin-left: auto;
margin-right: auto;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="outer">
<div class="middle">
<div class="sketches" align=center>
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>
</div>
</div>
Used technique to center vertically from here.
CSS
a) .sketches selector
1) Insert display: flex; declaration
2) Instead of the CSS property: align-content add justify-content
.sketches {
display : flex;
justify-content : center;
/* can be removed */
min-width : 350px;
}
img {
border-radius: 50%;
border: 1px solid #000000;
}
<div class="sketches">
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</div>
Hi Everybody and tks in advance for your help... I'm looking for the best practice to resolve a simple question:
.left {
float: left;
width: 79%;
margin-right: 1%;
}
.left img {
float: right;
}
.right {
float: right;
width: 20%;
}
<div class="main">
<div class="left">
<img src="http://placehold.it/200x200" />
</div>
<div class="right">A TEXT</div>
</div>
How should I center the text vertically at the middle of the image (obviusly not using px in margin-top or bottom, because the width/height of the image will be dinamic).
Thanks!
You could use flexbox. See the example:
.main{
display: flex;
align-items: center;
}
https://jsfiddle.net/zb2ozq1k/1/
I'd get rid of float and use table-cells instead. Then, use vertical-align:middle for the text.
Like this:
.main{
display: inline-table;
border: 1px solid blue;
}
.left {
width: 79%;
margin-right: 1%;
display: table-cell;
border: 1px solid green;
}
.right {
width: 20%;
border: 1px solid red;
display: table-cell;
vertical-align: middle;
}
<div class="main">
<div class="left">
<img src="http://placehold.it/200x200" />
</div>
<div class="right">A TEXT</div>
</div>
h1 {
display: inline;
vertical-align:top;
}
<div class="middle">
<img src="http://placekitten.com/200/150" >
<h1>A TEXT</h1>
</div>