I have random white space inside my website.
My HTML (Laravel) is build like this:
<ul class="thumbnails" style="max-width: 100%;">
#foreach($img as $image)
<li class="span2 thumbnail">
<div class="overflow-hidden">
<img src="{{ Config::get('app.url') }}/{{ $image }}" />
</div>
</li>
#endforeach
</ul>
This is the output:
And every time I refresh the page, there is another white space.
How can I fix this?
You might want to read up on the grid system to understand why this is happening.
Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via negative margin on .rows.
In other words, if you look at bootstrap.css:
.row {
margin-right: -15px;
margin-left: -15px;
}
You can fix your code adding the row class to your <ul> element so you have:
<ul class="thumbnails row">
Or, just add the margin-left and margin-right properties.
am i correct that you want the thumbnails to line up 5 times, than start a new row of 5?
Then you have to build in a counter that closes a row, and start a new row:
Beware of code: i do not know laravel, went true documentation to write this, it could be wrong, main focus here is the idea i am giving you:
<ul class="thumbnails" style="max-width: 100%;">
<?php $i=0 ?>
#foreach($img as $image)
<li class="span2 thumbnail">
<div class="overflow-hidden">
<img src="{{ Config::get('app.url') }}/{{ $image }}" />
</div>
</li>
<?php $i++ ?>
#if ($i === 5)
</ul><ul class="thumbnails" style="max-width: 100%;">
#endif
#endforeach
</ul>
And be sure to read the answer by WEX, about the grid system.
Related
I just create footer with 4 columns, and last column contain two rows of div. I want that last column to be left aligned so i use justify-content-start for the first row, and it works. But when i try it to second row, which is search bar with button, the justify-content-start doesn't work.
So I tried with flex-row, but it doesn't work either. Here is my web view right now.
I want that search bar and button are parallel with the visitor counter above. Any suggestions for me to fix this things up?
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<div class="col-lg-3 offset-lg-1">
<div class="row mb-4 justify-content-start">
<div class="card text-white visitor-card" style="width: 16rem;">
<div class="card-body">
<h5 class="card-title">Total Pengunjung :</h5>
<?php
$date = date("Y-m-d");
$pengunjunghariini = $this->db->query("SELECT * FROM visitor WHERE date='".$date."' GROUP BY ip")->num_rows(); // Hitung jumlah pengunjung
$dbpengunjung = $this->db->query("SELECT COUNT(hits) as hits FROM visitor")->row();
$totalpengunjung = isset($dbpengunjung->hits)?($dbpengunjung->hits):0; // hitung total pengunjung
$bataswaktu = time() - 300;
$pengunjungonline = $this->db->query("SELECT * FROM visitor WHERE online > '".$bataswaktu."'")->num_rows(); // hitung pengunjung online`
?>
<h5 class="card-title">
<?php echo $totalpengunjung ?>
</h5>
</div>
</div>
</div>
<div class="d-flex flex-row" style="border-color: white;">
<div>
<form class="d-flex" action="<?= base_url('Home/search'); ?>" method="post">
<input class="form-control me-2" type="search" placeholder="Cari artikel ..." aria-label="Search">
<button class="btn btn-outline-primary" type="submit">Search</button>
</form>
</div>
</div>
</div>
The problem might be that your container of that search bar might already have 100% width of its parent, so that any horizontal alignment wont be possible, since it has no space to move to.
This is a very common issue, and to quickly find out what is going on, you can use some CSS debugging techniques, as weird as it sounds.
The best example of this layout debugging technique is to set a border to your div that you need to be aligned somehow (or on its children).
.container {
border: 1px solid lime
outline: 1px solid lime
}
Note: outline might be better in some cases, since it is not increasing width/height of your element
If your container is really as wide as its parent, try width: fit-content on it, so it shrinks and leaves some space to be aligned to. Hope this helps, and to the future as well :-)
I'm trying to get a small profile image to display on the left with a name and title on the right using bootstrap 4. Sometimes the titles are very long and can go onto the next line. My problem is the next line is the end of the image instead of the middle of the image. I've looked at a few examples online that work in the fiddler but when I copy and paste the code into my code it breaks.
Can anyone show me what I've done wrong. I would like to learn more of the theory so I don't have this problem.
I've converted this from php so there might be some " or ' left over that shouldn't be there and row isn't ended because there is more code for a similar second side.
Thanks
<div class="row">
<div class="cast-list col-6">
<h2 class="text-center">Cast</h2>;
<div class="row">;
<div class="col-6">;
<div>
<img class="img-responsive profilepic" src="//image.tmdb.org/t/p/w45">;
<span class="people profiletext"> . $person->name . </span>;
<span class="people profiletext"> . $person->character . </span>
</div>
</div>;
</div>;
</div>
.people{
padding-left: 10px;
}
.profilepic{
}
Hope the person name and character will comes in a single row. If yes then use the below code:
<div class="d-flex align-items-center">
<img class="img-responsive profilepic" src="//image.tmdb.org/t/p/w45">;
<span class="people profiletext"> . $person->name . </span>;
<span class="people profiletext"> . $person->character . </span>
</div>
Do not fix the container size. Since the values wont be same at all the time.
If it comes with longer data. then the container will be expanded aswell. To avoid that, You can fix it to static width and you have to use ellipsis
CSS:
.yourclass{
text-overflow: ellipsis;
white-space:no-wrap;
}
I have a sidebar item which contains a list of comments. I want this item to show only if there are any available comment in the beginning and in order for my template to work I have to put a different style to the first comment than the rest. All the comments are being passed on my Model.
Here is my approach:
#if(Model.Comments?.Count > 0) {
<div class="sidebar_item">
<div class="item_inner slider">
<h4>See what students say:</h4>
<div id="single_banner">
<ul class="slides">
#for (int i = 0; i < Model.Comments.Count; i++)
{
if (i > 0){
<li style="display:none;">
}
#if( i == 0)
{
<li>
}
#Model.Comments[i].Comment
<div class="carousal_bottom">
<div class="thumb">
<img src="img/courses/testi_thumb.png" draggable="false" alt="" />
</div>
<div class="thumb_title">
<span class="author_name">#Model.Comments[i].Student</span>
</div>
</div>
</li>
}
</ul>
</div><!--end banner-->
</div><!--slider-->
</div><!--end sidebar item-->
}
The problem is that this doesn't work and I get errors that some curly brackets are missing or that some elements haven't closed properly. Any help appreciated.
I get errors that [...] some elements haven't closed properly.
The following code isn't recommended because the engine isn't smart enough to determine start/ends for html elements in c# code:
if (i > 0){
<li style="display:none;">
}
#if( i == 0)
{
<li>
}
So I generally put the logic directly in the tag:
<li style="#(i > 0 ? "display:none;" : string.Empty)">
However I'm not really a fan of logic in my view. Additionally to make things easier IMHO, I would have a comment display template. And I personally think there is no good reason to not use classes. Eventually my code would look like:
controller:
foreach(var comment in Model.Comments)
{
comment.IsVisible = comment == Model.Comments.First();
}
view:
// Update Model with Property
// bool HasComments { get { return Comments.Any(); } }
// Then the code actually reads/documents itself
#if(Model.HasComments) {
<div class="sidebar_item">
<div class="item_inner slider">
<h4>See what students say:</h4>
<div id="single_banner">
<ul class="slides">
#Html.DisplayFor(m => m.Comments);
</ul>
</div><!--end banner-->
</div><!--slider-->
</div><!--end sidebar item-->
}
displaytemplates/comments.cshtml
#{
// View logic, it only deals with html/css/javascript
var liClass = model.IsVisible ? string.Empty : "is-not-visible";
}
<li class="#liClass">
#Model.Comments[i].Comment
<div class="carousal_bottom">
<div class="thumb">
<img src="img/courses/testi_thumb.png" draggable="false" alt="" />
</div>
<div class="thumb_title">
<span class="author_name">#Model.Student</span>
</div>
</div>
</li>
Less code and more encapsulated.
I'd also recommend reading Philip Walton - Decoupling Your HTML, CSS, and JavaScript
Is there any nice clean way to put nesteded button elements of a div in center with style set to "table" ?
Ideally I do not want to contain the buttons within an additional div.
<div class="the-tabs">
<button class="tool-button dark_mini"><img src="Tools-icon.png"></button>
<button class="help-button dark_mini"><img src="Info-icon.png"></button>
<button class="save-button dark_mini"><img src="Zoom-in-icon.png"></button>
<button class="save-button dark_mini"><img src="Save-icon.png"></button>
<div id="the_preview" style="width:<?php echo $third_w;?>px;height:<?php echo $third_h;?>px;">
<div id="loading"><img src="images/loading.gif"><br/>Loading .... </div>
<img src="<?php echo $the_img;?>" width=" <?php echo $width_new;?>px" height=" <?php echo $height_new;?>px" id="preview" class="preview_color"/>
</div>
</div>
Not 100% sure what you mean but here goes...
.the-tabs {
text-align: center;
}
That will centre the buttons within the parent div. Is that what you mean?
JSFiddle
I am modifying a wordpress theme completely, and have run into one very simple problem. Please look at my page here: wordpress blog When you scroll down, you can see the one blank area under the first post. For some reason, that block isn't floating left. Each post has the following css that fits in a 645px container:
.home-post-wrap { width: 285px; margin:0; float: left; background-color: #FFF; padding: 15px; overflow: hidden; border-bottom:1px dotted #C5C5C5; border-right:1px dotted #C5C5C5; }
Any idea on how to make the page flow correctly here?
crimson_penguin is correct. It's because the columns are different heights. Every 2 columns you wan't to do a clear. The easiest thing to do here would look at the index of the loop and echo a clearfix after every 2. You can do this with modulo, and/or apply a class to the ones at 1, 3, 5, etc... to clear:left.
Here is a PHP function of mine that I use to clear.
<?php
public static function cycle($count, $odd = 'odd', $even = 'even') {
return ($count % 2) ? $even : $odd;
}
?>
Basically, you pass it three arguments (the second and third are optional) where the first is the $count, or the object to look at (for example $i in a for loop) and $odd / $even are strings to be used when an odd or even item in the loop is encountered.
Here it is in action:
<?php foreach ($products as $key => $product): ?>
<li class="<?= Template::cycle($key) ?>">
<img src="<?= $product->get_photo('small') ?>" />
<div class="productMeta">
<h3><?= $product->get_full_name() ?></h3>
<p><?= $product->get_description() ?></p>
</div>
</li>
<?php endforeach; ?>
I'm doing the cycle on the $key which in this case happens to be 0, 1,... n. The result is the following:
<li class="odd">
<img src="http://arbesko.dev/wp-content/themes/arbesko/img/products/small/465.jpg" />
...
</li>
<li class="even">
<img src="http://arbesko.dev/wp-content/themes/arbesko/img/products/small/935.jpg" />
...
</li>
<li class="odd">
<img src="http://arbesko.dev/wp-content/themes/arbesko/img/products/small/350.jpg" />
...
</li>
Simply apply some clear:left to the odd ones, and you'll be all set!
It is floating to the left, the problem is that the first block is taller than the second, making it stick out below, and so the third block is still on the same "line" as the first two, like you would expect it to if the first block was twice as high.
What you probably want, is a <div style="clear: left;"></div> between every 2 blocks... but that might be hard to do in WordPress. Another potential solution would be min-height on them, but that wouldn't be quite as nice (and wouldn't work in IE6).