How to style a button that displays as an image - php

I have the following code:
#a img {
display: inline-block;
width: 14em;
margin-top: 20px;
float: left;
}
#a {
display: inline-block;
width: 14em;
margin-left: 3%;
margin-top: 20px;
float: left;
}
<button id='a' name='a' value='x'><img src='../../files/images/someimage.png' alt='text'></button>
This displays my image inside a grey box like a button. Is there a way to get ride of the grey box around it?
As I just want to display the image with the same functions as a button
Any help welcome

Something like this, you just need to remove default properties of button
#a{
background:none;
border:0;
outline:0;
}
<button id='a' name='a' value='x'><img src='../../files/images/someimage.png' alt='text'></button>

<button id='a' name='a' value='x'><img src='submit.gif' alt='text'></button>
<style>
button{
background:transparent;
border:none
}
<style>
You can specify background transparent for the button. If you want you can use input type="image" .

button {
background: url("http://placehold.it/200x50");
background-size: cover;
width: 200px;
height: 50px;
cursor: pointer;
}
button:hover {
border: thin solid red;
}
<button></button>

you can do via border:none. Just add it to your css
#a { display:inline-block; width:14em; margin-left:3%; margin-top:20px; float:left; border: none; outline: 0; background: none }
#a:focus, #a:hover { border: none; outline: 0; background: none }

Related

responsive top bar search box in mobile search button problem

I followed a guide on the internet to implement a search bar on top of my navigation bar and responsive, but i have a problem when viewing with mobile, my search box button is at below of my search box.
something like this.
here is my code in HTML
<div class="search-container">
<form action="/">
<input type="text" placeholder="seach..." name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
and my css
.topnav .search-container {
float: right;
}
.topnav input[type=text] {
padding: 6px;
margin-top: 8px;
font-size: 17px;
border: none;
}
.topnav .search-container button {
float: right;
padding: 6px 10px;
margin-top: 8px;
margin-right: 16px;
background: #ddd;
font-size: 17px;
border: none;
cursor: pointer;
}
.topnav .search-container button:hover {
background: #ccc;
}
#media screen and (max-width: 600px) {
.topnav .search-container {
float: none;
}
.topnav a, .topnav span, .topnav input[type=text], .topnav .search-container button {
float: none;
display: block;
text-align: left;
width: 100%;
margin: 0;
padding: 14px;
}
.topnav input[type=text] {
border: 1px solid #ccc;
}
How can I make the button in mobile view to be at the same row beside at right of my search box?
display: block; makes both input and button "put newline after", also they both are width: 100%; which is bad for both elements, if you make them inline-block (they already are by default) and set width that both fits, they be next to each other.
For example like this:
body, html { /* just example */
margin: 0;
padding: 0;
background-color: grey;
}
.topnav:after { /* clearfix so the .topnav container keeps its size properly */
content: "";
clear: both;
display: table;
}
.topnav .search-container {
float: right;
}
.topnav input[type=text] {
padding: 6px;
margin-top: 8px;
font-size: 17px;
border: none;
}
.topnav .search-container button {
/* no need for float: right; here, you can comment-out the whitespace in html */
padding: 6px 10px;
margin-top: 8px;
margin-right: 16px;
background: #ddd;
font-size: 17px;
border: none;
cursor: pointer;
text-align: center;
/* non-flex version require harcoded width (unless you correct it with javascript) */
width: 40px;
}
.topnav .search-container button:hover {
background: #ccc;
}
#media screen and (max-width: 600px) {
.topnav .search-container {
float: none;
}
.topnav .search-container input[type=text] {
border: 1px solid #ccc;
padding: 14px;
/* padding (left+right), border (left+right), button width */
width: calc(100% - 28px - 2px - 40px);
/* bit easier like that: */
/*
box-sizing: border-box;
width: calc(100% - 40px);
*/
}
.topnav .search-container button {
margin-right: 0;
/* correcting height difference between input[type=text] with border and button without border */
padding: 15px 14px;
}
}
<div class="topnav">
<div class="search-container">
<form action="/">
<input type="text" placeholder="seach..." name="search"><!--
--><button type="submit"><i class="fa fa-search">...</i></button>
</form>
</div>
</div>
There is major disadvantage with that aproach and that is the need of hardcoded width of button.
Another way is to use position: absolute;, old fashion but simple, for example like this:
// little demonstation of variable width
var times = 4;
setInterval(function(){
document.querySelector('button>i').innerText = '.'.repeat(times++);
if(times>6){ times = 3; }
}, 1000);
body, html { /* just example */
margin: 0;
padding: 0;
background-color: grey;
}
.topnav:after { /* clearfix so the .topnav container keeps its size properly */
content: "";
clear: both;
display: table;
}
.topnav .search-container {
float: right;
}
.topnav input[type=text] {
padding: 6px;
margin-top: 8px;
font-size: 17px;
border: none;
}
.topnav .search-container button {
/* no need for float: right; here, you can comment-out the whitespace in html */
padding: 6px 10px;
margin-top: 8px;
margin-right: 16px;
background: #ddd;
font-size: 17px;
border: none;
cursor: pointer;
text-align: center;
}
.topnav .search-container button:hover {
background: #ccc;
}
#media screen and (max-width: 600px) {
.topnav .search-container {
float: none;
}
.topnav .search-container input[type=text] {
border: 1px solid #ccc;
padding: 14px;
box-sizing: border-box;
width: 100%;
}
.topnav .search-container button {
position: absolute;
top: 0;
right: 0;
margin-right: 0;
/* correcting height difference between input[type=text] with border and button without border */
padding: 15px 14px;
}
}
<div class="topnav">
<div class="search-container">
<form action="/">
<input type="text" placeholder="seach..." name="search"><!--
--><button type="submit"><i class="fa fa-search">...</i></button>
</form>
</div>
</div>
Or you can use flex-box, which is modern and more flexible, for example like this:
// little demonstation of variable width
var times = 4;
setInterval(function(){
document.querySelector('button>i').innerText = '.'.repeat(times++);
if(times>6){ times = 3; }
}, 1000);
body, html { /* just example */
margin: 0; padding: 0;
background-color: grey;
}
.topnav:after { /* clearfix so the .topnav container keeps its size properly */
content: "";
clear: both;
display: table;
}
.topnav .search-container {
float: right;
}
/* following two blocks are most imporant */
.topnav .search-container form {
display: flex;
flex-wrap: nowrap;
align-items: stretch;
}
.topnav .search-container input[type=text] {
flex-grow: 1;
flex-shrink: 1;
min-width: 0;
}
.topnav input[type=text] {
padding: 6px;
margin-top: 8px;
font-size: 17px;
border: none;
}
.topnav .search-container button {
/* no need for float: right; here, you can comment-out the whitespace in html */
padding: 6px 10px;
margin-top: 8px;
margin-right: 16px;
background: #ddd;
font-size: 17px;
border: none;
cursor: pointer;
text-align: center;
/* no need for hardcoded width */
}
.topnav .search-container button:hover {
background: #ccc;
}
#media screen and (max-width: 600px) {
.topnav .search-container {
float: none;
}
.topnav .search-container input[type=text] {
border: 1px solid #ccc;
padding: 14px;
}
.topnav .search-container button {
margin-right: 0;
padding: 14px; /* height is automatically corrected by flex */
}
}
<div class="topnav">
<div class="search-container">
<form action="/">
<input type="text" placeholder="seach..." name="search"><!--
--><button type="submit"><i class="fa fa-search">...</i></button>
</form>
</div>
</div>

