Button moves down whenever I place text in it - css

I am trying to make a TicTacToe game as my first project and for some reason no matter what I do when I click one of the cells they go down a line and are not in the same row as the others.
this is an example
here is the css:
button {
width: 30%;
height: 200px;
text-align: center;
line-height: 0.85px;
cursor: pointer;
display: inline;
margin: 0px;
font-size: 14rem;
}
this is the typescript where I insert X and O in and the html where I present a button:
public place ()
{
if (this.reserved())
{
if(this.player==1)
{
this.xory = 'X'
this.player++
}
else
{
this.xory = 'O'
this.player--
}
}
}
<button (click) = "place()">{{xory}}</button>

I suggested to use as content of your empty boxes to compensate the alignment when the player didn't fill it with a choice.
By the way it was hard to say how you should initialize that value since you are using Angular.
So you can just opt for using the vertical-align:bottom; in your css rule as showed in this example:
button {
width: 30%;
height: 200px;
cursor: pointer;
text-align: center;
font-size: 10rem;
display: inline;
vertical-align: bottom;
margin: 0 0 3px 0;
padding: 0;
}
<button></button>
<button>O</button>
<button></button>
<button>X</button>
<button></button>
<button></button>
<button></button>
<button>O</button>
<button>X</button>

Related

html/css button transparent second layer hover effect

I want to implement a button. It is like this when it's not hovered:
the transparent rounded-bourder rectangle in the right is supposed to move left and cover the entire button in 1 second, when hovered. so, after hover, we'll have something like this:
My problem is that I don't know what to do. I found some code on the internet but either it comes from left to right or it pushes my arrow icon and text out of my button! I don't want my arrow icon or text change at all. I just want that the vright transparent rectangle move to right upon hover and then come back to it's original place.
My css code for my button withoug effect is this:
.btn {
color: white;
display: flex;
flex-direction: row-reverse;
Border: 2px solid white;
border-radius: 10px;
height: 80%;
padding-top: 10px;
width: 100%;
text-align: center;
margin-top: 0px;
padding-right: 0px;
vertical-align: middle;
text-decoration: none;
background-color: #fb815e;
font-size: 18px;
font-family: 'Vazir', sans-serif;
}
update:
The effect should also reverse with the same speed when there's no hover.
You'll want one element to be relative (wrapper) and the button / stretching part to be absolute. That way it will act as an overlay. You'll be relying on the transition for the one second, and width for the covering part.
This is, as far as I can tell, the exact button you want.
Edit: You asked for it to return, that's done by a second transition. One in the hover and a second one in the regular non-hover tag itself.
Disclaimer: I have no idea what the (Arabic?) text I used says.
.btn {
cursor: pointer;
height: 40px;
width: 200px;
color: white;
display: flex;
flex-direction: row-reverse;
border-radius: 10px;
vertical-align: middle;
text-decoration: none;
background-color: #fb815e;
font-size: 18px;
font-family: 'Vazir', sans-serif;
position: relative;
text-align: center;
line-height: 40px;
border: none;
margin: 0;
padding: 0;
}
.btn:hover .btn-inside {
width: 100%;
transition: width 1s ease;
}
.btn-inside {
opacity: 0.5;
border-radius: 10px;
background-color: #fc9c81;
width: 20%;
height: 40px;
line-height: 40px;
text-align: left;
position: absolute;
transition: width 1s ease;
}
.text {
margin: auto;
}
span {
display: inline-block;
}
<button class="btn">
<span class="text">العاشر ليونيكود</span>
<span class="btn-inside"> 🡠</span>
</button>
You can do something like
className:hover{
//do stuff here
}
and then play around with opacity or whatever you wish to :)

Make opaque div with text appear over image box over image upon hover

