Dealing with flexbox while changing an element - css

I have a problem with styling my bar, which works on flexbox.
bar
As you can see, there is three divs inside: one sticked to the left border and another sticked to right border; there is also a small div in the middle showing the amount of comments (80px) and I want it to go left and stick to the div on left. Is it a chance to manage this with flexbox, without changing for display: inline-block?
The bar has a class .article__metas.
The div in the middle is .social_item.
<div class="article__metas">
<div class="item date">
//showing date
</div>
<div class="seperator"></div>
<?php
/**
$clist = get_the_category_list(', ');
if (!empty($clist)) {
?>
<div class="item categories">
<?php
echo $clist;
?>
</div>
<div class="seperator separator-categories"></div>
<?php } */
?>
<?php
$share = $app->getPostStats();
if ($share->comment_count > 0 || $share->share_count > 0):?>
<div class="item social_item">
<?php
if ($share->comment_count > 0) {
echo '<span>';
echo '<img src="' . _img_url('comment.svg') . '"/>';
echo '<span class="amount">' . $share->comment_count . '</span>';
echo '</span>';
}
if ($share->share_count > 0) {
echo '<span>';
echo '<img src="' . _img_url('share.svg') . '"/>';
echo '<span class="amount">' . $share->share_count . '</span>';
echo '</span>';
}
?>
</div>
<?php endif; ?>
<?php get_template_part('inc/article/share'); ?>
</div>
And Sass:
.article__metas {
color: #888888;
font-size: 12px;
display: flex;
border-bottom: 1px solid #e5e5e5;
justify-content: space-between;
#include link-color('a', '#888');
a:hover {
text-decoration: underline;
}
.item {
padding: 20px;
&:first-child {
padding-left: $cards_left;
}
}
.seperator {
display: block;
align-self: stretch;
width: 1px;
background-color: #e5e5e5;
}
.social_item {
display: flex;
align-items: center;
justify-content: space-between;
span + span {
margin-left: 20px;
}
& > span {
display: block;
white-space: nowrap;
img {
width: 16px;
display: inline-block;
}
}
img {
margin-top: 2px;
margin-right: 9px;
}
}
}
Thank you in advance!

Please check if this is what you need. SCSS doesn't work here, so you need to copy to your own environment.
.ariticle__metas is now aligned left and .social_item has a margin-left:auto
Fiddle here
.article__metas {
color: #888888;
font-size: 12px;
display: flex;
border-bottom: 1px solid #e5e5e5;
justify-content: left;
#include link-color('a', '#888');
a:hover {
text-decoration: underline;
}
.item {
padding: 20px;
&:first-child {
padding-left: 10px;
}
}
.seperator {
display: block;
align-self: stretch;
width: 1px;
background-color: #e5e5e5;
}
.social_item {
display: flex;
align-items: center;
justify-content: space-between;
margin-left: auto;
span + span {
margin-left: 20px;
}
& > span {
display: block;
white-space: nowrap;
margin-right: 10px;
img {
width: 16px;
display: inline-block;
}
}
img {
margin-top: 2px;
margin-right: 9px;
}
}
}
<div class="article__metas">
<div class="item">Dodano 18.04.2016</div>
<div class="seperator"></div>
<div class="item">1</div>
<div class="seperator"></div>
<div class="social_item">
<span>Spodobal Ci</span>
<img src="http://placehold.it/15" />
<img src="http://placehold.it/15" />
<img src="http://placehold.it/15" />
<img src="http://placehold.it/15" />
</div>
</div>

Related

CSS Z-index, drop down arrow floating above main menu

