I have a division that has a background image but it needs to be a varible size. I'm using three images. One of the top, one for the bottom and a repeating one for the middle.
I've only got one div to work with and given the middle background image to that and then used the before and after pesudo classes to place the other images. The image from the main division shows up behind these two since they are semi transparent. Is there a way round this in css or a better method to do it?
HHTML:
<div class="faq">
<strong>Q. Who was the greatest business man?</strong><br />
<p><strong>A. </strong>Noah. He kept his stock afloat, while the rest of the world went into liquidation.</p><br />
<strong>Q. How should my employees let off steam?</strong><br />
<p><strong>A. </strong>Take them see to see the comedian Sampson. He'll bring the house down.</p><br />
</div>
CSS - style
.faq{
background: transparent url(../images/image_middle.png) repeat-y center;
color: #ffffff;
display: block;
}
.faq:before {
background: transparent url(../images/image_top.png) no-repeat center top !important;
}
.faq:after {
background: transparent url(../images/image_bottom.png) no-repeat center bottom !important;
}
CSS - layout
.faq:before {
padding-top: 20px;
display: block;
content: "\A";
}
.faq:after {
padding-top: 14px;
display: block;
content: "\A";
}
.faq{
margin: 20px 0 5px !important;
padding: 0 20px 0 15px !important;
}
The best way to do this is by using multiple backgrounds - see https://developer.mozilla.org/en-US/docs/CSS/Using_CSS_multiple_backgrounds. in this way, you can specify the 3 different images and their positions as styles for the element. List the top image first.
If your browser support requirements won't work with CSS multiple backgrounds, you can get the same result by styling other elements - such as a h1 or p:last inside your div. This approach is more complicated, since you have to be very careful about the position of elements inside that div.
Note that a background or image will always show through transparent areas of an image above it. If you don't want this, you must put something opaque into that cover-up image - such as the background color that you're trying to fade to.
For more detailed help, please post a self contained example of the code you're working with.
Related
I am trying to avoid using position absolute for my mobile-first, responsive website./ I am having a tough time getting the h1 and p tag in front of the image. With position absolute comes more troubles down the road, so I would like to avoid that. Also any advice for dealing with those svg lines or should I remove them? Here's my code:
.climate {
padding: 2em 1em 5rem;
}
.reverse {
font-size: 2.5rem;
font-weight: var(--fw-normal);
color: var(--clr-light);
z-index: 10;
}
.disaster-graphic {
background-color: var(--clr-background);
}
.graphic-image {
z-index: 1;
margin: -150px 0 0 205px;
padding: 0;
}
.greenroof {
max-width: 600px;
}
<section class="climate disaster-graphic">
<h2 class="reverse">Reverse the climate disaster</h2>
<p class="orange">Learn what it takes to bring your business to the next level.</p>
<div class="graphic-image">
<img src="/images/greene 1.png" class="greenroof">
</div>
z-index can be tricky. Unfortunately, when working with z-index you have to at least position the element of which you are trying to move along the z-axis. Some helpful reading about z-index:
4 reasons your z-index isn't working (and how to fix it)
To solve your problem, you can simply add position: relative to your .graphic-image. Furthermore, change it's z-index from 1 to -1. Lastly, you do not need to have a z-index: 10 on .reverse. On elements where z-index is not specified, it is set to auto (0). So in this case -1 < 0.
I used a placeholder image and also changed the color of your text just so you can see it in front of the image.
Regarding your "SVG lines", you'll have to post some more code to get further assistance with that issue.
body{
color: goldenrod; /* to be removed, just so you can see the text in front of image */
}
.climate {
padding: 2em 1em 5rem;
}
.reverse {
font-size: 2.5rem;
font-weight: var(--fw-normal);
color: var(--clr-light);
/*remove z-index: 10 */
}
.disaster-graphic {
background-color: var(--clr-background);
}
.graphic-image {
z-index: -1; /*change z-index to -1*/
margin: -150px 0 0 205px;
padding: 0;
position: relative; /*add position*/
}
.greenroof {
max-width: 600px;
}
<section class="climate disaster-graphic">
<h2 class="reverse">Reverse the climate disaster</h2>
<p class="orange">Learn what it takes to bring your business to the next level.</p>
<div class="graphic-image">
<!-- placeholder image -->
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/800px-Image_created_with_a_mobile_phone.png" class="greenroof">
</div>
z-index only sets the z-order of a positioned element or a flex item. That is to say z-index does nothing unless either you specify the position of the element or the element is a flex item. In your case neither of those are true so z-index does nothing.
The easiest solution is to simply add position: relative to .reverse and .orange.
I've quickly put together a working codepen for context.
Regarding the svg lines, there are many ways you could deal with them but it depends what your goal is. I am going to assume you always want them "attached" to the orange box like in the image you've shared but don't want their existence to impact the layout of the rest of the elements.
That being the case, I would suggest using position: absolute on the svg with the svg element being a direct child of .orange (which you will have now added position:relative to solve your z-index issue). This will "attach" the svg to the orange box so that wherever the orange box goes, the green lines go too. It would be helpful to see more of your code so that part of your question could be answered in more detail.
Personally I would have made the orange box an element and placed the <p> tag inside it rather than styling the <p> to look like text inside and orange box. You may have had a reason for doing it your way though. The codepen I added above contains my solution for the svg lines by the way.
So I have probably an easy question to answer...
I am working on the site fairhopemicrocottages.com, and on the "About" page, the bullet points using the "li" tag are not aligned properly.
I want the bullet points to be on the first word, not in the middle of the 2 sentences. Very annoying.
This is definitely caused by the fact that I took this site design from another site I found, and worked around the CSS, but cannot edit the CSS. (Or can I?)
If someone can help me with a work around to solve this problem, that would be great! Thanks!
Bonus question: On the front page, I like the picture I found, however it does not blend in well with the navbar text and my image, the text is hard to see for old people like my parents.
Is there a work around to change the color of that section at the top to black? Just so the text and image can be read easily?
On line 56 in your stylesheet is something like this:
li {
background: black url("../img/list.png") no-repeat scroll left center;
}
Change it to left top, and it moves it up:
background: black url("../img/list.png") no-repeat scroll left top;
But that's not good on your li's - they are too high then, so set a specific top like so:
background: url("../img/list.png") no-repeat scroll left 10px;
To fix the issue in your top nav to change it to black, just add background to that section:
#slideshow header, .black header {
border-bottom: 1px dotted rgba(255, 255, 255, 0.15);
position: relative;
z-index: 10;
background: black;
}
You are replacing default list bullets with a custom background and that background has a centered position, therefore:
li { background: url("../img/list.png") no-repeat left 11px; }
By replacing the left center with left 11px, your bullets will appear where you want them to.
Additionally, you could solve this by changing up your styles:
Add this style:
ul {
list-style: url("../img/list.png");
}
Remove this style:
li {
background: url("../img/list.png") no-repeat left center;
}
I'm fairly new to CSS / HTML, but usually can figure something out. Not with this issue though... I've spent 2 days trying to fix it with no joy
Using WP 3.9.1 and WooThemes Mystile which comes with a custom css to make changes in; no child theme needed. When I place images with captions on a page using left align, some will and others vigorously refuse. In older WP, it was always align all images left to create rows, but not with 3.9.1 it seems. I've tried everything I can think of, but those images that are supposed to be aligned left are actually right of center.
Using Firebug or Safari Inspector, I've tried to align them left and even using a negative margin-left will not place the image where it belongs. It's almost like there's some kind of page break, for lack of a better term, that is making it set right of center. Like it thinks that position is left.
I am not using any gallery or plugin, just adding images to the pages with captions in the text box, not visual. Most of my Galleries under Store are a mess. :(
Here's an example of one: Tuscany Gallery Most of the Galleries I want 2 landscape in a row or 3 verticals. Sometimes with an odd number of images I might center 1 - 3 images, but most are left align.
Any help would be very appreciated! Thanks!
Re: the Body css code
I have a few color changes and more div#attachmet_number (didn't think you needed all them), but this is about it.
:active, :focus {
outline-style: none !important;
-moz-outline-style:none !important;
}
a {
outline-style: none;
-moz-outline-style: none;
}
a:before {
outline: none !important;
}
a:imag {
outline: 0px none;
}
#sidebar .post-46 {
display: none !important;
}
article.post-46 img.alignleft {
margin: 0 1.618em 1em 16px;
}
.post .alignleft, .type-page .alignleft {
margin-bottom: 50px;
}
.post-282 .wp-caption img, .type-page .wp-caption img {
margin: 0 0 0 0.4em;
}
div#attachment_283 {
margin-left: 42px;
}
div#attachment_286 {
margin-left: 42px;
}
div#attachment_291 {
margin-left: 42px;
}
I'm not quite sure if that's what you need or not. The div#attachment_number is the image within a box with caption (title) below it.
HTML of images with caption
[caption id="attachment_516" align="alignleft" width="407"] Duomo di Pisa[/caption]
Following your comments above on your question, your fourth photo (Autumn Drive) specifically is getting pushed to the right by the bottom edge of your second photo (Duomo di Pisa).
It appears that you've added a specific width to each div in your HTML. If you were to add there also a specific, equal height to each div, then they would align and allow the divs below to float to the left.
A greater ideal might be to declare a class for your landscape-oriented divs in your CSS, define a uniform width and height there, and assign that class to all landscape-oriented divs. That way, you could easily change that width and height in one place, and it would apply to all divs with that class assigned (and multiple classes can be assigned to a single div; just separate them by spaces, like class="landscape framed dark" for example).
I read once how to create cross-browser rounded buttons with shadow using images, I lost my bookmarks unfortunately that's why I ask does anybody remember the technique.
There is left side picture i.e
And then very wide body image which ends up with right curved border/shadow like this :
So at the end you end up with one button which can be used with multiple sizes? I was googling this, but it seems noways everyone use css without images.
Does anybody knows how this technique is called or can refer me to the link? or give me code example, I'd appreciate any of those
When using an image for the start and one for end of the button, these technique is called "sliding doors" and there are myriads of search results with any search engine…
For an introduction read the A List Apart article: http://www.alistapart.com/articles/slidingdoors
But as Neurofluxation asked you in the comment above: Why the hell would you do that years after we have multiple other methods of styling a button in CSS? The A List Apart article for example is from 2003 - which is an age in Internet terms.
This technique is a variation of the "Sliding Doors" technique:
http://www.alistapart.com/articles/slidingdoors/
http://css-tricks.com/snippets/css/perfect-css-sprite-sliding-doors-button/
http://azadcreative.com/2009/03/bulletproof-css-sliding-doors/
Basically you use markup like this:
<button><span>Text</span></button>
Then style the span with the edge image to the side, overlapping the main background image of the parent element. Something like this:
button {
background:url(main-image.png) top right no-repeat;
border:0;
padding:0;
width:80px; /* with only 1 "door", you might need to set a width */
/* other resets may be necessary */
}
span {
background:url(left-door.png) left top no-repeat;
}
button, span {
height:37px; /* height of your sprite */
display:block;
}
Demo: http://jsfiddle.net/Kqs3m/
Your results may vary depending on your sprites and the natural width of the content.
Here's the technique which I think you are looking for (using the same images you attached):
HTML:
<a href="#" class="button">
<span>Small</span>
</a>
<a href="#" class="button">
<span>Large button</span>
</a>
CSS:
.button {
background: url('http://i.stack.imgur.com/htUHL.png') no-repeat left top;
padding-left: 9px;
height: 37px;
display: inline-block;
text-decoration: none;
color: #555;
text-shadow: 0 1px 1px #FFF;
font-family: sans-serif;
font-size: 0.8em;
}
.button span {
background: url('http://i.stack.imgur.com/ID6nO.png') no-repeat right top;
display: inline-block;
height: 37px;
padding: 5px 12px 5px 3px;
}
.button:hover span {
color: #333;
}
Link to the demo: http://jsfiddle.net/v284q/
Using CSS properties instead of images can make your applications faster.
In this case you could just use: Border-Radius, Box-Shadow combined with a gradient background.
Here you can find a good Gradient Editor:
http://www.colorzilla.com/gradient-editor/
How to use Border-radius and Box-shadow:
http://www.css3.info/preview/rounded-border/
http://www.css3.info/preview/box-shadow/
Right now we have a web page with a bunch of link sections on one page. Each section has a header like so:
This header background is actually two images. The first is just a rectangle and the second has the slanted side on it. As I was looking at this solution, I was wondering if I could solve this with CSS instead of images. While I am not a CSS guru, I did look at a number of examples and was able to get something similar working. However, when I attempt to put text on top of the background, it ends up above the color instead of inside it. The CSS I have also has a fixed size, which is less than idea. I would rather specify a percentage of the available area and have it fill in the color.
Here is the code I've been working with:
<STYLE type="text/css">
.mini_banner
{
display:inline;
border-bottom:30px solid blue;
border-left:0px solid transparent;
border-right:30px solid transparent;
}
</STYLE>
I wanted to apply this to a cell in a table. I also don't want to break compatibility with modern browsers. My "customers" (mostly internal people) are going to be primarily on IE8 or later but I don't want to limit myself if I can help it.
So first, is this possible? Second, how would I accomplish this? And third, is there a way to make it relative in scale instead of fixed?
I would say that you'll have less headaches all the way around if you revert to using a single background image - in this case, a white image with the notch cut out (a PNG-24 with alpha transparency). Make it bigger than you think you need by about 200%, then do something like this:
.minibanner {
background: blue url(..images/notch.png) no-repeat middle right;
font-size: 1.5em;
}
The reason is that relying on border sizes may result in some whackiness across browsers, and it will definitely look weird if any element runs to two lines.
If you make the notch image 200-300% larger, but vertically align it in the middle of the background, and you do increase the font-size, the box will grow, but your white notch will grow right along with it.
UPDATE:
The only other way I can see pulling this off is to add a non-semantic element, such as a or something similar, after your text:
<div>
<p>Hello text</p>
<span></span>
</div>
Then in your CSS:
p {
background: blue;
color: white;
float: left;
padding: 0 20px;
height: 50px;
margin:0;
line-height: 50px;
}
span {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 0px solid transparent;
display: inline-block;
border-left: 50px solid blue;
}
See this JSFiddle.
The shape is based on this tutorial on CSS triangles. Now, I've only tried this on a webkit based browser, and it works. You will have to adjust the heights every time you want to change font size, so that is a drawback.
I made it work without an extra span: jsFiddle
.mini_banner
{
width:18em; height:1.5em;
color:white; font-weight:bold; padding-left:0.5em;
margin-bottom:.5em;
}
.mini_banner:before {
display:inline-block; content:''; overflow:hidden;
width:17em; height:0;
margin-bottom:-1.5em; margin-left:-.5em;
border-bottom:1.5em solid blue;
border-right:1.5em solid transparent;
}
Tested in FF, Safari, Opera and IE. (Works in IE8, but not in IE7)