Html css Card aligment - html

I need to show the image in the right side of card how can i do this ? not by margin-left because If title size is more then the image will show in next line
<div class="block_container1">
<div class="tit" *ngFor="let c of cdata">{{c.name}}</div>
<div style="text-align: right;"><img src="assets/imgs/32.png"></div>
</div>
.block_container1 > div {
display: inline-block;
vertical-align: middle;
}

The <div> element containing the <img> element could be set to float to the right by making use of the CSS property float: right;. Keep in mind to clear the float property for the next <div> element.For proper alignment use line-height for your <div> elements
Below is a working snippet:
.block_container1>div {
display: inline-block;
vertical-align: middle;
}
.tit {
line-height: 38px
}
.myImg {
float: right;
line-height: 38px
}
<div class="block_container1">
<div class="tit" *ngFor="let c of cdata">hello</div>
<div class="myImg"><img src="https://www.w3schools.com/tags/smiley.gif"></div>
</div>

One way would be to make the image the background of your block_container1 class, mark the background-position as "top right", and make sure it doesn't repeat:
.example {
min-height:500px;
background-image:url('https://cdn3.iconfinder.com/data/icons/fabric-features-clothes-materials-glyph/64/41_design-sample-color-palette-128.png');
background-repeat:no-repeat;
background-position:top right;
margin:40px;
}
<div class="example">
<h2>Example</h2>
This is an example.
</div>
You can add padding around the image by giving .block_container1 a margin. You can learn more about background positions here.