I have text that appears on top of an image when you hover over the image. Originally, I also had the entire image go opaque upon hovering.
Now I've decided I want to make only a section of the image go opaque upon hovering, the part with the text. I tried the tutorial here. Unfortunately, once I made those changes, nothing appears when I hover over the image -- not the text or any opaque filter.
Here is my html file:
<div class="container">
<div class="main">
<div class = "JFK">
<h6>JFK</h6>
<div class = "transbox">
<p> to
from</p>
</div>
</div>
/* continues on*/
Here is my css:
JFK {
position: relative;
left: 110px;
height: 300px;
width: 300px;
bottom: 40px;
background-image: url(https://media-cdn.tripadvisor.com/media/photo-s/03/9b/2d/f2/new-york-city.jpg);
line-height: 200px;
text-align: center;
font-variant: small-caps;
display: block;
}
.transbox{
margin: 30px;
background-color: $ffffff;
border: 1px solid black;
opacity: 0.6;
display: none;
}
.JFK h6{
font-size: 30px;
font-variant: small-caps;
font-weight: 600;
}
.transbox p{
position: relative;
top: -90px;
word-spacing: 100px;
font-size: 30px;
font-variant: small-caps;
font-weight: 600;
color: #c4d8e2;
display: none;
}
.JFK p a{
color: #c4d8e2;
top: -30px;
}
.JFK:hover transbox p {
display: block;
}
.JFK:hover{
display: block;
}
.JFK: hover transbox{
display: block;
opacity:0.6;
}
I thought I had added a wrapper class as suggested here by adding the transbox div. I also tried the background-color:rgba(255,0,0,0.5); trick mentioned here. No luck -- still nothing happens upon hover. Any suggestions?
Your problem lies with these 2 pieces of code in your css:
.JFK:hover transbox p {
display: block;
}
.JFK: hover transbox{
display: block;
opacity:0.6;
}
Firstly . is missing from the class transbox - is should be .transbox
Secondly there is a space between .JFK: and hover remove the space and it should all work.
.JFK:hover .transbox p {
display: block;
}
.JFK:hover .transbox{
display: block;
opacity:0.6;
}
Your code is not complete. In the "tutorial" you said you tried, <div class = "transbox"> is just a box with transparent background that is positioned above another box, with a background-image. You said you need "only a section of the image go opaque upon hovering".
Also, your CSS is not valid. "JFK" is a class, in the first row, so is ".JFK".
Then, is
.transbox {
margin: 30px;
background-color: #ffffff;
}
You wrote again with errors.
You can use:
.transbox{
margin: 30px;
background-color: rgba(255,255,255,0.6);
border: 1px solid black;
}

Rating system using CSS (hover from left to right)

Is there a simple way to reverse the colour order when hovering?
Using this trick here I have the order right > left:
&:hover,
&:hover ~ button {
color: red
}
The fiddle with the right > left: https://jsfiddle.net/celio/Lowc1ruh/
Example with the left > right: https://css-tricks.com/examples/StarRating/
It is impossible for me to use float, position: absolute; and anything that changes the right order of my current html.
Plain CSS example:
button {
margin: 0;
padding: 5px;
border: none;
background: transparent;
display: inline-block;
}
button:before {
content: "⋆";
font-size: 5rem;
line-height: 1;
}
button:hover,
button:hover ~ button {
color: red;
}
<div class="wrapper">
<button></button>
<button id="2"></button>
<button></button>
<button></button>
<button></button>
</div>
One way would be to make all the child button elements color: red; when hovering over .wrapper. Then use the sibling selector (~) to change any elements after the currently hovered element to color: black;.
You should remove any whitespace between the elements (in this case I put them into one line in the HTML) to ensure that the cursor is always hovering over a star.
Example with plain CSS:
.wrapper button {
margin: 0;
padding: 5px;
border: none;
background: transparent;
display: inline-block;
}
.wrapper button:before {
content: "⋆";
font-size: 5rem;
line-height: 1;
}
.wrapper button:hover ~ button {
color: black;
}
.wrapper:hover button {
color: red;
}
<div class="wrapper">
<button></button><button id="2"></button><button></button><button></button><button></button>
</div>
JS Fiddle using SASS

gwt Checkbox Text alignment

I changed the check box style in gwt, but the text is not appearing in the middle (Vertically). It appears on the top.
I tried to add padding, but that didn't help. Adding padding to the left works fine, but padding to the top doesn't work.
label {
display: inline-block;
cursor: pointer;
position: relative;
padding-left: 25px;
padding-top: 5px;
margin-right: 5px;
font-size: 12px;
}
input[type=checkbox] {
display: none;
padding-top: 5px;
}
label:before {
background-image: url(images/csscheckbox.png);
content: "";
display: inline-block;
width: 22px;
height: 22px;
margin-right: 10px;
position: absolute;
left: 0;
/*border-radius:5px 5px 0px 0px;*/
}
.gwt-CheckBox {
padding-top: 5px;
}
.gwt-CheckBox label:before {
padding-top: 5px;
}
input[type=checkbox]:checked+label:before {
background-position: 0 -22px;
background-image color: aqua;
font-size: 12px;
text-align: center;
line-height: 13px;
}
.agreement {
margin-left: 5px;
}
What could be the problem?
Actually your CSS should target the CheckBox Label instead of the the Checkbox. So try something like this
input[type="checkbox"] + label{ padding-top : 5px ;
vertical-align: top; }
This is a known behavior. Add the vertical-align sub or middle to the label (this depends on the label font-size)
label
{
vertical-align : middle;
}
Another solution to not depend on the css and font size will be to seperate the checkBox and label in a table row (again some css to to keep it together :( but it will be one time and fool-proof) .
EDITS :
HorizontalPanel horizontalPanel = new HorizontalPanel();
horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
CheckBox box = new CheckBox();
InlineLabel inlineLabel = new InlineLabel("Option1");
horizontalPanel.add(box);
horizontalPanel.add(inlineLabel);
RootPanel.get().add(horizontalPanel);
Output :
Normal Font Size
label {
position: static;
align-self: center;
}

Why does this CSS button mess with <a> tags?

Here is my CSS
button {
border: 0 none;
cursor: pointer;
padding: 0 15px 0 0;
text-align: center;
height: 30px;
line-height: 30px;
width: auto;
}
button a {
color:white;
text-decoration:none;
}
button.rounded {
background: transparent url(/images/button/btn_right.png) no-repeat scroll right top;
clear: left;
font-size: 0.8em;
}
button span {
display: block;
padding: 0 0 0 15px;
position: relative;
white-space: nowrap;
height: 30px;
line-height: 30px;
}
button.rounded span {
background: transparent url(/images/button/btn_left.png) no-repeat scroll left top;
color: #FFFFFF;
}
button.rounded:hover {
background-position: 100% -30px;
}
button.rounded:hover span {
background-position: 0% -30px;
}
button::-moz-focus-inner {
border: none;
}
Here is the code for my "button" with a link in it.
<button class="rounded"><span>Profile</span></button>
The issue is it does not link to the href when i click on it.
Anyone know why?
Incidentally, it's not a CSS problem. It's a "i don't understand buttons" problem:
http://www.w3schools.com/tags/tag_button.asp
A button can have "submit", "button" or "reset" actions. If you are using the "button" action you should provide the javascript necessary in the OnClick event to navigate to the page in question.
I believe button needs a type and value attribute.
http://www.w3schools.com/tags/tag_button.asp
You can also add onclick like:
<button onclick="location.href='/profile.php';">Profile</button>
But, since its just a regular link, you'll have a easier time using the <a> tag and styling it with CSS.

Resources