css - vertical space being added on elements with display:inline-block [duplicate] - alignment

This question already has an answer here:
Why aren't these elements with display:inline-block properly aligned?
(1 answer)
Closed 7 years ago.
I've got a series of thumbnail container elements with the css property display:inline-block but when they line up next to each other, the second element has more space at the top than the first (see attached image). Any idea why this happens? Is there a better way to line these elements up next to each other? I know that floating them solves this issue, but it seems like floating isn't the best way to go about this.
Here's my code:
HTML:
<article class="thumb_container">
<div class="thumb_content">
<img src="images/perlin.jpg" alt="Perlin Lines" class="thumb_img"/>
<header class="thumb_header">Perlin Lines</header>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget lectus ac libero iaculis interdum nec id tortor. quis, ullamcorper id nisi. Etiam ut.
More...
</p>
</div>
</article>
<article class="thumb_container">
<div class="thumb_content">
<img src="images/branching.gif" alt="Branching" class="thumb_img"/>
<header class="thumb_header">Branching</header>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget lectus ac libero iaculis interdum nec id tortor. quis, ullamcorper id nisi.
More...
</p>
</div>
</article>
CSS:
.thumb_container { display: inline-block; margin-left: 20px; width:220px; background: #fff; -moz-box-shadow: 1px 1px 1px rgba(10, 72, 90, 0.2); -webkit-box-shadow: 1px 1px 1px rgba(10, 72, 90, 0.2); box-shadow: 1px 1px 1px rgba(10, 72, 90, 0.2); }
.thumb_container:first-child { margin-left: 0px; }

Just add vertical-align: top where you have display: inline-block.
More info here: Why aren't these elements with display:inline-block properly aligned?

You have to think it this way: Inline blocks are basically inline elements with a bit of enhanced behaviour. So what happens, when you place inline elements next to each other? Here an example:
<p>This is <strong>a</strong> <span>stupid</span> example.</p>
In this sentence a and stupid are separated by a white space. That's what you would expect. In your example one article tag is separated with a white space from the next one. So the simplest solution is to strip the white space between the tags like this:
<article>
...
</article><article>
...
</article>
Another solution is to float the container, but the display:inline-block is rendered rather useless, when you use floats. You can simply strip it.

Sometimes floating is the best answer.
.thumb_container {
display: inline-block;
float: left; <-------
margin: 0 0 0 20px;
width: 220px;
background: #fff;
-moz-box-shadow: 1px 1px 1px rgba(10, 72, 90, 0.2);
-webkit-box-shadow: 1px 1px 1px rgba(10, 72, 90, 0.2);
box-shadow: 1px 1px 1px rgba(10, 72, 90, 0.2);
}
.thumb_container:first-child { margin-left: 0px; }

Related

Putting content under a row that takes up 100% of the viewport in bootstrap 5

I'm trying to make a web page that starts with a image next to some text. I got that to work but when I try to put content under that it works on desktop but when the columns get stacked the content below covers the second column. I don't do a heap of web design so this might be a easy fix.
Here are some images:
These images are scrolled down the image fill the whole viewport.
Working on desktop
Not working when stacked
Here is my code:
index.html
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="vendors/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="resources/css/style.css" rel="stylesheet">
<title>Name</title>
</head>
<body>
<div class="container-fluid">
<div class="row vh-100">
<div id="welcomeImg" class="col-lg-4 h-100 welcomeImg" style="background-image: url('https://via.placeholder.com/1080x1920?text=Image');">
<div class="h-100" id="mobileOverlay">
<div class='icon-scroll'></div>
</div>
</div>
<div class="col-lg-8">
<h3>text</h3>
</div>
</div>
<div>
<h1>Content</h1>
<h5>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At consectetur lorem donec massa sapien faucibus et. Malesuada pellentesque elit eget gravida cum sociis. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper velit. Consequat semper viverra nam libero.</h5>
</div>
</div>
<!--Scripts-->
<!-- BootStrap -->
<script src="vendors/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Others -->
<script src="resources\js\reactive.js"></script><!--This is just a script that hides the mobileOverlay div if the display is over a certain size. The issue still happends with this removed-->
</body>
</html>
style.css
body, html {
height: 100%;
}
.welcomeImg {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
/* A scroll animation by Khalil Benihoud on code pen https://codepen.io/khalilbenihoud/pen/wBJVLK */
.icon-scroll,
.icon-scroll:before {
position: absolute;
left: 50%;
}
.icon-scroll {
width: 40px;
height: 70px;
margin-left: -20px;
top: 80%;
margin-top: -35px;
box-shadow: inset 0 0 0 1px #fff;
border-radius: 25px;
}
.icon-scroll:before {
content: '';
width: 8px;
height: 8px;
background: #fff;
margin-left: -4px;
top: 8px;
border-radius: 4px;
-webkit-animation-duration: 1.5s;
animation-duration: 1.5s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-name: scroll;
animation-name: scroll;
}
#-webkit-keyframes scroll {
0% {
opacity: 1;
}
100% {
opacity: 0;
transform: translateY(46px);
}
}
#keyframes scroll {
0% {
opacity: 1;
}
100% {
opacity: 0;
transform: translateY(46px);
}
}
Just take away the vh-100 class from the row and give it to the div with the id welcomeImg instead of the h-100 class. This should do the trick.
<body>
<div class="container-fluid">
<div class="row">
<div id="welcomeImg" class="col-lg-4 vh-100 welcomeImg" style="background-image: url('https://via.placeholder.com/1080x1920?text=Image');">
<div class="h-100" id="mobileOverlay">
<div class='icon-scroll'></div>
</div>
</div>
<div class="col-lg-8">
<h3>text</h3>
</div>
</div>
<div>
<h1>Content</h1>
<h5>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At consectetur lorem donec massa sapien faucibus et. Malesuada pellentesque elit eget gravida cum sociis. Molestie ac feugiat sed lectus vestibulum mattis ullamcorper velit. Consequat semper viverra nam libero.</h5>
</div>
</div>
</body>

