Why is my button not fully lining up? - html

I've got a button posted here:
http://buttontest.raptorshop.com/
But for some reason, it isn't entirely lining up. What can cause this?
I tried changing line height, padding, etc.
Here's the CSS code I have:
a.gbutton {
background: transparent url('buttonside.png') no-repeat scroll top right;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 82px;
margin-right: 6px;
padding-right: 46px; /* sliding doors padding */
text-decoration: none;
}
a.gbutton span {
background: transparent url('buttonmain.png') no-repeat;
display: block;
line-height: 68px;
padding: 5px 0 5px 18px;
}
I am modifying this from a tutorial I found online, and perfect CSS placement has always been a difficult item for me.

The sliding door technique works because extending a rectangle won't change its look. But extending a ellipse will, so your code won't work as you expect.
Here is the best I could get:
a.gbutton {
background: transparent url('buttonside.png') no-repeat scroll right top;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 82px;
margin-right: 10px;
padding-right: 51px;
text-decoration: none;
}
a.gbutton span {
background: transparent url('buttonmain.png') no-repeat left top;
background-size: 100% auto;
display: block;
line-height: 68px;
padding: 5px 0 5px 18px;
height: 100%;
width: 100%;
}
Update
Just use a single image and specify the CSS:
background-size: 100% auto;

Related

Button with image

I have this code:
.subbmitCommentBtn {
background: url("../images/ikon2.png") no-repeat center top;
padding-right: 15px;
padding-left: 15px;
color: white;
cursor: pointer;
height: 56px;
width: 253px;
background-color: #AF191F;
background-position: left;
background-repeat: no-repeat;
font-weight: bold;
border-radius: 20px;
border: none;
}
<input type="submit" value="Dodaj komentarz" class=" subbmitCommentBtn">
I need to add more space on the left. I would like the picture to move away from the left edge of the button (ex. padding left:10px).
How to fix it?
You need to set the background-position rather than the padding. By default, the background also covers the padding, so changing the padding doesn't influence that.
.subbmitCommentBtn {
background: url("https://i.stack.imgur.com/HOZcL.png") no-repeat center top;
padding-right: 15px;
padding-left: 15px;
color: white;
cursor: pointer;
height: 56px;
width: 253px;
background-color: #AF191F;
background-position: 10px top; /* changed from "left" */
background-repeat: no-repeat;
font-weight: bold;
border-radius: 20px;
border: none;
}
<input type="submit" value="Dodaj komentarz" class="subbmitCommentBtn">
Please note that I also had to change the background image URL for the purpose of this snippet, so don't copy the whole bunch over.
Use background-position to get padding effect. An example below:
.subbmitCommentBtn {
background: url("https://cdn.pixabay.com/photo/2018/02/04/01/54/paper-planes-3128885_1280.png") no-repeat; /* added an image for snippet */
background-size: 40px 40px; /* set background-size: 40px width and 40px height */
background-position: 15px center; /* left:15px and vertical-align:middle */
color: #f4f6f9;
cursor: pointer;
height: 56px;
width: 253px;
background-color: #d94452;
font-weight: bold;
letter-spacing: 1px;
border-radius: 20px;
border: none;
}
<input type="submit" value="Dodaj komentarz" class="subbmitCommentBtn">

Aligning background image for a div element in css

