How to preserve style of parent - html

I have the following piece of code in a foreach:
FOREACH:
<div class="col-md-1" style="max-width: 50% !important" id="pageList_{{ presentationPage.position }}">
<a href="/customer/presentations/{{ id }}/edit?position={{ presentationPage.position }}">
<div class="slide-preview" style="background-color:{% if (presentationPage.position == activePresentationPage.position) %}#ffffff{% else %}#bbbbbb{% endif %}; border: 1px solid #000000; width:100%; padding:2px 5px; margin:5px; color:#000000; text-align:center;">
{{ presentationPage.position }}
</div>
</a>
</div>
ENDFOREACH
Which looks like this when rendered:
However, when I add something similar as an element or a div as you can see in the code below:
<div>
FOREACH:
<div class="col-md-1" style="max-width: 50% !important" id="pageList_{{ presentationPage.position }}">
<a href="/customer/presentations/{{ id }}/edit?position={{ presentationPage.position }}">
<div class="slide-preview" style="background-color:{% if (presentationPage.position == activePresentationPage.position) %}#ffffff{% else %}#bbbbbb{% endif %}; border: 1px solid #000000; width:100%; padding:2px 5px; margin:5px; color:#000000; text-align:center;">
{{ presentationPage.position }}
</div>
</a>
</div>
ENDFOREACH
</div>
The entire thing looks like this when rendered:
And I can't seem to find out why. A simple inspect doesn't bring any insights.

That is because the div that you put around the two elements doesn't have a specified width and height. Therefore the div will base its width and height on the size of its content. Then, your two elements will base their width and height on their parent's width and height, so it will get very small.
So if you give the parent div a width and height it should work out okay.

Related

Bootstrap carousel and column will not stay next to each other

Goal:
I would like to create a bootstrap row where there is a carousel on the left and text blocks on the right. I have labeled these "Left Column" and "Right Column" respectively within the HTML comments.
Problem:
I'm not able to get the carousel and text to stay in columns. Instead, they stack on top of each other, with the carousel on top and the next column going below it.
Context:
I've tried a few different things by moving around divs and creating new ones. I've already tried to remove the flex CSS styling and I've tried to remove all padding and margins. I've reviewed several stack overflow questions that seemed similar, but none of the problems seems similar to mine or the suggestions do not help.
It does not appear that there is anything within the main CSS that is causing this issue, because I am able to get other columns and rows to work correctly on the same page. However, I'm adding it here just in case with a screenshot.
HTML
<div class="container">
<div class="row">
<!-- Left Column Start -->
<div class="col-6" id="carousel-contain">
<div id="plantCarousel" class="carousel slide col-6" data-ride="carousel" data-interval="false">
<ol class="carousel-indicators">
{% for image in plant.plant_images.all %}
{% if forloop.first %}
<li data-target="#plantCarousel" data-slide-to="{{forloop.counter0}}" class="active"></li>
{% else %}
<li data-target="#plantCarousel" data-slide-to="{{forloop.counter0}}"></li>
{% endif %}
{% endfor %}
<li data-target="#plantCarousel"></li>
</ol>
<div class="carousel-inner">
{% for image in plant.plant_images.all %}
{% if forloop.first %}
<div class="carousel-item active">
{% else %}
<div class="carousel-item">
{% endif %}
<img src="{{ image.images.url }}" alt="{{ plant.name }}">
</div>
{% endfor %}
</div>
<a class="carousel-control-prev" href="#plantCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#plantCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<!-- Left Column Ends -->
<!-- Right Column Start -->
<div class="col-6">
<p> <b>Latin Name: </b>{{ plant.latin_name }} </p>
<br>
<p><b>Description: </b></p>
<p> {{ plant.description }} </p>
<br>
<br>
</div>
<!-- Right Column Ends -->
</div>
</div>
CSS
/* Sticky footer styles
-------------------------------------------------- */
html {
position: relative;
min-height: 100%;
font-size: 14px;
}
#media (min-width: 768px) {
html {
font-size: 16px;
}
}
body {
margin-bottom: 60px; /* Margin bottom by footer height */
}
.container {
max-width: 960px;
}
.pricing-header {
max-width: 700px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px; /* Set the fixed height of the footer here */
line-height: 60px; /* Vertically center the text there */
background-color: #f5f5f5;
}
img {
max-width: 100%;
max-height: 100%;
}
How it appears on the page:
After digging around even further, I discovered that I accidentally added an extra </div> which caused my row to end before the right column could be added into the row.