PHP while loop creates space between buttons

I'm trying to use a while loop to dynamically create buttons based on the number of outcomeId, but when I try to create the buttons with the loop, it creates gaps between the buttons.
<div class="outcomes">
<?php
//echo "<button class=\"outcomebtn\">Outcome A</button>";
//echo "<button class=\"outcomebtn\">Outcome B</button>";
$arrayLength = count($_SESSION['outcomeId']);
$i = 0;
while ($i < $arrayLength){
$num = $_SESSION['outcomeId'][$i];
echo "<button class=\"outcomebtn\">Outcome $num</button>";
$i = $i + 1;
}
?>
</div>
When I include the commented buttons, there are no gaps between any buttons. It only happens when I comment out the buttons that are not included in the loop.
Below is the webpage (1) including commented buttons (2) only using buttons from loop:
edit: here is my .css
.outcomes{
display: grid;
grid-template-columns: 1fr;
width: 100%;
height: 200px;
}
.outcomebtn{
font-size: 20pt;
color: rgba(10, 99, 231, 0.829);
text-align: left;
font-size: 20px;
height: 65px;
background-color: transparent;
border-color: 2px lightgray;
}
Reproducing the problem
The problem reproduces only when there are exactly 2 buttons on the page:
.outcomes {
display: grid;
grid-template-columns: 1fr;
width: 100%;
height: 200px;
}
.outcomebtn {
font-size: 20pt;
color: rgba(10, 99, 231, 0.829);
text-align: left;
font-size: 20px;
height: 65px;
background-color: transparent;
border-color: 2px lightgray;
}
<div class="outcomes">
<button class="outcomebtn">Outcome 1</button>
<button class="outcomebtn">Outcome 2</button>
</div>
Reason
The problem happens because .outcomes class has fixed height in 200px.
Possible solution
One of the possible solutions is to get rid of this height css-property in .outcomes class at all:
.outcomes {
display: grid;
grid-template-columns: 1fr;
width: 100%;
}
.outcomebtn {
font-size: 20pt;
color: rgba(10, 99, 231, 0.829);
text-align: left;
font-size: 20px;
height: 65px;
background-color: transparent;
border-color: 2px lightgray;
}
<div class="outcomes">
<button class="outcomebtn">Outcome 1</button>
<button class="outcomebtn">Outcome 2</button>
</div>
I found the problem was that my CSS had an unnecessary height variable in the outcomes class. Once I removed that, it was fixed.

