Extend length of button using CSS - html

I have the following snippet of HTML code which displays a button.
<span class="xp-b-submit xp-b-submit-btn xp-b-right">
Post Search
</span>
In addition to the HTML code, there is the CSS style sheet.
.xp-b-submit-btn {
background-attachment: scroll;
background-clip: border-box;
background-color: transparent;
background-image: url("../../images/new_blue_button.png");
background-origin: padding-box;
background-position: -1px 50%;
background-repeat: no-repeat;
background-size: auto auto;
}
.xp-b-submit {
background-position: right -32px;
}
.xp-b-submit, .xp-b-leftSide, .xp-b-submit-large, .xp-b-submit-large .xp-b-leftSide {
background-attachment: scroll;
background-clip: border-box;
background-color: transparent;
background-image: url("../images/buttonBG.png");
background-origin: padding-box;
background-position: 0 0;
background-repeat: no-repeat;
background-size: auto auto;
display: block;
}
.xp-b-right {
float: right;
}
The problem that I'm facing is the my button is not long enough. I want to extend it by about 20px but I'm quite new to CSS, and what I'm doing is taking pre-existing code, and modifying it. I've been playing around with the attributes in Firebug, but I have no idea where to start, what tabs are responsible for affecting what elements, etc.

Ok, here are a couple of options:
This changes the padding, adding 10px on each side, giving you something closer to the desired width. Presumably the padding is not already at 0, so it's not exactly 10px additional on each side. You can adjust to your liking. (Think of padding as the distance between your content/text and the edge of the container, which in this case is the button)
padding-left: 10px; padding-right: 10px;
This sets the exact width of the element (again, in this case that would be the button). Adjust the 500px value to match your needs.
width: 500px;

give the xp-t-bold class padding. That will increase the width of the parent span as well.
.xp-t-bold
{
padding:20px; // overall width will be increased by 40px.
}

I added width to your .xp-b-submit-btn class. (Also a border, so you could see what is happening... you can remove it.)
.xp-b-submit-btn {
background-attachment: scroll;
background-clip: border-box;
background-color: transparent;
background-image: url("../../images/new_blue_button.png");
background-origin: padding-box;
background-position: -1px 50%;
background-repeat: no-repeat;
background-size: auto auto;
width:95px;
border:1px solid black;
}
http://jsfiddle.net/jasongennaro/HPVmv/

Related

span with background-image become bigger

https://jsfiddle.net/r7d5fLe4/
<span class="emote" style="background-image: url(https://static-cdn.jtvnw.net/emoticons/v2/90076/default/dark/1.0);">
I have some same spans with background-image.
Why the images become a little bigger except the last one in a line?
I suggest doing this on your body with CSS only. Putting it on a span could be problematic. Unless you want it to only be the background of an independent section, then I would use a div instead of span. (See example two). See the CSS changes in example one.
example one
body {
background-image: url('https://static-cdn.jtvnw.net/emoticons/v2/90076/default/dark/1.0');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
padding: 0.4em 0.2em;
position: relative;
box-sizing: border-box;
}
example two
div {
width: 100px;
height: 100px;
background-image: url('https://static-cdn.jtvnw.net/emoticons/v2/90076/default/dark/1.0');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
padding: 0.4em 0.2em;
position: relative;
box-sizing: border-box;
}
<div></div>
All in all, I suggest a higher-res (larger) image for a background.

Basic SVG background image size property

