I'm making a simple game for my coding course and have been stumped by this strange outline around my images. At first I thought it was Bootstrap 3, but when I plugged the bare bones into a jsfiddle I've got the same outline. Note that this is not the thumbnail border that gets set in thumbnail images. I've thought about overwriting some border # rule but haven't a clue as to what to try.
I've redone the images thinking this might be some artifact of Inkscape, but nope. Any help in either removing the border or making it transparent would be appreciated.
css, note the commented out attempts:
#tommy img {
background: url(http://s32.postimg.org/4fdqh7dxh/tommy200.png);
height: 200px;
width: 200px;
/*
border: transparent !important;
background: transparent;
border-width: 0 !important;
border: none !important;
border: none;
border: 0px;
border-color: #7A45D2 !important; attempt to at least affect the darn thing.
*/
}
and the bit of html:
<div id="tommy" class= "theGroup player-up">
<p>Tommy</p><img>
</div>
the jsfiddle is here: fiddle
The border is coming from you using an img tag without a src specified and the background set as an image. There are two ways you could fix this:
1) Keep setting the image via the background url, but use a different element (probably a div).
HTML:
<div id="tommy" class= "theGroup player-up">
<p>Tommy</p>
<div/>
</div>
CSS:
#tommy div {
background: url(http://s32.postimg.org/4fdqh7dxh/tommy200.png);
height: 200px;
width: 200px;
}
2) Keep using an img tag, but set the image via the src attribute instead of the background.
HTML:
<div id="tommy" class= "theGroup player-up">
<p>Tommy</p>
<img src="http://s32.postimg.org/4fdqh7dxh/tommy200.png"/>
</div>
CSS:
#tommy img {
height: 200px;
width: 200px;
}
HTML:
<div id="tommy" class= "theGroup player-up">
<p>Tommy</p><img src="http://s32.postimg.org/4fdqh7dxh/tommy200.png">
</div>
CSS:
#tommy img {
height: 200px;
width: 200px;
}
Create a transparent gif and save it in your img folder. Then use this code. Works like a charm, gone are the ugly borders.
<div>
<img src="img/transparent.gif" id="tommy" class="theGroup player-up">
<p>Tommy</p>
</div>
#tommy {
background: url(http://s32.postimg.org/4fdqh7dxh/tommy200.png);
height: 200px;
width: 200px;
}
Related
I'm using html and css to make a website.
I made a div and assigned a class to it. I called that class profile_pic. And when I make changes in CSS to that class nothing changes. That div with a class is not being affected by CSS and I don't know why.
If I put the class in an img tag, then the changes will apply. But when I put the class back in that div, changes disappear. Can someone please explain what's happening?
.profile_pic {
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 25px;
display: inline-block;
}
<div class="profile_pic">
<img src="https://via.placeholder.com/100">
</div>
<div>
<img class="profile_pic" src="https://via.placeholder.com/100">
</div>
The changes do apply. You can see this if you inspect the elements with your browser. The reason they don't seem to in the first example is because you aren't constraining the image to the div. If you do that with, for example, overflow: hidden, you then see that it works.
One minor issue is that since object-fit applies to "replaced elements" such as images, and not structural elements like divs, your image position is shifted in the first case. You could remedy this by applying width of 100% to the image.
.profile_pic {
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 25px;
display: inline-block;
overflow: hidden;
}
.profile_pic img {
max-width: 100%;
}
<div class="profile_pic">
<img src="https://via.placeholder.com/100">
</div>
<div>
<img class="profile_pic" src="https://via.placeholder.com/100">
</div>
Showing an alternative approach using clip-path:
.profile_pic {
display: flex;
width: 50px;
height: 50px;
clip-path: circle(25px);
}
<div class="profile_pic">
<img src="https://via.placeholder.com/100">
</div>
Hi!
I'm using bootstrap 4 and making my own project. After some time I found a problem which I can't fix. I have placed an image into a div section and made the div to be 200px of height & width and overflow will be hidden. Then I made the height of the image 100% of the div and gave a background color(bg-light) and border(5px solid black) to the div. But the background color is seen 1px left, top and right of the div and the image is placed after the 1 px left, right and top.
HTML:
<div class="profile-image-container">
<img class="profile-image" src="image.jpg" />
</div>
CSS:
.profile-image-container{
width: 200px;
height: 200px;
border: 5px solid black;
overflow: hidden;
}
.profile-image{
height: 100%;
}
I didn't understand your question properly.. please tell us what you want as a output.
Find the code below, whatever I understand so far
<img class="profile-image" src="img.jpg" width=100% />
Below is the code from the original question, with a placeholder image.
Unlike the image posted to the question, there is no white border between the enclosing div and the image.
The may be some additional CSS that was not included in the question to account for the white border between the div and the image.
.profile-image-container{
width: 200px;
height: 200px;
border: 5px solid black;
overflow: hidden;
}
.profile-image{
height: 100%;
}
<body style="background-color:#e0e0e0; padding:0.5rem">
<div class="profile-image-container">
<img class="profile-image" src="https://via.placeholder.com/210x200" />
</div>
</body>
I want to create 2 buttons with a sprite-img as background. But the image doesn´t show up.
Maybe there is an interference with background css of the grid?
The document structure is like this:
<body>
<div class="container"> // this has a background color that seems not to affect
<div class="row"> // this has no background
<div class="column"> // this has a background color that seems to affect
<div class="wrapper-for-buttons"> // here are the divs for th background image
<div class="I-want-a-BG-image"> // here shall the background image go
What I have tried:
I´ve checked the image URL with in the very same html page. This works.
I´ve checked the html code and css in another (clean) html document. This works, too.
I have a very specific selector for the different cols as they change background colors on other pages.
But: I´ve checked the selector of the div that shall get the background-image in the very same html page with making a ´border´ and a ´background-color´. This works.
So I don´t know where to search anymore…
Any hints are very appreciated.
Thanks in Advance
CSS
.container {
display: block;
width: 95%;
margin-left:auto;
margin-right: auto;
background-color: #0F0;
}
/* Does this selector make trouble? */
[class|="col"] {
float: left;
min-height: 1px;
background-color: #F0F;
}
#testImage {
display: block;
position: relative;
float:left;
width: 200px;
height: 200px;
background: url("./src/img/contact/mailphone.png") 0 0;
border: 5px solid green;
}
HTML
<address id="imprint">
<div class="container">
<div class="row clearfix">
<div class="col-70">
<p>this col is not of interest</p>
</div>
<div class="col-30">
<div class="mailphonewrapper">
<div id="testImage"></div>
</div>
</div>
</div>
</div>
</address>
I am displaying the images in a circular way inside a div tag like this:
My issue is: Suppose an image(ex 2nd image) is not loaded/ present. Even then it should display it in a circular manner. But it is displaying in a square like below image:
I want image tag to be circular even though the image is not present.
Fiddle link
Then also it should display in circular. But it is displaying as square like below image
I'd argue that you probably want to fallback to some other image or some other placeholder. You can achieve it like so:
<img src="https://material.angul.io/assets/img/examples/shiba2.jpg"
class="company"
onerror="this.src='https://via.placeholder.com/70x70'">
Note the onerror. You can attach a handler function to do more complex things like hiding the img element, and showing some other placeholder element.
You can use CSS clip-path to force a circular cut-out, which will then apply to any image that you try to put in (good or broken).
Demo:
.image { width: 60px; height: 60px; }
.clip-circle { clip-path: circle(30px at center); }
<div style="background: #ffddcc">
Broken images: <img src="does-not-exist.png" class="image">
<img src="does-not-exist.png" class="image clip-circle">
</div>
<br />
<div style="background: #ffddcc">
Good images: <img src="https://via.placeholder.com/60x60" class="image">
<img src="https://via.placeholder.com/60x60" class="image clip-circle">
</div>
Not sure if this gives a better display than the other answers... but at least it answers the question :-) Also, browser support for this is not quite universal: see https://caniuse.com/#feat=css-clip-path.
In this scenario you have to use Javascript because you can't know with HTML/CSS if an image is broken
So here is a solution to either hide the image or replace it with another image just like #MrSaints has mentioned
To Hide:
<img src="Error.src" onerror="this.style.display='none'"/>
To Replace:
<img src="Error.src" onerror="this.src='fallback-img.jpg'"/>
Javascript solution for multiple broken images:
document.addEventListener("DOMContentLoaded", function(event) {
document.querySelectorAll('img').forEach(function(img){
img.onerror = function(){this.style.display='none';};
})
});
<img src="error.src">
<img src="error.src">
<img src="error.src">
<img src="error.src">
You can put the images in div and apply the radius on the div by adding overflow:hidden
.img-container{
border-radius: 50%;
height:70pt;
width:70pt;
float: left;
overflow:hidden;
margin:5px;
}
img{
height:70pt;
width:70pt;
}
<div class="img-container"><img src="https://material.angular.io/assets/img/examples/shiba2.jpg" class="company"></div>
<div class="img-container"><img src="https://material.angular.io/assets/img/examples/shiba2.jpg" class="company"></div>
AFAIK we can't make the invalid image tag as circular. But we can do some workarounds by wrapping the img tag in a div and then specifying border-radius: 50%; overflow: hidden to the div and enclose the image within.
.company {
border-radius: 50%;
height: 100%;
width: 100%;
}
div {
border-radius: 50%;
height: 70pt;
width: 70pt;
float: left;
overflow: hidden;
border: 1px solid #555;
}
<div><img src="https://material.angular.io/assets/img/examples/shiba2.jpg" class="company">
</div>
<div>
<img src="https://material.angular.io/assets/img/examples/shib2.jpg" class="company">
</div>
JSFiddle
You can tackle this issue with JS as #MrSaints is showing, but also this can fail as well. I was thinking more as a CSS solution and defaulting this to a color/nothing, but keep the circle shape.
.circle-image {
height:70pt;
width:70pt;
float: left;
border-radius: 50%;
margin: 5px;
background-size: cover;
background-position: center;
background-color: transparent;
background-image: url('https://material.angular.io/assets/img/examples/shiba2.jpg');
box-shadow: 0px 1px 3px rgba(0,0,0,0.3);
box-sizing: border-box;
}
.broken-image {
background-image: url('https://material.angular.io/assets/img/examples/shiba2.jpgssss');
}
<div class="circle-image">
</div>
<div class="circle-image broken-image">
</div>
I'm pretty new to the front-end materials so bear with me
while I try to explain the question.
I'm having an issue trying to align three boxes together side by side.
However, when I try to add the <p> tag within the box, a top margin
gets added. Here is what I mean.
<div class="work-box">
<div class="box">
<div class="idea">
</div>
<p>Hello World</p>
</div>
<div class="box">
<div class="idea">
</div>
</div>
<div class="box">
<div class="idea">
</div>
</div>
</div>
As you can see, the boxes are wrapped within the "work-box" class. Here is the CSS code.
.work-box {
text-align: center;
}
.box {
margin-top: 30px;
display: inline-block;
width: 30%;
height: 300px;
background-color: #495159;
border: solid #A1E8CC thick;
}
.idea {
height: 50%;
background: url('img/idea.svg') center no-repeat;
background-size: contain;
}
I have been struggling with this issue for this whole entire day and I just cannot figure it out. Please help!
Thank you so much.
Solution: Add vertical-align: top to your .box class.
Explanation: The effect that you saw was because for all inline elements, the vertical-align is defaulted to baseline.
This behaves funny when you have inline elements inside of your .box. Because it will try to align the last inline element to the baseline of all your inline elements.
Try adding vertical-align:middle; to the box class.
.box {
margin-top: 30px;
display: inline-block;
vertical-align:middle;
width: 30%;
height: 300px;
background-color: #495159;
border: solid #A1E8CC thick;
}
See Codepen Example here .
You try using <span>Hello world</span> instead of <p> tag. Moreover, <p> tag is out of .idea div. Is it ok? I think it should be inside of <div class="idea">