Position image left of Bootstrap container - html

I'm trying to build a simple web page and I need an image to be positioned on the left of the container. Ideally I'd like to make sure the image resize nicely when the browser window is resized but still keeps its position independently from the text. What I'm trying to achieve looks something like this:
The text part is inside the Bootstrap container CSS class. Not sure how to achieve the look I need - tried a few things with image being inside a wrapper with absolute position on the same level as the container div, but then I can't seem to center the image inside the wrapper (vertically).
This is what I have so far:
.header {
background-color: #333333;
}
.logo-wrapper {
position: absolute;
}
.logo {
position: relative;
/* padding-top: 50%; */
height: 100%;
}
<div class="header">
<div class="logo-wrapper">
<img src="assets/logo.png" class="logo">
</div>
<div class="container">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<h3>Sed tristique augue turpis, ullamcorper convallis augue fermentum vel. Cras a tempus nulla. Vestibulum congue sollicitudin vulputate</h3>
<h2> Integer vitae tortor id elit pharetra dignissim</h2>
</div>
</div>
</div>

.logo-wrapper {
width: 20%;
display: table-cell;
vertical-align: middle;
}
.logo-wrapper img{
max-width:100%
}
.container{
width:80%;
display: table-cell;
}
<div class="header">
<div class="logo-wrapper">
<img src="https://pixabay.com/static/uploads/photo/2015/03/04/22/35/head-659652_640.png" class="logo">
</div>
<div class="container">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<h3>Sed tristique augue turpis, ullamcorper convallis augue fermentum vel. Cras a tempus nulla. Vestibulum congue sollicitudin vulputate</h3>
<h2> Integer vitae tortor id elit pharetra dignissim</h2>
</div>
</div>
</div>

.header {
background-color: #333333;
line-height:1.5em;
display:inline;
}
.container{
float:right;
width:70%;
padding-left:10%;
}
.logo-wrapper {
float:left;
width:20%;
}
.logo-wrapper img{
max-width:100%
}
}
.logo {
position: relative;
/* padding-top: 50%; */
height: 100%;
}
<div class="header">
<div class="logo-wrapper">
<img src="https://pixabay.com/static/uploads/photo/2015/03/04/22/35/head-659652_640.png" class="logo">
</div>
<div class="container">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<h3>Sed tristique augue turpis, ullamcorper convallis augue fermentum vel. Cras a tempus nulla. Vestibulum congue sollicitudin vulputate</h3>
<h2> Integer vitae tortor id elit pharetra dignissim</h2>
</div>
</div>
</div>
I think the answer of #Mitul is correct. But there's a slight modification in the solution of Mitul. If you want no text below the image, you should modify it like.

Related

HTML/CSS float issues

I'm trying to get a layout like this picture below but I'm not doing very well.
As you can see, I'm trying to put a picture on the left and a somewhat-complicated div on the right. So far, I've been trying with float without much luck:
#image {
height: 50px;
width: 100px;
float: left;
}
#text {
float: left;
}
.column {
width: 20%;
float: left;
padding-left:10px;
}
.column::after {
clear: both
}
<div id="main_section">
<img id="image" src="http://tny.im/knQ" alt="link picture" />
<div id="text">
<h2> This is the main overhead title </h2>
<p class="column">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id lacinia arcu. Sed risus ligula, placerat varius accumsan quis, gravida ut erat.</p>
<p class="column">Maecenas ante ex, dignissim a scelerisque euismod, fermentum at elit. Curabitur convallis, sapien sit amet facilisis interdum.</p>
<h2> This is the end of the section </h2>
</div>
</div>
Sorry to ask a trivial question, I'm googling all over and can't get this to work.
The issue is that #text takes 100% width. So it comes below the image. If you set a specific width for #text, it will float.
#text {
width: 500px;
}
Please try this once
#image {
padding-top:100px;
height: 50px;
width: 100px;
}
.column {
width: 20%;
padding-left:10px;
}
.column::after {
clear: both
}
#main_section{
display: flex;
}
.wrapper{
display: flex;
}
<div id="main_section">
<img id="image" src="http://tny.im/knQ" alt="link picture" />
<div id="text">
<h2> This is the main overhead title </h2>
<div class="wrapper"><p class="column">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id lacinia arcu. Sed risus ligula, placerat varius accumsan quis, gravida ut erat.</p>
<p class="column">Maecenas ante ex, dignissim a scelerisque euismod, fermentum at elit. Curabitur convallis, sapien sit amet facilisis interdum.</p></div>
<h2> This is the end of the section </h2>
</div>
</div>
Can you please check the below code? Hope it will work for you. We have solved it with the help of the flex property. If you want to get two elements side by side then flex property is easy and very useful in comparison to float & it sets the flexible length on flexible items.
Please refer to this link: https://jsfiddle.net/yudizsolutions/bysj29tx/1/
.d-flex {
display: flex;
display: -webkit-flex;
}
#image {
height: auto;
align-self: flex-start;
-webkit-align-self: flex-start;
width: 100px;
flex-shrink: 0;
}
h2 {
margin-top: 0px;
}
.row {
margin: 0px -5px;
}
.column {
width: 50%;
padding: 0px 5px;
}
<div class="d-flex" id="main_section">
<img id="image" src="http://tny.im/knQ" alt="link picture" />
<div id="text">
<h2> This is the main overhead title </h2>
<div class="row d-flex">
<p class="column">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id lacinia arcu. Sed risus ligula, placerat varius accumsan quis, gravida ut erat.</p>
<p class="column">Maecenas ante ex, dignissim a scelerisque euismod, fermentum at elit. Curabitur convallis, sapien sit amet facilisis interdum.</p>
</div>
<h2> This is the end of the section </h2>
</div>
</div>