I wish i never had to ask this but im confused.
So i have a basic background image on my div and for some reason when i set the background-size: 246px 70px; it does not work, only if i use !important it works.
.footer div.image-logo {
height: 70px;
width: 246px;
background-size: 246px 70px;
background-position: center;
background: url(/images/svg/five_Logo.svg) no-repeat;
margin: 20px auto;
}
Now basically you would think other css is overwriting it, well thats my rookie thought but it is not, when i inscpect the div with the background image, and click the tab "computed" to check the current state of the background-image-size it says background-size:auto;, and when i click on this to see where it gets the property auto it shows 246px 70px style.css?ver=1.0.5:2266 .footer div.image-logo which is the css where i set my background size to background-size: 246px 70px;.
I would like to be able to set the background size without using !important
The background shorthand includes background-size:auto and this is overriding your previous background-size statement.
Put the background-size statement after the background shorthand statement.
div {
width: 400px;
height: 300px;
margin: 1em auto;
}
.one {
background-size: 200px 100px;
background: url(http://www.placebacon.net/400/300) no-repeat; /* I win */
}
.two {
background: url(http://www.placebacon.net/400/300) no-repeat;
background-size: 200px 100px; /* I win */
}
<div class="one"></div>
<div class="two"></div>
Syntax is;
background-image
background-position
background-size
background-repeat
background-attachment
background-origin
background-clip
background-color
Ex:
body {
background-image: url(photo.jpg);
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
background-origin: padding-box;
background-clip: border-box;
background-color: #ccc;
}
Therefore you might want to re-order. (Clear cookies as well)

CSS image width 100%, but still has some background

I have the following website:
www.thewhozoo.com
It works fine on a desk top, but for some reason on a mobile device's browser, it has a grey bar down the side.
I have the following code:
css
body {
background-color: #4B5961;
width: 100%;
margin: 0;
}
.top-container {
float: left;
width: 100%;
background: linear-gradient( rgba(0,0,0,0.1), rgba(0, 0, 0, 0.1) ),url('../images/background1.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
html
<body>
<div id="image-head" class="top-container">
The grey line down the side is the same as the background color of the body (#4B5961).
As you can see, I have the body width and the background image width both set at 100%. So I would not expect to see the grey line. I think it is a result of the scroll bar.
If anyone can advise how I can remove this, I would appreciate the help.
Check your style this css rule, take out the padding-left: 10px;:
.wz-title {
color: #B2D137;
font-weight: bold;
/* padding-left: 10px; */
font-size: 110%;
text-shadow: 0px 0px 10px rgba(0,0,0,0.7), 0px 0px 1px rgba(0,0,0,0.4);
}
Remove the padding with .wz-title. For some reason, removing padding fixes it.
.wz-title {
padding-left: 0;
}
Here:
Set overflow-x:hidden; on your body, that'll fix it:
body {
overflow-x:hidden;
}
Try this:
body, body * {
box-sizing: border-box;
}
By using above code you will never face any problem with padding ever. :)

background-clip with background-size cover beaks cover?

I have a div with a background image. I want the image to always have at least a 1% left and bottom margin/padding. The container of the div is a dynamic absolutely positioned box which can have a size of 5% or 95% (and everything in between with CSS transition).
I chose to achieve this by putting the background-image on that div which has min-height of 5% and width of 100%. The background is not repeating, centred and set to be contained within the area (background-size: contain). I decided to go with a 1% padding and background-clip CSS property to content-box, which should mean that the background covers only the content which starts at 1% away from the border. I chose padding and not margin, because box-sizing is set to border-box, therefore a width 100% with additional padding would not increase the size of the div which is not the case with margin.
However this did not work as expected:
When using background-clip: content-box together with background-size: contain, the background is contained within the border-box and not content-box and the padding cuts away the areas between the content and border.
Example:
div {
background-size: contain;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url(http://www.ghacks.net/wp-content/uploads/2011/04/standard-google-image-search.jpg);
float: left;
width: 200px;
height: 200px;
}
.clipped {
border: 1px solid blue;
padding: 20px;
background-clip: content-box;
}
.normal {
border: 1px solid green;
padding: 20px;
background-size: contain;
}
<div class="clipped">
</div>
<div class="normal">
</div>
So the questions are:
Is this the normal behaviour?
Where is this documented?
What would be the solution to achieve what I need?
p.s. I am not English so apologies for possible mistakes or misconceptions. Also I will try to explain better in case you did not understand the issue.
Yes, this is normal behavior. The content-box does not mean the image is sized within it, it means it gets clipped by it.
https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip
In below sample I used a pseudo class to achieve it
div {
position: relative;
float: left;
width: 200px;
height: 200px;
border: 1px solid blue;
}
div::before {
content: '';
position: absolute;
left: 20px;
top: 20px;
right: 20px;
bottom: 20px;
background-size: contain;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url(http://www.ghacks.net/wp-content/uploads/2011/04/standard-google-image-search.jpg);
}
<div>
</div>

Percentage width and height hides background image

Demo
.moving_background
{
background-image: url("../image/quote3.jpg");
background-position: 50% center; /*Centering property*/
background-repeat: no-repeat;
height: 100px;
margin: 20px;
width: 100px;
border:1px solid;
}
If i change the width and height to 100%, it is not showing the border to me. I don't understand the reason. Please let me know this
I am trying to center this div in the body. Any other ways are also welcome except negative top, left, margin values.
Any idea?
The issue is that background-image does not count as content in your div, so what you have is an empty div, hence it has no height. A way around this is to add the image inside the div, then hide it.
HTML
<div class="moving_background">
<image src="http://placehold.it/100x100" class="background"/>
</div>
CSS
.moving_background {
background-image: url("http://placehold.it/100x100");
background-position: 50% center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
margin: 20px;
width: 100%;
border:1px solid;
}
.background {
visibility: hidden
}
JSFiddle: http://jsfiddle.net/nhg33xek/4/