How do I remove the white space between 2 divs [duplicate] - html

This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 6 years ago.
I have two divs that contain two pictures, but there is always this weird tiny blank space in between them. I tried setting the margins and paddings to 0 for both of the divs in css but it still doesn't work.
Here is my code:
#selector{
width: 100%;
height: 100%;
margin-bottom: 0;
padding: 0;
}
#break-1{
display: block;
margin: auto;
padding: 0;
width: 100%
height: 20px;
}
#break-1 img{
width: 100%;
}
<div>
<img src="http://placehold.it/350x150" alt="" id='selector'>
</div>
<div id="break-1">
<img src="http://placehold.it/350x150" alt="">
</div>

img is inline element and by default is vertical-align:baseline,
you could fix that two ways:
- add display:block
#selector {
width: 100%;
height: 100%;
margin-bottom: 0;
padding: 0;
}
#break-1 {
display: block;
margin: auto;
padding: 0;
width: 100%;
height: 20px;
}
img {
width: 100%;
display: block
}
<div>
<img src="//placehold.it/100" alt="" id='selector'>
</div>
<div id="break-1">
<img src="//placehold.it/100" alt="">
</div>
- add vertical-align:bottom
#selector {
width: 100%;
height: 100%;
margin-bottom: 0;
padding: 0;
}
#break-1 {
display: block;
margin: auto;
padding: 0;
width: 100%;
height: 20px;
}
img {
width: 100%;
vertical-align: bottom
}
<div>
<img src="//placehold.it/100" alt="" id='selector'>
</div>
<div id="break-1">
<img src="//placehold.it/100" alt="">
</div>

Related

Put image next to h1

How do I put the image next to the h1 text? The image on the left and the text on the right. Thanks in advance!
img {
width: 150px;
height: 150px;
}
h1 {
padding: 25px;
border: 0px;
margin: 0px;
height: 30%;
width: 70%;
}
<header class="head">
<img src="https://static.nike.com/a/images/f_jpg,q_auto:eco/61b4738b-e1e1-4786-8f6c-26aa0008e80b/swoosh-logo-black.png" class="pic">
<h1 class="home" id="home">Hi</h1>
It may be most efficient to use flexbox to resolve this layout issue. Adding
display: flex; to the parent element will create the row layout you're looking for and some additional CSS properties will center the children elements if desired. Check out the complete guide here to really control the position of every element if needed.
.head {
display: flex;
justify-content: center;
}
img {
width: 150px;
height: auto;
max-width: 100%;
}
h1 {
padding: 25px;
border: 0;
margin: 0;
align-self: center;
}
<header class="head">
<img src="https://static.nike.com/a/images/f_jpg,q_auto:eco/61b4738b-e1e1-4786-8f6c-26aa0008e80b/swoosh-logo-black.png" class="pic">
<h1 class="home" id="home">Hi</h1>
</header>
Either add float: right to h1:
img {
width: 150px;
height: 150px;
}
h1 {
float: right;
padding: 25px;
border: 0px;
margin: 0px;
height: 30%;
width: 70%;
}
<header class="head">
<img src="https://static.nike.com/a/images/f_jpg,q_auto:eco/61b4738b-e1e1-4786-8f6c-26aa0008e80b/swoosh-logo-black.png" class="pic">
<h1 class="home" id="home">Hi</h1>
Or display: inline-block to h1:
img {
width: 150px;
height: 150px;
}
h1 {
display: inline-block;
padding: 25px;
border: 0px;
margin: 0px;
height: 30%;
width: 70%;
}
<header class="head">
<img src="https://static.nike.com/a/images/f_jpg,q_auto:eco/61b4738b-e1e1-4786-8f6c-26aa0008e80b/swoosh-logo-black.png" class="pic">
<h1 class="home" id="home">Hi</h1>
Keep in mind that the image has a fixed width and the text has a relative width, so it will automatically flow over to the next line if the total width allowance is exceeded. To prevent this, simply set width: fit content on the h1.