I have two separate collapsible menu scripts I've implemented onto my website. With the second menu, a collapsible information display that has a arrow that rotates when the information menu is open, the arrow itself floats above everything else, even when the main drop down menu covers it. I have messed with the z-index of both items but can not figure out how to fix it. I have attached the relative code as well as photos of the problem area.
THIS IS MY CSS FOR MY MAIN HAMBURGER MENU AND THE BUTTON IN THE TOP LEFT CORNER
/* [ON BIG SCREENS] */
/* (A) WRAPPER */
#hamnav {
width: 100%;
background: #333333;
/* Optional */
top: 0;
position: fixed;
border-bottom: 1px solid #999999;
}
/* (B) HORIZONTAL MENU ITEMS */
#hamitems { display: flex;
z-index:100;
}
#hamitems a {
flex-grow: 1;
flex-basis: 0;
padding: 5px;
color: #D5DBDB;
text-decoration: none;
text-align: center;
font-size: 12px;
line-height: 20px;
border-left: 1px solid #999999;
border-right: 1px solid #999999;
border-bottom: 1px solid #666666;
font-family; Verdana;
z-index:100;
}
#hamitems a:hover {
background: #999999;
color: #D5DBDB;
}
/* (C) HIDE HAMBURGER */
#hamnav label, #hamburger { display: none; }
/* [ON SMALL SCREENS] */
#media screen and (max-width: 768px){
/* (A) BREAK INTO VERTICAL MENU */
#hamitems a {
box-sizing: border-box;
display: block;
width: 100%;
border-top: 1px solid #999999;
font-family: Verdana;
z-index:100;
}
/* (B) SHOW HAMBURGER ICON */
#hamnav label {
display: inline-block;
color: #FFFFFF;
background: #333333;
font-style: normal;
font-size: 2.0em;
padding: 5px;
padding-left: 12px;
}
/* (C) TOGGLE SHOW/HIDE MENU */
#hamitems { display: none; }
#hamnav input:checked ~ #hamitems { display: block; }
}
/* [DOES NOT MATTER] */
html, body {
padding: 0;
margin: 0;
color: #FFFFFF;
background-color: #000000;
bgcolor: #000000;
}
THIS IS MY CSS FOR THE COLLAPSIBLE INFORMATION MENU WHICH DISPLAYS THE BULLET ABOVE THE FLOATING MAIN MENU WHEN I DROP IT. NOTHING ELSE FLOATS ABOVE THE MAIN MENUE.
input[type='checkbox'] {
display: none;
}
.wrap-collabsible {
margin: 10px 5px 20px 5px; }
.lbl-toggle {
display: block;
font-weight: bold;
font-family: monospace;
font-size: 1.2rem;
text-transform: uppercase;
text-align: center;
padding: 1rem;
color: #DDD;
background: #000000;
cursor: pointer;
border-radius: 7px;
transition:
all 0.25s ease-out;
}
.lbl-toggle:hover {
color: #FFF;
}
.lbl-toggle::before {
content: ' ';
display: inline-block;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid currentColor;
vertical-align: middle;
margin-right: .7rem;
transform: translateY(-2px);
transition: transform .2s ease-out;
}
.toggle:checked+.lbl-toggle::before {
transform: rotate(90deg) translateX(-3px);
}
.collapsible-content {
max-height: 0px;
overflow: hidden;
transition: max-height .25s ease-in-out;
}
.toggle:checked + .lbl-toggle + .collapsible-content {
max-height: 5000px;
}
.toggle:checked+.lbl-toggle {
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.collapsible-content .content-inner {
background: #000000;
border-bottom: 1px solid #FFFFFF;
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
padding: .5rem 1rem;
}
.collapsible-content p {
margin-bottom: 0;
font-size: 15px;
font-family: Verdana;
margin-left: auto;
margin-right: auto;
text-align: justify;
line-height: 25px;
}
THIS IS THE MARKUP AS REQUESTED, THIS PRINTS THE COLLAPSIBLE INFORMATION MENU WITH THE TROUBLESOME BULLET POINT (CHECKBOX)
if (isset($v) && $v==1){
echo "<div class='wrap-collabsible'>";
echo "<input id='collapsible' class='toggle' type='checkbox'>";
echo "<label for='collapsible' class='lbl-toggle'>Alphabetical name jump</label>";
echo "<div class='collapsible-content'>";
echo "<div class='content-inner'>";
echo "<p>";
$sql = "SELECT user_id, username FROM user_reg ORDER BY username";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result, MYSQLI_NUM))
{
$id=$row[0];
$username=$row[1];
echo "<a href='#$id' class=block>$username</a>";
echo " ";
}
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
} // END IF V1
THIS IS THE HAMBURGER MENU WHICH IS ALLOWING THE TROUBLESOME BULLETPOINT TO BE DISPLAYED ABOVE IT
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body bgcolor="#000000">
<!-- (A) MENU WRAPPER -->
<nav id="hamnav">
<!-- (B) THE HAMBURGER -->
<label for="hamburger">☰</label>
<input type="checkbox" id="hamburger"/>
<!-- (C) MENU ITEMS -->
<div id="hamitems">
<a href=admin_panel.php?v=8>Unoff, Verif & Photo <?php echo "($total8)"; ?></a>
<a href=admin_panel.php>Offic, Verif <?php echo "($total)"; ?></a>
<a href=admin_panel.php?v=7>Unnoff, Verif, No Photo <?php echo "($total7)"; ?></a>
<a href=admin_panel.php?v=2>UnVerif <?php echo "($total2)"; ?></a>
<a href=admin_panel.php?v=1>Active <?php echo "($total1)"; ?></a>
<a href=admin_panel.php?v=3>Blocked <?php echo "($total3)"; ?></a>
<a href=admin_panel.php?v=4>Inactive <?php echo "($total4)"; ?></a>
<a href=admin_panel.php?v=5>Test Account</a>
<a href=admin_panel_orders.php>Orders <?php echo "($total6 new)"; ?></a>
<a href=admin_email_log.php?v=7>Remind Log</a>
<a href=admin_panel_polls.php>Poll #1 Log <?php echo "($total_poll votes)"; ?></a>
<a href=admin_messages.php>Contact Mess <?php echo "($total_mess new)"; ?></a>
<a href=admin_refer_friend_log.php>Refer FRND Log <?php echo "($total_log)"; ?></a>
<a href=admin-edit-store-items.php>Products <?php echo "($total_products out of stock)"; ?></a>
<a href=admin-create-coupon.php>Coupons <?php echo "($total_coup left)"; ?></a>
</div>
</nav>
I solved this issue using style="position: relative; z-index: 0;" for the elements that must appear below other elements. The elements that must appear on top should have z-index: 1;
For details check out the 3rd point in this article!

