I have created a Table of Content (ToC) using a Div element and styled it with the following HTML and CSS:
h3.articletitle {
font-weight: bold;
font-size: 30px;
border-bottom: 1px solid #4F120B;
}
h4.articlesubtitle {
font-weight: bold;
font-size: 22px;
border-bottom: 1px solid #4F120B;
}
h5.articlesubtitle {
font-weight: bold;
font-size: 18px;
border-bottom: 1px solid #4F120B;
}
#toc_container {
background: rgba(92, 9, 0, 0.14);
border: 1px solid #4F120B;
display: block;
font-size: 90%;
margin-bottom: 1em;
margin-right: 1em;
padding: 20px;
width: auto;
}
<div class="book">
<h3 class="articletitle">Title</h3>
<article>
<div style="float: left; margin-left: auto;" id="toc_container">
<p class="toc_title">Contents</p>
<ul class="toc_list">
<li><a href="#Scociety">Society</a></li>
<ul>
<li><a href="#ArtHistory">Art</a></li>
<li><a href="#PopCulture">Pop Culture</a></li>
<li><a href="#HighCulture">High Culture</a></li>
<li><a href="#CommunicationAndTheSpreadOfIdeas">Communication And The Spread Of Ideas</a></li>
<li><a href="#Holidays">Holidays</a></li>
<li><a href="#GenderAndGenderRoles">Gender and Gender Roles</a></li>
<li><a href="#SubculturesAndAlternativeLifestyles">Subcultures and Alternative Lifestyles</a></li>
<li><a href="#UniversalFears">Universal Fears</a></li>
</ul>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<h4 class="articlesubtitle" id="Society">Society</h4>
<h5 class="articlesubtitle" id="ArtHistory">Art</h5>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
</div>
The issue I am facing is with the borders under the headers extending into the ToC's div. How can I make them wrap around the text? I have tried placing them in separate divs and adjusting the width using percentages, but it only works when in fullscreen mode. When resizing, the borders end up overlapping the ToC.
This is my first experience with web design, so please explain any solutions in simple terms.