How to make good view with bootstrap and html? - php

I have a little problem.I'm still, learn to program and I don't have very good knowledge.
I'm trying to make view like this:
In this view items are located very evenly.
In my view items are not looking good:
Why i have to repair in my code to look like this online shop view?
My code is here:
<?php foreach($posts as $post) : ?>
<div class="col-xs-12 col-sm-6 col-md-4">
<h3><?php echo $post['title']; ?></h3>
<?php if($this->session->userdata('logged_in')) :?>
<small class="post-date">Posted on: <?php echo $post['created_at']; ?> in <strong><?php echo $post['name']; ?></strong></small>
<?php endif ?>
<div class="zoom-in">
<img class="post-thumb" src="<?php echo site_url(); ?>assets/images/posts/<?php echo $post['post_image']; ?>">
</div>
<?php echo word_limiter($post['body'],10); ?>
<b></b>
<input type="button" class="btn btn-danger addcart" productid="<?php echo $post['id'] ?>" value="Добави в количката">
<p><a class="btn btn-link" href="<?php echo site_url('/posts/'.$post['slug']); ?>">Read more</a></p>
</div>
<?php endforeach; } ?>
Thank you in advance!

resize Image Like this
html, body {
color: #333;
font-size: 16px;
line-height: 20px;
}
body {
margin: 20px;
}
h1 {
line-height: 1.2;
margin-bottom: 35px;
text-align: center;
}
h2 {
text-align: center;
}
img {
height: auto;
max-width: 100%;
}
.image-grid {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin: 0 auto 35px;
max-width: 920px;
}
.svg-image-grid {
clear: both;
margin: 0 auto 35px;
max-width: 920px;
overflow: hidden;
position: relative;
}
/** Screen readers only class from Bootstrap */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0,0,0,0);
white-space: nowrap;
clip-path: inset(50%);
border: 0;
}
/** Actual code examples */
/** Background */
.image-bg {
background-position: center center;
background-size: cover;
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
margin: 5px;
width: calc(25% - 10px);
}
.image-bg-placeholder {
height: 100%;
visibility: hidden;
width: 100%;
}
/** Object-fit */
.image-fit {
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
margin: 5px;
position: relative;
width: calc(25% - 10px);
}
.image-fit-placeholder {
height: 100%;
visibility: hidden;
width: 100%;
}
.image-fit-img {
bottom: 0;
height: 100%;
left: 0;
object-fit: cover;
object-position: center;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
/** Absolute positioning */
.image {
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
margin: 5px;
overflow: hidden;
position: relative;
width: calc(25% - 10px);
}
.image-placeholder {
height: 100%;
visibility: hidden;
width: 100%;
}
.image-img {
left: 50%;
max-height: 150%;
max-width: 177%;
position: absolute;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
/** SVG */
.image-svg {
float: left;
margin: 5px;
padding-bottom: calc(25% - 10px);
position: relative;
width: calc(25% - 10px);
}
.image-svg svg {
bottom: 0;
display: block;
height: 100%;
left: 0;
position: absolute;
right: 0;
top: 0;
width: 100%;
}
/** Responsive grid */
#media (max-width: 480px) {
.image,
.image-fit,
.image-bg,
.image-svg {
width: calc(50% - 10px);
}
.image-svg {
padding-bottom: calc(50% - 10px);
}
}
<h1>Techniques to crop and resize images with CSS</h1>
<h2>Image as a background</h2>
<div class="image-grid">
<a href="https://www.flickr.com/photos/teroauralinna/33704491300" class="image-bg" style="background-image:url(https://farm3.staticflickr.com/2809/33704491300_1df01dd919_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm3.staticflickr.com/2809/33704491300_1df01dd919_z_d.jpg" alt="Cropped image as a background example" />
</a>
<a href="https://www.flickr.com/photos/teroauralinna/33704488370" class="image-bg" style="background-image:url(https://farm3.staticflickr.com/2848/33704488370_9572b9d270_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm3.staticflickr.com/2848/33704488370_9572b9d270_z_d.jpg" alt="Cropped image as a background example" />
</a>
<a href="https://www.flickr.com/photos/teroauralinna/34088934825" class="image-bg" style="background-image:url(https://farm4.staticflickr.com/3947/34088934825_0acfe80a04_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm4.staticflickr.com/3947/34088934825_0acfe80a04_z_d.jpg" alt="Cropped image as a background example" />
</a>
<a href="https://www.flickr.com/photos/teroauralinna/34088930595" class="image-bg" style="background-image:url(https://farm4.staticflickr.com/3956/34088930595_2b84cec168_z_d.jpg)" target="_blank">
<img class="image-bg-placeholder" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
<img class="image-bg-img sr-only" src="https://farm4.staticflickr.com/3956/34088930595_2b84cec168_z_d.jpg" alt="Cropped image as a background example" />
</a>
</div>

Related

how to put an icon on an image with Php CSS?

I have images in a file with its name in the database. And I would like to display it in a responsive list. But I would like to add for each image an icon in a corner (or text below the frame) of the image to remove it if necessary. here is my html and php code
<?php
$sqlimage = "SELECT * FROM images where `id_user` = '".$customer_id."'";
$result = mysqli_query($conn, $sqlimage);
foreach ($result as $imageShow) {
?>
<div class="container">
<h1>Image Galerry</h1>
<div class="image-container">
<div class="image">
<img src="<?php echo 'Media/'.$imageShow['file_name'] ?>" alt="">
<div>
<i class='fa fa-trash' style='color: red'></i>
</div>
</div>
<div class="linkDelete"
style="font-size: 13px;position:absolute;text-align:center; width:26px; padding-top:3px">
Delete
</div>
<?php
}
mysqli_close($conn);
?>
</div>
<div class="popup-image">
<span>×</span>
<img src="Media/3-20220714-68033.jpg" alt="">
</div>
</div>
And here is my CSS3 code to display the images
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container{
position: relative;
min-height: 100vh;
background-color: #191C24 !important;
}
.container h1{
font-size: 40px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-weight: normal;
padding: 15px;
color: #333;
text-align: center;
text-transform: capitalize;
}
.container .image-container{
display: flex;
flex-wrap: wrap;
gap:15px;
justify-content: center;
padding: 10px;
}
.container .image-container .image{
height: 250px;
width: 350px;
border: 10px solid #fff;
box-shadow: 0 5px 15px rgba(0, 0, 0, .1);
overflow: hidden;
cursor: pointer;
float: left;
}
.linkDelete{
float: left;
clear: left;
}
.container .image-container .image img{
height: 100%;
width: 100%;
object-fit: cover;
transition: .2s linear;
}
.container .image-container .image a{
height: 100%;
width: 100%;
object-fit: cover;
transition: .2s linear;
}
.container .image-container .image:hover img{
transform: scale(1.1);
}
.container .popup-image{
position: fixed;
top: 50px;
left: 0px;
background: rgba(0, 0, 0, .9) ;
height: 100%;
width: 100%;
z-index: 100%;
display: none;
}
.photo-name{
position: absolute;
width: 100%;
bottom: 30px;
text-align: center;
background-color: cyan;
}
/* .image-container{
position:relative;
}
.image-container a{
position:absolute;
bottom:0px;
right:0px;
} */
.container .popup-image span{
position: absolute;
top: 0;
right: 10px;
font-size: 60px;
font-weight: bolder;
color: #fff;
cursor: pointer;
z-index: 100;
}
.container .popup-image img{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border: 5px solid #333;
border-radius: 5px;
width: 75%;
object-fit: cover;
}
#media (max-width:768px){
.container .popup-image img{
width: 95%;
}
}
I would like to have an image and on this image there is the icon which tells me the link to delete which is already prepared
I tried several ways but each time I find the icon in a position since the images with different dimensions.
If there was a possibility if not below the image a link to delete it and thank you in advance.
Set position: relative; on .image. Then set a class on the parent div for the icon. I called it .icon-wrapper. Set this parent to position: absolute; with top: 0;. Then you can use width and height: 100%; so it falls directly on top of your .image div.
Then you can use display: flex; with align-items: center; and justify-content: center; on .icon.wrapper to align the icon vertically and horizontally.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: relative;
min-height: 100vh;
background-color: #191C24 !important;
}
.container h1 {
font-size: 40px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-weight: normal;
padding: 15px;
color: #333;
text-align: center;
text-transform: capitalize;
}
.container .image-container {
display: flex;
flex-wrap: wrap;
gap: 15px;
justify-content: center;
padding: 10px;
}
.container .image-container .image {
height: 250px;
width: 350px;
border: 10px solid #fff;
box-shadow: 0 5px 15px rgba(0, 0, 0, .1);
overflow: hidden;
cursor: pointer;
float: left;
}
.linkDelete {
float: left;
clear: left;
}
.container .image-container .image img {
height: 100%;
width: 100%;
object-fit: cover;
transition: .2s linear;
}
.container .image-container .image a {
height: 100%;
width: 100%;
object-fit: cover;
transition: .2s linear;
}
.container .image-container .image:hover img {
transform: scale(1.1);
}
.container .popup-image {
position: fixed;
top: 50px;
left: 0px;
background: rgba(0, 0, 0, .9);
height: 100%;
width: 100%;
z-index: 100%;
display: none;
}
.photo-name {
position: absolute;
width: 100%;
bottom: 30px;
text-align: center;
background-color: cyan;
}
/* .image-container{
position:relative;
}
.image-container a{
position:absolute;
bottom:0px;
right:0px;
} */
.container .popup-image span {
position: absolute;
top: 0;
right: 10px;
font-size: 60px;
font-weight: bolder;
color: #fff;
cursor: pointer;
z-index: 100;
}
.container .popup-image img {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border: 5px solid #333;
border-radius: 5px;
width: 75%;
object-fit: cover;
}
#media (max-width:768px) {
.container .popup-image img {
width: 95%;
}
}
i {
font-size: 3em;
color: red;
}
.image {
position: relative;
}
.icon-wrapper {
position: absolute;
width: 100%;
height: 100%;
top: 0px;
display: flex;
align-items: center;
justify-content: center;
}
<script src="https://kit.fontawesome.com/6140596fcb.js" crossorigin="anonymous"></script>
<div class="container">
<h1>Image Galerry</h1>
<div class="image-container">
<div class="image">
<img src="https://dummyimage.com/300/000/fff" alt="">
<div class="icon-wrapper">
<i class="fa-solid fa-trash"></i>
</div>
</div>
<div class="linkDelete" style="font-size: 13px;position:absolute;text-align:center; width:26px; padding-top:3px">
Delete
</div>
</div>
<div class="popup-image">
<span>×</span>
<img src="Media/3-20220714-68033.jpg" alt="">
</div>
</div>
Thanks for adding the delete icon. But this one blocked me from displaying the full size image when I click inside the photo (the popup-image class action).
In the CSS
.container .popup-image img{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border: 5px solid #333;
border-radius: 5px;
width: 75%;
object-fit: cover;
}
#media (max-width:768px){
.container .popup-image img{
width: 95%;
}
}
And in the HTML
<div class="popup-image">
<span>×</span>
<img src="Media/3-20220714-68033.jpg" alt="">
</div>

