One of the issues I'm facing now is that I have a flexbox(which should be irrelevant) with an inner div that's horizontally centered in the parent. I want an unordered list to be aligned horizontally with the text in the inner div, but even with text-align: center, it seems to be off by a couple of pixels(to the right) and I cannot figure out why(I can't believe I've never ran into this problem up until now). The '.right' div is actually a child of another element, but that should be irrelevant, so I'll just post the part I actually need. Is this just a product of the ul's initial styles?
.right {
text-align: center;
order: 2;
//background: yellow;
flex-basis: 100%;
height: 100%;
}
.right .headbox{
border-bottom: 1px solid orange;
margin: auto;
width: 60%;
height: auto;
}
.right .list{
text-align: center;
margin: auto;
width: 60%;
height: auto;
}
ul{
list-style: none;
}
.headbox h3{
color: orange;
}
<div class="right">
<div class="headbox">
<h3>Visit Us</h3>
</div>
<div class="list">
<ul>
<li>Overview</li>
<li>Hours</li>
<li>Admission</li>
<li>Directions</li>
</ul>
</div>
</div>
Add padding: 0 to your <ul> to override the browser's default styling.
Your <ul> still have the default padding from the browser's default stylesheet.
You can use the padding-left: 0; to disable that padding.
ul{
list-style: none;
padding-left: 0;
}
.right {
text-align: center;
order: 2;
//background: yellow;
flex-basis: 100%;
height: 100%;
}
.right .headbox{
border-bottom: 1px solid orange;
margin: auto;
width: 60%;
height: auto;
}
.right .list{
text-align: center;
margin: auto;
width: 60%;
height: auto;
}
ul{
list-style: none;
padding-left: 0;
}
.headbox h3{
color: orange;
}
<div class="right">
<div class="headbox">
<h3>Visit Us</h3>
</div>
<div class="list">
<ul>
<li>Overview</li>
<li>Hours</li>
<li>Admission</li>
<li>Directions</li>
</ul>
</div>
</div>
Related
<style>
* {
margin: 0;
padding: 0;
}
.navbar {
background-color: black;
color: white;
}
.navbar ul li {
display: inline-block;
margin-top: 20px;
padding-bottom: 20px;
}
.box1 {
background-color: red;
width: 33.3333333%;
height: 600px;
display: inline-block;
}
.box2 {
background-color: blue;
width: 33.3333333%;
height: 600px;
display: inline-block;
}
.box3 {
background-color: greenyellow;
width: 33.3333333%;
height: 600px;
display: inline-block;
}
.bottombar {
background-color: black;
color: white;
height: 50px;
text-align: center;
}
</style>
<doctype html>
<html>
<head>
</head>
<body>
<div class="navbar">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact us</li>
</div><div class="box1">
</div><div class="box2">
</div><div class="box3">
</div><div class="bottombar"> © copyright reserved 2020-2021</div>>
</body>
</html>
Here i made three boxes box1,box2 and box 3 of different colours of
three different colors and managed to arrange them side by side along
width using CSS property (display: inline-block).But when I insert a
single letter in any of these boxes ,that box goes down.
I had same problem, the thing im using is a margin-right of -0.25em on all elements inside, there is probably other solutions but this is mine
<style>
* {
margin: 0;
padding: 0;
}
.navbar {
background-color: black;
color: white;
}
.navbar ul li {
display: inline-block;
margin-top: 20px;
padding-bottom: 20px;
}
.container div{
margin-right: -0.25em;
}
.box1 {
background-color: red;
width: 33.3333333%;
height: 600px;
display: inline-block;
}
.box2 {
background-color: blue;
width: 33.3333333%;
height: 600px;
display: inline-block;
}
.box3 {
background-color: greenyellow;
width: 33.3333333%;
height: 600px;
display: inline-block;
}
.bottombar {
background-color: black;
color: white;
height: 50px;
text-align: center;
}
</style>
<doctype html>
<html>
<head>
</head>
<body>
<div class="navbar">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact us</li>
</div>
<div class="container">
<div class="box1">
test
</div>
<div class="box2">
test
</div>
<div class="box3">
test
</div>
</div>
<div class="bottombar"> © copyright reserved 2020-2021</div>>
</body>
</html>
I'm quite new to HTML and CSS. I have a list that serves as a navigation bar for a website, which is inside the div "inner header." I was able to align the "nav" container (in teal) to the right edge of the "inner header" container, but I am struggling to do the same for the items within nav (in red).
Containers Appearance
Essentially, I would like the text to align with the teal on the right side, but I noticed no matter what I do, the red will not expand. I've tried changing width to 100%, but that causes each word to separate into three rows (possible due to the display type?).
If I add width: 98px, it gets closer to my desired outcome, but it doesn't perfectly align with the teal.
Close to desired outcome
Any advice is appreciated!
.inner_header {
width: 1000px;
height: 100%;
display: block;
margin: 0 auto;
background-color: #8ecae6;
display: flex;
justify-content: center;
align-items: center;
}
.nav {
float: right;
height: 100%;
width: 70%;
background-color: teal;
text-align: right;
}
.nav a {
height: 100%;
display: table;
table-layout: fixed;
float: left;
padding: 0px 20px;
background-color: red;
overflow: hidden;
width: 98px;
}
.nav a:last-child {
padding-right: 0px;
}
.nav a li {
display: table-cell;
vertical-align: middle;
height: 100%;
font-family: 'Montserrat';
font-weight: 300;
}
<div class="header">
<div class="inner_header">
<div class="logo_container">
<img src=".png">
<img src=".jpeg">
</div>
<p>Text <br> Text</p>
<ul class="nav">
<a>
<li>Home</li>
</a>
<a>
<li>Data</li>
</a>
<a>
<li>Tool</li>
</a>
</ul>
</div>
</div>
I still don't understand what you wanted, I'm just taking a guess here and tried to get the result closer to your screenshot and based on what you explained.
.inner_header {
width: 1000px;
height: 100%;
display: block;
margin: 0 auto;
background-color: #8ecae6;
display: flex;
justify-content: center;
align-items: center;
}
.nav {
float: right;
height: 100%;
width: 70%;
display: table;
background-color: teal;
text-align: right;
padding:0;
}
.nav a {
height: 100%;
display: table-cell;
padding: 0px 20px;
background-color: red;
overflow: hidden;
width: auto;
}
.nav a:last-child {
padding-right: 0px;
}
.nav a li {
display: table-cell;
vertical-align: middle;
height: 100%;
font-family: 'Montserrat';
font-weight: 300;
}
<div class="header">
<div class="inner_header">
<div class="logo_container">
<img src=".png">
<img src=".jpeg">
</div>
<p>Text <br> Text</p>
<ul class="nav">
<a>
<li>Home</li>
</a>
<a>
<li>Data</li>
</a>
<a>
<li>Tool</li>
</a>
</ul>
</div>
</div>
So I have a silly question, how do I get my divs on the right side? I have main content but I need to set up four divs on the right side. It looks like this and I need to add div1 - 4. Am I supposed to add width:100%; float: left in .main_container?
Question #2 - I would like to group main_info1 - 3 under one div like main so that I could use .main in css with max-width: 900px; overflow: hidden; margin-left: 20px; attributes for all divs without the need for repeating but when I do that main_info2 jumps up and ignores main_info1 lists. Thanks.
HTML:
<div class="main_container">
<div class="title_container">
<h1>Title</h1>
</div>
<aside>
<div class="small_blocks">
<div class="block1">
<span>Text</span>
</div>
<div class="block2">
<span>Text</span>
</div>
</div>
</aside>
<div class="content clearfix">
<div class="image1">
<img src="img/img1.jpg">
</div>
<div class="image2">
<img src="img/img2.jpg">
</div>
</div>
<div class="main_info">
<h2>Title</h2>
<p>Text</p>
</div>
<div class="main_info2 clearfix">
<h2>Title</h2>
<ul>
<li>
<p>Text</p>
</li>
</ul>
</div>
<div class="main_info3 clearfix">
<h2>Title</h2>
<p>Text</p>
</div>
</div>
CSS:
.main_container {
width: 1360px;
margin: 0 auto;
background: url("../img/bg.jpg") left top no-repeat;
background-color: #0c0334;
}
.title_container {
display: table;
}
.title_container h1 {
float: left;
display: table-cell;
vertical-align: top;
margin-top: 50px;
margin-left: 20px;
line-height: 66px;
}
.small_blocks {
min-width: 900px;
overflow: hidden;
}
.small_blocks div {
height: 55px;
margin-top: 30px;
}
.small_blocks .block1 {
float: left;
margin-left: 20px;
background: #390b5d;
width: 595px;
line-height: 52px;
}
.small_blocks .block1 span {
font-size: 30px;
padding-left: 20px;
font-weight: 100;
}
.small_blocks .block2 {
float: left;
width: 285px;
background: #e26c34;
padding-left: 20px;
line-height: 52px;
vertical-align: middle;
}
.small_blocks .block2 span {
font-size: 30px;
padding-left: 10px;
font-weight: 100;
vertical-align: middle;
display: inline-block;
}
.clearfix:after {
content: "";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.content {
width: 900px;
height: 377px;
overflow: hidden;
margin: 20px 0 0 20px;
}
.content .image1 {
float: left;
width: 268px;
}
.content .image2 {
float: left;
margin-left: 10px;
width:100%;
max-width: 622px;
}
.main_info {
max-width: 900px;
overflow: hidden;
margin-top: 60px;
margin-left: 20px;
}
.main_info h2 {
height: 34px;
border-bottom: 1px solid #390b5d;
}
.main_info2 {
max-width: 900px;
overflow: hidden;
margin: 60px 0px 0px 20px;
background: #110321;
}
.main_info2 h2 {
background: #390b5d;
min-height: 55px;
width: 880px;
padding-left: 20px;
height: 34px;
color: #fff;
line-height: 52px;
}
.main_info3 {
max-width: 900px;
overflow: hidden;
margin: 60px 0px 0px 20px;
background: #390b5d;
}
.main_info3 h2 {
min-height: 55px;
width: 880px;
padding-left: 20px;
height: 34px;
color: #fff;
line-height: 52px;
}
I think you are a newbie. You should work hard to master in HTML and CSS. :)
However, here is a solution. Please inspect them closely. Hopefully you will get your answers.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
img {
display: block;
}
.clearfix:after {
content: "";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.wrapper {
min-width: 1000px;
max-width: 1360px;
margin: 0 auto;
padding: 0 20px;
}
.title_container {
padding-top: 50px 0 30px;
}
.title_container h1 {
line-height: 66px;
}
.small_blocks {
height: 55px;
overflow: hidden;
margin-bottom: 20px;
font-size: 30px;
font-weight: 100;
line-height: 52px;
color: #fff;
}
.small_blocks > div {
height: inherit;
float: left;
padding-left: 20px;
}
.small_blocks .block1 {
background: #390b5d;
width: 66.111111%;
}
.small_blocks .block2 {
width: 33.888889%;
background: #e26c34;
}
.content {
/*height: 377px;*/
overflow: hidden;
margin-bottom: 60px;
}
.content > div img {
width: 100%;
height: auto;
}
.content .image1 {
float: left;
width: 29.777778%;
}
.content .image2 {
float: left;
width: 70.222222%;
padding-left: 10px;
}
.main_container {
width: 68.181818%;
float: left;
}
.main_info {
margin-bottom: 60px;
background: #d7d7d7;
}
.main_info .head {
padding-left: 20px;
background: #000;
color: #fff;
}
.main_info h2 {
height: 34px;
line-height: 34px;
}
.main_info .body {
padding: 20px;
}
.sidebar {
width: 31.818182%;
padding-left: 20px;
float: right;
}
.sidebar_block {
min-height: 150px;
margin-bottom: 20px;
padding: 20px;
background: #000;
color: #fff;
}
<div class="wrapper">
<header class="title_container">
<h1>Title</h1>
</header>
<main class="main_container">
<div class="small_blocks">
<div class="block1">
<span>Block 1</span>
</div>
<div class="block2">
<span>Block 2</span>
</div>
</div>
<div class="content clearfix">
<div class="image1">
<img src="http://dummyimage.com/268x377/000/fff.jpg&text=image1">
</div>
<div class="image2">
<img src="http://dummyimage.com/622x377/000/fff.jpg&text=image2">
</div>
</div>
<section class="main_info">
<div class="head">
<h2>Main Info-1 h2</h2>
</div>
<div class="body">
Main info 1
</div>
</section>
<section class="main_info">
<div class="head">
<h2>Main Info-2 h2</h2>
</div>
<div class="body">
Main info 2
</div>
</section>
<section class="main_info">
<div class="head">
<h2>Main Info-3 h2</h2>
</div>
<div class="body">
Main info 3
</div>
</section>
</main>
<aside class="sidebar">
<section class="sidebar_block">Div 1</section>
<section class="sidebar_block">Div 2</section>
<section class="sidebar_block">Div 3</section>
<section class="sidebar_block">Div 4</section>
</aside>
</div>
Regarding the questions in your comment:
Actually float works. As you use a fixed width width: 420px;, probably there has no enough space for the second ul to accommodate it in a single row. Use width: 50%; or below and see the changes. Or, you can check it in a wider screen, like, 1360px resolution.
Yes, for smaller devices.
This is a basic example. I used percentage values for the column width. So columns may become very narrower in smaller devices. To prevent that, I used min-width: 1000px for .wrapper. This will prevent narrower column width, but cause a horizontal scroll-bar in smaller devices.
I'm working on a navigation bar that needs to display multiple divs side by side. But the parent div doesn't have a fixed width. Just some padding. So the question is how can I achieve this?
.nav {
width: 100%;
height: 50px;
}
.nav ul {
width: 100%;
height: 50px;
}
.nav ul li {
display: inline;
list-style-type: none;
background: gray;
padding: 10px 30px;
margin: 0 10px;
height: 100%;
position: relative;
}
#container {
position: absolute;
left: 0;
top: 100%;
background: black;
padding: 10px;
}
#container .category {
position: relative;
display: inline-block;
width: 50px;
height: 80px;
}
<div class="nav">
<ul>
<li>AB
<div id="container">
<div class="category" style="background: #4285f4;"></div>
<div class="category" style="background: #ea4335;"></div>
<div class="category" style="background: #fbbc05;"></div>
<div class="category" style="background: #34a853;"></div>
</div>
</li>
<li>CD</li>
<li>EF</li>
<li>GH</li>
</ul>
</div>
Those four colored divs must be inline.
You can use display: flex on the #container element. The default direction for the elements inside a container with display set to flex is row. So the elements go from left to right.
.nav {
width: 100%;
height: 50px;
}
.nav ul {
width: 100%;
height: 50px;
}
.nav ul li {
display: inline;
list-style-type: none;
background: gray;
padding: 10px 30px;
margin: 0 10px;
height: 100%;
position: relative;
}
#container {
position: absolute;
left: 0;
top: 100%;
background: black;
padding: 10px;
display: none;
}
.nav li:hover > #container {
display: flex;
}
#container .category {
position: relative;
display: inline-block;
width: 50px;
height: 80px;
}
<div class="nav">
<ul>
<li>AB
<div id="container">
<div class="category" style="background: #4285f4;"></div>
<div class="category" style="background: #ea4335;"></div>
<div class="category" style="background: #fbbc05;"></div>
<div class="category" style="background: #34a853;"></div>
</div>
</li>
<li>CD</li>
<li>EF</li>
<li>GH</li>
</ul>
</div>
I'm struggling to make one of my web pages prettier.
The page has a couple of lists that can have anywhere from 0 to 500+ elements. The lists start from different levels / y-coordinate. How can I adjust the height of the lists so that they get stretched to occupy the rest of the height in the browser, along with the page's footer? Kind of like an email client with email folders and emails listed side-by-side as scrollable lists.
Is it possible to do it without complex calculations involving heights of elements above the lists?
Here is the sample page I created to clarify the question:
http://jsfiddle.net/dilipvshah/gh2Au/
CSS
.header {
width: 800px; height: 50px; border: solid 1px black; text-align: center; vertical-align: middle;
}
.footer {
width: 800px; height: 20px; border: solid 1px black; text-align: center; vertical-align: middle;
}
.subHeader {
display: table-cell; height: 50px; text-align: center;
}
.content {
display: table; width: 800px; text-align: center;
}
.contentInner {
display: table-row; width: 100%; text-align: center;
}
.contentLeft {
display: table-cell; width: 30%; border: solid 1px black; text-align: center;
}
.contentRight {
display: table-cell; height: 400px; border: solid 1px black; text-align: center;
}
.tableLayout {
display: table; width: 100%;
}
.tableRowLayout {
display: table-row; width: 100%;
}
.listLeft {
list-style: none; text-align: left; max-height: 500px; overflow-y:auto;
}
.listRight {
list-style: none; text-align: left; max-height: 500px; overflow-y:auto;
}
HTML
<body>
<div class="header">
Header
</div>
<div class="content">
<div class="contentInner">
<div class="contentLeft">
Left
<ul id="leftList" class="listLeft">
<li> ... </li>
[ ... ]
</ul>
</div>
<div class="tableLayout">
<div class="tableRowLayout">
<div class="subHeader">
Sub-header
</div>
</div>
<div class="tableRowLayout">
<div class="contentRight">
Right
<ul id="rightList" class="listRight">
<li> ... </li>
[ ... ]
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
Footer
</div>
</body>
Adding an image to clarify the question.
The key to this is to use position:absolute with top:0;bottom:0 to ensure that the lists exactly fill up the remaining window height.
FIDDLE
Note:
I have removed the markup/css connected with tables. (This reduces a lot of the markup and css)
The javascript in the fiddle has nothing to do with the layout - it's just to create the dummy lists' content