Im writing a tank-game in dart. It's 27 * 27 table. For every single field I use background-image attribute. For example my tank consits of 4 small fields. Tank takes only 1 small field on raster. But through pseudo-class .bg-player-left:before if achieved, that tank looks like it 4 field-tank. Same idea with bullets. It takes only one field on raster, but looks like 2. The problem is, that top-left position of this objects is always black.
.bg-water {
background-image: url("../img/water-field.png");
background-size: cover;
background-repeat: no-repeat;
}
.bg-bush {
background-image: url("../img/bush-field.png");
background-size: cover;
background-repeat: no-repeat;
opacity: 0.8;
}
.bg-bullet-up, .bg-bullet-down, .bg-bullet-left, .bg-bullet-right,
.bg-player-up, .bg-player-down, .bg-player-left, .bg-player-right {
position: relative;
}
.bg-player-up:before {
content: "";
position: absolute;
top: 0;
left: 0px;
right: -15px;
bottom: -15px;
background-image: url("../img/player-tank-left.png");
background-size: contain;
background-repeat: no-repeat;
z-index: 1;
}
.bg-bullet-up:before {
content: "";
position: absolute;
top: 0;
left: 0px;
right: -15px;
bottom: -15px;
background-image: url("../img/bullet-left.png");
background-size: contain;
background-repeat: no-repeat;
z-index: 1;
}
You can also try by yourself (https://javajunikorn.github.io/BattleCity/build/web/html/test.html)
In order to move tank you need to start the game from mobile or in browser inspector for mobile version.
interesting idea to morph the object with pseudoclass.
Could it be that you have a css color background set to black, which on that png for bullet and tank creates this distortion?
If I go here: https://javajunikorn.github.io/BattleCity/build/web/img/bullet-left.png
I can see this attribute in css:
background: #0e0e0e;
Related
Is it possible to use CSS to make the background of the top 5% of a page a solid color, and two different background images for the remaining 65% and 30%?
This is how I need it to look:
Edit 2: So there are numerous ways to accomplish this.
Pseudo elements: I think this is the best method, as it avoids extra elements in the markup and allows good control of scaling/cropping. Example below.
Multiple containers: Works just like pseudo elements, but with the added disadvantage of extra elements in the markup. The best support across older browsers, but these days, pseudo elements are quite well supported. Example below.
Multiple backgrounds: This may be suitable for solid colors or gradients, but for most images scaling and cropping will be problematic if using percentages for size. Example below.
1. Pseudo Elements
Just add ::before and ::after pseudo elements to the pagewrapper, supply background images, and position accordingly.
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.pagewrap {
position: relative;
height: 100%;
background-color: green;
}
.pagewrap::before {
content: "";
position: absolute;
top: 5%;
left: 0;
height: 65%;
width: 100%;
background-image: url("https://i.postimg.cc/nckTrT6T/21.jpg");
background-size: cover;
background-position: center;
}
.pagewrap::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
height: 30%;
width: 100%;
background-image: url("https://i.postimg.cc/qvDLXqB3/Optical-Illusion-Brain-washer-27.jpg");
background-size: cover;
background-position: center;
}
<div class="pagewrap">
</div>
2. Multiple Containers
Just replace the pseudo elements in above example with container divs in the html.
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.pagewrap {
position: relative;
height: 100%;
background-color: green;
}
.mid65 {
position: absolute;
top: 5%;
left: 0;
height: 65%;
width: 100%;
background-image: url("https://i.postimg.cc/nckTrT6T/21.jpg");
background-size: cover;
background-position: center;
}
.btm30 {
position: absolute;
bottom: 0;
left: 0;
height: 30%;
width: 100%;
background-image: url("https://i.postimg.cc/qvDLXqB3/Optical-Illusion-Brain-washer-27.jpg");
background-size: cover;
background-position: center;
}
<div class="pagewrap">
<div class="mid65"></div>
<div class="btm30"></div>
</div>
3. Multiple Background Images
Use multiple background images:
background-image: url("image1.jpg"), url(image2.jpg);
then use the same comma separated syntax
for background-repeat: no-repeat, no-repeat; (same value need not repeat)
and background-size: 100% 30%, 100% 65%;,
etc..
The background position is the tricky part though, because it doesn't seem to work as one might expect (Temani Afif kindly provided a very informative link in the comments below ). But this seems to achieve the desired result of 5% 65% 30%:
background-position: bottom left, 0% 15%;
Edit: Replaced gradients with actual images so you can see how image stretching may be an issue with this method. More suitable for solid colors or gradients.
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.pagewrap {
position: fixed;
width: 100%;
height: 100%;
background-color: blue;
background-image: url("https://i.postimg.cc/qvDLXqB3/Optical-Illusion-Brain-washer-27.jpg"), url("https://i.postimg.cc/nckTrT6T/21.jpg");
background-size: 100% 30%, 100% 65%;
background-position: bottom left, 0% 15%;
background-repeat: no-repeat;
}
<div class="pagewrap"></div>
I am trying to make a website, but I have a problem. I have a image, I need it to always fill the complete screen. Just like they do on this website: http://mollyandmepecans.com
This is my website: https://mountainweb-cemre2002.c9users.io/Homepage.html
Thanks!
Remove your image element, and then add this CSS:
body {
background-image: url("MountEverest.png");
background-position: center;
background-repeat: no-repeat;
background-size:cover;
}
Or, if you don't want to use the background, add this to your HTML to replace your image element:
<div class="hero"></div>
And this to your CSS:
.hero {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: -100;
background-image: url("MountEverest.png");
background-position: center;
background-repeat: no-repeat;
background-size:cover;
}
use object-fit if you need to cover img element.
.hero{
object-fit: cover;
}
https://css-tricks.com/almanac/properties/o/object-fit/
I am trying to set a background image for my wordpress website.
.content:before {
content: "";
background-image: url("gfx/SevenWonders.jpg");
/*background: #fff;*/
background-size:600px 700px;
background-repeat: no-repeat;
position: absolute;
z-index: -9999;
top: 0;
right: 28.5%;
bottom: 0;
left: -10000px;
}
this is my css code with background-image. I resized the size because the image
is pretty large for my website. AND! after adding background-repeat: no-repeat,
the background is not displayable. I see only white background.
Of course, I googled to find the solutions, but almost all of them are saying
about syntax error, but I cannot find any syntax mistakes in my code ..
check this fiddle. Problem is with your left property value in css.
.content:before {
content: "";
background-image: url("https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150");
/*background: #fff;*/
background-size:600px 700px;
background-repeat: no-repeat;
position: absolute;
z-index: -9999;
top: 0;
right: 28.5%;
bottom: 0;
left: 0px;
}
I have a div with a background color and a background image. The div calls this class:
.cakebg {
background-color: #F8BBD0;
background-image: url(img/cake.png);
background-size: 25%;
background-position: right top;
background-repeat: no-repeat;
}
I am trying to make only the image somewhat transparent. I tried this:
.cakebg {
background-color: #F8BBD0;
background-image: url(img/cake.png);
opacity: 0.6;
background-size: 25%;
background-position: right top;
background-repeat: no-repeat;
}
But that makes the entire div transparent.
So I tried this:
.cakebg {
background-color: #F8BBD0;
background-image: url(img/cake.png) opacity(0.6);
background-size: 25%;
background-position: right top;
background-repeat: no-repeat;
}
But that makes the image disappear entirely. Can this be done?
What you're trying to do on that single element isn't possible, but there's plenty of ways that could do the same thing with very little extra effort. Probably the best way would be to either add an additional child element to the .cakebg element with the same dimensions that only has the background image, with opacity. Such as:
.cakebg .child-element {
height: 100%;
width: 100%;
background-image: url(img/cake.png);
opacity: 0.6;
}
If you're trying to keep your markup clean, you can even add this as a pseudoelement. Such as the following:
.cakebg:after {
content: "";
height: 100%;
width: 100%;
background-image: url(img/cake.png);
opacity: 0.6;
}
If neither of those methods work, a last resort could be editing the image to have that opacity baked in from your favorite editing software. Hopefully some of these methods might help!
There is no CSS property background-opacity, but you can fake it by inserting a pseudo element with regular opacity the exact size of the element behind it.
.cakebg {
background-color: #F8BBD0;
background-size: 25%;
position: relative;
}
.cakebg::after {
content: "";
background: url(img/cake.png);
opacity: 0.5;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
OR you can simply use an trasparent png image as background
There is no CSS property to make just the background transparent, but you can fake it by inserting a pseudo element with the same size of element behind it and change the opacity of this.
.cakebg {
background-color: #F8BBD0;
background-size: 25%;
background-position: right top;
background-repeat: no-repeat;
}
.cakebg::after {
content: "";
background-image: url(img/cake.png);
opacity: 0.5;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
Please note that that question was already asked quite often, read here for example.
I want to add some corner effects to a module in Joomla 3. What I'm trying to do it add corner tabs like you'd see in an old photo album (I tried to include an attachment, but don't have enough posts). I'm using a Module Class Suffix to add them because I plan to use them on various modules of different sizes and want them to be positioned correctly regardless of how tall or wide a module happens to be.
But I can only get one to show up. If I add more than one suffix, it is ignored.
This is the syntax I'm using in Joomla to add them:
style-color badge-br badge-ul
"style-color" is styling that displays the background and text effects for the module. The "badge-XX" denote each of the corner effects. ul is "upper left", br is "bottom-right", etc.
Here is the CSS I'm using for the corner effects:
.module .badge-ul {
background-position: 0 0px;
background-image: url(../images/texture/photo_corners.png);
top: -7px;
left: -7px;
height: 60px;
width: 60px;
z-index: 1001;
}
.module .badge-ur {
background-position: 0 -60px;
background-image: url(../images/texture/photo_corners.png);
bottom: -7px;
left: -7px;
height: 60px;
width: 60px;
z-index: 1101;
}
.module .badge-bl {
background-position: 0 -120px;
background-image: url(../images/texture/photo_corners.png);
bottom: -7px;
left: -7px;
height: 60px;
width: 60px;
z-index: 1201;
}
.module .badge-br {
background-position: 0 -180px;
background-image: url(../images/texture/photo_corners.png);
bottom: -7px;
right: -7px;
height: 60px;
width: 60px;
z-index: 1301;
}
Obviously I'm missing something. But I can't figure out what. If it matters, I'm using a YooTheme template (Cloud).
Any help would be greatly appreciated!
You cant do it like that. You can only have one value for each css property.
background-position: 0 0px;
background-position: 0 -180px;
background-position: 0 -120px;
...
You may only have one background-position for each dom element. If you want 4 backgrounds you need 4 dom elements
I suggest you rethink the way you want to go about creating the background.
Add multiple backgrounds
http://www.css3.info/preview/multiple-backgrounds/
#example1 {
width: 500px;
height: 250px;
background-image: url(sheep.png), url(betweengrassandsky.png);
background-position: center bottom, left top;
background-repeat: no-repeat;
}