how to select first child div from div parent

I have a movie card where the content is dynamic. I'm trying to select the first child DIV of the left-side-bar, however, since the content is dynamically generated, the background-color is changed to all divs.
#left-side-bar div:first-child {
background-color: #e50914 !important;
}
<div id="left-side-bar">
<h3 style="border-bottom: 1px solid red; padding-bottom: 7px">
Top 5 movies
</h3>
#foreach (var movie in Model.SidebarData.TopMovies) {
<a asp-controller="Home" asp-action="Detail" asp-route-id="#movie.Id">
<div class="card-sb">
<center><img src="#movie.ImageUrl" /></center>
<p>#movie.Title</p>
<span class="crown">
<i class="fas fa-crown" style="color: goldenrod"></i>
#movie.Views
</span>
</div>
</a>
}
</div>
The :first-child selector is intended, like the name says, to select the first child of a parent tag.
But in your example there is a tag as a parent element on the div. So if you apply nth-of-type to it, you will solve your problem. So this example will work as follows.
#left-side-bar a:nth-of-type(1) .card-sb {
background:red;
}
#left-side-bar .card-sb:first-child {
background-color: #e50914 !important;
}
<div id="left-side-bar">
<h3 style="border-bottom: 1px solid red; padding-bottom: 7px">
Top 5 movies
</h3>
#foreach (var movie in Model.SidebarData.TopMovies) {
<a asp-controller="Home" asp-action="Detail" asp-route-id="#movie.Id">
<div class="card-sb">
<center><img src="#movie.ImageUrl" /></center>
<p>#movie.Title</p>
<span class="crown">
<i class="fas fa-crown" style="color: goldenrod"></i>
#movie.Views
</span>
</div>
</a>
}
</div>
Add an Id to your div, then refer to it to change the attribute of that specific element.
<div class="card-sb" id="CardSb">
then refer to it in your style sheet:
#CardSb {background-color: #e50914}
or try this:
/* Selects every first element among any group of siblings */
#left-side-bar a:nth-child(1n) {color: #e50914;}

Html image bigger than div border

My image is higher than my div, how do I tell my div to resize if something inside it is bigger? Here's my code:
<div {% if editable %}style="overflow-wrap: break-word; border-color: grey; border-style: solid; border-radius: 25px"{% else %}style="border-color: grey; border-style: solid; border-radius: 25px"{% endif %}>
<h4>{{ new.header }}</h4>
<p><img src="{{ new.file.url }}" style="max-width: 250px; float: left; height: auto">{{ new.text|safe }}</p>
<p align="right">Дата: <strong>{{ new.added }}</strong></p>
{% if editable == True %}
<a href="{% url 'create_news' %}?news_id={{ new.pk }}" style="display: inline; float: right; padding-right: 5px; margin: 0">
<button type="submit" class="btn btn-warning">изменить</button>
</a>
<form onsubmit="return confirm('Вы точно хотите удалить новость?');" method="post" style="display: inline; float: right; padding-right: 5px; margin: 0" action="{% url 'news_delete' news_pk=new.pk %}">
{% csrf_token %}
<button type="submit" class="btn btn-danger">удалить</button>
</form>
{% endif %}
</div>
The image is floated, so it can go out of its parent container. To avoid that, you can add overflow: auto to the parent container (i.e. the div your HTML example code starts with) That way, the whole floated image will be inside its parent and the border will go around it.
I've tried clearfix as Ahmed Tag Amer suggested, it worked.