So I am new to css,and have been trying to develop a basic website as a college project,but I am having problems aligning the background image for a div with class name mainhead,it leaves a whitespace at left of the screen.
Whatever width I set it to,there is a blank white space on the left.
I dont know what to do,I havent set any padding or margins and also specified left: 0px,but no joy.
The class I am having problem with is the mainhead class
Here is the code,please help!
.loginbox
{
position: fixed;
top: 0px;
margin: 0px;
left: 0px;
font-weight: bold;
background-color: #2C2C2C;
text-align: right;
width: 1370px;
height: 40px;
}
.loginbut
{
background-color: #2C2C2C;
font-family: "Avant Garde",Avantgarde,"Century Gothic",CenturyGothic,AppleGothic,sans-serif;
font-size: 100%;
color: #c9c9c9;
text-align: right;
margin-right: 50px;
margin-top: 5px;
border-color: #2C2C2C;
border-radius: 8px;
top: 10px;
text-decoration: none;
outline: none !important;
}
.loginbut:hover
{
background-color: #000000;
}
.mainhead
{
background-image: url("grey.jpg");
background-repeat: none;
border: 1px solid black;
font-family: "Avant Garde",Avantgarde,"Century Gothic",CenturyGothic,AppleGothic,sans-serif;
top: 40px;
width: 1360px;
height: 170px;
color: #c9c9c9;
text-align: center;
}
.mainhead h1
{
font-family: "Avant Garde",Avantgarde,"Century Gothic",CenturyGothic,AppleGothic,sans-serif;
font-size: 300%;
}
Use background-position: center center; and background-size: cover; and remove width from mainhead. Hope it should work
http://www.w3schools.com/cssref/playit.asp?filename=playcss_background-size&preval=cover
Try using this reset code by Eric Meyer enter link description here and also set the .mainhead div to 100%.

Having a sprite image inside a button with text

I'm trying to create a button and here is the demo so far.
Right now I can't figure out how I can position the sprite image so that only the black icon is visible.
Does anyone know how I can fix this?
This is what I want to achieve with the button:
No hover:
Hover:
Here is the code I have:
HTML:
<a class="top-language" href="#" alt="Choose your language">Language</a>
CSS:
.top-language {
border: 1px solid #ddd;
padding: 5px;
text-decoration: none;
color: #000;
position: relative;
font-weight: bold;
font-size: 13px;
padding-right: 10px;
padding-left: 35px;
background: url("http://imageshack.com/a/img853/7081/1u5z.png") no-repeat 0 0;
}
.top-language:hover {
background: url("http://imageshack.com/a/img853/7081/1u5z.png") no-repeat 0 -22;
}
This will work. Here is a jsfiddle
.top-language {
border: 1px solid #ddd;
width: 100px;
color: #202020;
padding-left: 10px;
padding-right: 10px;
display: block;
font-weight: bold;
font-size: 13px;
width: 80px;
margin: 0;
line-height: 22px;
text-align: right;
text-decoration: none;
background: url("http://imageshack.com/a/img853/7081/1u5z.png") no-repeat top left ;
}
.top-language:hover {
background-position: bottom left;
color: #d13030;
}
You can either:
a. reduce the height of the button;
b. increase the vertical gap between the two sprites in the image itself;
c. background: url(...) no-repeat 0 2px; adjust the value to push out the red icon
.top-language {
display: block;
width: 22px;
height: 22px;
font-size: 13px;
background: url('http://imageshack.com/a/img853/7081/1u5z.png') bottom;
text-indent: -99999px;
}
.top-language:hover {
background-position: 0 0;
}
You can provide image display position as follows:
display:inline-block

CSS3 Child Elements Width Not Respecting Parent Container Width