Try the flexbox approach:
.block_container {
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="block_container1">
<div class="tit" *ngFor="let c of cdata">{{c.name}}</div>
<div style="text-align: right;"><img src="assets/imgs/32.png"></div>
</div>

Related

Vertically Aligning Text & Image [duplicate]

Why won't vertical-align: middle work? And yet, vertical-align: top does work.
span{
vertical-align: middle;
}
<div>
<img src="https://via.placeholder.com/30" alt="small img" />
<span>Doesn't work.</span>
</div>
Actually, in this case it's quite simple: apply the vertical align to the image. Since it's all in one line, it's really the image you want aligned, not the text.
<!-- moved "vertical-align:middle" style from span to img -->
<div>
<img style="vertical-align:middle" src="https://via.placeholder.com/60x60" alt="A grey image showing text 60 x 60">
<span style="">Works.</span>
</div>
Tested in FF3.
Now you can use flexbox for this type of layout.
.box {
display: flex;
align-items:center;
}
<div class="box">
<img src="https://via.placeholder.com/60x60">
<span style="">Works.</span>
</div>
Here are some simple techniques for vertical-align:
One-line vertical-align:middle
This one is easy: set the line-height of the text element to equal that of the container
<div>
<img style="width:30px; height:30px;">
<span style="line-height:30px;">Doesn't work.</span>
</div>
Multiple-lines vertical-align:bottom
Absolutely position an inner div relative to its container
<div style="position:relative;width:30px;height:60px;">
<div style="position:absolute;bottom:0">This is positioned on the bottom</div>
</div>
Multiple-lines vertical-align:middle
<div style="display:table;width:30px;height:60px;">
<div style="display:table-cell;height:30px;">This is positioned in the middle</div>
</div>
If you must support ancient versions of IE <= 7
In order to get this to work correctly across the board, you'll have to hack the CSS a bit. Luckily, there is an IE bug that works in our favor. Setting top:50% on the container and top:-50% on the inner div, you can achieve the same result. We can combine the two using another feature IE doesn't support: advanced CSS selectors.
<style type="text/css">
#container {
width: 30px;
height: 60px;
position: relative;
}
#wrapper > #container {
display: table;
position: static;
}
#container div {
position: absolute;
top: 50%;
}
#container div div {
position: relative;
top: -50%;
}
#container > div {
display: table-cell;
vertical-align: middle;
position: static;
}
</style>
<div id="wrapper">
<div id="container">
<div><div><p>Works in everything!</p></div></div>
</div>
</div>
Variable container height vertical-align:middle
This solution requires a slightly more modern browser than the other solutions, as it makes use of the transform: translateY property. (http://caniuse.com/#feat=transforms2d)
Applying the following 3 lines of CSS to an element will vertically centre it within its parent regardless of the height of the parent element:
position: relative;
top: 50%;
transform: translateY(-50%);
Change your div into a flex container:
div { display: flex; }
Now there are two methods to center the alignments for all the content:
Method 1:
div { align-items: center; }
DEMO
Method 2:
div * { margin: auto 0; }
DEMO
Try different width and height values on the img and different font size values on the span and you'll see they always remain in the middle of the container.
You have to apply vertical-align: middle to both elements to have it been centered perfectly.
<div>
<img style="vertical-align:middle" src="http://lorempixel.com/60/60/">
<span style="vertical-align:middle">Perfectly centered</span>
</div>
The accepted answer does center the icon around half of the x-height of the text next to it (as defined in the CSS specs). Which might be good enough but can look a little bit off, if the text has ascenders or descenders standing out just at top or bottom:
On the left, the text is not aligned, on the right it is as shown above. A live demo can be found in this article about vertical-align.
Has anyone talked about why vertical-align: top works in the scenario? The image in the question is probably taller than the text and thus defines the top edge of the line box. vertical-align: top on the span element then just positions it at the top of the line box.
The main difference in behavior between vertical-align: middle and top is that the first moves elements relative to the box's baseline (which is placed wherever needed to fulfill all vertical alignments and thus feels rather unpredictable) and the second relative to the outer bounds of the line box (which is more tangible).
The technique used in the accepted answer works only for single-lined text (demo), but not multi-line text (demo) - as noted there.
If anyone needs to vertically center multi-lined text to an image, here are a few ways
(Methods 1 and 2 inspired by this CSS-Tricks article)
Method #1: CSS tables (FIDDLE) (IE8+ (caniuse))
CSS:
div {
display: table;
}
span {
vertical-align: middle;
display: table-cell;
}
Method #2: Pseudo element on container (FIDDLE) (IE8+)
CSS:
div {
height: 200px; /* height of image */
}
div:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em; /* Adjusts for spacing */
}
img {
position: absolute;
}
span {
display: inline-block;
vertical-align: middle;
margin-left: 200px; /* width of image */
}
Method #3: Flexbox (FIDDLE) (caniuse)
CSS (The above fiddle contains vendor prefixes):
div {
display: flex;
align-items: center;
}
img {
min-width: 200px; /* width of image */
}
This code works in IE as well as FF:
<div>
<img style="width:auto; height:auto;vertical-align: middle;">
<span>It does work on all browsers</span>
</div>
Because you have to set the line-height to the height of the div for this to work
For the record, alignment "commands" shouldn't work on a SPAN, because it is an in-line tag, not a block-level tag. Things like alignment, margin, padding, etc won't work on an in-line tag because the point of inline is not to disrupt the text flow.
CSS divides HTML tags up into two groups: in-line and block-level. Search "css block vs inline" and a great article shows up...
http://www.webdesignfromscratch.com/html-css/css-block-and-inline/
(Understanding core CSS principles is a key to it not being quite so annoying)
Basically, you'll have to get down to CSS3.
-moz-box-align: center;
-webkit-box-align: center;
Use line-height:30px for the span so that text is align with the image:
<div>
<img style="width:30px; height:30px;">
<span style="line-height:30px;">Doesn't work.</span>
</div>
Another thing you can do is set the text's line-height to the size of the images within the <div>. Then set the images to vertical-align: middle;
That's seriously the easiest way.
Haven't seen a solution with margin in any of these answers yet, so here is my solution to this problem.
This solution only works if you know the width of your image.
The HTML
<div>
<img src="https://placehold.it/80x80">
<span>This is my very long text what should align. This is my very long text what should align.</span>
</div>
The CSS
div {
overflow:hidden;
}
img {
width:80px
margin-right:20px;
display:inline-block;
vertical-align:middle;
}
span {
width:100%;
margin-right:-100px;
padding-right:100px;
display:inline-block;
vertical-align:middle;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
Write these span properties
span{
display:inline-block;
vertical-align:middle;
}
Use display:inline-block; When you use vertical-align property.Those are assosiated properties
background:url(../images/red_bullet.jpg) left 3px no-repeat;
I generally use 3px in place of top. By increasing/decreasing that value, the image can be changed to the required height.
You can set image as inline element using display property
<div>
<img style="vertical-align: middle; display: inline;" src="https://placehold.it/60x60">
<span style="vertical-align: middle; display: inline;">Works.</span>
</div>
Using flex property in css.
To align text vertically center by using in flex using align-items:center; if you want to align text horizontally center by using in flex using justify-content:center;.
div{
display: flex;
align-items: center;
}
<div>
<img src="http://lorempixel.com/30/30/" alt="small img" />
<span>It works.</span>
</div>
Using table-cell in css.
div{
display: table;
}
div *{
display: table-cell;
vertical-align: middle;
}
<div>
<img src="http://lorempixel.com/30/30/" alt="small img" />
<span>It works.</span>
</div>
On a button in jQuery mobile, for instance, you can tweak it a bit by applying this style to the image:
.btn-image {
vertical-align:middle;
margin:0 0 3px 0;
}
Multiline solution:
http://jsfiddle.net/zH58L/6/
<div style="display:table;width:30px;height:160px;">
<img style="display:table-cell;width:30px;height:60px;padding:50px" src='...' />
<div style="display:table-cell;height:30px;vertical-align:middle">
Multiline text centered vertically
</div>
</div>
<!-- note: img (height + 2x padding) must be equal to root div height -->
Works in all browers and ie9+
It can be confusing, I agree. Try utilizing table features. I use this simple CSS trick to position modals at the center of the webpage. It has large browser support:
<div class="table">
<div class="cell">
<img src="..." alt="..." />
<span>It works now</span>
</div>
</div>
and CSS part:
.table { display: table; }
.cell { display: table-cell; vertical-align: middle; }
Note that you have to style and adjust the size of image and table container to make it work as you desire. Enjoy.
Display flex with align-items: center; is the best way for vertically align the items
div {
display: flex;
align-items: center;
}
<div>
<img src="https://via.placeholder.com/30" alt="small img" />
<span>it works.</span>
</div>
div {
display: flex;
align-items: center;
}
<div>
<img src="http://lorempixel.com/30/30/" alt="small img" />
<span>It works.</span>
</div>
Firstly inline CSS is not recommended at all, it really mess up your HTML.
For aligning image and span, you can simply do vertical-align:middle.
.align-middle {
vertical-align: middle;
}
<div>
<img class="align-middle" src="https://i.stack.imgur.com/ymxaR.png">
<span class="align-middle">I'm in the middle of the image! thanks to CSS! hooray!</span>
</div>
Not sure as to why it doesn't render it on your navigation's browser, but I normally use an snippet like this when trying to display a header with an image and a centered text, hope it helps!
https://output.jsbin.com/jeqorahupo
<hgroup style="display:block; text-align:center; vertical-align:middle; margin:inherit auto; padding:inherit auto; max-height:inherit">
<header style="background:url('http://lorempixel.com/30/30/') center center no-repeat; background-size:auto; display:inner-block; vertical-align:middle; position:relative; position:absolute; top:inherit; left:inherit; display: -webkit-box; display: -webkit-flex;display: -moz-box;display: -ms-flexbox;display: flex;-webkit-flex-align: center;-ms-flex-align: center;-webkit-align-items: center;align-items: center;">
<image src="http://lorempixel.com/60/60/" title="Img title" style="opacity:0.35"></img>
http://lipsum.org</header>
</hgroup>
In 2022 and with nearly 96% unprefixed browser support, I'm surprised no one has suggested the use of a grid layout.
In this JSFiddle, 3 lines are all that are necessary to achieve the OP's objective (but multiple alignments are presented for comparison):
div {
display: grid;
grid-template-columns: min-content max-content;
align-items: center
}
An additional UI nicety would include the optional use of the gap property, which enables modulation of the space between each grid-item within the parent grid container (div).
Advantages of grid layout
Easy vertical AND horizontal alignment of grid-items
Modulation of space between grid-items
Any size image (using min-content) and text length (one line using max-content or wrapped (not shown in fiddle) using min-content) would work - no need to hard-code the image dimensions in the CSS (both usages demonstrated in the demonstrated in JSFiddle)
Modern approach
Disadvantages of grid layout
Older browser support is more challenging
Grid layouts generally require more experienced developers to implement properly - not as simple as block/inline-block display
<!DOCTYPE html>
<html>
<head>
<style>
.block-system-branding-block {
flex: 0 1 40%;
}
#media screen and (min-width: 48em) {
.block-system-branding-block {
flex: 0 1 420px;
margin: 2.5rem 0;
text-align: left;
}
}
.flex-containerrow {
display: flex;
}
.flex-containerrow > div {
justify-content: center;
align-items: center;
}
.flex-containercolumn {
display: flex;
flex-direction: column;
}
.flex-containercolumn > div {
width: 300px;
margin: 10px;
text-align: left;
line-height: 20px;
font-size: 16px;
}
.flex-containercolumn > site-slogan {font-size: 12px;}
.flex-containercolumn > div > span{ font-size: 12px;}
</style>
</head>
<body>
<div id="block-umami-branding" class="block-system block-
system-branding-block">
<div class="flex-containerrow">
<div>
<a href="/" rel="home" class="site-logo">
<img src="https://placehold.it/120x120" alt="Home">
</a>
</div><div class="flex-containerrow"><div class="flex-containercolumn">
<div class="site-name ">
This is my sitename
</div>
<div class="site-slogan "><span>Department of Test | Ministry of Test |
TGoII</span></div>
</div></div>
</div>
</div>
</body>
</html>
You probably want this:
<div>
<img style="width:30px; height:30px;">
<span style="vertical-align:50%; line-height:30px;">Didn't work.</span>
</div>
As others have suggested, try vertical-align on the image:
<div>
<img style="width:30px; height:30px; vertical-align:middle;">
<span>Didn't work.</span>
</div>
CSS isn't annoying. You just don't read the documentation. ;P