how to reduce white space(right width) in my box

Hello I have two contents in my table, so two boxes that contain contents in html. I want to reduce the distance between these two boxes, but I realized size of one box is too big that they are just white space. I'm having trouble reducing that size. can someone please help me with this?
so, cell x and cell y that's in same row to be located closer.
<table class="table">
<tr id="cell">
---------------------------------------------------------------(one cell)
<td class="vert-align">
<div class="voting-space">
<a href="/post/{{ post.slug }}/vote?is_up=1" class="vote">
<span class="glyphicon glyphicon-triangle-top col-md-12" aria-hidden="true"></span></a>
<br />
<span class="col-md-12" style="height:1px; font-family: 'Passion One', cursive; bottom:10px; padding-left:0.01em;
"><h4 id="vote_count_{{ post.slug }}">{{ post.get_vote_count }}</h4></span> <br>
<a href="/post/{{ post.slug }}/vote?is_up=0" class="vote">
<span class="glyphicon glyphicon-triangle-bottom col-md-12" aria-hidden="true"></span></a>
</div>
</td>
--------------------------------------------------------------------(the other cell)
<td class="vert-align">
{% if post.url %}
<h4 id="line">
<img src="{{post.image}}" height="85" width="85"/><span id="title-font">{{ post.title }}</span>
<span style="margin-left: 15px;" class="domain">({{ post.domain }})</span>
<span class="discuss" style="color:red;">토론장 입장</span>
<br />
<span class="post-info">{{ post.pub_date | timesince }}전/{{ post.moderator.username }}작성/<i class="fa fa-eye"></i>{{post.views}}/{{post.category}}</span>
</h4>
{% else %}
<h4>{{ post.title }}<span style="margin-left: 15px; "class="domain">({{ post.domain }})</span></h4>
{% endif %}
For controlling "cellpadding" in CSS, you can simply use padding on table cells. E.g. for 10px of "cellpadding":
td {
padding: 10px;
}
For "cellspacing", you can apply the border-spacing CSS property to your table. E.g. for 10px of "cellspacing":
table {
border-spacing: 10px;
border-collapse: separate;
}
This property will even allow separate horizontal and vertical spacing, something you couldn't do with old-school "cellspacing".

How can I decrease the height of cell?

I am trying to decrease the height of the table cells by using the following CSS, but it is not working.
.table tr>td.vert-align{
vertical-align: middle;
height: 5px;
padding: 10px 0 10px 0;
border-bottom: 1px solid #eaebec;
}
This is my HTML code:
<td class="vert-align">
{% if post.url %}
<h4><a href="{{ post.url }}" style="margin-left: 15px;"> <img src="{{post.image}}" height="70" width="70"/>
{{ post.title }}</a><span style="margin-left: 15px;" class="domain">
({{ post.domain }})</span></h4>
{% else %}
<h4>{{ post.title }}<span style="margin-left: 15px; "class="domain">({{ post.domain }})</span></h4>
{% endif %}
<ol class="post-info">
<div class="btn-group btn-breadcrumb">
<span class="btn btn-default">{{ post.moderator.username }</span>
<span class="btn btn-default">{{ post.pub_date | date }}</span>
<span class="btn btn-default">{{post.views}}</span>
discuss
{{post.category}}
</div>
</ol>
</td>
I'm trying to display title/image/domain name in one line that fits nicely to the table, but right now height of the table is too long it just looks odd. I tried height:5px but it won't work
I see no use of a table in your code, but the problem might be caused by you having a ".table" selector instead of a "table" selector.
Dot means classname, no dot means html tag. Please give it a look and if this is not the answer post your whole html code to get a better look at it.
You have already class for your td, so directly use it in your selector.
.vert-align{
vertical-align: middle;
height: 5px;
padding: 10px 0 10px 0;
border-bottom: 1px solid #eaebec;
}
Update:
Decrease the height of your image which is inside the td to decrease the height of cell.