how to horizontally inline from using bootstrap or css - php

I have read many questions and many articles but cant find my answer Here is my code result
Here is my code
.checkout-cart-total {
background-color: #f5f5f5;
padding: 45px;
}
#media only screen and (max-width: 575px) {
.checkout-cart-total {
padding: 30px;
}
}
.checkout-cart-total h4 {
flex-basis: 18px;
line-height: 23px;
font-weight: 600;
color: #292929;
}
.checkout-cart-total h4:first-child {
margin-top: 0;
margin-bottom: 25px;
}
.checkout-cart-total h4:last-child {
margin-top: 15px;
margin-bottom: 0;
}
.checkout-cart-total h4 span {
float: right;
display: block;
}
.checkout-cart-total ul {
border-bottom: 1px solid #292929;
}
.checkout-cart-total ul li {
color: #292929;
font-size: 14px;
line-height: 23px;
font-weight: 600;
display: block;
margin-bottom: 16px;
}
.checkout-cart-total ul li span {
color: #292929;
float: right;
}
.checkout-cart-total p {
line-height: 30px;
font-weight: 600;
color: #292929;
padding: 10px 0;
border-bottom: 1px solid #292929;
margin: 0;
}
.checkout-cart-total p span {
float: right;
}
<div class="col-12 mb-60">
<h4 class="checkout-title">Cart Total</h4>
<div class="checkout-cart-total">
<h4>Product <span>Total</span></h4>
<ul>
<?php
$cartres = $fetchcart->fetchAll(PDO::FETCH_ASSOC);
foreach($cartres as $row){
?>
<li>
<input type="text" disabled value="<?php echo $row['p_name']; ?>" name="product_name[]" style="color:#292929;font-size:14px;font-weight:600;display:inline;float:left;border:none;background:transparent;"> X
<input type="text" disabled value="<?php echo $row['qty']; ?>" name="qty[]" style="color:#292929;font-size:14px;font-weight:600;display:inline;float:left;border:none;background:transparent;">
<span><input type="text" disabled value="<?php echo $row['price']; ?>" name="product_name[]" style="color:#292929;font-size:14px;font-weight:600;float:left;display:inline;border:none;background:transparent;"><input type="text" disabled value="<?php echo $row['p_id']; ?>" hidden name="product_id[]" style="color:#292929;font-size:14px;font-weight:600;float:left;display:inline;border:none;background:transparent;"></span>
</li>
<?php } ?>
</ul>
</div>
</div>
Help me to figure out how to align this I have done many techniques like the form-inline bootstrap class but doesn't work for me. Because I am submitting two data at a time so I cant use form-inline class first form is for user details and second for product details and checkout at a time.

The best design can be achieved using tables. This is what tables are used for - representation of data. You can also use <input type="number"> for quantity and update total price accordingly.
DOCS: https://getbootstrap.com/docs/4.5/content/tables/
/*DEMO*/body{padding:2rem}input[type="number"]{max-width:75px}
tbody th,tbody td{vertical-align:middle!important}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="row">
<div class="col-12">
<h4>Cart Total</h4>
<table class="table table-striped table-hover">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Product</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Lorem Ipsum</td>
<td>1400</td>
<td><input class="form-control form-control-sm" type="number" value="1"></td>
<td>1400</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Dolor Sit Amet</td>
<td>425</td>
<td><input class="form-control form-control-sm" type="number" value="2"></td>
<td>850</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Lorem Lorem</td>
<td>850</td>
<td><input class="form-control form-control-sm" type="number" value="1"></td>
<td>850</td>
</tr>
</tbody>
</table>
</div>
</div>

I think its better to use Table layout or Display Flex or Grid layout.
All the theories below are from w3school,
Table Layout:
The table-layout property defines the algorithm used to lay out table cells, rows, and columns.
The main benefit of table-layout: fixed; is that the table renders much faster. On large tables, users will not see any part of the table until the browser has rendered the whole table. So, if you use table-layout: fixed, users will see the top of the table while the browser loads and renders rest of the table. This gives the impression that the page loads a lot quicker!
Display Flex:
Click here
HTML:
<div> // display:flex, flex-direction:column, justify-content:space-around
<div> // display:flex, flex-direction:row, justify-content:space-around
<div> </div>
<div> </div>
</div>
<div> // display:flex, flex-direction:row, justify-content:space-around
<div> </div>
<div> </div>
</div>
</div>
Grid Layout:
Link here
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.
My choice:
There are always different approaches to do a thing, but in the situation, you mention I would prefer to go with display: flex method.

Related

Adjusting the div inside a table cell using DomPDF in Laravel

