This question already has answers here:
Using percentage values with background-position on a linear-gradient
(2 answers)
Closed 3 years ago.
For background-size, we can use percentage, setting the width and height of the background image in percent of the parent element. Now if the html goes like this:
<section>
<p>Background-size by percentage.</p>
</section>
and I set up background image for <p>. Now which one is the parent element of the background image, <p> or <section>? Thanks.
Parent element means the background image's parent. It's <p>.
Try to set different width on <p> and <section>, like width: 500px and width: 1000px
You will get it.
Related
This question already has answers here:
Percentage Height HTML 5/CSS
(7 answers)
Closed 1 year ago.
In html I have a container in the body to contain every element and I want it to take up the whole height of the page.
When I make the height 100% it only sets it to the size needed to contain the elements, so I have to apply 100vh to the height for it to work. How can I make setting the height to 100% work?
The html and body elements themselves don't have 100% height, so setting the height of something in them to 100% doesn't work. You need to set the html and body elements to 100% as well
html, body {
height: 100%;
}
This question already has answers here:
CSS: Width in percentage and Borders
(5 answers)
How to make an element width: 100% minus padding?
(15 answers)
Closed 2 years ago.
I have 3 issues:
I can see a part of the parent white background bottom (& right side sometimes) under its child that have a 100% width & height (see green arrow on my screenshot)
The child width is set to 100% but when i inspect it is larger than the parent (see the red arrow on the screenshot)
My line-height is line-height:30px; and my font-size:30px; but there is a different spacing on top and bottom of the text (see the blues arrows on my screenshot). This prevent me from centering correctly vertically my text
Note: My browser zoom is on 100%
Fiddle: https://jsfiddle.net/gr85n2es/
This question already has answers here:
Applying a background to <html> and/or <body>
(2 answers)
Why does styling the background of the body element affect the entire screen?
(7 answers)
Closed 4 years ago.
Hi I'm newbie in HTML and CSS, sorry if my question sounds too basic:
I set background color to be green for element as the picture below shows:
You can see that the content of is currently 366*18, and according to W3C:
The background of an element is the total size of the element, including padding and border (but not the margin).
so green color should only apply on the content of whose size is 366*18, since the height is 18px, so the green color should only apply with a height of 18px, but why green color applies all the way down to the end of the page?
You want to target just the 'p' tag here.
Inline:
<p style="background-color: green"></p>
or CSS:
p { background-color: green; }
This question already has answers here:
Scale div to fit background image
(4 answers)
Closed 5 years ago.
Can I stretch a div to fit the background image's width and height using only CSS? And if yes, how?
Div has width and height unset.
I am NOT asking how to scale the image into a div.
I am NOT asking how to scale the image into a div with specific width and height.
ie.
<div class="banner"
styles="width: auto; height: auto; background-image: url(unknown-size-img.jpg)">
</div>
I have a suggestion, but may not be a good method.
Put the same image as a tag inside the DIV. So the container div will take the same size of the . Then make the zero opacity and may be pointer-events 'none' like below
<div class="banner" styles="width: auto; height: auto; background-image: url(unknown-size-img.jpg)">
<img src="unknown-size-img.jpg" alt="image" title="image" style="opacity:0 ; pointer-events: none" />
</div>
This question already has answers here:
Shrink-to-fit div and paragraph, based on image?
(6 answers)
Closed 8 years ago.
I have a div with an img and a p tag. I want the div to "shrink-wrap" the image and let the text organically wrap. However, I'm trying to do this with absolutely no javascript or constraints (ie width=300px / 50% etc) as my frame needs to be fluid.
Here's an example of something similar to what I have now: How can I make the outer dive match the size of the "Google" image without using fixed sizes or javascript?
http://jsfiddle.net/pVF74/
div {
border:1px solid black;
display:table;
width:1%;
}
http://jsfiddle.net/pVF74/2/
Add display: inline-block; to your div's class.
Example here http://jsfiddle.net/r9rLr/