Why is this overflow wrap breaking my alignment for post boxes? [duplicate]

When two inline-block divs have different heights, why does the shorter of the two not align to the top of the container? (DEMO):
.container {
border: 1px black solid;
width: 320px;
height: 120px;
}
.small {
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
}
<div class="container">
<div class="small"></div>
<div class="big"></div>
</div>
How can I align the small div at the top of its container?
Because the vertical-align is set at baseline as default.
Use vertical-align:top instead:
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align:top; /* <---- this */
}
http://jsfiddle.net/Lighty_46/RHM5L/9/
Or as #f00644 said you could apply float to the child elements as well.
You need to add a vertical-align property to your two child div's.
If .small is always shorter, you need only apply the property to .small.
However, if either could be tallest then you should apply the property to both .small and .big.
.container{
border: 1px black solid;
width: 320px;
height: 120px;
}
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align: top;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
vertical-align: top;
}
Vertical align affects inline or table-cell box's, and there are a large nubmer of different values for this property. Please see https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align for more details.
Use display: flex property for the parent div
The flexbox items are aligned at the start of the cross-axis.
By default, the cross-axis is vertical. This means the flexbox items will be aligned vertically at the top.
So when you apply the display: flex property to the parent div, it sets its child elements with vertical-align: top.
See the following code:
.container {
border: 1px black solid;
width: 320px;
height: 120px;
display: flex;
/** CSS flex */
}
.small {
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
}
<div class="container">
<div class="small"></div>
<div class="big"></div>
</div>
Browser Compatibility: Flexbox is very well supported across modern browsers.
<style type="text/css">
div {
text-align: center;
}
.img1{
width: 150px;
height: 150px;
border-radius: 50%;
}
span{
display: block;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type='password' class='secondInput mt-4 mr-1' placeholder="Password">
<span class='dif'></span>
<br>
<button>ADD</button>
</div>
<script type="text/javascript">
$('button').click(function() {
$('.dif').html("<img/>");
})
Add overflow: auto to the container div.
http://www.quirksmode.org/css/clearing.html This website shows a few options when having this issue.

Button does not lined properly

As you can see from the picture above , my button will not line properly if they had content inside them.
Please enlighten me why
[ EDIT ]
CSS
.button {
position: relative;
background-color: #4CAF50;
border: 2px solid black;
color: #FFFFFF;
padding: 0;
width: 250px;
height: 200px;
text-align: center;
font-size: 20px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
margin-bottom: 2px;
}
and here is my button
<button class="button" id="Btn2"><span>(2)<br><?php
$id=$_GET['room'];
$day="02";
$month=date("m");
$year=date("Y");
( SQL retrieve data )
$i=1;
while ($reserve = mysqli_fetch_array($result2)){ echo $i.". ".$reserve['room_name']." ".$reserve['start_time']." - ".$reserve['end_time']."<br>";
$i++;
}
?> </span></button>
the answer would be css styling ,
which is
vertical-align:bottom;

Centre an Image

I'm trying to horizontally center an image. However it does not move from the left side of the page. This answer does not work in my case. What am I doing wrong?
#container {
width: 100%;
border: 2px yellow dashed;
height: 100px;
}
#profile-image img{
margin-left: auto;
margin-right: auto;
border: 2px orange solid;
}
mypage:
<div id="container">
<div id="profile-image">
<p><img src="<?php echo $data['profile_image_url'];?>" alt="me"></p>
</div>
to make any div or anything horizontally at center , common css approach will be,lets have a width and declare margin:0 auto;
#profile-image{
width:400px;
margin:0 auto;
}
Try this: http://jsfiddle.net/rua4d/2/
#container {
width: 300px;
border: 2px yellow dashed;
height: 100px;
display:table-cell;
position:relative;
vertical-align:middle;
}
#profile-image img{
margin-left: auto;
margin-right: auto;
border: 2px orange solid;
display:block;
position:relative;
vertical-align:middle;
text-align:center;
width:50px;
}
You just need to add display:block to your image's style. Images are inline elements, and inline elements ignore margins.
why cant this work?
#profile-image p { text-align: center; }
#profile-image img { display: inline; }
that way you won't need to specify the width.. if you want margins to work together with the text-align: center you would need inline-block instead:
#profile-image p { text-align: center; }
#profile-image img { display: inline-block; }

Categories