I am trying to arrage image and text in align in the same. I tried below for not working. How arrage like in the image.
<div >
<img src="~/Content/Images/u130.png" alt="" />
<div>
<span style="display:inline; ">Belong to a membership of more than 110,000 members in 141 countries and receive recognition for your contributions</span>
</div>
Try inlining the img and putting both elements in the same div. Also, spans are inline by default so you don't include the style property.
<div>
<img src="~/Content/Images/u130.png" style="display: inline;">
<span>
Belong to a membership of more than 110,000 members in 141
countries and receive recognition for your contributions
</span>
</div>
use <div>s and vertical-align: middle like below:
img {
height: 30px;
}
div {
display: inline-block;
vertical-align: middle;
max-width: 500px;
}
<div>
<img src="http://moneta.com.mx/web/wp-content/uploads/2014/02/check.png" alt="" />
</div>
<div>
<span>Belong to a membership of more than 110,000 members in 141 countries and receive recognition for your contributions</span>
</div>
You are going to be hard pressed to make it align with multiple rows of text depending on which browsers you are trying to support. The vertical-align property is handled very differently between browsers, especially older browsers.
What I usually do is hack it a little bit by setting my text containers to position: relative; and then absolute position my image outside to the left and center using top and negative margins.
To apply this to your code you should be able to simply copy the .feature:after rule into your style sheet. Update the image path with your image, the height/width to match your image size, and the top margin should be changed to half the height of your bullet image. After that, it will actually create the image DOM element for you via the pseudo selector.
.feature {
max-width: 300px;
padding: 10px 30px;
position: relative;
}
.feature:after {
background: url(http://hotmexchili.com/media/infortis/blocks/product_view/bullet.png) center center no-repeat;
content: "";
display: block;
height: 17px;
left: 0px;
margin-top: -8.5px;
position: absolute;
top: 50%;
width: 17px;
}
<div class="feature">
This is a single line feature
</div>
<div class="feature">
This is a longer feature that should wrap to two lines but still have the icon centered on the left!
</div>
div {
display: inline-block;
vertical-align: top;
max-width: 90%;
}
I prefer using jQuery to set the max-width by subtracting the width of img.
v-align the img at top would make it align with the first line.
<div>
<img src="~/Content/Images/u130.png" alt="" />
</div>
<div>
<span>Belong to a membership of more than 110,000 members in 141 countries and receive recognition for your contributions</span>
</div>
Related
I'm trying to blur the edges of an image like the picture shown at https://stackoverflow.com/a/24953573.
I need to do this on a foreground image (not one set in css) because the img url is dynamically changed. But box-shadow seems to have no effect on a foreground image. Also I'm using the Bootstrap 4.3 img-fluid class.
In other words, the code at the SO post referenced above works, but the edges on this image are not blurred (css inline for simplicity):
<img src="/images/mypic.jpg"
class="img-fluid"
style="box-shadow: 0 0 5px 5px white inset;">
.img-fluid sets max-width: 100% and height:auto. I tried over-riding these with specific values (which I don't want to do to maintain a responsive image), but it had no effect either.
You need to wrap img tag by div element with class name of .img-blur so use the :after pseudo-element can be used to insert some content after the content of an element.
.img-blur{
position: relative;
display: inline-block;
}
.img-blur:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-shadow: inset 0 0 10px 10px #ffffff;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<div class="container">
<div class="row" >
<div class="col-4 my-3">
<div class="img-blur">
<img class="img-fluid" src="https://via.placeholder.com/400x400/22ff22">
</div>
</div>
<div class="col-4 my-3">
<div class="img-blur">
<img class="img-fluid" src="https://via.placeholder.com/400x400/ffff22">
</div>
</div>
<div class="col-4 my-3">
<div class="img-blur">
<img class="img-fluid" src="https://via.placeholder.com/400x400/22ff22">
</div>
</div>
</div>
</div>
There is a problem with style images with inset.
But you have 2 alternatives to do this. You can add a container with position relative and inside put img with class img-fluid and div with positon absolute to this container.
The second option is to set a container with position relative and img inside and style that container with pseudo-class ::after.
If you will do that it works but there will be a problem with the right box-shadow that if img is smaller than a container. You can fix these if you will use some JS code.
I made an example with jQuery ( cause you are using bootstrap and bootstrap is using jquery).
https://codesandbox.io/s/flamboyant-wing-z9lhm
Unfortunally, CSS 'Inset' Box shadows don't work on img tags. To workaround this, you have a few couple options, for example, is possible wrap the image on a div tag and use a pseudo-element to apply the box-shadow on it.
The problem here is that, as standard, the div tag is a "Block" element, and as so will cover the entire parent width. You could fix this applying a display: inline-block or a float: left property. Perhaps is not the best "standard-compliant", but will work on this case. I attach a example with this concept below:
div {
position: relative;
display: inline-block;
}
div:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-shadow: 0 0 5px 5px white inset;
}
<div>
<img src="https://picsum.photos/200/300" class="img-fluid">
</div>
I made this simple pen to explain my problem
https://codepen.io/yonatanmk/pen/VdwGvG
When I place 2 images next to each other with width 50% of the parent they always wind up too wide to be placed side by side and end up stacked on top of each other like block elements.
Why does this happen?
How can I place the 2 images side by side while occupying the full width of the parent div without any space in between them. Having a width of 49% allows the images to be placed side by side but now there's a space between them.
display : inline-block does not seem to help.
Thank you
My code
html
<div>
<img src="http://www.planwallpaper.com/static/images/kitty-cat.jpg" />
<img src="http://www.planwallpaper.com/static/images/kitty-cat.jpg" />
<div>
css
div {
width: 500px;
}
img {
width: 50%;
}
This results in
With the code sample you provided, you can float the images and this will place them side by side with no margin.
img {
width: 50%;
float: left;
}
This is possible with the Classattribute which will specify the class name for the HTML element.
Your HTML code will look like this
<div class="row">
<div class="column">
<img src=http://www.planwallpaper.com/static/images/kitty-cat.jpg alt="planwallpaper" style="width:100%">
</div>
<div class="column">
<img src="http://www.planwallpaper.com/static/images/kitty-cat.jpg"alt="Forest" style="width:100%">
</div>
And use the following code for the CSS
.column {
float: left;
width: 33.33%;
padding: 5px;
}
This will clear floats after image containers
.row::after {
content: "";
clear: both;
display: table;
}
I have an inline-block element put inside a line of text:
.icon element has vertical-align: middle;, which results in this picture:
As you can see, the icon is not aligned with the middle of the text, it is a little bit lower, whilst the text alignment looks OK. The .button-content has line-height equal to the height of the parent. I tried to wrap the text elements around the icon:
And got this result:
The coin went up a little relatively to the text, whereas the whole line went down a pixel or two.
What is the proper way to align an inline-block element inside a lign of text? And what are these text chunks and how do they behave? Do they have display:inline; or something, because I can't see their properties in the DevTools?
Vertical-align doesn't work like you would think it would. It's used in HTML tables, but doesn't work in divs. It's been a pain for a while. Luckily, nowadays you can achieve this easily with flexbox.
To achieve this, wrap your two bits of copy in individual span elements, so your structure looks like:
<div class="button-content">
<span>buy for</span>
<div class="icon"></div>
<span>1000</span>
</div>
Then your css should look like this:
.button-content{
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 130px;
}
Or if you can't support flexbox, your .button-content can be set to display: table-cell; and the vertical-align: middle; should work.
I strongly recommend flexbox.
Unless your span elements are styled, the result will be the same with or without them.
With vertical-align: middle; position: relative; top: -1px; you can get some nice results.
.icon {
display: inline-block;
width: 10px;
height: 10px;
background: blue
}
.top {
vertical-align: top;
}
.bottom {
vertical-align: bottom;
}
.middle {
vertical-align: middle;
}
.moveup {
position: relative;
top: -1px;
}
<div class="button">
<span>Buy for</span>
<div class="icon"></div>
<span>1000</span>
</div>
<div class="button">
Buy for
<div class="icon"></div>
1000
</div>
<hr>
<div class="button">
Buy for
<div class="icon top"></div>
1000 vertical-align: top;
</div>
<div class="button">
Buy for
<div class="icon bottom"></div>
1000 vertical-align: bottom;
</div>
<div class="button">
Buy for
<div class="icon middle"></div>
1000 vertical-align: middle;
</div>
<hr>
<div class="button">
Buy for
<div class="icon middle moveup"></div>
1000 vertical-align: middle; top: -1px;
</div>
Simple answer
I have not seen a simple answer yet, so I'll just post mine:
.icon_tpye-gold {
vertical-align: -5px; /* << or another value to center the inline element vertically */
}
A suggestion: be consistent with class names (so icon_type-gold is clearer when named icon_type_gold or icon-type-gold, this looks less sloppy)
The icon actually IS aligned vertically, but relating to the complete line-height, including the space below the baseline reserved for the descenders of characters like y, g, p etc . (also the y in your button Text)
You can try to add position: relative; and bottom: 3px; (try different values) to that inline-block to move it up.
I have multiple elements in the a single div.
I want to align one element as "text-align: right" and another element "text-align: left"
Check the below code:
<div class="image_meaning" style="display: none; background-color: white; height: 35px; margin-left: 1px;">
<input type="checkbox" id="points" value="Temporal Filter" style="text-align: left; "/>
<label for="tempral_filter" style="text-align: left; ">Points</label>
<img style="text-align: right;" src="{{ STATIC_URL }}img/cross.png"/>-abc
<img style="text-align: right;" src="{{ STATIC_URL }}img/blue_triangle.png"/>-cde
</div>
but when I run the code it places both the element to the left.
any idea how to do it?
Answer
There are a few ways to solve your issue the most common one is using the css float property (as of 2016). The more modern ways are using flexbox or grid.
Solution using flexbox
You could use display: flex to do this.
Flexbox is only supported by newer browsers, If IE (9 and below) is your friend please stay away from this method.
Example html:
<div class="wrapper">
<div class="block"></div>
<div class="block"></div>
</div>
Example css:
.wrapper { display: flex; }
.block { width: 50%; }
Live demo.
Solution using grid
You could use the new display: grid to do this.
Grid layout is only supported by the most modern browsers (Sep 2017), If you are building on evergreen browsers then great, if not use flex.
Example html:
<div class="wrapper">
<div class="block"></div>
<div class="block"></div>
</div>
Example css:
.wrapper {
display: grid;
grid-template-columns: 1fr 1fr;
}
Live demo.
Solution using float
The css float property is the classic way to do this and can be dated back to prehistoric times so it supports basically every browser. The only caveat to this would be the clearfix issue (see below).
Example html:
<div class="wrapper">
<div class="block-left"></div>
<div class="block-right"></div>
</div>
Example css:
.block-left { float: left; }
.block-right { float: right; }
Please be aware that floated elements cause their parent to disregard them when it comes to their height. If that is an issue (usually it is), you can use the clearfix hack to solve this situation.
You would define it like so:
.cf:before,
.cf:after {
content: " ";
display: table;
}
.cf:after { clear: both; }
And then on your parent element:
<div class="wrapper cf">
This will allow the parent to correctly receive the floated elements height.
Read more about what is the clearfix hack.
Live demo.
Other solutions
Solution using inline-block
You could also possibly use the inline-block property to put your elements side by side.
Note that the inline-block option will need to account for white space in the html between the blocks. To counter this, either remove the space like below, add a negative margin or define the font-size on the parent as 0.
Example html:
<div class="wrapper">
<div class="block"></div><div class="block"></div>
</div>
Example css:
.block { display: inline-block; }
/* Optional zero font for wrapper
Then reset blocks to normal font-size */
.wrapper { font-size: 0; }
.block { font-size: 16px; }
/* Optional negative margin if you can't
remove space manually in the html.
Note that the number is per use case. */
.block { margin-left: -.25em; }
Live demo.
Solution using position: absolute
Another way to do it would be to absolutely position your elements with a relative container. This method has the issue of being less flexible than the others when building responsive layouts and alike.
Example html:
<div class="wrapper">
<div class="block block-left"></div>
<div class="block block-right"></div>
</div>
Example css:
.wrapper { position: relative; }
.block { position: absolute; }
.block-left { left: 0; }
.block-right { right: 0; }
Live demo.
Why your solution is not working
You are using the text-align css property which will effect inline elements and text but it can't be used to shift the element like you would with the float property.
The text-align property effects the children of the element it is applied to.
Use float: left and float: right instead of text-align
uparrow.gif and downarrow.gif
So, it would look like so:
How can I create 3 divs and style them with CSS so those arrows are positions with the top arrow above the bottom arrow?
<div class="vote">
<div class="uparrow" />
<div class="downarrow" />
</div>
Should I create a "vote" div with restricted width? Would I float: top and float: bottom the two arrow divs with the background set as my two images? I plan on having content directly to the right of the vote arrows so it needs to be restricted and tight.
Don't use divs for an image - there's already a perfectly good img tag!
<div class="vote">
<img alt="^" title="vote up" src="/images/up.arrow.png" />
<img alt="v" title="vote down" src="/images/down.arrow.png" />
</div>
And then simply:
.vote
{
width: 15px;
float: left; clear: left;
}
.vote img
{
display: block;
float: none; clear: both;
}
You may want to add some margin to the .vote to separate it from the content it will be next to.
By default, <div> elements are block-level meaning they are one-per-line and will expand horizontally to fill their container.
Adding the click handling is another problem. You could include the <a> and <img> elements in the uparrow and downarrow elements or you do it in CSS as you suggested (the less compatible way). Another option is registering DOM events with Javascript.
HTML:
<div class="vote">
<div class="uparrow" />
<div class="downarrow" />
</div>
CSS:
div.vote {
width: 50px;
float: left;
}
div.uparrow {
background-image: url(...);
}
div.downarrow {
background-image: url(...);
}
Use 2 divs. Float the text div left and put the two images in a single div. use display: block on the images to force one below the other.
A more semantic and efficient solution than divs would be this, which also takes care of positioning the vote box.
.content-item {padding-left:110px;position:relative; width:500px;border:1px solid red;}
.vote{width:100px;position:absolute; top:0; left:0;border:1px solid red;}
.vote h4 {style heading how you like}
.vote img{width:100px;height:30px;background:black;}
<div class="content-item"> content
<div class="vote">
<h4>Vote</h4>
<img alt="vote up" src="..." />
<img alt="vote down" src="..." />
</div>
</div>