PHP while loop creates space between buttons - php

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.

Related

Is there a way to make an overlay with an arrow AND border like google?

I am working on my code to create a green circle with your name on it with an arrow and border just like the one that google use.
please find the sample image below.
I have already created a green circle and a name using css and html which you can see it here.
<div class="profileImage">
<span id="profilename" class="profilename"></span>
<div class="flex-container">
</div>
</div>
.profileImage {
-webkit-background-size: 32px 32px;
background-size: 32px 32px;
background-color: green;
-webkit-border-radius: 50%;
border-radius: 50%;
display: block;
float: right;
margin-right: 18px;
margin-top: 12px;
overflow: hidden;
position: relative;
height: 32px;
width: 32px;
z-index: 0;
}
.profilename {
text-align: center;
color: white;
font-size: 14px;
line-height: 32px;
margin-left: 5px;
font-weight: bold;
}
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
}
$(document).ready(function() {
var firstName = 'Robert';
var lastName = 'Jones';
var intials = firstName.charAt(0)+""+lastName.charAt(0);
document.getElementById("profilename").innerHTML = intials;
});
When I click on a green circle, I want to display the overlay with a border but I have got no idea how to do this. I tried to find it on google but I couldn't find it.
Can you please show me an example how I can display the overlay with a grey border that come with my first name, last name, email address and a signout button?
Thank you.
Ok I'll get you started with an overlay that includes an arrow with a border around the whole thing.
Basically, you're doing a bit of "visual miss direction". We used CSS borders to generate a triangle of the SAME color as the box background. This gets positioned its (height - border width) above the box. This puts the triangle OVER the top of the border, effectively hiding it.
Then there's a second triangle with a color that matches the border of the box. We position this triangle BEHIND the first triangle (using z-index) and offset the second triangle the border width from the first. This makes for a "fake" border because only the border width of the second triangle shows.
body {
margin: 50px;
}
.overlay {
position: absolute;
width: 300px;
height: 200px;
// styling
background-color: #fff;
border: 1px solid #ccc;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
border-radius: 4px;
}
.arrow {
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #fff transparent;
top: -9px;
right: 10px;
}
.arrow:after {
content:"";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #ccc transparent;
left:-10px;
top:-1px;
z-index:-1;
}
<div class="overlay">
<div class="arrow"></div>
<div class="overlayContent">
</div>
</div>
We used two elements (arrow and content) inside the overlay wrapper because we're rounding the corners using overflow:hidden this would cause our arrows to be cut off as well. So instead we'll have an extra container. The content area uses flexbox to push the button bar to the bottom regardless of the size. There are other ways to do this but this is easy.
body {
margin: 50px;
}
.overlay {
position: absolute;
width: 300px;
height: 200px;
// styling
background-color: #fff;
border: 1px solid #ccc;
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
border-radius: 4px;
}
.arrow {
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #fff transparent;
top: -9px;
right: 10px;
}
.arrow:after {
content:"";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #ccc transparent;
left:-10px;
top:-1px;
z-index:-1;
}
.overlayContent {
position:absolute;
z-index: 1;
top:0; right:0; bottom:0; left:0;
overflow:hidden;
border-radius: 4px;
display:flex;
flex-direction: column;
justify-content: space-between;
}
.top {
flex-basis: 70%;
}
.bottom {
flex-basis: 30%;
border-top: 1px solid #ccc;
background-color: #f5f5f5;
}
<div class="overlay">
<div class="arrow"></div>
<div class="overlayContent">
<div class="top"></div>
<div class="bottom"></div>
</div>
</div>
That's the fundamentals of the overlay. Try filling in the content you want and ask more questions if you need help.

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;

How to style a button that displays as an image

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 }

Css style not working

