Having encountered various challenges (not to come across as a complaining troublemaker), my current struggle lies in determining the most effective way to float two divs alongside each other. One with a fixed width and the other with a percentage width to occupy the remaining space.
The structure of my HTML Code is as follows:
<div class="wrapper">
<div class="sidebar">
</div>
<div class="content">
<div class="tile">
<h1>Catalogs</h1>
<p>1</p>
</div><!--
--><div class="tile">
<h1>Products</h1>
<p>2</p>
</div><!--
--><div class="tile">
<h1>Specifications</h1>
<p>3</p>
</div><!--
--><div class="tile">
<h1>New Products</h1>
<p>4</p>
</div>
</div>
<div style="clear:both"></div>
</div>
As for my CSS code:
@charset "utf-8";
/* CSS Document */
/* WEB FONTS
font-family: 'Ubuntu', sans-serif;
font-family: 'Oswald', sans-serif;
font-family: 'Francois One', sans-serif;
*/
body {
background-color:#191919;
margin: 0 auto;
overflow:hidden;
font-family: 'Ubuntu', sans-serif;
}
.wrapper{
width: 100%;
min-height: 900px;
margin: 0 auto;
}
.sidebar{
width: 20%;
height: 100%;
float: left;
color:white;
background-color:#191919;
margin:0 auto;
display: block;
}
.content{
width: 80%;
height: 1000px;
float: right;
color:white;
background-image:url(Assets/background1.png);
background-size: cover;
background-repeat: no-repeat;
margin:0 auto;
}
.tile{
width: 25%;
height: 100%;
display:inline-block;
margin: 0 auto;
color:white;
background-color:rgba(0,0,0,0.7);
transition: opacity 1s;
opacity: .3;
float: left;
}
.tile:hover {
opacity: 1;
}
.tile h1{
font-family: 'Francois One', sans-serif;
background-color:rgba(110,0,1,0.77);
width: 100%;
height: 50px;
text-align:center;
line-height: 50px;
}
.tile p{
}
#item {
padding-left: 25px;
font-family: 'Francois One', sans-serif;
}
a {
color:white;
text-decoration:none;
}
This arrangement, solely reliant on CSS, aims to keep my sidebar menu at a fixed width while allowing the content to occupy the remaining 'x' pixels. Unfortunately, when the page size reduces significantly, the sidebar text overlaps. Hence, the reason for desiring a fixed width.
My attempt to address this dilemma was through jQuery:
function widthAdjuster(wrapper, sidebar, content, tile){
var wrapperWidth = $(wrapper).width();
var sidebarWidth = $(sidebar).width();
var newWidth = wrapperWidth - sidebarWidth;
var newWidgetWidth = newWidth/4;
$(content).css("width", newWidth);
$(tile).css("width", newWidgetWidth);
}
function masterFunc(){
widthAdjuster('.wrapper','.sidebar','.content','.tile');
$(window).resize(widthAdjuster('.wrapper','.sidebar','.content','.tile'));
}
This function automatically adjusts the content width and resizes each tile accordingly. Upon window resize, it recalculates the dimensions. However, I am curious if there is a pure CSS solution to prevent the need for jQuery adjustments that may be criticized by reviewers?