I have a CSS table and I would like to have space in-between the cells but not at the left of the first image and the right of the last image.
Here is a screenshot of what I have:
Here is a screenshot of what I would like:
The current HTML is:
<div id="footer">
<div class="lower"><img src="images/one.jpg" alt="Ring being put on finger"/></div>
<div class="lower"><img src="images/two.jpg" alt="The mens trousers"/></div>
<div class="lower"><img src="images/three.jpg" alt="Flowers"/></div>
<div class="lower"><img src="images/four.jpg" alt="The rings"/></div>
</div>
and the CSS is
#footer {
display: table;
width: 100%;
max-width: 1024px;
margin-top: 1%;
}
.lower {
display: table-cell;
}
#footer img {
width: 100%;
height: auto;
max-width: 256px;
}
Please bear in mind that this is a responsive webpage so I would like the space to always remain however I would like the space to change according to device size, so using %.
Apply this.
#footer {
display: flex;
justify-content: space-between;
width: 100%;
max-width: 1024px;
background-color: #F00;
padding: 0;
margin: 0;
max-height: content-height;
}
.lower {
margin-left: 2%;
}
#footer img {
width: 100%;
height: 100%;
}
Demo
hi pls apply this css and set padding
.lower {
display: table-cell;
padding:0 20px;
}
.lower:first-child{ padding-left:0}
.lower:last-child{ padding-right:0}
Try display: flex; instead of display: table;
Give display: flex; and justify-content: space-between; to the parent.
Use CSS adjacent element selector:
.lower + .lower {
padding-left: 20px;
}
#footer {
display: table;
width: 100%;
max-width: 1024px;
margin-top: 1%;
}
.lower {
display: table-cell;
}
.lower + .lower {
padding-left: 20px;
}
#footer img {
width: 100%;
height: auto;
max-width: 256px;
}
<div id="footer">
<div class="lower"><img src="images/one.jpg" alt="Ring being put on finger"/></div>
<div class="lower"><img src="images/two.jpg" alt="The mens trousers"/></div>
<div class="lower"><img src="images/three.jpg" alt="Flowers"/></div>
<div class="lower"><img src="images/four.jpg" alt="The rings"/></div>
</div>
Related
I have structure like this:
img {
width: auto;
height: 200px;
}
.cards {
display: flex;
justify-content: center;
margin-top: 2em;
width: 80%;
flex-wrap: wrap;
}
.card {
margin: 1em;
box-shadow: 0 0 6px #000;
object-fit: cover;
}
.info {
padding: 1em;
border-top: none;
}
<div class='cards'>
<div class="card">
<img src="https://picsum.photos/id/1004/5616/3744" alt="1004" />
<div class="info">
<h3>Greg Rakozy</h3>
<div><small>https://unsplash.com/photos/SSxIGsySh8o</small></div>
</div>
</div>
</div>
on computers with long width image is rendered a little wrong.
how can I fix this so that it displays correctly, i.e. sticks to the '.card' block?
First you need to limit the width of you main container:
.cards {
display: flex;
justify-content: center;
margin-top: 2em;
width: 80%;
flex-wrap: wrap;
max-width: 1440px; /* whatever you desire */
margin-left: auto; /* center the container */
margin-right: auto; /* center the container */
}
Then each image should take 100% for it's container:
.card {
margin: 1em;
box-shadow: 0 0 6px #000;
object-fit: cover;
flex: 0 0 25%; /* each card will be 25% width */
}
img {
width: 100%;
height: 200px;
object-fit: cover;
}
Adding those to .card class
width: 100%;
height: auto;
Google how to make image responsive with css, it's not related to React.
.card {
width: 100%;
height: auto;
}
You can either put those images in a div.img-container and set the div width & height like this.
.img-container {
width: 100%;
height: // as you want;
}
and then put that image inside .img-container and set the image width to 100%.
.container {
width: 350px;
height 350px;
border: 2px solid black;
border-radius: 5px;
}
.container .img-container {
width: 100%;
height: 200px;
}
.container .img-container img {
width: 100%;
height: 100%;
}
.container .card-info {
width: 100%;
height: auto;
}
<div class="container">
<div class="img-container">
<img src="https://picsum.photos/200">
</div>
<div class="card-info">
<h5>Title</h5>
<small>Your link here</small>
</div>
</div>
and either set image width 100% and height auto.
I'm trying to insert 3 images in my main section. I want to align them but my third image stays at the bottom of my page. I tried to shrink the images but nothing change. I used "margin-left" "margin-bottom" and "float" but nothing works.
main section h1 {
margin-right: 10px;
margin-top: 150px;
float: left;
}
main section h2 {
margin-top: 200px;
margin-left: auto;
margin-right: auto;
}
main section h3 {
margin-top: 150px;
margin-left: 10px;
float: right;
}
You can use display: flex, for example:
HTML
<body>
<div>
<img src='1.jpg'>
<img src='2.jpg'>
<img src='3.jpg'>
</div>
</body>
CSS
*{
margin: 0;
padding: 0;
}
body{
width: 100vw;
height: 100vh;
display: flex;
align-items: center;//ALIGN DIV VERTICALLY
}
div{
display: flex;
justify-content: center;//ALIGN IMG'S HORIZONTALLY
width: 100%;
}
img{
width: 300px;
height: 180px;
}
img:nth-of-type(2){
margin: 0 20px
}
Look the result in this link: https://imgur.com/a/VwmvRjp
I have an horizontal scrollbar class="filter_list" into a wrapper div class="wrapper". I want this scrollbar to be always 100% of the wrapper div and I want this wrapper div to be responsive.
It's working fine if I only have one item in my filter list but as soon as I put more than the wrapper width size, it's not responsive anymore.
Here are some pictures to illustrate the problem :
Responsive and working fine :
OK
The scrollbar is blocking the width of the wrapper that doesn't shrink to fit the dimension of the window (we can see that the picture of the girl is no longer it's 100% square size):
NOT OK
Here is the code :
body {
display: flex;
align-items: center;
justify-content: center;
}
.wrapper {
width: 800px;
display: flex;
justify-content: flex-start;
flex-direction: column;
align-items: center;
}
.magic_wand {
margin: 15px 0px 20px;
max-width: 50px;
}
.ico_magic_wand {
width: 100%;
height: 100%;
object-fit: contain;
}
.picture_preview {
width: 100%;
margin-bottom: 50px;
height: 100px;
}
.picture_preview img {
width: 100%;
height: 100%;
object-fit: contain;
}
.filter_list {
width: 100%;
background-color: blueviolet;
overflow-x: auto;
white-space: nowrap;
font-size: 0;
}
.filter:last-child {
margin-right: 0px;
}
.filter {
display: inline-block;
height: 150px;
width: 150px;
background-color: blue;
margin-right: 15px;
}
<body>
<div class="wrapper">
<div class="magic_wand">
<img src="img/ico/magic_wand.png" class="ico_magic_wand">
</div>
<div class="picture_preview">
<img src="https://images.unsplash.com/photo-1527514086375-0a7bae9089be">
</div>
<div class="filter_list">
<div class="filter">
</div>
<div class="filter">
</div>
<div class="filter">
</div>
<div class="filter">
</div>
</div>
</div>
</body>
I would like to understand why the div class="filter_list" width won't shrink with it's parent div while reducing the width of the window and how to fix the problem, thanks a lot !
Try this code.. I can't understand your question.. it may ur expectation,, else explain it clearly..
css
.filter {
display: inline-block;
height: 150px;
width: 21.3%;
background-color: blue;
margin-right: 15px;
}
.filter:nth-child(4n+4) {
margin-right: 0px;
}
Please remove ur css code and add this codes.. I think display:flex; is the issue for ur code..
body {
margin:0px;
}
img {
max-width: 100%;
height: auto;
}
.wrapper {
width: 800px;
margin: 0 auto;
text-align: center;
}
.magic_wand {
margin: 15px auto 20px;
max-width: 50px;
}
.picture_preview {
width: 100%;
margin-bottom: 50px;
height: 100px;
}
.picture_preview img {
height: 100%;
}
.filter_list {
width: auto;
background-color: blueviolet;
overflow-x: auto;
white-space: nowrap;
font-size: 0;
}
.filter:last-child {
margin-right: 0px;
}
.filter {
display: inline-block;
height: 150px;
width: 150px;
background-color: blue;
margin-right: 15px;
}
#media only screen and (max-width: 1024px) {
.wrapper {
width: 100%;
}
}
How can i vertically / horizontally align this item with auto generated width / height without using the classic top:50% left:50% transform: translate(-50%,-50%)
css setup without alignments
#container {
width: 200px;
height: 100px;
background-color: lightblue;
}
#myImage {
width: auto;
height: auto;
max-height: 100px;
max-width: 200px;
}
I'm not entirely sure what you're trying to achieve but this is the image with no fixed height or width set in the CSS. I assume from your OP that you want is centered as such - so if the image dimensions changed it will stay centralized along both axis.
Note the only limitations you face are those older browsers that don't support flex. If that's a problem you can use display: table; and display: table-cell; to good effect.
http://jsfiddle.net/dLLan/29/
css:
#container {
width: 250px;
max-height: 250px;
height: 250px;
position: relative;
display: flex;
justify-content: center;
align-items: center;
background-color: lightblue;
}
#myImage {
//removed
}
You can use something like that:
#helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
#container {
width: 200px;
height: 100px;
background-color: lightblue;
text-align:center;
}
#myImage {
width: auto;
height: auto;
max-height: 100px;
max-width: 200px;
vertical-align: middle;
}
<div id="container">
<div id="helper"></div>
<img id="myImage" src="http://s3.amazonaws.com/hirethings/photo/7250/images/thumbnail.jpg?1274508483" />
</div>
Flexbox should be fine here depending on your Browser support requirements.
There is no need to position the image...the flex will do that.
.container {
width: 200px;
height: 100px;
background-color: lightblue;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 1em;
}
.large {
width: 300px;
height: 200px;
}
.myImage {
width: auto;
height: auto;
}
<div class='container'>
<img class='myImage' src='http://s3.amazonaws.com/hirethings/photo/7250/images/thumbnail.jpg?1274508483' />
</div>
<div class='container large'>
<img class='myImage' src='http://lorempixel.com/image_output/food-q-c-250-160-5.jpg' />
</div>
I want to know, can I do this mark up use just display: table; and display: table-cell for columns:
For example 1 and 3 columns width is 15% of the screen and last one is 70%.
If I try to do it like this:
Page:
#content #left-column
{
display: table-cell;
width: 15%;
}
#content #mainContent
{
display: table-cell;
padding-right: 22px;
width: 70%;
}
#content #right-column
{
display: table-cell; /* width: 300px;*/
width: 15%;
}
I`ll get mark-up like this .
How cam I create correct markup?
-------Edited-------------------------------
I have to add this code to fix my problem.
content
{
display: table;
width: 100%;
}
Seems your code works.. I just added the parent element with display: table; and it's fine.
#content
{
display: table;
width: 100%;
}
#content div
{
border: 1px dashed #000;
}
#content #left-column
{
display: table-cell;
width: 15%;
}
#content #mainContent
{
display: table-cell;
padding-right: 22px;
width: 70%;
}
#content #right-column
{
display: table-cell; /* width: 300px;*/
width: 15%;
}
It's possible you have a markup error, did you use something like this?
<div id="content">
<div id="left-column">
Left column
</div>
<div id="mainContent">
Main Content
</div>
<div id="right-column">
Right column
</div>
</div>
http://jsfiddle.net/2dMfZ/1/