Text vertical-align with another element

In the following snippet, I have a title and an image, both divs are within a container div. the image is floated right and will have a fixed height of 80px. What I want is title on the left, image on the right side of the same row, and the text the bottom aligned with the image. First I tried inline-block on .text-element and inline on .text-element-content, but vertical-align doesn't seem to work there. After a few tries and some reading, I came up with the following solution with display: table/table-cell, plus setting a fix height for .text-element, then the vertical-align: bottom worked. But then I saw another (small) problem. Now the lowerste point of "p" in title text is on the same line with the bottom line of image. But I want the bottom of other letters like "e", "d", "t" on the same line with the image-bottom line. I tried vertical-align: baseline but it seems it is for something else entirely... Is there a way to achieve what I want? And is there a better way to get vertical-align: bottom without table/table-cell? For certain reason, I may not change the DOM, only the CSS on it, and I may not use flex-box either.
The solution with a different line-height won't solve my problem entirely because it only works with this special case and as soon as the font is changed, I'll need another line-height.
.container-element {
position: relative;
}
.image {
float: right;
}
.text-element {
display: table;
height: 80px;
}
.text-element-content {
display: table-cell;
vertical-align: bottom;
}
<div class="container-element">
<div class="image">
<img src="https://image.ibb.co/eTiV6a/Unbenannt_1.png">
</div>
<div class="text-element">
<div class="text-element-content">I'm a title with help</div>
</div>
</div>
You could try adjusting the line-height property for the text:
.container-element {
position: relative;
border-bottom: 1px solid red;
}
.image {
float: right;
}
.text-element {
display: table;
height: 80px;
line-height: .7;
}
.text-element-content {
display: table-cell;
vertical-align: bottom;
}
<div class="container-element">
<div class="image">
<img src="https://image.ibb.co/eTiV6a/Unbenannt_1.png">
</div>
<div class="text-element">
<div class="text-element-content">I'm a title with help</div>
</div>
</div>
Even though you stated, that you cannot use flex-box (because of IE), I will answer with a flex-box solution. IE11 works fine with flexbox. See Known issues on caniuse.com.
Combined with order a solution could look something like this:
.container-element {
display: flex;
justify-content: space-between;
align-items: baseline;
}
.image {
order: 2;
}
.text-element {
order: 1;
}
<div class="container-element">
<div class="image">
<img src="https://image.ibb.co/eTiV6a/Unbenannt_1.png">
</div>
<div class="text-element">
<div class="text-element-content">I'm a title with help</div>
</div>
</div>
This should do it inspired by bootstrap.
.container-element {
position: relative;
}
.media-left,.media-right {
display: table-cell;
vertical-align: top
}
.media-right {
padding-left: 10px
}
.media-left {
padding-right: 10px
}
.media-bottom {
vertical-align: bottom
}
<div class="container-element">
<div class="media-left media-bottom">
I'm a title with help
</div>
<div class="media-right">
<img src="https://image.ibb.co/eTiV6a/Unbenannt_1.png">
</div>
</div>