I am adding a feature in my project wherein users can convert their data into pdf, but i am having a problem with css. How can i adjust this div so that it will align in the border of my table? padding and margin does not work since the table cell also adjusts. or a im adding the wrong px? I displayed the table border so that you can see how far the border of the div is. Here's the code
<table border="" style="border-collapse: collapse;font-size:12px;text-align: left;">
<tr>
<td colspan="2">
<b>Email </b>
<div style="display: inline-block;border-bottom:.7px solid black;height:15px;padding:0px;width:200px;overflow:hidden;">
{!! $usermodel->email !!}
</div>
</td>
</tr>
</table>
If you want to align the div with the border of the table, you can add a vertical-align property to the td element with a value of top. This will align the top of the div with the top of the table cell.
You can also try setting the height of the td element to the height of the div plus any additional padding you want to add. This will ensure that the entire div is contained within the table cell.
<table border="" style="border-collapse: collapse;font-size:12px;text-align: left;">
<tr>
<td colspan="2" style="vertical-align: top; height: 30px;">
<b>Email </b>
<div style="display: inline-block; border-bottom: .7px solid black; height: 15px; padding: 7.5px 0; width: 200px; overflow: hidden;">
{!! $usermodel->email !!}
</div>
</td>
</tr>
</table>
Since you are using running styles, on this occasion, I suggest (perhaps could be bettered):-
<table border="" style="border-collapse: collapse;font-size:12px;text-align: left;">
<tr>
<td colspan="2"; style="font-size:18px; padding: 2px" >
<b><sup>Email </sup></b>
<div style="font-size:15px;padding: 2px 0px 2px; border-bottom: 1px solid black; display:inline-block; width: 220px; overflow: hidden;">
{!! $blackmamba#gmail.com !!}
</div>
</td>
</tr>
</table>
Try doing it in an external CSS stylesheet.

Dynamically adding select2 to DOM which gets data from DB

I have a HTML table where user can choose products from MySql db.
I have a "add new row" possibility where new row is added to DOM.
Once I add new row, select-2 is no longer functioning in this new row - I beleive it is a problem, that it is searching for input only in first example of select-2 dropdown. How can I show dropdown for each instance?
Code:
<table id="add_new" style="width: 100%; margin-top:40px;" class="col-12 col-lg-12 col-md-12 col-sm-12 col-xl-12">
<thead>
<tr>
<th style="text-align:left; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 10%;">
Zap. št.: </th>
<th style="text-align:left; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 50%;">
Naziv artikla </th>
<th style="text-align:left; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 20%;">
Količina </th>
<th style="text-align:right; font-size: 10px; color:#8f8f8f; padding-bottom: 15px; width: 20%;">
EM (kos/m/colli,...) </th>
</tr>
</thead>
<tbody>
<tr id="mainsection">
<td> <p href="#" id="count" style="font-size: 13px; text-decoration: none; line-height: 1; color:#909090; margin-top:0px; margin-bottom:0;">
1</p> </td>
<td contenteditable style="padding-top:0px; padding-bottom:5px;">
<h4 style="font-size: 16px; line-height: 1; margin-bottom:0; color:#303030; font-weight:500; margin-top: 10px;">
<select class="form-control select2-multiple" id="dd_artikli" data-width="100%">
<option value="">Select country</option>
<?php
if (count($itemRecords_artikli) > 0) {
foreach ($itemRecords_artikli as $ct) {
?>
<option value="<?php echo $ct['id']; ?>">
<?php echo $ct['name']; ?>
</option>
<?php
}
}
?>
</select>
</h4>
</td>
<td contenteditable> <p href="#" style="font-size: 13px; text-decoration: none; line-height: 1; color:#909090; margin-top:0px; margin-bottom:0;"> </p> </td>
<td contenteditable style="padding-top:0px; padding-bottom:0; text-align: right;"> <p style="font-size: 13px; line-height: 1; color:#303030; margin-bottom:0; margin-top:0; vertical-align:top; white-space:nowrap;"> </p> </td>
</tr>
</tbody>
</table>
<script>
var number = 1;
document.getElementById("newsectionbtn").onclick = function() {
var container = document.getElementById("add_new");
var section = document.getElementById("mainsection");
var count = document.getElementById('count');
number++;
count.textContent = number.toString();
container.appendChild(section.cloneNode(true));
}
</script>
<
?php
/*
#Author: Sanjay Kumar
#Project: PHP MySQLi How To Use Select2 for Multiple Select Tutorial
#Email: onlinewebtutorhub#gmail.com
#Website: https://onlinewebtutorblog.com/
*/
// Include the database configuration file
require 'dbconfig.php';
$countrySelect = $conn->prepare("SELECT * FROM artikli");
$countrySelect->execute();
$countries = $countrySelect->get_result();
$itemRecords_artikli = array();
while ($item = $countries->fetch_assoc()) {
extract($item);
$itemDetails = array(
"id" => $id,
"name" => $naziv
);
array_push($itemRecords_artikli, $itemDetails);
}
?>
After drop-down bind run this command.
jQuery('#dd_artikli').select2();
Or use the jquery ready function.
$(document).ready(function() { jQuery('#dd_artikli').select2(); });

Horizontal scroll div per row

i am trying to make a table which has an individual horizontal scroll per table row which is dynamic. my code only works for the whole table itself but not the individual rows.
<table class="table-mainprojects">
<tr>
<th>Date Disbursed:(YYYY-MM-DD)</th>
<th>Disbursed<br>Project<br>Fund<br>(PHP)</th>
</tr>
while($row = mysqli_fetch_assoc($result)){?>
<div class="horizontal">
<tr>
<td><?php echo "$row[date_disbursed]"; ?><br/> </td>
<td><?php echo number_format($row['cost_disbursed'], 2); ?> <br/>
</td>
<input type="hidden" name="id" id="hiddenField" value="<?php echo
"$row[id]";?>" />
</tr>
</div>
<?php } ?>
</table>
CSS
.table-mainprojects {
display: block;
white-space: nowrap;
overflow: auto;
}
.table-mainprojects > .horizontal {
display: block;
overflow: auto;
white-space: nowrap;
}
Instead of using a classic table, maybe try using divs and revise your html as a flex or grid. It's easy enough to make a table out of a grid or flex:
<style>
.table > div.row {
display: grid;
grid-template-columns: auto auto 200px 200px;
overflow: auto;
max-width: 300px;
}
div.row div {
padding: 10px;
}
</style>
<div class="table">
<div class="row">
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
<div class="row">
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
</div>
</div>
Here is an example of that scenario: https://jsfiddle.net/qcc14hdk/

Submit button not centering

I have an HTML form and I have all the inputs except for the submit button in a table. I centered everything in the table besides except for the submit button, even though I tried numerous things to center it to no avail. Please help me center my submit button under my table with the other inputs!
Here is my HTML page:
<html>
<head>
<link rel="stylesheet" href="Site.css">
<?php include("Header.php"); ?>
</div>
</head>
<body>
<div id="main">
<h1>About</h1>
<form action="Insert.php" method="post">
<table>
<tr>
<td><span>First name:</span></td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td><span>Last name:</span></td>
<td><input type="text" name="lastname"></td>
</tr>
<tr>
<td><span>Age:</span></td>
<td><input type="number" name="age"></td>
</tr>
</table>
<input type="submit">
</form>
<?php include("Footer.php");?>
</div>
</body>
</html>
And here is my CSS:
body {
font-family: "Trebuchet MS", Verdana, sans-serif;
background-color: #4C875E;
color: #C9C9C9;
}
#main {
padding: 20px;
background-color: #1C404A;
border-radius: 0 4px 4px 4px;
}
h1 {
border-bottom: 3px solid #4C875E;
color: #4C875E;
}
#swag {
left: 0;
line-height: 200px;
margin-top: -100px;
position: absolute;
top: 50%;
width: 100%;
border-bottom: 0;
text-align: center;
color: #BABABA;
}
ul#menu {
padding: 0;
position: relative;
margin: 0;
}
ul#menu li {
display: inline;
}
ul#menu li a {
background-color: #1C404A;
padding: 10px 20px;
text-decoration: none;
line-height: 2.8em;
color: #C9C9C9;
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover {
background-color: #e8eef4;
}
#bg {
background: url(assets/banner.jpg) no-repeat center center fixed;
background-size: 100% auto;
}
table {
margin: 0 auto;
}
Try putting it inside your table:
<table>
<tr>
<td><span>First name:</span></td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td><span>Last name:</span></td>
<td><input type="text" name="lastname"></td>
</tr>
<tr>
<td><span>Age:</span></td>
<td><input type="number" name="age"></td>
</tr>
<tr>
<td colspan='2'><center><input type="submit"></center></td>
</tr>
</table>
FIDDLE
Try this:
<tr>
<td><input type="submit"></td>
</tr>
</table>
Working Example
Try this:
<center><input type="submit"></center>
LIVE DEMO
You should put the input button inside the table in a new rowUse td colspan to merge 2 columns To center the button, use attribute align="center".
Code
<table>
<tr>
<td><span>First name:</span></td>
<td><input type="text" name="firstname"/></td>
</tr>
<tr>
<td><span>Last name:</span></td>
<td><input type="text" name="lastname"/></td>
</tr>
<tr>
<td><span>Age:</span></td>
<td><input type="number" name="age"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"/></td>
</tr>
</table>
As far as I know there is no exact way to center things in CSS with a single command. However there are some ways that you can do it manually. I would do one of two things. First (forgive me if this seems too simple) I might just add something like & nbsp;& nbsp;& nbsp;& nbsp;& nbsp; in front of the submit button. So that would just add some space in front of it (and it scales pretty nicely if the user zooms in).
The other thing I would do (and probably the better solution) would be to change the width of the parent div (so that it is just wide enough to fit the form) and then get the width of that like so:
parseInt(getComputedStyle(document.getElementById('main')).width)
divide it by two to get the center, then place the button at the center minus half the width of the button:
parseInt(getComputedStyle(getElementById("mySubmitButtonId")).width)
Note: place it using margin-left

