Make element appear to the right of a div - html

I'm making this little website, and I'm trying to make user profiles. I'm honestly not the best with HTML and CSS but basically, my problem is, that I want to display the profile picture in the top left of the "jumbotron" (I'm using bootstrap), and have the username just to the right of it, with a little paragraph/quote/motto beneath the username. However, I cannot get it to work.
Here is my current code:
HTML
<div class="container">
<!-- Profile Jumbotron-->
<div class="jumbotron">
<div class="profile-picture">
</div>
<h1><?php echo "$profile_name" ?></h1>
</div>
</div>
CSS:
.jumbotron {
margin-top: 5%;
margin-bottom: 2%;
}
.profile-picture {
width: 200px;
height: 200px;
background-color: white; /* Just as a test profile picture */
}
Here is the result of this code
I have tried to right-align the text, but to no avail.
Of course, there's the obvious float:right, which works well enough, but then the height of the jumbotron gets all screwed up! Unless I am doing something wrong with that.
So with all that said, I hope someone can help me, as you seem pretty helpful here!
Thank you for taking the time to read my issue, and I hope you can assist me in fixing it!

<div class="container">
<!-- Profile Jumbotron-->
<div class="jumbotron col-md-12">
<div class="profile-picture pull-left col-md-5">
<img class="img img-responsive" src="Your image" style="width:200px"/>
</div>
<h1 class="pull-right col-md-7">
<?php echo "$profile_name" ?>
</h1>
</div>
</div>
.profile-picture {
background-color: white; /* Just as a test profile picture */
}
I think something like this would do the trick since you are using bootstrap framework. Note the css classes I have put pull-left and pull-right. col-md-5 and col-md-7 are used to divide the div columnwise.
by using img-responsive you will be able to proportionally align image inside the div.

You can do one easy thing (picture, name and quote are all divs):
<------------------- LARGE DIV ------------------->
<---PICTURE(float:left) NAME(float:right)
<br>
QUOTE(float: right)
<------------------------------------------------->
How to accomplish this:
<div id="profileContainer" style="width: 800px;">
<div id="picture" style="width: 200px; float: left;"><img src="yourimage.jpg"></div>
<div id="name" style="width: 400px;"><?php echo "$profile_name" ?></div>
<br>
<div id="quote" style="width: 400px; float:right;">Text about stuff</div>
</div>
So basically you have the profileContainer div with a width you want, the picture with the width of the div being the picture size and the name floating to the right. By changing the profileContainer width you can get the name closer to the picture, or you can also set a margin-right: #px; on the Name and the Quote.

Related

Why can't I fix my image to the left side of my bootstrap website?

I have tried using ml-auto class, float: left, the float-left class, and fixed-left class, but none of those have worked in fixing my image to the left. I don't want to use margin since that's not responsive on different sizes(some white-space is present there most of the time). I have looked at other people who had the same question, but the answers to those were just the owner having a typing mistake, and after looking through mine, I haven't found any.
Please leave an explanation or a link so I can learn which of these methods to use to push my image to the right and which is more suitable for different situations. Here's my JSfiddle, this includes all of my HTML and CSS.
https://jsfiddle.net/1kdtjmh8/
Here is the code for the image I'm having issues with
<div class="container">
<div class="row">
<div class="col-lg img-col">
<img class="img-fluid home-image ml-auto" src="HomeImage.jpg" alt="">
</div>
Here is the CSS
.home-image{
height: 100vh!important;
width: auto!important;
display: block;
float:left;
}
You are using container which has a max width of 1140px which is creating the space. you can replace that with container-fluid and this should solve the issue
Please go through below codepen.io URL you will find the working solutions for your query.
It can resolved with two resolutions:-
By making the container class to container-fluid and keep all the css and html as it is.
Visit this Link:- https://codepen.io/nimesh049/pen/NWjaxaY
.userImage{
height: 150px!important;
width: auto!important;
float:right;
}
<div class="container">
<div class="row">
<h1>Image Holder</h1>
<div class="col-lg img-col">
<img class="d-block userImage " src="https://www.pngfind.com/pngs/m/610-6104451_image-placeholder-png-user-profile-placeholder-image-png.png" alt="" />
</div>

How to remove space from container

I have a container on my landing page and it makes white space. I want it full screen. I try to make the top and right 0px, but the right still edge.
This is what looks like
And this is what I want
The code
<section class="zerra-porto">
<div class="container">
<div class="row">
<div class="col align-self-center">
<h1 class="mb-4">
Hi, My Name is <br />
Sumnit Parfit
</h1>
<p>A Front End Developer</p>
Get to know
</div>
<div class="col">
<img src="/images/foto.png" alt="" class="landing-pic" />
</div>
</div>
</div>
</section>
.zerra-porto .landing-pic {
position: relative;
right: 0px;
top: 0px;
z-index: -1;
}
Can you please check the below code? Hope it will work for you. Based on your question, we have understood that you need your content inside the container but you want your banner image outside the container, for that, we have made modifications in your HTML structure and positioned the Image in right as per your required screenshot.
Please refer to this link: https://jsfiddle.net/yudizsolutions/zgcydft1/

