CSS3 - Use part of an image for background [duplicate] - css

This question already has answers here:
How can I display just a portion of an image in HTML/CSS?
(5 answers)
Closed 6 years ago.
I want to use some images as backgrounds but I have no control over the images. If the images are 500px x 500px , is it possible with just CSS3 to scale the image down to 200px x 200px and then only use 100px x 100px from the center?

You could use something like this:
div {
width:100px;
height:100px;
background-size: 200px 200px;
background-position: center;
background-image: 'your image here';
}

Related

Is there a way to have IMG width:100%, margin 10px automatically fit inside a div of fixed width without spilling out [duplicate]

This question already has answers here:
Display a div width 100% with margins
(6 answers)
100% width minus margin and padding [duplicate]
(6 answers)
Closed 2 years ago.
I have a div with a fixed width (can change, but use fixed as an example). Text and Images will be displayed inside the div of varying sizes including 100% width. Images will have a 10px margin.
When I display a 100% width IMG, it spills outside of the div on the right side slightly. Is there a CSS way (or other?) to automatically have the IMG display within the div, accounting for the 10px margin on either side and NOT spill outside, while keeping the width:100% value?
I know I can workaround it by using a calculated amount, like width:94.5% (2nd image) for a 400px wide div container, but I would rather not have to do it this way as this results in recalculating every time the container width changes...maybe this is the best way after all?
Don't want to use overflow:hidden, as this will give a cut-off look...
Sample code:
<style>
.editor {
width:400px;
border-style:solid;
}
.editor img {
object-fit: cover;
object-position: top;
display: block;
margin:10px;
border-style:solid;
}
</style>
<div class="editor"">
<p>Spills over</p>
<img style="width:100%" src="http://www.google.com.br/images/srpr/logo3w.png">
<p>Looks right, but uses odd calculated width</p>
<img style="width:94.5%" src="http://www.google.com.br/images/srpr/logo3w.png">
</div>

How to "fill" background image? [duplicate]

This question already has answers here:
Background images: how to fill whole div if image is small and vice versa
(7 answers)
Closed 4 years ago.
I'm making a website where I need to have a notable difference between fill and center background images. My template is this:
Center: Uses native resolution to determine size.
Fill: Fits sides to fill screen without changing aspect ratio. Two sides exactly fit screen, while other two are cut off.
I managed to get centered with
.center {
background-repeat: no-repeat;
background-size: auto auto;
background-position: center center;
}
But I can't figure out how I would do fill. Any insight?
I believe you want background-size: cover. Other background-size options.

How do I make my background-image fit the entire screen CSS [duplicate]

This question already has answers here:
Fit website background image to screen size
(14 answers)
Closed 4 years ago.
CSS:
body{
background-image:url("img-address");
}
I want the image not to repeat itself multiple times, but to span the entire screen. I don't want to use a normal image I want to use background-image.
you can use background-size:
https://www.w3schools.com/cssref/css3_pr_background-size.asp
body {
background-size: 100% 100% ;
}
or
body {
background-size: cover;
}
Use background-repeat: none and background-size: cover
Try to use background-size: cover; as described in this article: https://css-tricks.com/perfect-full-page-background-image/
It will make the image stretch to fill the available space and scale accordingly to the size of its container.
Let me know how it goes :)
You can use the following to make it fit:
background-size:cover; Resize the background image to cover the entire container, even if it has to stretch the image or cut a little bit off one of the edges
background-size:contain; Resize the background image to make sure the image is fully visible
So it does not repeat: background-repeat: no-repeat;
https://www.w3schools.com/cssref/css3_pr_background-size.asp

How to create rounded corners like the sample? [duplicate]

This question already has answers here:
Div with rounded border
(3 answers)
Closed 4 years ago.
consider blue section as a container like div. I want to have this with rounded corners like the sample. I used border-radius property but couldn't create the same. Also I searched a lot and couldn't fine anything like this.
p.s. I know clip-path property is a good option for this but I want something with more support on browsers.
Use border-radius on the bottom corners;
div {
width: 100%;
height: 250px;
border-radius: 0 0 50% 50%; /* topleft topright bottomright bottomleft */
background: #f90;
}
<div></div>

Can you declare the background-size in shorthand for the background: [duplicate]

This question already has answers here:
background-size in shorthand background property (CSS3)
(5 answers)
Closed 8 years ago.
I am used to writing out my background properties in shorthand like so...
background: #444 url(hero.jpg) no-repeat center right;
Is there anyway I can incorporate the background-size property into my shorthand? What about some of the new css3 background properties? Are they are able to be written in shorthand?
Yes. The full CSS3 syntax is:
background: color position/size repeat origin clip attachment image|initial|inherit;
Note: If one of the properties in the shorthand declaration is the background-size property, you must use a / (slash) to separate it from the background-postion property, e.g. background:url(smiley.gif) 10px 20px/50px 50px; will result in a background image, positioned 10 pixels from the left, 20 pixels from the top, and the size of the image will be 50 pixels wide and 50 pixels high.

Resources