CSS after before same width

Is it possible for CSS pseudoelements to have the same width relative to content?
This is the result that I want
My attempt:
.item::before, .item:after{
background: url(https://i.imgur.com/rL1l2Rd.png) center center no-repeat;
content: ' ';
height: 100px;
display: inline-block;
vertical-align: middle;
width: 300px;
}
<h1 class='item'>content</h1>
<h1 class='item'>larger content</h1>
Use flexbox for this
.item::before,
.item:after {
background: #000;
align-self:center;
height:7px;
border-radius:10px;
content: ' ';
margin:5px 5px 0;
}
h1 {
display:flex;
}
.item::before {
flex-basis:200px;
}
.item::after {
flex-grow:1;
}
<h1 class='item'>content</h1>
<h1 class='item'>larger content</h1>

why is div tag not working with css

I'm having issue styling grid view for my product list page. What i want is to style it in a way that four products will be display on each row and with maximum of three rows per page. Currently, what i have is product displaying vertically. Any help?
My code for product.php is:
<?php
$result=mysql_query("select * from products") or die("select * from products"."<br/><br/>".mysql_error());
while($row=mysql_fetch_array($result)){
?>
<div id="product-grid">
<div class="product-item">
<div class="product-image"><img src="<?php echo $row['picture']?>" /></div>
<div><strong><?php echo $row['name']?></strong></div>
<div class="product-description"><?php echo $row['description']?></div>
Price:
<div class="product-price">$<?php echo $row['price']?></div>
<div><input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['serial']?>)" /></div>
<?php } ?>.
My style is something like this but its not having any desirable effect.
body{width:610px;}
#product-grid {border-top: #F08426 2px solid;margin-bottom:30px;}
#product-grid .txt-heading{background-color: #FFD0A6;}
.product-item { float:left; background:#F0F0F0; margin:15px; padding:5px;}
.product-price {color:#F08426;}
.product-image {height:100px;background-color:#FFF;}
Any help will be appreciated.
You can use flex
Checkout demo below
demo
#product-grid {
display: flex;
flex-wrap:wrap;
}
.product-item {
display: inline-block;
background: #ccc;
margin:10px 0 0 10px;
width: calc(100% * (1/4) - 12px - 1px)
}
close product-item div u just forgot to close product-item div that's why your css is not working.
<?php
$result=mysql_query("select * from products") or die("select * from products"."<br/><br/>".mysql_error());
while($row=mysql_fetch_array($result)){
?>
<div id="product-grid">
<div class="product-item">
<div class="product-image"><img src="<?php echo $row['picture']?>" /></div>
<div><strong><?php echo $row['name']?></strong></div>
<div class="product-description"> <?php echo $row['description']?> </div>
Price:
<div class="product-price">$ <?php echo $row['price']?> </div>
<div>
<input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['serial']?>)" />
</div>
</div> <!--here you forgot-->
</div>
<?php } ?>
and apply overflow:hidden on #product-grid and width as you want width with float:left no need to add float:left on .product-item so just remove it
#product-grid {
border-top: #F08426 2px solid;
margin-bottom: 30px;
overflow: hidden;
float: left;
width: 25%;
}
fiddle here
Note: I recommend to you use product-item as a class not id always use class for multiple item with same name
thanks
Thanks to every one that respond to my question. It gave me an insight into fixing the problem. I was able to get my grid working using the below code
body {
font-family: "open san", verdana, sans-serif;
font-size: 12px;
line-height: 1.5em;
color: #333;
background: #ffffff;
margin: 0;
padding: 0;
text-align: center;
width: 100%;}
.prod-box{
width: 200px; height: 340px;
padding: 10px; margin: 15px;
background-color: #fff;
float: left;
}
.prod-box img:first-child, .prod-box-list img:first-child{width: 190px; float: left;}
.prod-box h3 a{
text-decoration: none;
width:140px;
float: left;
margin: 5px 0;
color:#888;
font: italic normal 14px georgia;
font-style: italic;
}
.prod-box p{ display: none;}
.prod-box .old{
margin-right: 20px;
color: #be0000 !important;
text-decoration: line-through;
}
.prod-box .price{
width: 60px;
display: inline;
float: left;
font: italic 13px georgia;
color: #181818;
}
.prod-box .cart-ico{
border-radius: 20px;
width: 35px; height: 35px;
float: right;
margin: 5px;
cursor: pointer;
}
.prod-box .cart-ico:hover{
background-color: #7eb800;
}