I am trying to keep my ul and li elements that are inside of a div to respect the div's width with margin-left: auto. I am also not wanting ul/li to extend out of the div. I want the ul and li elements to stay inside the div container. From what I have read, this code is correct because I have the child elements contain a width which should be according to div's width.
#phonequeue {
display: block;
width: 400px;
height: 800px;
border-width: 5px;
border-color: white;
border-style: solid;
float: right;
margin-top: -650px;
}
li {
display: block;
padding: 15px;
text-align: left;
height: 1.2 em
padding-left: 15px;
padding-right: 15px;
margin: 0px 0px 4px 0px;
background-color #555
-webkit-border-radius: 15px;
border-radius: 40px;
background: -webkit-gradient(linear, 0% 0%, 0% 30%, from(#444), to(#111));
font-family: verdana, arial, helvetica, sans-serif;
font-size: 22px;
width: 100%;
margin: auto;
}
ul {
list-style-type: none;
width: 100%;
margin: auto;
}
index.html:
<div id="phonequeue">
<ul>
<li class="avail">
<span class="pname">John Doe</span>
<span class="ptime">03:00</span>
</li>
</ul>
</div>
UPDATE: Here is a working example. The element width is 430px; when the parent div is 400px;. I would the child elements to center themselves in div and have their width respecting the parents width. http://jsfiddle.net/FBvQJ/4/
I believe the problem was with the use of width: 100%
Check this jsFiddle and let me know if this answers your question.
This is the updated CSS to solve the overlapping width:
phonequeue {
display: block;
width: 200px;
border: 1pt solid green;
}
ul{
border: 1pt solid red;
list-style-type: none;
margin: auto;
padding: 0;
}
li {
display: block;
padding: 15px;
text-align: left;
height: 1.2em;
margin: 0px 0px 4px 0px;
-webkit-border-radius: 15px;
font-size: 22px;
margin: auto;
border: 1pt solid #ccc;
}
I don't think you need to define the full width for each element.
If you'd like the text centered in the DIV, remove the width on the LI tag and make the margin:
margin: 0px auto 4px auto;
That will center the text within the div.
If I'm understanding your question correctly (which is dubious) I believe you can achieve the centering you require by removing the 100% widths and using text-align:center:
li {
display: block;
padding: 15px;
text-align: left;
height: 1.2 em;
padding-left: 15px;
padding-right: 15px;
margin: 0px auto 4px auto;
background-color #555;
-webkit-border-radius: 15px;
border-radius: 40px;
background: -webkit-gradient(linear, 0% 0%, 0% 30%, from(#444), to(#111));
font-family: verdana, arial, helvetica, sans-serif;
font-size: 22px;
text-align:center; /* < this (or not, if you don't actually want it centred after all) */
}
ul {
list-style-type: none;
padding:0; /* < and this */
margin: 0;
}
Demo fiddle
And later, when you decide that you want the time on the right use
.ptime {float:right;}
example

Align text vertically center of h2 tag with a background

I have a h2 tag that has a background image as an icon. I want to align the text vertically within the h2 tag but it doesn't work. I have tried using the display: table-cell; but that hasn't worked either. The text may also crossover onto two lines.
HTML:
<ul class="FeatureRow">
<li><span><h2 class="SpeechBg">Need some help?</h2><p>Feel free to get in contact with us</p></span></li>
<li><span><h2 class="PinBg">Great locations!</h2></span></li>
<li><span><h2 class="ViewBg">View our apartments</h2></span></li>
</ul>
CSS:
a {
color: #2b6893;
text-decoration: none;
}
.FeatureRow{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.FeatureRow li{
float: left;
padding: 10px;
margin: 10px;
height: auto;
-webkit-box-shadow: 0px 4px 8px #f5f5f5;
-moz-box-shadow: 0px 4px 8px #f5f5f5;
box-shadow: 0px 4px 8px #f5f5f5;
background-color: #fdfdfd;
background-image: -moz-linear-gradient(top,#fbfbfb,#ffffff);
background-image: -webkit-gradient(linear,0 0,0 100%,from(#fbfbfb),to(#ffffff));
background-image: -webkit-linear-gradient(top,#fbfbfb,#ffffff);
background-image: -o-linear-gradient(top,#fbfbfb,#ffffff);
background-image: linear-gradient(to bottom,#fbfbfb,#ffffff);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbfbfb',endColorstr='#ffffffff',GradientType=0);
filter: progid:DXImageTransform.Microsoft.gradient(enabled= false);
}
.FeatureRow span{
display: block;
width: 260px;
}
.FeatureRow h2{
background-repeat: no-repeat;
padding-left: 65px;
font-size: 22px;
height: auto;
min-height: 60px;
color: #3F92ED;
}
.SpeechBg{
background-image: url(http://joshblease.co.uk/Apartments/images/icons/speech.png);
}
.PinBg{
background-image: url(http://joshblease.co.uk/Apartments/images/icons/pin.png);
}
.ViewBg{
background-image: url(http://joshblease.co.uk/Apartments/images/icons/view.png);
}
JSFiddle Example: http://jsfiddle.net/YPnTp/
In .SpeechBg, .PinBg, and .ViewBg, add line-height: ##px;, where ## is the height (in px) of the background images.
Change your
.FeatureRow h2 , add line-height
css as follows
.FeatureRow h2{
background-repeat: no-repeat;
padding-left: 65px;
font-size: 22px;
height: auto;
min-height: 60px;
color: #3F92ED;
line-height:2.5em;
}