CSS Flexbox Align Center

I'm trying to align content in a flex box centered (vertical and horizontal). In my example it works as long the screen is big enough.
Problems:
When the content is bigger than 100vh in the ".wrapper" class. The content will be cut of at the top.
When i set the ".wrapper" to "100vh" and I add the ".header" div, this div should be excluded from the "100vh" otherwise i will get a scrollbar for nothing.
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<title>FlexBox</title>
<meta name="infoription" content="">
<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #f8f9fa;
font-family: Roboto,Helvetica,Arial,Lucida,sans-serif;
color: #55595c;
}
.wrapper {
display: flex;
justify-content: center;
align-content: center;
height: 100vh;
flex-wrap: wrap;
}
.content {
background-color: #ffffff;
max-height: 350px;
max-width: 300px;
min-height: 350px;
min-width: 300px;
margin: 10px;
position: relative;
border: 1px solid #dfdfdf;
border-radius: 0.25rem;
}
.content:after {
/* background: none repeat scroll 0 0 transparent; */
bottom: 0;
content: "";
display: block;
height: 10px;
left: 50%;
position: absolute;
background: #55595c;
transition: width 0.4s ease 0s, left 0.4s ease 0s;
width: 0;
}
.content:hover:after {
width: 100%;
left: 0;
}
.thumb {
background-color: #55595c;
height: 150px;
border-top-left-radius: 0.25rem;
border-top-right-radius: 0.25rem;
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
}
.info {
padding: 10px;
text-align: justify;
}
/* Responsive layout - screen is bigger than 1000px wide */
#media (min-width: 1000px) {
.bodysize {
width: 1000px;
margin: auto;
}
</style>
</head>
<body>
<div class="bodysize">
<div class="header">
<h1>Example Page</h1>
</div>
<div class="wrapper">
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[1]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[2]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[3]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[4]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[5]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[6]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[7]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[8]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
<div class="content">
<div class="thumb">
<h3>Thumbnail</h3>
</div>
<div class="info">
<h3>[9]</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean turpis felis, dapibus ac tellus at, imperdiet consectetur ante. Mauris vulputate arcu nibh, et convallis felis mattis id.</p>
</div>
</div>
</div>
</div>
</body>
</html>
Example pictures:
Problem 1 - scrollbar because of "height: 100vh;".
Problem 2 - content floating out of the browser top. also because of "height: 100vh;".
Questions:
1) How can I set a dynamic height so the wrapper always fills the rest of the available space?
2) If the content is smaller than than the wrapper height it should be centered vertical but if the content is bigger, there is not center needed.
Any ideas how I can fix this?
>>> SOLUTION <<<
I added the .bodysize, removed the height from the wrapper and added "flex-grow: 1" to the wrapper. .bodysize { display: flex; flex-flow: column; height: 100vh; }
Try to set height: auto; and max-height: 100vh; at your wrapper.
Otherwise, your wrapper always would have 100% height even having few elements inside. The scrollbar would should appear when the content exceeds 100vh.
.wrapper {
display: flex;
justify-content: center;
align-content: center;
height: auto;
max-height: 100vh;
flex-wrap: wrap;
}