HTML, CSS & PHP cross browser styling

I'm a self taught coder and usually I can figure out problems for myself but this ones a stubborn one. I'm redesigning a website for my friend and I've successfully coded the mobile version of his site, but the desktop version is proving to be difficult.
The site is a database for a home bar, tracking; Drinkers, Shots, Units and Tabs. The index page is a leaderboard with Drinkers & Last Drink bought. My problem is positioning the Drinkers Ranks on the leaderboard to work across multiple web browsers.
It's meant to look like this: (screenshot)
http://giblets-grave.co.uk/previews/1400x900_GG-desktop_design_final.jpg
The alternating background is something I'm willing to scrap if it makes echoing results easier.
I've tried using tables, divs, ul/li's.. sample of what I used:
<table cellpadding="0" cellspacing="0">
<col width="85px" />
<col width="65px" />
<col width="65px" />
<tr>
<th colspan="3" align="left">Chris Clarkson</th>
</tr>
<tr>
<td>
<div class="crop round-five body-shadow" >
<img src="uploads/1.jpg" class="" />
</div>
</td>
<td>
<ul><h2>382.73</h2><li>units</li></ul><br />
</td>
<td>
<ul><h2>613</h2><li>shots</li></ul><br />
</td>
</tr>
</table>
but its just coming out as a big mess, can anyone help?
Definitely should be using table to do this in my opinion.
As for displaying the alternating colors, you would want to apply a background color to the tr's using nth-child() pseudo-class.
JSFIDDLE: http://jsfiddle.net/XYh7f/
HTML:
<div class="container">
<div class="leaderboard">
<table id="main">
<tr>
<td>Leaderboard</td>
</tr>
<tr>
<td>
<table class="client">
<tr>
<th colspan="3">Chris Clarkson</th>
</tr>
<tr>
<td>IMG</td>
<td>267.26 units</td>
<td>457 shots</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="client">
<tr>
<th colspan="3">Chris Clarkson</th>
</tr>
<tr>
<td>IMG</td>
<td>267.26 units</td>
<td>457 shots</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div class="drinks">
<table id="main-data">
<tr>
<td class="data-title"><h2>Last Drinks Served</h2></td>
</tr>
<tr>
<table class="data">
<tr>
<td class="data-time">Time</td>
<td class="data-shots">Shots</td>
<td class="data-drink">Drink</td>
<td class="data-drinker">Drinker</td>
<td class="data-date">Date</td>
</tr>
<tr>
<td class="data-time">Time</td>
<td class="data-shots">Shots</td>
<td class="data-drink">Drink</td>
<td class="data-drinker">Drinker</td>
<td class="data-date">Date</td>
</tr>
<tr>
<td class="data-time">Time</td>
<td class="data-shots">Shots</td>
<td class="data-drink">Drink</td>
<td class="data-drinker">Drinker</td>
<td class="data-date">Date</td>
</tr>
</table>
</tr>
</table>
</div>
</div><!-- END CONTAINER -->
CSS:
/* CONTAINER STYLES */
.container {
width: 960px;
}
.leaderboard {
float: left;
}
.drinks {
float: left;
}
/* LEADER BOARD STYLES */
table {
color: #eee;
width: 200px;
background: none;
}
tr { background: none; }
td { background: none; }
#main {
text-align: center;
}
#main tr:nth-child(odd) {
background: #444;
}
#main tr:nth-child(even) {
background: #555;
}
#main tr td .client tr {
background: none;
}
/* LAST DRINKS SERVED STYLES */
#main-data {
width: 740px;
}
#main-data tr:nth-child(odd) {
background: #444;
}
.data {
width: 740px;
}
.data tr:nth-child(odd) {
background: #222;
}
.data td {
border-right: 1px solid #000;
}
.data tr:nth-child(even) {
background: #333;
}
.data-title {
padding: 0 0 0 60px;
}
.data-time {
text-align: right;
width: 120px;
}
.data-shots {
text-align: right;
width: 60px;
}
.data-drink {
text-align: center;
width: 240px;
}
.data-drinker {
text-align: left;
width: 200px;
}
.data-date {
width: 140px;
}

Categories