How to remove white margins around div element and image?

remove white space around image html
how to remove white space between images in html
how to remove space around image in html
white space between image and border
css remove white space below image
how to remove white space in css
outlook adding space around images
how to remove space between two images in bootstrap

I'm trying to remove the whitespace around my header photo, which should cover the entirety of the page. I'm running a local server on my computer (localhost) to test this PHP file.

I've already tried all of the relevant answers I could find here on Stack Overflow. I've looked up multiple threads and done the following: 1) reset the CSS styles by changing margins and padding to 0 2) surrounded the image tag with body tags, which should now be reset 3) Changed the width setting to 100% and height to auto

index.php:

<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div class="container">
    <img class="image" 
src="https://cdn.shopify.com/s/files/1/0533/2089/files/header- 
design-position-absolute_fcabc9a2-0fdb-4057-a6fb-f84f16840eba.png? 
v=1507118933" alt="Header Picture">
    <div class="name"> ⏤ NAME ⏤ </div>
<div class="tagline"> traveler. consultant. developer.</div>
    </div>
</body>
<html>

style.css:

* { 
    margin:0; 
    padding:0; 
}
/* container holding both the header photo and text */
.container {
     position: relative;
     text-align: center;
     color: white;
} 
/* main header image */
.image {
    filter: drop-shadow(8px 8px 10px gray); filter: contrast(75%);
    width: 100%;
    height: auto;
}
/* name text */
.name {
    position: absolute;
    top: 17.5%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 600%;
    font-weight: bold;
    overflow: hidden;
white-space: nowrap;
}
/* tagline text */
.tagline {
    position: absolute;
    top: 23.5%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 200%;
    font-family: "Comic Sans MS", cursive, sans-serif;
}

All I want is for there to be no white space around the picture such that it stretches across the page. Instead, I keep getting white space around the edges that I can't get rid of.

Upadte I'm implementing some of the changes now and seeing why suddenly this simplified version works. It must be something in the rest of my code (which I have not included) Let me reupdate this code with the rest of it first.

This works fine when tested locally and on jsfiddle. However your HTML is missing a <head> tag. The CSS <link> should go inside of it.

Delete white space between divs, How do I get rid of the white space around an image in HTML? I am admittedly a beginner, but I also did a fair amount of searching before posting this. There seems to be extra space around my div element. I also would like to point out that I tried many combinations of border: 0, padding:0, etc. and nothing seemed to get rid of the white space. Here is the code:

My first suggestion here is to use the background-image CSS property as then you gain more control over the image box, and you can then set the actual page body or section to render the image.

.your-image {
  background-image: url("photographer.jpg"); /* The image used */
  background-color: #cccccc; /* Used if the image is unavailable */
  height: 500px; /* You must set a specified height */
  background-position: center; /* Center the image */
  background-repeat: no-repeat; /* Do not repeat the image */
  background-size: cover; /* Resize the background image to cover the entire container */
}

One thing to note is that the <img> tag is included in screen readers while background images are not, making your website more user-friendly to those who use screen readers as the background here is less relevant to the content.

One thing to think about is that all HTML elements have their own predefined margins and padding as well as other attributes based on the browser they are rendered in, an example of this is the 8px margin placed on the <body> element by default in most browsers, which can be overwritten in your code by being explicitly defined.

Just as a side note, there are some libraries that assist with the incongruencies between our different browsers and how they render our elements, I would take a look at normalize.css which is a great CSS only library with plenty of documentation.

Spaces Between Images in HTML, . However, this is a bad way to do what you want to do. You should float the elements if thats what you want to do. Are you trying to create an inline grid with your own CSS rules using the inline-block display mode? Probably you are frustrated and asking to yourself "Why the hell is there a space between my elements!?".

It seems that the problem in your image so, try to crop the image.

* { 
    margin:0; 
    padding:0; 
}
/* container holding both the header photo and text */
.container {
     position: relative;
     text-align: center;
     color: white;
} 
/* main header image */
.image {
    filter: drop-shadow(8px 8px 10px gray); filter: contrast(75%);
    width: 100%;
    height: auto;
}
/* name text */
.name {
    position: absolute;
    top: 17.5%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 600%;
    font-weight: bold;
    overflow: hidden;
white-space: nowrap;
}
/* tagline text */
.tagline {
    position: absolute;
    top: 23.5%;
    left: 40%;
    transform: translate(-30%, 50%);
    font-size: 200%;
    font-family: "Comic Sans MS", cursive, sans-serif;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body style=" background-color: #000000">
<div class="container">
    <img class="image" 
src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="Header Picture">
    <div class="name"> ⏤ NAME ⏤ </div>
<div class="tagline"> traveler. consultant. developer.</div>
    </div>
</body>
<html>

How to Remove White Space Under an Image Using CSS, How do I get rid of the white border on my website? This means your image will no longer act like flowing text and will no longer have a gap below it! Caveats: Changing from display: inline means your img tag will ignore things like text-align: center, and other alignments specific to displaying elements inline. Image credit: buhsnarf on flickr. About the Author

Remove "Padding" White Space around Image., How do I reduce the gap between two images in HTML? CSS Margins. The CSS margin properties are used to create space around elements, outside of any defined borders.. With CSS, you have full control over the margins. There are properties for setting the margin for each side of an element (top, right, bottom, and left).

How 2 remove white space around images in IE - Get Started, previous element immediately before the next element on the next line. Printing with Zero Margins - White Border Still Appears I am printing certificates and do not want a border to appear so I set the margins to zero. Once I print, the document still prints out a white border around the document.

How do I reduce empty space between photo and text, Answer: Use the CSS display property. <title>Remove White Space Below Images</title> <style> .img-box{ width: 125px; border: 4px solid #333; } .img-box img{ display: block; Default margins, borders and padding are all 0, so when you wrap a div around some text, there is no space between its edges and the text. div elements obey the box model strictly, while adding padding etc. to table cells can be interpreted a bit more loosely by browsers. Default widths for all block-level elements are 100%.

Comments
  • Provide your screenshot with problem. Its actually working here as you need.
  • The only white space I can see is the descender at the bottom, which you can solve with vertical-align:top; or display:block
  • I think your picture has white spaces by itself, I tested your code here and it works jsfiddle.net/5bLv4rzw
  • The image has no proper height to stretch all the window. change the mage and try