Text not aligning next to image inside box

This is the html for my box with the title text and image inside it.
<div id="about">
<div id="title"> <h3><b>About</b></h3></div>
<div id="text"><p>Text</p></div>
<div id="img"><img src="img/3.jpg" height="300" width= "400" alt="?">
</div>
and this is the css
#about {
color: white;
padding: 10px;
position: relative;
width: 90%;
height: 325px;
background: lightgrey;
top: 30px;
margin: 0 auto;
overflow: auto;
color: white;
background: #262626;
box-sizing: border-box;
}
#text {
width: 720px;
position: relative;
top: 30px;
float: right;
}
#title {
float: right;
position: relative;
right: 725px;
top: 0px;
}
#img {
}
My problem is that because my title is always 725px to the right, if I had a title larger than 5 letters it isnt right next to the picture or else I'll have to position it again, is there an easier way around this? Because doing it manually is frustrating.
Thanks.
You can solve this much easier using flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Put the title and text in a own wrapper .text-wrapper and place the img before the wrapper.
On your parent about use follow property, to place them each to other:
.about {
display: flex;
}
Some refactoring: You don't really ned a div around the image for this case. And I recommend you to use class in case of id. Check out the snippet:
.about {
display: flex;
}
.text-wrapper {
padding-left: 20px;
}
<div class="about">
<img src="https://www.telegraph.co.uk/content/dam/news/2016/08/23/106598324PandawaveNEWS_trans_NvBQzQNjv4Bqeo_i_u9APj8RuoebjoAHt0k9u7HhRJvuo-ZLenGRumA.jpg?imwidth=450" height="300" width="400" alt="?">
<div class="text-wrapper">
<div class="title">
<h3><b>Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. Proin eget tortor risu</b></h3>
</div>
<div class="text">
<p>Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. Proin eget tortor risus. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Pellentesque in ipsum id orci porta dapibus. Vestibulum ac diam sit amet quam vehicula
elementum sed sit amet dui.
suscipit tortor eget felis p
Sed porttitor lectus nibh.</p>
</div>
</div>
</div>
Try to remove floating from title and text and 'right' property from .title, then add 'float: left' to the picture.

Text out of limit of box in Css