Css position on web page

Can someone help me with this? I want make this design, But I have problem with position. Here is image
Here is code
> https://plnkr.co/edit/Smyes7rZXVcqq5IugW2o?p=preview
The below skeleton will work for you best.
Set parent div's height and display to table (min-height won't work for you here). You can vertically align contents inside the parent div if you set child div's display to table-cell and vertical-align to middle. The child content will automatically align vertically even if the content height changes.
<div class="container">
<div class="col-sm-6 left">
<div class="inner">
<span>become our partner</span>
contact us
</div>
</div>
<div class="col-sm-6 right">
//right side content
</div>
</div>
.left{
height: 500px;
background: #ccc;
display: table;
}
.inner{
display: table-cell;
vertical-align: middle;
text-align: center;
}
.inner span, .inner a{
display: block;
text-transform: uppercase;
}

Alignment changes on entering text within a div with display inline-block

Stuck on a problem where when I enter text in a div with display property set to inline-block. Here's the HTML:
<div class="row" id="section">
<div class="sectionheading">
</div>
<div class="sectionheading">
</div>
<div class="sectionheading">
</div>
<div class="sectionheading" id="sectionheading">
<span>Text</span>
</div>
</div>
CSS:
.sectionheading {
display: inline-block;
width: 6px;
background-color: #df5e5e;
height:35px;
}
#sectionheading {
width: 150px !important;
}
#section {
margin-left:10px;
margin-top: 40px;
}
The problem is with the div having id 'sectionheading'. When I have text in it like in the HTML given it shifts downwards for some reason, however when the div is empty it is aligned properly with the other divs. What's the problem here?
Use vertical-align: top; will solve your issue.
If you are using display: inline-block; you need to set vertical:align property of the div. Because default it's vertical-align value is baseline.
.sectionheading {
background-color: #df5e5e;
display: inline-block;
height: 35px;
vertical-align: top;
width: 6px;
}
Check Fiddle Here.
Try like this: Demo
.sectionheading {
vertical-align:top;
}
Another option for solve this issue..
.sectionheading {
display: inline-block;
width: 6px;
background-color: #df5e5e;
height:35px;
float: left;
margin-right:10px;
}
#sectionheading {
width: 150px !important;
}
#section {
margin-left:10px;
margin-top: 40px;
}
<div class="row" id="section">
<div class="sectionheading">
</div>
<div class="sectionheading">
</div>
<div class="sectionheading">
</div>
<div class="sectionheading" id="sectionheading">
<span>Text</span>
</div>
</div>
The reason why such happens when there is text is because there is a height given by default and with no proper padding height added. You can either add vertical-align: top; or add line-height: 24px; and remove height.
Fiddle : Example