How do I make my embedded pdf file to be full screen on my website?

This is what I've got but this doesn't solve the problem for different devices and screen sizes.
<html>
<body>
<iframe src="FILE LINK" width="1920" height="1080"></iframe>
</body>
</html>
How do I make it full screen? I've tried width: 100%; height: 100%
For reaching fullscreen in this case you need to use height: 100vh;, width: 100%;
body {
margin: 0;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
.landing {
width: 100%;
height: 100vh;
}
.image-list {
margin: 0;
padding: 0;
list-style: none;
width: 100%;
height: 100vh;
border: 6px solid #00f;
overflow: hidden;
}
.image-list .image {
border: 6px solid #f00;
width: 100%;
height: 400px;
background-size: cover;
background-position: center center;
height: 100vh;
}
.centered-element {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background: #fff;
padding: 1rem;
width: 280px;
}
.centered-element ul {
margin: 0;
padding: 0;
list-style: none;
}
.centered-element ul span {
opacity: 0.4;
}
<!-- body -->
<section class='landing'>
<ul class='image-list'>
<li class='image'
style='background-image: url(https://unsplash.it/1600/1600)'>
</li>
<li class='image'
style='background-image: url(https://unsplash.it/1600/1800)'>
</li>
<li class='image'
style='background-image: url(https://unsplash.it/1600/1700)'>
</li>
</ul>
</section>
<!-- /body -->
Well, a simple snippet like the following one did the trick for me:
body {
height: 100%;
width: 100%;
margin: 0;
padding: 5px;
box-sizing: border-box;
}
html {
height: 100%;
}
<iframe src="#" width="100%" height="100%"></iframe>
Just play with the containers.
You should of course set your own container sizes to 100% and not html and body.

how to fix dynamic images in bootstrap 4

I've a working app build in php/JQuery and bootstrap 3. I will convert this to bootstrap 4 and I've issues. In bootstrap 3 the dynamic images from the database were aligned 4 in a row. And if there were more than 4 images it created a new row. In bootstrap 4 the images are only shown in 1 column vertically.
Here is my coding:
getcustomer.php:
$i=$_REQUEST["id_ind"];
$sel="select * from customer_segment where industry_id='".$i."' LIMIT 12";
$qry=mysqli_query($conn, $sel);
while($row=mysqli_fetch_array($qry, MYSQLI_BOTH))
{
echo '
<h3><div class="col-12 col-lg-3 col-xl-3 customer_image count" style="position: relative;" id="'.$row[3].'">
<label class="container1">
<div class="customer-img" onclick="getdata_cont('.$row[0].')"><?php echo $row_ind["description"];>
<div class="img-fluid"> <img src="images/'.$row[3].'" class="picture"></div>
<div class="on-overlay" id="img-fluid" >
<span class="span1">'.$row[1].'</span>
<input type="radio" checked="checked" name="radio">
<span class="checkmark"></span>
</div>
</div>
</div>
</label>
</div><h3>';
}
?>
index.php:
<!-- Step 2: Choose customer segment -->
<div class="row" id="customer_segment_hide">
<div class="col-md-12 col-8" style="text-align: center;margin-top: 50px;margin-bottom: 37px;">
<div class="div2 ">
<h2>2</h2>
</div>
<span class="span"><b>Choose Customer Segment </b></span>
<p class="p1">By clicking on a image below you go to the third step</p>
</div>
<div class="container">
<div class="col-md-12 addd">
<div class="pppp">
<p style="color: #FFF;font-size: 17px; text-align:center;margin-bottom:25px"><h4>How might we help?</h4></p>
</div>
</div>
</div><!-- Step 2: Close-->
</div>
<!-- JS: get customers segment -->
<script>
function getdata(id_ind)
{
$.ajax({
url:"getcustomer.php",
// ids= industry_id
data:{id_ind:id_ind},
type:'GET',
success: function(data){
$('.pppp').html(data);
}
});
}
</script>
style.css:
/* create blue square step 2 & 3 */
.addd{
background-color: #198bd1;
position:relative;
height: 430px;
margin-bottom: 132px;
}
/* create bigger blue square step 2 when there more then 8 images */
.addd2{
background-color: #198bd1;
position: relative;
height: 670px;
margin-bottom: 290px;
}
/* Step 2 plot images and defined width */
.pppp{
display: inline-block;
width: 100%;
padding: 30px 0;
}
/* image card size */
.customer-img{
width:75%;
margin:0 auto;
position:relative;
}
.customer-img img {
border-radius:20px;
width:100%;
z-index: 999;
height: 235px;
}
.on-overlay{
display:table;
position:absolute;
top:0;
left:0;
width:100%;
height:235px;
text-align:center;
background: rgba(0,0,0,0.3);
border-radius:20px;
padding-bottom: 123%;
}
.on-overlay span:not(.checkmark){
/*line-height: 9;
vertical-align:middle;
color:#fff;
display: table-cell;*/
position: absolute;
margin-left: -36%;
color: #fff;
text-align: center;
width: 76%;
top: 20%;
}
.checkmark {
position: absolute;
top: 74%;
left: 70%;
height: 25px;
width: 25px;
border-radius: 50%;
}
/* Title card */
.span1 {
display: inline-block;
font-size: 1.5rem;
text-align: center;
}
.choose
/* The container */
.container1 {
display: block;
position: relative;
/*padding-left: 35px;*/
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default checkbox */
.container1 input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* On mouse-over, add a grey background color */
.container1:hover input ~ .checkmark {
}
/* When the checkbox is checked, add a blue background */
.container1 input:checked ~ .checkmark {
background-color: #2196F3;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.container1 input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.container1 .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.col-xl-3 {
width: 25%;
text-align: center;
}
.os-img-overlay {
position: absolute;
background: rgba(34,34,34,.3);
left: 37px;
top: 5px;
border-radius: 30px;
width: 71%;
height: 350px;
}
.close {
cursor: pointer;
position: absolute;
top: 7%;
padding: 12px 16px;
transform: translate(0%, -50%);
left: 0;
}
.os-img-title {
color: #f5f5f5;
font-family: 'Lato',sans-serif;
font-weight: bold;
font-size: 20px;
letter-spacing: 1px;
text-align: center;
width: 100%;
z-index: 2;
padding: 0 2px;
line-height: 20px;
max-width: 175px;
}

Dynamic donut chart not correctly calculating sizes of strips

I'm trying to make a dynamic donut chart with data coming from custom fields in Wordpress.
At the moment it's not calculating the strips in the chart correctly - here's my fiddle https://jsfiddle.net/sq6mh5wp/. Just as an example I've set the four strips to be a quarter but it's only showing 3 strips, where am I going wrong?
Here's the actual template:
<div class="container">
<div class="donut-chart-block block">
<div class="donut-chart">
<?php if( have_rows( 'pie_chart' ) ):
$counter = 1; ?>
<?php while( have_rows( 'pie_chart' ) ): the_row(); ?>
<div class="clip clip-<?php echo $counter; ?>" style="transform: rotate(<?php echo the_sub_field( 'number' ); ?>deg);">
<div class="item item-<?php echo $counter; ?>" data-rel="<?php echo the_sub_field( 'number' ); ?>" style="transform: rotate(<?php echo the_sub_field( 'number' ); ?>deg);"></div>
</div>
<?php $counter++;
endwhile; ?>
<?php endif; ?>
<div class="center"></div>
</div>
</div>
</div>
Here's the CSS:
.donut-chart-block {
overflow: hidden;
}
.donut-chart {
position: relative;
width: 200px;
height: 200px;
margin: 0px;
border-radius: 100%;
margin-left: auto;
margin-right: auto;
}
.donut-chart .center {
background: white;
position: absolute;
top: 50px;
left: 50px;
height: 100px;
width: 100px;
border-radius: 70px;
}
.clip {
border-radius: 50%;
clip: rect(0px, 200px, 200px, 100px);
height: 100%;
position: absolute;
width: 100%;
}
.item {
border-radius: 50%;
clip: rect(0px, 100px, 200px, 0px);
height: 100%;
position: absolute;
width: 100%;
font-family: monospace;
font-size: 1.5rem;
}
.donut-chart .item-1 {
background-color: #178c8e;
}
.donut-chart .item-2 {
background-color: #1e5eaa;
}
.donut-chart .item-3 {
background-color: #eac947;
}
.donut-chart .item-4 {
background-color: #143753;
}
.donut-chart .item-5 {
background-color: #0faeb1;
}
Your first clip is set to 0deg rotation. However, 0 degrees on a pie chart has 0 width. Zero = Zero so you will want to change the first clip to a positive number. Then you will need to adjust the rest accordingly.
You made mistakes in calculations. You must rotate correctly.
.donut-chart-block {
overflow: hidden;
}
.donut-chart {
position: relative;
width: 200px;
height: 200px;
margin: 0px;
border-radius: 100%;
margin-left: auto;
margin-right: auto;
}
.donut-chart .center {
background: white;
position: absolute;
top: 50px;
left: 50px;
height: 100px;
width: 100px;
border-radius: 70px;
}
.clip {
border-radius: 50%;
clip: rect(0px, 200px, 200px, 100px);
height: 100%;
position: absolute;
width: 100%;
}
.item {
border-radius: 50%;
clip: rect(0px, 100px, 200px, 0px);
height: 100%;
position: absolute;
width: 100%;
font-family: monospace;
font-size: 1.5rem;
}
.donut-chart .item-1 {
background-color: #178c8e;
}
.donut-chart .item-2 {
background-color: #1e5eaa;
}
.donut-chart .item-3 {
background-color: #eac947;
}
.donut-chart .item-4 {
background-color: #143753;
}
.donut-chart .item-5 {
background-color: #0faeb1;
}
<div class="container">
<div class="donut-chart-block block">
<div class="donut-chart">
<div class="clip clip-1" style="transform: rotate(0deg);">
<div class="item item-1" data-rel="90" style="transform: rotate(90deg);"></div>
</div>
<div class="clip clip-2" style="transform: rotate(90deg);">
<div class="item item-2" data-rel="180" style="transform: rotate(90deg);"></div>
</div>
<div class="clip clip-3" style="transform: rotate(270deg);">
<div class="item item-3" data-rel="270" style="transform: rotate(90deg);"></div>
</div>
<div class="clip clip-4" style="transform: rotate(180deg);">
<div class="item item-4" data-rel="360" style="transform: rotate(90deg);"></div>
</div>
<div class="center"></div>
</div>
</div>
</div>
<!-- begin snippet: js hide: false console: true babel: false -->

CSS: Vertically align user profile picture and username in header

The header was vertically aligned before I tried including the user's profile picture, but I can't seem to get it now. After trial and error, this is what I have so far:
HTML/PHP:
<ul id="right-side">
<li>
<a href="">
<img src="<?php echo $user['profile_pic'];?>" id="profilepic">
<?php echo $user['user_name'];?>
</a>
</li>
</ul>
CSS:
nav {
position: fixed;
right: 0px;
top: 0px;
z-index: 1000;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
}
#right-side {
display: inline;
float: right;
text-align: right;
}
#right-side a {
vertical-align: middle;
}
#profilepic {
height:50px;
width 50px;
border-radius:50px;
}
You can try this code.
nav {
position: fixed;
right: 0px;
top: 0px;
z-index: 1000;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
padding: 0 10px;
}
#right-side {
display: inline;
float: right;
text-align: right;
}
#right-side li {
list-style-type: none;
}
#right-side a {
display: flex;
align-items: center;
}
#right-side a img {
margin-right: 10px;
}
#profilepic {
height:50px;
width 50px;
border-radius:50px;
}
<nav>
<ul id="right-side">
<li>
<a href="">
<img src="https://cdn.onlinewebfonts.com/svg/img_235843.png" id="profilepic">
John
</a>
</li>
</ul>
</nav>
I assume you mean you want the username and picture to both be aligned vertically, side by side? If so, check out this fiddle.
CSS
#right-side {
display: inline;
float: right;
text-align: right;
}
#profile-pic {
left: 0;
float: left;
width: 50px;
}
#profile-name {
margin-left: 55px;
top: 0;
}
#profilepic {
height: 50px;
width: 50px;
border-radius: 50px;
}
HTML
<ul id="right-side">
<div id="profile-pic">
<img src="https://i.stack.imgur.com/34AD2.jpg" id="profilepic">
</div>
<div id="profile-name">
User Name
</div>
</ul>

Categories