In the follwing example the text goes out of the box. And when I reduce the size of the borowser the size of the boxes shring resposively but the text becomes mixed and unorganized. How can solve this?
<html>
<head>
<meta charset="utf-8">
<title>This is an email template</title>
<style>
body {
background-color: rgba(79, 183, 227, 0.4);
direction: rtl;
}
body * {
font-family: Tahoma;
}
a:link {
text-decoration: none;
margin-right: 25px;
color: #46B1F9;
}
#wrap {
background-color: #e0f2f6;
margin: auto;
width: 75%;
padding: 15px;
border: 1px solid grey;
}
.item {
border: 1px solid #95A5A6;
border-radius: 5px;
margin-bottom: 25px;
width: 60%;
display: inline-block;
}
.item p {
font-size: 1em;
}
.item img {
float: left;
width: 30%;
}
.item .notice {
text-align: center;
float: right;
padding-top: 25px;
padding-right: 25px;
width: 50%;
height: 1em;
}
/*clearfixes*/
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {
display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfix {
height: 1%;
}
.clearfix {
display: block;
}
/* End hide from IE-mac */
</style>
</head>
<body>
<div id="wrap">
<div style="padding:15px;">
<div class="item clearfix">
<div class="notice">
<p><strong>Lorem ipsum</strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus sollicitudin aliquet. Fusce dolor leo, egestas non nisi in, aliquam ullamcorper diam. Quisque placerat tortor in porta egestas. Aenean et elementum purus. Nunc eget nulla blandit, volutpat libero non, finibus purus. Vivamus vitae tellus at risus commodo varius.</p>
</div>
<img src="http://s14.postimg.org/wqzq39iht/image.jpg" alt="" />
</div>
<div class="item clearfix">
<div class="notice">
<p>
<strong>اLorem ipsum</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus sollicitudin aliquet. Fusce dolor leo, egestas non nisi in, aliquam ullamcorper diam. Quisque placerat tortor in porta egestas. Aenean et elementum purus. Nunc eget nulla blandit, volutpat libero non, finibus purus. Vivamus vitae tellus at risus commodo varius.</p>
</div>
<img src="http://s10.postimg.org/y4kk17q21/image.jpg" alt="" />
</div>
<div class="item clearfix">
<div class="notice">
<p><strong>Lorem ipsum</strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus sollicitudin aliquet. Fusce dolor leo, egestas non nisi in, aliquam ullamcorper diam. Quisque placerat tortor in porta egestas. Aenean et elementum purus. Nunc eget nulla blandit, volutpat libero non, finibus purus. Vivamus vitae tellus at risus commodo varius.</p>
</div>
<img src="http://s3.postimg.org/xca6ju1kj/image.jpg" alt="" />
</div>
</div>
</div>
</div>
</div>
</body>
</html>
If you are trying to expand the block by content, removing height from .item .notice should fix the issue.
In all cases your text will overflow the box , so you should add overflow:scroll to notice class
Depends on what you are trying to do.
If the boxes must be a fixed height there are couple of different strategies.
The easiest thing to do is to turn off the height restriction to the notice class. However, this will reflow your document and push everything down.
On the other hand, if you want to keep the current layout, I cannot provide you a unilateral decision as the padding, height and overflow will conflict with each other on this element.

Change div order with CSS

I've following HTML structure which can not be changed. It contains three vertical divs. I want to change the position of divs using CSS only so that the second div appears at top most and the first and third divs appear after this (only important thing is that second div should appear at top).
I am trying using the following CSS code, it displays the second div at top, but hides the first div. How can I display the other two divs after this? All three div's have different heights.
HTML:
<div class="wrap">
<div class="one">
This should be third.
</div>
<div class="two">
This should be first.
</div>
<div class="three">
This should be second.
</div>
</div>
CSS:
.wrap{
width: 100px;
overflow: hidden;
position: relative;
}
.one, .two, .three{
width: 100px;
margin-bottom: 10px;
background: yellow;
}
.two{
position: absolute;
top: 0;
background: green;
}
JSFiddle:
http://jsfiddle.net/UK6vK/
You use this style code for .one and .three
.one, .three{
width: 100px;
margin-bottom: 10px;
background: yellow;
float:right;
}
and set for .two this style
.two{
position: absolute;
top: 0;
background: green;
left:0;
width:100%;
}
None of these worked for me, but a couple tweaks to Saeed's seems to - basically duplicate the second div and use it for layout only, ie,
HTML
<div class="wrap">
<div style="position:relative;" class="two">
<strong>This should be first..</strong>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi auctor diam eget lorem vehicula aliquam. Aliquam ac tellus eget justo facilisis malesuada. Curabitur mi sapien.</p>
</div>
<div class="one">
<strong>This should not be first..</strong>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</div>
<div class="two">
<strong>This should be first..</strong>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi auctor diam eget lorem vehicula aliquam. Aliquam ac tellus eget justo facilisis malesuada. Curabitur mi sapien.</p>
</div>
<div class="three">
<strong>This can be 2nd or third.</strong>
<p> Aliquam ac tellus eget justo facilisis malesuada. Curabitur mi sapien, bibendum sed eleifend non, pretium eget arcu. Vivamus et augue nec quam rutrum tempor in in urna. </p>
</div>
</div>
position:relative means other elements will be shifted down by this element (which anyway appears behind/in front of the DIV that's been shifted up).
CSS:
.one, .three{
width: 100%;
margin-bottom: 10px;
background: yellow;
float:right;
}
.two{
position: absolute;
top: 0;
background: green;
left:0;
width:100%;
margin-bottom:10px;
}
I realize you said the HTML can't be changed so pedantically-speaking this isn't an answer to your question, however in my case the reason I can't change the HTML structure is because I want a default mobile layout that re-orders when #media is screen and (min-width: 700px;). I can make the dummy div disappear (z-index or whatever) unless I need it for re-organizing the layout (without relying on JS).
http://jsfiddle.net/UK6vK/83/