this is my worksite - mysite i have created a page and called it to the home page using the following code
<div class="hilight-hometext">
<?php if(is_front_page()) :
$home_page_post_id = 308;
$home_page_post = get_post( $home_page_post_id, ARRAY_A );
$content_home = $home_page_post['post_content'];
$content_title = $home_page_post['post_title'];
?><?php
echo $content_home;
endif; ?></div>
and the result is
<div class="hilight-hometext">
<div id="hilightbox">
<div class="hilightbox-text">
<h2>At Salisbury we want everyone to understand their landscaping choices</h2>
Our latest landscaping innovation is our Outdoor Vision questionnaire. We’ll guide you through a set of questions that will help you realize what you want out of your yard.
</div>
<!-- end tier 2 text -->
<div class="hilightbox-action">
<a class="myButton" href="resources/the-outdoor-vision-tool/">GET STARTED</a>
Your Outdoor Vision
</div>
</div></div>
i have added the styling as follows
#hilightbox {
background: url(../img/action-bg.jpg);
width: 100%;
margin: 20px auto;
}
#hilightbox .hilightbox-text {
width: 75%;
float: left;
margin: 0;
}
#hilightbox .hilightbox-action {
width: 25%;
float: left;
padding: 15px 0;
}
.myButton {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #c9df23), color-stop(1, #747728));
background: -moz-linear-gradient(center top, #c9df23 5%, #747728 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#c9df23', endColorstr='#747728');
background-color: #c9df23;
display: inline-block;
color: #ffffff;
font-family: Arial;
font-size: 20px;
font-weight: bold;
padding: 14px 14px;
text-decoration: none;
text-shadow: 1px 1px 0px #747728;
}
but the background image and the styles are not showing up.Please help!! Thanks
I think if you just add this:
#hilightbox {
background: url(../img/action-bg.jpg);
width: 100%;
margin: 20px auto;
overflow: hidden;
}
it will solve you problem.
currently your container div #hilightbox does not know about child div's (.hilightbox-text and hilightbox-action) height & width because of float:left property.

layout CSS working perfectly in safari but not in firefox?

I have used Safari to view my layout up until now. Everything appeared perfectly as I wanted it to in Safari, a simple layout with a logo, navigation bar, header image, and then a two column body area. However, in Firefox, both the header image and logo are not even displaying, and the two column float for the body area is not working and instead sinking into one... I am not sure what is going on, or what types of problems I will encounter in other browsers, but maybe someone can find what is wrong:
body {
background-color: some color;
background-attachment:fixed;
margin: 0;
padding: 0;
}
#wrapper {
width: 950px;
background-color: some color;
margin: 0 auto;
text-align: left;
border-right: 1px solid some color;
border-left: 1px solid some color;
}
#logo {
background-image: url('some url');
height: 100 px;
text-align: left;
border-style: none;
}
#navigation {
background-color: some color;
text-align: center;
border-top: 2px solid some color;
border-bottom: 2px solid some color;
height: 30 px;
}
#navigationElement {
display: inline-block;
padding-top: 2 px;
padding-left: 10 px;
padding-right: 10 px;
border-style: none;
}
#navigationElement a:link {
color: some color;
text-decoration: none;
}
#navigationElement a:hover {
color: some color;
font-weight: bold;
}
#headerImg {
background-image: url('some url');
height: 200 px;
text-align: left;
border-style: none;
}
#left {
background-color: some color;
width: 475 px;
float: left;
text-align: center;
border-style: none;
}
#leftElement {
background-color: some color;
padding: 40 px;
text-align: center;
border-style: none;
}
#right {
background-color: some color;
width: 475 px;
float: right;
text-align: center;
border-style: none;
}
#rightElement {
background-color: some color;
padding: 40 px;
text-align: center;
border-style: none;
}
#footer {
background-color: some color;
height: 40 px;
text-align: left;
border-style: none;
clear: both;
}
Here is the html code:
<body>
<div id="wrapper">
<div id="logo"></div>
<div id="navigation">
<div id="navigationElement">nav 1</div>
<div id="navigationElement">nav 2</div>
<div id="navigationElement">nav 3</div>
</div>
<div id="headerImg"></div>
<div id="bodyArea">
<div id="left">
<div id="leftElement">
left element text 1
</div>
<div id="leftElement">
left element text 2
</div>
</div>
<div id="right">
<div id="rightElement">
right element text 1
</div>
<div id="rightElement"> 
right element text 2
</div>
</div>
<div id="footer">some footer text</div>
</div>
</body>
It's probably because you are using spaces between values and px in height attributes (i.e height: 100 px; should be height: 100px;). Different browsers handle these kind of errors differently, so it's always a good idea to validate your css when you're having weird errors: http://jigsaw.w3.org/css-validator/
Remove the spaces between your pixel values.
height: 100 px; to height: 100px;

Categories