How to center images on a DIV? [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 10 months ago.
I'm practising CSS so I'm working on a simple image gallery.
I would like to center the images horizontally on the div but I don't know how to do it. Thanks.
How it looks: https://imgur.com/a/cs5lQhE
(the pink background is just for reference)
html:
<main>
<div class="images">
<img src="img/1.jpg" />
<img src="img/2.jpg" />
<img src="img/3.jpg" />
<img src="img/4.jpg" />
<img src="img/5.jpg"/>
<img src="img/6.jpg"/>
<img src="img/7.jpg"/>
<img src="img/8.jpg"/>
</div>
</main>
css:
*{
padding:0;
margin:0;
}
body{
background-color:#000;
}
.h {
width: 200px;
color: #fff;
padding: 30px 0 30px 0;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.images {
width: 100%;
height: 800px;
background-color: #ff8787;
}
img {
width: 410px;
height: 250px;
vertical-align: top;
float: left;
margin: 0 10px 20px 10px;
padding: 5px;
border: 1px solid #fff;
opacity: 0.85;
}
img:hover{
opacity:1.0;
}
You could use display flex to horizontally center
div {
display: flex;
justify-content: center;
}

How do I position a div with a colored background over a preceding image? [duplicate]

This question already has answers here:
How to overlay images
(11 answers)
Closed 3 years ago.
Stumped.
I have a basic card with an image and a text tag I want to float over the image.
The tag should have a background color behind the text and above the image.
The background of the text goes behind the image instead.
https://codepen.io/Mikeritteronline/pen/LwJYaR
html
<div class="card">
<div class="card__image">
<img src="https://placehold.it/1024x768" alt="">
</div>
<div class="card__tag">
<p>Image Tag</p>
</div>
</div>
css
img {
max-width:100%;
height: auto;
margin: auto;
}
.card {
max-width: 320px;
margin: auto;
}
.card__tag p{
background: blue;
color: lime;
padding: 0.25rem;
margin-top: -3rem;
}
You can add position to achieve what you want.
.card {
position: relative;
}
.card__tag p {
position: absolute;
}
I think its best if you position the div not the p like so:
(also generaly try to avoid positioning absolute if you do not have to)
img {
max-width:100%;
height: auto;
margin: auto;
}
.card {
max-width: 320px;
margin: auto;
}
.card__tag{
z-index: 1;
position:relative;
top: -3rem;
}
.card__tag p{
background: blue;
color: lime;
padding: 0.25rem;
}
<div class="card">
<div class="card__image">
<img src="//placehold.it/1024x768" alt="">
</div>
<div class="card__tag">
<p>Image Tag</p>
</div>
</div>
add
position: relative
to the p tag like
.card__tag p{
background: blue;
color: lime;
padding: 0.25rem;
margin-top: -3rem;
position: relative;
}
Add position:relative to .card and position:absolute to .card__tag
Here is the updated fiddle:
img {
max-width: 100%;
height: auto;
margin: auto;
}
.card {
max-width: 320px;
margin: auto;
position: relative;
}
.card__tag p {
background: blue;
color: lime;
padding: 0.25rem;
margin-top: -3rem;
}
.card__tag {
position: absolute;
}
<div class="card">
<div class="card__image">
<img src="//placehold.it/1024x768" alt="">
</div>
<div class="card__tag">
<p>Image Tag</p>
</div>
</div>

How can i put this 4 images inside of 1 image?

I am stuck at the moment to put this 4 images (in the same row) inside of the div with image.
Html:
.iniciRo img {
width: 100%;
}
.iniciRo .coluna img {
width: 270px;
z-index: 4;
}
.iniciRo>div {
padding: 30px 0 10px 0;
}
.iniciRo .row>div {
padding-bottom: 20px;
}
.coluna {
position: relative;
padding-left: 15px;
padding-right: 15px;
float: left;
}
.row {
width: 100%;
margin-left: auto;
margin-right: auto;
margin-top: 0;
margin-bottom: 0;
max-width: 75em;
}
<div class="iniciRo">
<img src="assets/images/Rodape/backbot.png">
<div>
<div class="row">
<div class="coluna">
<img src="assets/images/Rodape/visitas-escolas.png" />
</div>
<div class="coluna">
<img src="assets/images/Rodape/rafc.png" />
</div>
<div class="coluna">
<img src="assets/images/Rodape/rioavetv.png" />
</div>
<div class="coluna">
<img src="assets/images/Rodape/galeri.png" />
</div>
</div>
</div>
</div>
I already tried to use z-index but nothing happened.
Any help is going to be appreciated, please help me...
Like this:
coluna img {
position: relative;
padding: 50em;
}
.iniciRo img{
position: absolute;
width: 100%;
}
.iniciRo > div{
padding: 30px 0 10px 0;
}
.iniciRo .row > div{
padding-bottom: 20px;
}
.coluna{
position: relative;
padding-left: 15px;
padding-right: 15px;
margin-bottom: 30em;
}
.row{
position: relative;
display: flex;
flex-direction: column;
width: 100%;
max-width: 75em;
clear: both;
}
In other words you want position: absolute for the iniciRo img, position: relative for .row, and the use of flexbox for .row. Here's a JS Fiddle.
Use this Flexbox css code
<div class="flex-container">
<div>
<img src="https://placehold.it/350x150" />
</div>
<div>
<img src="https://placehold.it/350x150" />
</div>
<div>
<img src="https://placehold.it/350x150" />
</div>
<div>
<img src="https://placehold.it/350x150" />
</div>
</div>
.flex-container{
display:flex;
}
.flex-container div {
flex:1;
margin:5px;
}
img {
width:100%;
}

Auto height removing float

I've made some code where the "section" that automatically determines the height when the content is inside, however, I want to have multiple columns in the same row and the columns are currently stacking.
How would I set the columns on to the same row without using float element as it takes the auto height of the section away?
.section {
width:100%;
padding-top: 60px;
padding-right: 0px;
padding-bottom: 62px;
padding-left: 0px;
background-color: #f5f5f5;
position: relative;
}
.row {
position: relative;
width: 100%;
max-width: 1080px;
margin: auto;
padding: 33px 0;
}
.column{
width: 100%;
position: relative;
z-index: 9;
}
.container {
overflow: hidden !important;
position: relative;
bottom: 0;
left: 0;
right: 0;
background-color: transparent;
width: 300px;
height: 500px;
border-radius: 0px;
}
<div class="section">
<div class="row">
<div class="column">
<div class="container">
<img src="img.png">
<div class="content_block">
<div class="text">
<h2>Title</h2>
<a>2 reports</a>
</div>
</div>
</div>
</div>
<div class="column">
</div>
</div>
</div>
The easiest way would be to use flexbox.
So just add ..
display: flex;
.. and you could probably remove the width (or set it to 50%)
.row {
display: flex;
position: relative;
width: 50%;
max-width: 1080px;
margin: auto;
padding: 33px 0;
}
There are other ways of course (colspan, inline-block) but flexbox will give you even-height columns and make any other formatting much easier.