How to get list symbols via keyword?

I have seen on site tradingview.com/chart and I would like create a search bar like search bar in tradingview site. I have tried to get list stock in yahoo finance but I feel it is not enough. Here is my code.
js
<script type="text/javascript">
$(document).ready(function(){
$("#searchStock").keyup(function () {
alert("a");
var temp = $("#searchStock").val();
$.ajax({
type: "get",
dataType: 'jsonp',
jsonpCallback: temp,
crossDomain: true,
url: "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=" + temp + "&region=US&lang=en-US&row=ALL&callback=" + temp,
success: function (data, status, xhr) {
//console.log(data.ResultSet.Result);
$(".list_results").html("");
$.each(data.ResultSet.Result, function (key, value) {
$(".list_results").append("<li style='cursor: pointer'><span class='result_key' style='width:40%; display:inline-block;'>" + value.symbol + "</span><span class='result_name' style='width: 60%;display: inline-block;'>" + value.name + "</span></li>")
});
$(".search_stock_results").fadeIn();
}
})
});
});
</script>
<style>
#resizable-4 {
/*max-width:1822px;*/
background:#f3f3f3;
height:951px;
position: relative;
}
#searchStock{
background-color: white;
border: 1px solid #eee;
color: #524f4f;
font-size: 13px;
font-weight: 600;
height: 28px;
padding: 0 0 0 7px;
width: 80px;
text-transform: uppercase;
}
.list_results {
margin-bottom: 10px;
margin-left: 0 !important;
margin-right: 10px;
margin-top: 10px;
}
.search_stock_results {
background: #fff none repeat scroll 0 0;
border: 1px solid #ddd;
margin-top: 2px;
position: absolute;
width: 48%;
top:45px;
}
.list_results > li {
color: black;
font-weight: normal;
line-height: 30px;
list-style: outside none none;
}
#allex a:hover
{
background: none !important;
border: none !important;
}
.nav-tabs > li.active > a, .nav-tabs > li.active > a:hover, .nav-tabs > li.active > a:focus {
border-bottom: 3px solid green !important;
color: #555 !important;
cursor: default;
}
.nav-tabs > li > a {
border:none !important;
}
.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited {
color: #333;
text-decoration: none;
}
.nav > li > a:hover, .nav > li > a:focus {
background: rgba(0, 0, 0, 0) none repeat scroll 0 0 !important;
text-decoration: none;
}
</style>
<div class="input-group">
<input type="text" class="form-control box-corner" id="searchStock"/>
</div>
<div class="search_stock_results" style="display: none;">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#all">All</a></li>
<li><a data-toggle="tab" href="#stock">Stock</a></li>
<li><a data-toggle="tab" href="#futures">Futures</a></li>
<li><a data-toggle="tab" href="#forex">Forex</a></li>
<li><a data-toggle="tab" href="#cfd">CFD</a></li>
<li><a data-toggle="tab" href="#bitcoin">Bitcoin</a></li>
<li><a data-toggle="tab" href="#index">Index</a></li>
<li><a data-toggle="tab" href="#economy">Economy</a></li>
<li style="float: right" id="allex">All exchanges <i class="fa fa-caret-down"></i></li>
</ul>
<div class="tab-content" style="margin-top:0 !important;">
<div id="all" class="tab-pane fade in active">
<ul class="list_results" style="height:150px;overflow-y:scroll"></ul>
</div>
<div id="stock" class="tab-pane fade">
<ul class="list_results" style="height:150px;overflow-y:scroll"></ul>
</div>
<div id="futures" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
</div>
<div id="cfd" class="tab-pane fade">
<h3>Menu 3</h3>
<p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
</div>
<div id="bitcoin" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
</div>
<div id="index" class="tab-pane fade">
<h3>Menu 3</h3>
<p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
</div>
<div id="economy" class="tab-pane fade">
<h3>Menu 3</h3>
<p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
</div>
</div>
</div>