Multiple divs in absolute

I reached to a problem in my website.
My website is showing all the records in she same page, that each record calls the main div called "work" and inside of that one is calling another one called "worktitle".
I want the worktitle div stays like the image:
Image
But the problem is on the second row. The divs that belongs to the seconda row are in the same place as the first row.
Like you can see here:
Website
HTML Code
<div id="box1">
<?php do { ?>
<div id="work">
<a href="<?php echo $row_works['url']; ?>" target="new">
<img src="images/<?php echo $row_works['image']; ?>" />
<div class="worktitle">
<span class="infotec"><?php echo $row_works['infotec']; ?><br/>
<?php if ((isset($_GET['lang'])) && ($_GET['lang']=="en")) {
echo $row_works['descriptionen']; }
else {
echo $row_works['descriptionpt'];
} ?>
</span>
<span class="title"><?php echo $row_works['title']; ?></span>
</div>
</a>
</div>
<?php } while ($row_works = mysql_fetch_assoc($works)); ?>
</div>
CSS Code
#work {
float: left;
margin: 0px;
padding: 0px;
width : 200px;
border: solid 1px #787879;
}
#work a{
color: #FFF;
text-decoration:none;
}
#work a:hover {
opacity: 0.5;
}
#work img {
margin: 0px;
width: 200px;
z-index: 9;
}
a img{
border: 0;
}
.worktitle {
position: absolute;
top: 200px;
background-color: #787879;
opacity: 0.6;
font-weight: bold;
font-size: 14px;
z-index: 10;
}
.infotec {
font-weight: normal;
font-size:9px;
}
.title {
text-align: right;
}
What am i doing wrong? Please help me out.
First of all id's must be unique in your html so change #work to .work then try giving it a relative position and aligning your description to the bottom.
.work{
position: relative;
}
.worktitle {
position: absolute;
bottom: 0;
}

Simple CSS Images Side By Side

I'm having a problem displaying images side by side inside of an overflow box.
They seem to be going to the end of the box then going to a new line for some reason.
Here's what I got:
<div style="overflow-x:auto; overflow-y:hidden; white-space:nowrap; width:500px; height:145px;">
<?php
for ($i=1; $i<=9; $i++) {
echo "<table><tr><td>";
echo "<img src=\"images/store/" . $i . ".jpg\" height=\"100px\" />";
echo "<br /><center><img src=\"images/store/buy.png\" width=\"75px\" /></center></td></tr></table>";
}
?>
</div>
Any help would be amazing!
I would recommend updating and formatting your code better, then addressing the issue you're having.
Don't echo out HTML tags using PHP.
Don't use inline-styles applied directly to the tags (use classes/ids)
Don't use tables, for non-tabular data.
With that said, here is a working example of what I believe you're trying to achieve:
http://jsfiddle.net/a8yDv/
PHP/HTML:
<div class="images">
<ul>
<?php for ($i=1; $i<=9; $i++) : ?>
<li>
<img src="images/store/<?php echo $i; ?>.jpg" class="top-image" alt="" />
<img src="images/store/buy.png" class="bottom-image" alt="" />
</li>
<?php endfor; ?>
</ul>
</div>
CSS:
.images {
border: 5px solid red;
height: 145px;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
width: 500px;
}
.images ul {
list-style-type: none;
margin: 0;
padding: 0;
white-space: nowrap;
}
.images li {
display: inline-block;
text-align: center;
}
.images img {
display: block;
margin: 0 auto;
}
.images img.top-image {
height: 100px;
margin-bottom: 5px;
}
.images img.bottom-image {
width: 75px;
}
/* Clearfix - http://css-tricks.com/snippets/css/clear-fix/ */
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-block; }
/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */
You could use the white-space:nowrap; property in your styles:
div {
overflow-x:auto;
overflow-y:hidden;
white-space:nowrap;
width:500px;
height:100px;
}
Demo.
I believe all I really had was a bug, and #Yamo seemed to point it out for me. Everything works fine now!
<div style="overflow-x:auto; overflow-y:hidden; white-space:nowrap; width:500px; height:145px;">
<table><tr>
<?php
for ($i=1; $i<=9; $i++) {
echo "<td><img src=\"images/store/" . $i . ".jpg\" height=\"100px\" />";
echo "<br /><center><img src=\"images/store/buy.png\" width=\"75px\" /></center></td>";
}
?>
</tr></table>
</div>

Resources