HTML Bootstrap placing an image into a column within row

I am using a container with a row construct to make a header. I would like for the leftmost column to have an image. However, whenever I add an image it gets added full sized. I would like it to be limited to the set size of that column.
This is my current HTML code:
.logo {
max-width: 100%;
max-height: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="jumbotron" >
<div class="container">
<div class="row">
<div class="col-xs-1">
<div class="image-container">
<center>
<img src="https://i.pinimg.com/originals/fb/76/5b/fb765b8752d50de50cfa15203f9a7acd.png" alt="test" class="logo">
</center>
</div>
</div>
<div class="col-xs-10">
<h2><center>TEST HEADER</center></h2>
<h4><center>TEST SUBTEXT</center></h4>
</div>
<div class="col-xs-1">
<center>wowow</center>
</div>
</div>
</div>
</div>
I tried adding the in my CSS file but it did not change anything.
How can I have it such that the image follows the set size of the container?
Try adding the below css:
.image-container .logo{
width:100%;
}
The image is taking the full size of the col-xs-1 column. Just it is taking padding from left and right which all col- classes have.
If you want to make image a little bigger, then define its height (or width any one ) in px.
like the below:
.image-container .logo {
width: 100px;
}

Need to keep image (horizontal / vertical) in a fixed height div

I am following my previous question that has two boxes, that have two images (can be vertical or horizontal), the issue is the height of boxes are fixed and when I change the window screen in some screen sizes the images bypass the border of the boxes.
I checked answers of these questions 1 and 2 but did not help much.
DEMO
CSS
.items { */
position: relative;
margin-bottom: 7px;
margin-left: 7px;
margin-right: 0px;
text-align: left;
background-color: red;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
border-bottom-left-radius: 20px;
padding-left: 1%;
height:260px;
}
.col-md-12.col-xs-12.btn>a>img {
float: right;
width: 100px;
height: 50px;
}
.col-md-12.col-xs-12.my-col {
padding-left: 100%;
}
.my-row {
bottom: 0;
padding-right: 0;
position: absolute;
}
.my-row {
bottom: 0;
padding-right: 0;
position: absolute;
}
.btn {
float: right;
bottom:0;
margin-right:-12px;
margin-bottom:-6px;
position:absolute;
right:0;
}
HTML
<div class="container-fluid">
<div class="row">
<div class="col-md-3 items">
<div class="row">
<div class="col-md-12 text-center">
<h4>T1</h4>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<h5>T2</h5>
</div>
</div>
<div class="row">
<div class="col-md-12 row text-center">
<a
href="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQKWYNnGt8d9G1sf8PE0TpOglpZ2dKnHWAP5FB_spYgelcToong"
title="T1" data-gallery rel="nofollow"> <img
id="imageresource"
src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQKWYNnGt8d9G1sf8PE0TpOglpZ2dKnHWAP5FB_spYgelcToong"
class="img-thumbnail" width="30%" style="margin-left: 30px;" />
</a>
</div>
</div>
<div>
<img src="#" class="btn" />
</div>
</div>
<div class="col-md-3 items">
<div class="row">
<div class="col-md-12 text-center">
<h4>T1</h4>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<h5>T2</h5>
</div>
</div>
<div class="row">
<div class="col-md-12 row text-center">
<a
href="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQKWYNnGt8d9G1sf8PE0TpOglpZ2dKnHWAP5FB_spYgelcToong"
title="T1" data-gallery rel="nofollow"> <img
id="imageresource"
src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQKWYNnGt8d9G1sf8PE0TpOglpZ2dKnHWAP5FB_spYgelcToong"
class="img-thumbnail" width="25%" style="margin-left: 30px;" />
</a>
</div>
</div>
<div>
<img src="#" class="btn" />
</div>
</div>
</div>
</div>
</div>
First off, the markup is over complicated for what you want and line 15 and 45 are applying bootstrap classes .col-md-12 and .row on the same element which is in incorrect. Bootstrap class .col-xx-nn must be assigned to a child element with a bootstrap class .row.
Getting back on track to what you want. I have simplified the HTML code to get your desired result, I think. Check it out and let me know what isn't right and I will change it and explain why.
https://jsfiddle.net/6y4uf16y/84/
What I did was create a container div around the sale image that uses the CSS flex box. This div will take up any remaining space. Therefore, if you change the height of your .items element. The flexbox container will adapt and the sale image will respond appropriately to the new size. There is no fixed heights here except for the one that was placed on the .items class of 260px which I believe is what you wanted.
The reason for this is that the bootstrap class .img-reponsive needs a height and/or width attribute to be responsive. Therefore, I have set the height and width equal to the flex box container around it. You can change the width value or .img-sale back to 30% if you wish.
Moreover, as a bonus, I have aligned the button to always be in the bottom right corner as I think you wanted it.
If this answer solves your problem, don't forget to mark it as the correct solution.
Cheers
Edit Sorry wrong JSFiddle link, correct link has been added. I also added proof that it is dynamic with multiple rows of text in the h4 and h5 elements.
You have to add class
.col-md-12 >a>img.btn {
float: right;
width: 100px;
height: 50px;
}
because .col-md-12.col-xs-12.btn>a>img is not applying to any of your given HTML div content
Is it a design requirement that the images get wider as the boxes get wider? If so, the only way to keep the images within the boxes is to increase the height of the boxes as you increase the height of the images.
If it's not a requirement that the images scale up, then you can see my solution here: http://jsfiddle.net/6y4uf16y/75/
All I did was remove the explicit widths from your images (the first was width="25%" and the second was width="30%") and instead used CSS to control the scale by limiting the max-height of the images. .items img {max-height:100px;}.
Since you have a fixed height and need to keep the images inside the boxes, you know for a fact that also have a fixed maximum height on the images
I am not sure if you can have line break on T1 & T2, otherwise you can do this
img{
max-height:170px;
width:auto
}
DEMO
i agree with #Bhavin Solanki and may be the one thing i will suggest that try to give the
width: 100px;
height: 50px;
in to percentages Or else you can go with Media queries for the particular image selectors that will help you to manage a lot
Your HTML Bootstrap code isn't totally correct:
You can't nest a .col-md-12 class inside a .col-md-3 class not
in my knowledge at least.
Your .rows classes are not always well positioned within the code
see the fiddle link that i prepared below.
I tried to do my best to understand what you want to achieve with your code i also ordered tags within your code so that your divs fit the window size regardless of its width.
EDIT
Try to define the width of your image with vw unit (width:15vw;) That will keep the image from crossing the containing item.
I illustrated an example for you here :
http://jsfiddle.net/merhzqwg/65/
Hope it helps.
OK this is the thing, your code is not very clean. there are some errors as well
for eg: you have used the id="imageresource" twice. An id can ONLY be used once on a single page. Very Important.
but i will provide a quick fix for this.
by default bootstrap adds max-width: 100%; height: auto; to the class img-thumbnail to override that what i have done is i have added a class to both of the images img-sale.
<img class="img-thumbnail img-sale" id="imageresource" src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQKWYNnGt8d9G1sf8PE0TpOglpZ2dKnHWAP5FB_spYgelcToong" width="30%" style="margin-left: 30px;" />
and added the following css:
.img-sale {
max-height: 170px;
width: auto;
}
http://codepen.io/anon/pen/OVwrpJ?editors=110
http://jsfiddle.net/6y4uf16y/82/
but the rest of the code is not recommended to proceed with.

CSS image grid without clear columns

A client asked me to fix their image grid CSS. While I thought they just screwed around to much with the HTML for it to function properly it seems the problem is a bit more technical then I initially thought.
Because I cannot think of the right keywords google isn't much help either.
My problem is this:
the banners are png's. And as you might figure, the bottom 3x1 banner should align to the bottom of the other 3x1 banner.
This isn't really a problem if I'm working with columns (in this case 2), but I that's not the case. Since sometimes an image takes on a width of multiple columns, there is no clear line in between.
HTML:
<div class="page-banners grid-container">
<div class="grid12-6 banner">
<img src="3x1.png" />
</div>
<div class="grid12-6 banner">
<img src="3x2.png" />
</div>
<div class="grid12-6 banner">
<img src="3x1.png" />
</div>
</div>
CSS:
.grid12-6 {
width: 48%;
}
.grid12-1, .grid12-2, .grid12-3, .grid12-4, .grid12-5, .grid12-6, .grid12-7, .grid12-8, .grid12-9, .grid12-10, .grid12-11, .grid12-12, .grid-full, .grid-col2-sidebar, .grid-col2-main {
display: inline;
float: left;
margin-left: 1%;
margin-right: 1%;
}
Changing
float:left;
to
display:inline-block;
doesn't do the trick, it just makes the first 3x1 banner vertically align to the baseline of 3x2.
The answer is probably fairly simple. But I've spend way to much time staring at it.
Below is an example (made in excel) for the page could 'look' like if all the images were inserted. Each color as a placeholder for a banner.
Basically, this is what I want, but without the javascript.
http://desandro.github.io/masonry/demos/basic-multi-column.html
It should be enough to put the images together into one column, havent tried it
<div class="page-banners grid-container">
<div class="grid12-6 banner">
<img src="3x1.png" />
<img src="3x1.png" />
</div>
<div class="grid12-6 banner">
<img src="3x2.png" />
</div>
</div>
you might need to adjust the space between them
It's hard to say as you are not giving us the real example of use but try setting the height on the banners as the lowest heigt and the inages will overflow naturaly like so:
.banner{height:100px}
http://fiddle.jshell.net/gndLuqqy/