JQuery Resizable: Unable to size child element to full height of parent

I'm using JQuery resizable and am unable to resize the child element contained in a parent div to the full height of the parent.
Here an example in jsfiddle: Try to drag the red box resizable handle down to make the red box fit the parent.
http://jsfiddle.net/ozsLegy4/3/
<div id="container1" class="container box">
<div id="box1" class="widget-container box">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
</p>
</div>
</div>
$(document).ready(function(){
$('#box1').css('top', '0px');
$('#box1').css('left', '0px');
$('#box1').css('z-index', 10);
$('.box').each(function(index){
$(this).draggable({
containment: "parent"
});
$(this).resizable({
containment: "parent"
});
});
});
.container{
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
border: 3px solid green;
width: 100%;
height: 100px;
margin: 0px;
position: relative;
z-index: 400;
}
.widget-container{
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
border: 3px solid red;
padding: 10px;
overflow: hidden;
width: 40px;
height: 50px;
position:absolute;
margin: 0px;
}
I assume the parent is not height enough to allow the drag handle to move further down.
Any ideas how to work around this?
Thanks!
I took out the box-sizing css statements for container and widget-container and it works as expected.
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;

How do I remove CSS from a string?

I've used the Sanitize Ruby gem with the following code:
result = Sanitize.clean(html)
It pulls the content from the page, but I still have this CSS in the sanitized result. How do I get rid of it so I just have the page text?
#fsb-social-bar { width: 100%; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; padding: 10px 0; margin: 0px 0 20px 0; float: left; background: #fff; position: relative; clear: both; } #fsb-social-bar a { border: 0px !important } #fsb-social-bar.fsb-fixed { position: fixed; top: -2px; z-index: 99999; } #fsb-social-bar .fsb-title { display: block; float: left; margin: 3px 20px 0 0; font-size: 16px; font-family: Arial, Helvetica, sans-serif; text-decoration: none; color: #333; } #fsb-social-bar .fsb-share-facebook { width: 120px; float: left; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-facebook.fsb-hide-count { width: 44px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-twitter { float: left; width: 135px; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-twitter.fsb-hide-count { width: 61px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-google { float: left; width: 105px; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-google.fsb-hide-count { width: 33px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-linkedin { float: left; width: 135px; padding: 3px 0 2px; height: 25px; } #fsb-social-bar .fsb-share-linkedin.fsb-hide-count { width: 61px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .fsb-share-pinterest { float: left; width: 115px; padding: 3px 0 2px; height: 25px;} #fsb-social-bar .fsb-share-pinterest.fsb-hide-count { width: 43px; overflow: hidden; margin-right: 30px; } #fsb-social-bar .socialite { display: block; position: relative; background: url(http://www.example.net/wp-content/plugins/floating-social-bar/images/fsb-sprite.png) no-repeat scroll 0 0; } #fsb-social-bar .socialite-loaded { background: none !important; } #fsb-social-bar .fsb-service-title { display: none; } #fsb-social-bar a { color: #333; text-decoration: none; font-size: 12px; font-family: Arial, Helvetica, sans-serif; } #fsb-social-bar .fsb-twitter { width: 105px; height: 25px; background-position: -13px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-twitter .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 69px; color: #333; } #fsb-social-bar .fsb-google { width: 75px; height: 25px; background-position: -136px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-google .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 41px; color: #333; } #fsb-social-bar .fsb-google .socialite-button { margin: 0 !important; } #fsb-social-bar .fsb-share-google .socialite-loaded .socialite-button{padding: 2px 0 0} #fsb-social-bar .fsb-facebook { width: 89px; height: 25px; background-position: -231px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-facebook .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 52px; color: #333; } #fsb-social-bar .fsb-facebook .socialite-button { margin: 0 !important;} #fsb-social-bar .fsb-share-facebook .socialite-loaded .socialite-button {padding: 2px 0 0} #fsb-social-bar .fsb-linkedin { width: 105px; height: 25px; background-position: -347px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-linkedin .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 70px; color: #333; } #fsb-social-bar .fsb-linkedin .socialite-button { margin: 0 !important; } #fsb-social-bar .fsb-pinterest { width: 88px; height: 25px; background-position: -484px -10px; line-height: 25px; vertical-align: middle; } #fsb-social-bar .fsb-pinterest .fsb-count { width: 30px; text-align: center; display: inline-block; margin: 0px 0 0 50px; color: #333; } #fsb-social-bar .fsb-pinterest .socialite-button { margin: 0 !important; } #fsb-social-bar .fsb-clear { clear: both; } #fsb-social-bar .fsb-clear:after { clear:both; content:; display:block; height:0; line-height:0; overflow:auto; visibility:hidden; zoom:1; } #media (max-width: 768px) { #fsb-social-bar.fsb-fixed { position: relative !important; top: auto !important; } } Facebook2 Twitter1 Google+0 LinkedIn0 Pinterest0 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at nisl auctor, dignissim odio vel, suscipit velit. Vivamus pretium velit quis sapien scelerisque ullamcorper. Vivamus ullamcorper lacus non magna suscipit laoreet. In hac habitasse platea dictumst. Nulla aliquam dolor nec neque auctor pretium. Nullam vitae enim nisl. In imperdiet lacinia nunc at congue. Aliquam posuere nulla vel ornare accumsan. Fusce vitae sapien et nulla fringilla congue quis eu tellus. Nunc vestibulum turpis eget convallis cursus. Integer ut sapien molestie odio interdum luctus. Vestibulum urna justo, sagittis ut sodales eu, rutrum a magna. Proin consequat convallis nibh vel semper. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque eu purus quis massa lobortis eleifend.
The solution needs to work on not only this text, but any string that could happen to have CSS. Thanks for your help.
If your CSS code is inside a style tag, you can use this one:
Sanitize.clean(content, :remove_contents => ['script', 'style'])
Other solution is css_transformer.rb.

jQuery unpleasant Draggable, Resizable interaction

When I resize the first div it causes the next div to jump 'up' the column.
To recreate: top div drag the resize handle.
jQuery
$(function() {
$('.portlet').draggable({ grid: [25, 25] }).resizable({ grid: [25, 25] });
});
Layout
<div class="portlet" id="P2">
<div class="portlet-header"><h3>News</h3></div>
<div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
</div>
<div class="portlet" id="Div1">
<div class="portlet-header"><h3>Feeds</h3></div>
<div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
</div>
CSS
.portlet
{
min-width: 100px;
min-height: 100px;
width: 100px;
height: 100px;
background-color: #C0C0C0;
}
Give #Div1 an absolute positioning of top:100px and it should stay put when resizing #P2. On initial resize of #Div1 it's inline positioning becomes changed and the browser bumps up #Div1 as you describe.

Resources