Vertically aligning h1 and keeping width at 100%

I have the following HTML:
<div class="section-cover dark-cyan" ng-style="{height: getCoverHeight()}">
<div class="container">
<h1 class="intro">Some intro text.</h1>
</div>
<div class="arrow-holder" ng-click="scrollTo('video-container');">
<span class="arrow"></span>
</div>
</div>
The .section-cover div changes height dynamically based on viewport size whenever the browser is resized. I need to align the <h1> element vertically inside the section-cover div. So far I've achieved that using display: table-cell however now I can't get the width to stick at 100%. Here's a JSFiddle example:
http://jsfiddle.net/AvrrM/
How can I modify this to vertically align the <h1> and keep the width at 100%?
Maybe something like this?
http://jsfiddle.net/AvrrM/1/
.section-cover {
position: relative;
display: table;
vertical-align: middle;
width: 100%;
}
.container{
display: table-cell;
background: red;
text-align: center;
vertical-align: middle;
}
Why is itsn't working?? because table-cell is similar to html table, you need to provide a container which is table type before you can make the table-cell occupy the full width!!
working fiddle
add this CSS in your markup :
html, body {
width: 100%;
height:100%;
margin:0;
padding:0;
}
#table {
width: 100%;
display:table;
text-align:center;
}
HTML
<div id="table">
<div class="section-cover dark-cyan" style="background: blue; color: white; height: 200px">
<!-- all inner html here -->
</div>
</div>