This question is kind of hard to explain with words, so I will link to a jsFiddle. jsFiddle. If you look at any of the links, you will see some boxes that are at different levels. These are supposed to tile across the screen, kind of like what you can see here. How can I stop them from having the weird vertical spacing above the elements and get them to tile properly? I think that it is caused by each elements contents having different heights, but I don't know how to fix it. Here is the code that you can find in the jsFiddle:
HTML:
<div id="elements">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id nunc ut erat facilisis pharetra. Sed egestas gravida mattis.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eu lectus eu purus pulvinar tincidunt. Phasellus at elit id nulla volutpat gravida sit amet vitae lorem. Nunc mattis venenatis varius. Aenean nec odio lorem. Nulla in turpis sed velit venenatis lacinia eget id ante. Maecenas quis massa nunc.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </div>
</div>
CSS:
#elements div {
display:inline-block;
width:250px;
height:250px;
border:solid thin #000;
}
Add vertical-align: top; to the CSS rule.
There are lot of techniques to fix this. Either float these elements like-
#elements div {
display:inline-block;
width:250px;
height:250px;
border:solid thin #000;
float:left;
}
or vertical-align: top; buyt as i think in case of inline-block elements flaot one is more robust that'll not last at any breakpoint and also where you haven't applied resets to the body.
Related
I've been trying to use css to fill the last line of a paragraph with dashes but i can't seem to find a way to do so.
Basically, i'm getting some data (text) from the database and output it to a paragraph but i don't know how much text it is nor do i know the size of the parent div.
With all of this in mind, I need to fill the remaining space in the last line of the paragraph with dashes.
For example:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eu malesuada lacus, in aliquam diam. Sed feugiat, leo tempor maximus accumsan, erat mi elementum nisi, quis vehicula nunc nibh in nibh.----------------------------------------------------------------------------------------------------------------
I've tried using some css codes i found but i couldn't adapt them to my situation some used display:flex (i think?) others were basically a lot of dashes and overflow:hidden which doesn't work because it hides everything on my paragraph after the first line.
Try
p {
position: relative;
overflow: hidden;
width: 100%;
}
p:after,
p::after {
content: "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
display: inline-block;
width: 100%;
height: auto;
z-index: -1;
position: absolute;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eu malesuada lacus, in aliquam diam. Sed feugiat, leo tempor maximus accumsan, erat mi elementum nisi, quis vehicula nunc nibh in nibh.</p>
Instead of dashes, you can use the hr tag. It does not need a closing tag.
Example of the hr tag:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eu malesuada lacus, in aliquam diam. Sed feugiat, leo tempor maximus accumsan, erat mi elementum nisi, quis vehicula nunc nibh in nibh.
I'm making a new website and in my sidebar I'm trying to add this section below but I'm struggling to get the about text to be to the right of the image. I've tried floating the text left but it didn't really work. The only CSS I've got so far is that the sidebar is 300px wide.
<div id="sidebarabout">
<h3>About Elliott Davidson</h3>
<img src="http://placehold.it/100x100"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
</div>
Add this css and check out
img{float:left;padding:0 15px 0 0}
https://jsfiddle.net/vasanthanvas/s4pb17tr/
Try like this
<p><img src="http://placehold.it/100x100"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
img{float:left;margin:0 15px 0 0}
Padding will squeeze your image little.
You can use margin instead of padding.
You need to set the img and p to be either inline or inline-block on their CSS styles.
And also - depending how you want your text to "float" it may need a width:
https://jsfiddle.net/xoL510og/ << Example
<div id="sidebarabout">
<h3>About Elliott Davidson</h3>
<img style='display:inline-block;' src="http://placehold.it/100x100"><p style='display:inline-block; width:400px;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
</div>
use display: table;
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.item-inner{
display: table;
width: 100%;
padding: 20px;
}
.item{
display: table-cell;
vertical-align: top;
}
.item-text{
padding-left: 15px;
}
<div class="item-inner">
<div class="item">
<img src="http://placehold.it/100x100" />
</div>
<div class="item item-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
</div>
When defining the img markup, make sure that it only affects the sidebarabout div. So define the div before img. Example:
#sidebarabout img{
float: left;
padding: 0 15px 0 0;
}
In case u declared a width in ur paragraph element, for example 200px, make sure to reduce this to 185px, since we're using a 15px padding. Otherwise it will mess up ur webpage because the div will become 315px width.
I noticed someone suggested using a margin. Don't use a margin, this will only push the image 15px to the left out of the div.
Also i'm missing a width, height and alt. Make sure to define ur img element the right way, otherwise it will not pass the W3C validator. Use the following:
<img src="http://placehold.it/100x100" width="100" height="100" alt="Description">
I'm using Bootstrap, and I'm trying to make a row of boxes be the same height.
Here is a dumbed-down example:
CSS:
.col-md-4 {
border:1px solid black;
height:100%;
}
Html:
<div class="row">
<div class="col-md-4">Less text</div>
<div class="col-md-4">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit</div>
<div class="col-md-4">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit
</div>
</div>
This results in the first box in the row being small, and the third box being very large. I want them all to have the same height.
How do I make the height of all the boxes in the row match the tallest box without setting a static height? I don't know how big the largets box will be. I know I could do this with a table, but that would not be optimal. Is there a way to do this with CSS?
Here is a bootply example. I did some googling but couldn't find what I was looking for.
CSS Only solution
Note: Use carefully and target the styles to your specific .col-md-4 elements. But for your code sample:
.col-md-4 {
display: table-cell;
float: none;
border:1px solid black;
height:100%;
}
Demo http://www.bootply.com/JXL6MYXiWO
$(document).ready(function(){
var highestCol = Math.max($('.div01').outerHeight(),
$('.div02').outerHeight(),
$('.div03').outerHeight());
$('.col-md-4').outerHeight(highestCol);
})
jQuery example, quite fast and effective.
Just give those divs additional unique classes, e.g. div01, div02, div03.
Check out http://jsfiddle.net/a7jow8c3/
Flexbox is probably your best option at this point in time. See this article: http://css-tricks.com/snippets/css/a-guide-to-flexbox/
And current browser support: http://caniuse.com/#feat=flexbox
I have a div in which i am showing some text and the div has fixed height and width and overflow hidden. But it is showing different text in firefox, chrome and safari. In chrome and safari one extra line of text is visible.If i remove:
-moz-column-count:2;
-webkit-column-count:2;
property then its working fine in all. But if add this property the it showing different text in firefox and chrome.
I am attaching snapshot for chrome and firefox.
<div style=" width: 710px; height: 70px;position:absolute;overflow:hidden;top=0;left=0;-moz-column-count:2;-webkit-column-count:2;z-index:102;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p> Vivamus mattis laoreet velit quis malesuada. Quisque tincidunt elit sit amet nibh volutpat id pretium nisl consequat. Quisque dictum lacus at mauris scelerisque auctor. Nulla adipiscing, sapien sit amet </p>
</div>
Chrome view
Fire fox View
You should cut your height or Width tag from that DIV. Further P element needs some style to showing them as column.
<style type="text/css">
div {
width: 710px;
position:absolute;
overflow:hidden;
top=0;
left=0;
-moz-column-count:2;
-webkit-column-count:2;
z-index:102;
}
p {
overflow: hidden;
float:left;
}
</style>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p> Vivamus mattis laoreet velit quis malesuada. Quisque tincidunt elit sit amet nibh volutpat id pretium nisl consequat. Quisque dictum lacus at mauris scelerisque auctor. Nulla adipiscing, sapien sit amet </p>
</div>
I know with images I can apply hspace, vspace, and/or align to make it go to one side or another with text flowing around it, but I'm wondering if it's possible to do something similar with an element like a div? If it is possible, how would one do that and comply with standards?
Try this it worked http://jsfiddle.net/q5swZ/1/
<div style="width:100px; height:100px; border:solid 1px red;
float:left; margin:0 10px">
</div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer
quis lorem dui. Aliquam ut arcu eros. Etiam viverra rhoncus
laoreet. Ut vel quam neque, sed rutrum mauris. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Nulla orci est, tincidunt
id pulvinar eget, ultrices non purus. Nullam tempor posuere sem,
quis porttitor neque eleifend quis.
<div style="clear:both"></div>
<br />
<div style="width:100px; height:100px; border:solid 1px red;
float:left; margin:0 10px">
</div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer
quis lorem dui. Aliquam ut arcu eros. Etiam viverra rhoncus
laoreet. Ut vel quam neque, sed rutrum mauris. Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Nulla orci est, tincidunt
id pulvinar eget, ultrices non purus. Nullam tempor posuere sem,
quis porttitor neque eleifend quis.
Simple css float property would do it or am I missing something