I have been searching and trying different methods for hours now. I just can't seem to get these two images and text all on one line. I want both the images and both text to all be on one line arranged image, text, image, text My images are coded like this with simple styles attacted
<img style='height: 24px; width: 24px; margin-right: 4px;' src='design/like.png'/><h4 class='liketext'>$likes</h4>
<img style='height: 24px; width: 24px; margin-right: 4px;' src='design/dislike.png'/><h4 class='liketext'>$dislikes</h4>
My "liketext" class is just has a simple text color modifier. With this code the first image and text are on the same line, and the the next image and text is on the line below. I want all four objects to be on the same line. I really have tried to solve this question on my own and appreciate any help given and hopefully this post can help others as well thank you!
You can either use (on the h4 elements, as they are block by default)
display: inline-block;
Or you can float the elements to the left/rght
float: left;
Just don't forget to clear the floats after
clear: left;
More visual example for the float left/right option as shared below by #VSB:
<h4>
<div style="float:left;">Left Text</div>
<div style="float:right;">Right Text</div>
<div style="clear: left;"/>
</h4>
You can simply center the image and text in the parent tag by setting
div {
text-align: center;
}
vertical center the img and span
img {
vertical-align:middle;
}
span {
vertical-align:middle;
}
You can just add second set below, and one thing to mention is that h4 has block display attribute, so you might want to set
h4 {
display: inline-block
}
to set the h4 "inline".
The full example is shown here.
<div id="photo" style="text-align: center">
<img style="vertical-align:middle" src="https://via.placeholder.com/22x22" alt="">
<span style="vertical-align:middle">Take a photo</span>
</div>
This question is from 2012, some things have changed from that date, and since it still receives a lot of traffic from google, I feel like completing it by adding flexbox as a solution.
By now, flexbox is the advised pattern to be used, even if it lacks IE9 support.
The only thing you have to care about is adding display: flex in the parent element. As default and without the need of setting other properties, all the children of that element will be aligned in the same row.
If you want to read more about flexbox, you can do it here.
.container {
display: flex;
}
img {
margin: 6px;
}
<div class="container">
<img src="https://placekitten.com/g/300/300" /> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
vertical-align: text-bottom;
Tested, this worked for me perfectly, just apply this to the image.
First, I wouldn't recommend using inline styles. If you must, you should try applying floats to each item:
<img style='float:left; height: 24px; width: 24px; margin-right: 4px;' src='design/like.png'/>
<h4 style='float:left;" class='liketext'>$likes</h4>
<img style='float:left; height: 24px; width: 24px; margin-right: 4px;' src='design/dislike.png'/>
<h4 style='float:left;" class='liketext'>$dislikes</h4>
It might require some tweaking afterwards, and clearing the floats.
See example at: http://jsfiddle.net/6Rpkh/
<style>
img.likeordisklike { height: 24px; width: 24px; margin-right: 4px; }
h4.liketext { color:#F00; display:inline }
</style>
<img class='likeordislike' src='design/like.png'/><h4 class='liketext'>$likes</h4>
<img class='likeordislike' src='design/dislike.png'/><h4 class='liketext'>$dislikes</h4>
A H4 elemental is a block display type element. You could force the H4 to have a inline display type, or simply use an inline element like P instead and style it however you require.
For reference: http://www.w3.org/TR/CSS21/visuren.html#propdef-display
So you'd change the display type of the H4 like:
<html>
<head>
<title>test</title>
<style type='text/css'>
h4 { display: inline }
</style>
</head>
<body>
<img style='height: 24px; width: 24px; margin-right: 4px;' src='design/like.png'/><h4 class='liketext'>$likes</h4>
<img style='height: 24px; width: 24px; margin-right: 4px;' src='design/dislike.png'/><h4 class='liketext'>$dislikes</h4>
</body>
</html>
In this case you can use display:inline or inline-block.
Example:
img.likeordisklike {display:inline;vertical-align:middle; }
h4.liketext { color:#F00; display:inline;vertical-align:top;padding-left:10px; }
<img class='likeordislike' src='design/like.png'/><h4 class='liketext'>$likes</h4>
<img class='likeordislike' src='design/dislike.png'/><h4 class='liketext'>$dislikes</h4>
Don't use float:left because again need to write one more clear line and its old method also..
try to insert your img inside your h4
DEMO
<h4 class='liketext'><img style='height: 24px; width: 24px; margin-right: 4px;' src='design/like.png'/>$likes</h4>
<h4 class='liketext'> <img style='height: 24px; width: 24px; margin-right: 4px;' src='design/dislike.png'/>$dislikes</h4>
Related
The image and text of this bootstrap card are supposed to be side by side, with the combo title + text centralized in relation to the image. But they are somewhat above the image.
Image of how it looks:
HTML:
<div class="card bg-transparent border-0 text-white mb-3" >
<div class="row g-0">
<div class="col-md-6">
<img src="../assets/images/cp/sobre-cid-1.jpg" class="img-fluid rounded-start img-esq" alt="cid-1">
</div>
<div class="col-md-6">
<div class="card-body">
<h3 class="card-title">TITLE</h3>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</div>
</div>
CSS:
.img-fluid.rounded-start {
height: calc(120px + 10vw);
width: 90vw;
object-fit: cover;
}
.img-esq {
border-radius: 0px 30px 30px 0px;
}
.img-dir {
border-radius: 30px 0px 0px 30px;
}
.card-title {
font-family: 'Martel';
font-size: 22px;
padding: 20px;
text-align: left;
font-weight: 600;
}
.card-title-right {
font-family: 'Martel';
font-size: 22px;
padding: 20px;
text-align: right;
font-weight: 600;
}
.card-text {
font-family: 'Martel';
font-size: 14px;
padding-left: 20px;
padding-right: 30px;
text-align: left;
}
.card-text-right {
font-family: 'Martel';
font-size: 14px;
padding-left: 30px;
padding-right: 20px;
text-align: right;
}
Additional info: The card is inside a div that gets the entire page, this is it's CSS:
.bg {
background-image: url(../images/cp/fundo.png);
background-position: center;
background-repeat: repeat-y;
background-size: cover;
margin-top: 0px;
text-align: center;
color: white;
display: flex;
flex-direction: column;
justify-content: center;
}
I mostly looked for margins and paddings. I tried changing padding-top and margin-top to zero, I even looked for this in the item above the bootstrap card, but nothing helped, there was only a br tag between the item above the card and the card itself. I also looked for a margin in the card and everything seems right.
EDIT 1:
I added to .row a display: flex and align-items:center, it is not perfectly centered but maybe I can use it, but there's still a big space in between each card:
EDIT 2:
I added to .row a margin-top: -80px and now the space between cards is good. Not the perfect solution I think but works for now.
To make the text vertically centered in relation to the image, I added margin-top: 60px to the cards' titles, and it pushed them down. Again, not perfect but works for now.
EDIT 3:
I fixed it. The problem was in a part of the CSS code I didn't know influenced the whole page. It was like this:
img {
width: 70%;
height: auto;
margin-top: 15%;
}
I thought it would only influence the class that was above it. Turns out, it influenced all the img tags.
I found out by deleting part by part of the CSS code in Codepen.
The problem may be caused by the calc() function in the height property for the img-fluid.rounded-start class. This function calculates the height of the image based on the size of the viewport, which could be causing the image to be larger or smaller than expected. Try to set fixed values to it.
Also, you can try and use align-items: center in the .bg class, this should align the elements at the center of the div.
I am trying to rotate text 90 degrees and vertically center it next to inline wrapped text. I need to keep the text inline so I can left-align the text itself, then center the whole thing when the text wraps.
It seems to work fine in Chrome when the text is on one line and when wrapped. In Firefox it seems to work fine when the text is on one line, but when wrapped, it does not vertically center the rotated text.
It seems like Firefox is not recognizing the height of the wrapped text.
Here is a fiddle showing what I'm working with. https://jsfiddle.net/hemmieweizen/7t5gh91z/12/ Notice on Firefox when you decrease the width of the output and the text wraps, the vertical text does not continue to center.
.title-container {
font-size: 70px;
position: relative;
}
.title-container .title {
position: relative;
}
.title-container .pre-title {
position: absolute;
bottom: 50%;
left: -55px;
transform: rotate(-90deg);
transform-origin: center bottom;
height: 22px;
border-bottom: 1px solid #000;
font-size: 16px;
text-transform: uppercase;
}
<h2 class="title-container m-b-0">
<span class="title">
<span class="pre-title h6 m-b-0">Your Agent</span>
Charles Smith
</span>
</h2>
Try to use a layout like flex; make both <span>Charles Smith</span> and <span>Your Agent</span> direct children of <h2> rather than nested children. Remove the hard-coded position rules from these elements, and let the flexbox manage them for you. You can still refine their positions with mere margin and padding.
#import url("https://d133rs42u5tbg.cloudfront.net/hero/assets/css/kv-custom-colors.css");
.title-container {
font-size: 70px;
position: relative;
display: flex; /* ADDED THIS NEW RULE */
flex-direction: row; /* ADDED THIS NEW RULE */
}
.title-container .pre-title { /* DID NOT CHANGE ANYTHING HERE */
position: absolute;
bottom: 50%;
left: -55px;
transform: rotate(-90deg);
transform-origin: center bottom;
height: 22px;
border-bottom: 1px solid #000;
font-size: 16px;
text-transform: uppercase;
}
.title-container .title {
/* REMOVED OLD POSITION RULE */
}
<section id="custom-about" class="position-relative p-y-3">
<div class="container p-y-3">
<div class="row">
<div class="col-xs-12 col-md-6">
<h2 class="title-container m-b-0">
<!-- CHANGED HIERARCHICAL STRUCTURE HERE -->
<span class="pre-title h6 font-sans m-b-0">Your Agent</span>
<span class="title">Charles Smith</span>
</h2>
</div>
<div class="col-xs-12 col-md-6 m-t-2">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<div class="col-xs-12 col-md-6 col-md-offset-6">
<div class="text-center">
<a class="btn btn-white" href="contact">Contact</a>
</div>
</div>
</div>
</div>
</section>
Does anyone happen to know how to create a layout similar to this in HTML? I am trying to make a "profile" based layout where it displays a picture where the person's name is directly in the right corner and a description is under the header, yet still to the right of the image. Here is a picture of what I am trying to create along with what I have tried to do.
.container {
position: relative;
}
.topright {
position: absolute;
top: 8px;
right: 16px;
font-size: 18px;
}
img {
width: 100%;
height: auto;
}
<body>
<h2>Image Text</h2>
<p>Add some text to an image in the top right corner:</p>
<div class="container">
<img src="img_5terre_wide.jpg" alt="Cinque Terre" width="1000" height="300">
<div class="topright">NAME HERE </div>
Sample text goes here
</div>
</body>
The problem with my code above is that the 'NAME HERE' message appears inside of the image and the sample text is below the image. I would prefer for them to both be on the right of the image. I have taken a simple approach to it, but if anyone knows how to incorporate it using CSS or another method, it would be appreciate it.
<!DOCTYPE>
<html>
<head>
<style>
.img{
width:250px;
height:250px;
}
h1{
display: inline-block;
vertical-align: top;
}
.text{
display: inline-block;
vertical-align: top;
display: inline-block;
width: 330px;
padding-left: 15px;
}
p{
font-size: 15px;
}
</style>
</head>
<body>
<image class="img" src="https://image.freepik.com/free-photo/image-human-brain_99433-298.jpg"></image>
<div class='text'>
<h1>NAME HERE</h1>
<P>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</body>
</html>
You can begin with something like this, I have made slightly modification to html.
You can use flex for the container class that will make the content to flow in row.
you need the right content to be in column so add flex and direction property to .topright{...} this will give you content one below the other.
.container {
position: relative;
display: flex;
border: 2px solid black;
width: 700px;
margin: 10px;
}
.topright {
width: 100%;
height: 50px;
font-size: 28px;
text-align: left;
display: flex;
flex-direction: column;
margin: 15px;
}
.text {
width: 100%;
font-size: 15px;
}
<body>
<h2>Image Text</h2>
<p>Add some text to an image in the top right corner:</p>
<div class="container">
<img src="http://placekitten.com/301/301" alt="Cinque Terre" width="300" height="300">
<div class="topright">NAME HERE
<div class="text">
What is Lorem Ipsum Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen
book it has? Easily generate Lorem Ipsum placeholder text in any number of characters, words sentences or paragraphs. Learn about the origins of the passage </div>
</div>
</div>
</body>
you can add img to div tag and provide witdth to both divs.
.container {
position: relative;
}
.topright {
top:0;
margin-left:20px;
position:absolute;
font-size: 18px;
}
.d-block{
dispaly:block;
}
img{width:100%}
.w-50{
width:48%;
display:inline-block
}
<div class="container">
<div class="w-50">
<img src="img_girl.jpg" alt="Cinque Terre" >
</div>
<div class="topright w-50">
<p class="d-block">NAME HERE</p>
<p class="d-block">Sample text goes here</p>
</div>
Background
I have a div with two columns. In column A, there will be a div with an "About Me" section. This is height X. In column B will be another image of a map. This is height Y. X is not equal to Y.
I am making both columns (combined) = to 100vw. Each column is defined as 50%.
(I can calculate the height of the map in column B with the following math (which can be seen more clearly in the linked Jfiddle): Image is 350x600px. If 350px = 50%, then 600px = ~171%. 171 / 2 = 85.5% so the following code snippet should give the correct transform value:
margin-top: 85.5%;
transform: translateY(-50%);)
Objective
I would like the column height to adjust to the height of the tallest element. The tallest element will most likely always be in column B. I would like the div in column A to sit halfway down the page. However, if I should ever change the order and want to put something taller in column A than in column B, it would be really great to have a fallback so that the element in column B repositions itself to become vertically centred. (But I can live without that and do it manually should I need to.)
Problem
Column heights aren't behaving themselves. The height of column A (shown in dark green) is higher than that of column B, even though the element in A is shorter.
Jfiddle
http://jsfiddle.net/ubjo1s3y/28/
(With nice bright div colours)
Code
css:
.column {
margin: -5px 0px 30px 0px;
float: left;
width: 50%;
height: auto;
background-color: green;
}
.row:after {
background-color: pink;
content: "";
display: table;
clear: both;
height: 0;
}
#aboutmecontainer {
background-color: aqua;
width: 90%;
float: left;
padding: 0px 5% 0px 5%;
margin-top: 85.5%;
transform: translateY(-50%);
}
#facephoto {
background-color: red;
float: left;
width: 130px;
margin: 0px 0px 10px 50%;
transform: translateX(-50%);
}
#aboutmetext {
background-color: yellow;
float: left;
width: 100%;
height: auto;
}
#map {
background-color: yellowgreen;
float: left;
width: 90%;
padding: 0px 5% 0px 5%;
}
html:
<div class="row">
<div class="column">
<!-- container for round face photo -->
<div id="aboutmecontainer">
<div id="facephoto">
<!-- photo -->
<img src="http://via.placeholder.com/200x200" alt="Face" style="height: 100%; width: 100%; object-fit: contain;" />
</div>
<!-- container for text underneath face photo -->
<div id="aboutmetext"><h3 style="color: #000000;">About Me</h3><p></p><h5 style="color: #000000;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</h5>
</div>
</div>
</div>
<div class="column">
<!-- div for map to right of "about me" section -->
<div id="map">
<!-- map picture can be edited in photoshop to add new countries -->
<img src="http://via.placeholder.com/350x600" alt="Map" style="width: 100%; height: 100%; object-fit: contain;">
</div>
</div>
</div>
First of all, I would definitely recommend learning how to use flexbox.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox.
Additionally, using floats in this situation is going to ruin the flow of the dom. There are situations where using floats can work, but it removes the targeted element from the regular flow of the dom and will always cause you grief if you don't know how to use floats.
Here is a revised jsfiddle that does not use flex. You want to set .column's display to inline-block and put font-size: 0 on .row (removing white-space). And remove all of your floats.
JSFiddle
Have you looked into Flexbox? It drastically simplifies this old height problem.
See this fiddle :
http://jsfiddle.net/uy2pqbkL/
Everything else is the same except the new properties added to your .row class.
.row {
display:flex;
align-items:center;
}
In order to follow correct web standards, I've tried to layout image and div inline. In orde to achieve that - I've used display:inline property.
But then I experienced the following issue: image renders from the center line, and div doesn't respect height parameter set to it. I've tried using line-height parameter, but that didn't give any useful results.
I've also tried various combinations with setting margin/padding to some values or to auto, or replacing div with span, or wrapping img and div with additional divs.
I've managed to achieve desired result by using position:absolute, but that doesn't help in cases where I want to use centered/relative positioning of the whole component...
Any clues or ideas or troubleshooting hints?
Please find the html example below:
<html>
<head>
<title>Test Page</title>
</head>
<body>
<div style="border: solid 2px green; height:40px;width: 600px;">
<span style="border:solid 2px green; position: absolute; height:50px; width: 50px;">
<i m g
style="display:inline; margin: 3px; padding:0px; border: solid 2px lightblue;"
height="38px"
width="38px"
src="someimage . JPG"
/>
</span>
<span style="position:absolute; left: 100px; width:400px; height:60px; margin:3px; border: solid 2px red;">
Some text that should be displayed in the center/middle of the div
</span>
</div>
<br />
<br />
<br />
<br />
<div style="border: solid 2px green; height:80px;width: 600px;">
<span style="border:solid 2px green; position: absolute; height:50px; width: 50px; vertical-align:bottom;">
123
</span>
<span style="position:absolute; left: 100px; width:400px; height:60px; margin:3px; border: solid 2px red;">
Some text that should be displayed in the center/middle of the div
</span>
</div>
</body>
</html>
Thanks for trying to help out.
First - the solution:
I've added few attributes to image tag and that helped a lot:
hspace="0" vspace="0" align="top" border="0"
Second: explanation:
Since I wanted to do "inline" (or "inline-block") thing, I had to figure out how inline/inline-block elements are laid-out by browsers. If you read CSS2 layout spec, you will soon find out that there is an issue with image and divs. Problem is with vertical-align - where image is aligned/rendered comparing to baseline, while divs go for bottom-line (or vice versa). That caused my example not be aligned.
Setting above mentioned params for the image tag helped.
Remarks:
Due to the complex history of IE5,6,7, Firefox, Gecko, WebKit, Chrome, CSS2 and BoxModel, there are some shortcomings to Layout model. Original problem comes from IE5 and 6 handling BoxModel in different way from CSS standard. That's maybe the main reason for having quirks mode and DTD standards.
However, this is a broad topic, if you want to find out more, I recoomend readin CSS2 spec and recommendation.
If you want to discuss it more - feel free to contact me via PM
Thanks again to all for helping and good luck with your Layouts
Kind regards
MP
Try this:
<div style="display: inline-block;"></div>
It's actually part of the CSS2 standard to display an inline thing as a block like a character.
One thing is, though, that <div>s are not supposed to occur inside of a <p> element, so you should instead use <span> tags.
I'm not sure exactly what you are trying to achieve. But it sounds like you want to float an image left with text in the div.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test Page</title>
<style>
.wrap {
border: solid 2px green;
width: 600px;
overflow:hidden;
}
.myimg {
display:inline;
margin: 10px;
padding:0px;
border:solid 2px green;
height:70px; width: 70px;
float:left;
}
</style>
</head>
<body>
<div class="wrap">
<img src="myimagepath" class="myimg" />
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
</body>
</html>