Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm at a loss here, I've been trying various things for a couple hours trying to get some text to center itself vertically in another div when it is only one line. When there are multiple times, it looks great and wraps beautifully.
Here is a photo of what I'm talking about:
photo
How can I fix the first instance (one line only) so it is centered vertically in the box? Here's a bootply.
Thank you!
Wrap the text you want to center in an HTML element and center that element using flexbox:
.list-item {
min-height: 52px;
border: 1px solid #E0E0E0;
display: flex;
align-items: stretch;
margin: 5px 0;
}
.list-item-status-container {
padding-right: 10px;
display: flex;
align-items: stretch;
border-left: 6px solid #90CAF9;
background-color: #E3F2FD;
max-width: 300px;
white-space: nowrap;
}
.list-item-status-content {
padding-left: 10px;
padding-right: 8px;
margin-top: auto;
margin-bottom: auto;
}
.list-item-content {
font-size: 17px;
display: block;
vertical-align: middle;
font-weight: 500;
padding-left: 8px;
padding-right: 8px;
display: flex;
flex-direction: column;
}
.list-item-content p,
.list-item-status-content > div {
margin-top: auto;
margin-bottom: auto;
}
.list-item-content > div {
width: 200px;
}
.item-unchecked-box {
color: #BDBDBD;
padding-right: 8px;
display: inline-block;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" rel="stylesheet" />
<div class="list-item">
<div class="list-item-status-container">
<div class="list-item-status-content">
<div>
<div class="item-unchecked-box">
<i class="fas fa-square fa-lg"></i>
</div>
Warning <i style="padding-left: 4px;" class="fas fa-caret-down status-caret-down"></i>
</div>
</div>
</div>
<div class="list-item-content">
<p>This should be vertically centered if there is room.</p>
</div>
</div>
<div class="list-item">
<div class="list-item-status-container">
<div class="list-item-status-content">
<div>
<div class="item-unchecked-box">
<i class="fas fa-square fa-lg"></i>
</div>
Warning <i style="padding-left: 4px;" class="fas fa-caret-down status-caret-down"></i>
</div>
</div>
</div>
<div class="list-item-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus, esse deleniti odio fugiat culpa excepturi enim omnis laborum distinctio officia odit laudantium aliquid sint, ad expedita alias. Voluptatem, eveniet, odio.</p>
</div>
</div>
You need to add text-center like below
<div class="list-item-content text-center">
This should be vertically centered if there is room
</div>
</div>
I'm assuming that you are using bootstrap?
You need css to set the parent container to display: table; then the container as display:table-cell;
.list-item-content{
height: 350px; width: 250px; background-color:#F1F1F1;
display: table;
}
.list-item-content .cell{
display:table-cell; text-align: center; vertical-align: middle;
}
<div class="list-item-content">
<div class='cell'>
This should be vertically centered if there is room
</div>
</div>
.list-item-content {
display: flex;
align-items: center;
min-height: 52px;
}
<div class="list-item-content">
This should be vertically centered if there is room
</div>
Since you set the min-height of .list-item to be 52px, that means it's also safe to assume .list-item-context min-height is also 52px.
Related
I'm trying to have 2 paragraphs, one below the other with different styling, and an image next to them and aligned with them in flexbox.
I cannot seem to get it to align next to the items. Currently, I have the image flex-end aligned to the right and the text on the left, but I need them to be together.
I have tried moving them in and out of being the same div but I'm just getting nowhere. I'm not sure what I need to do to get the placeholder image next to the hero-container text.
*,
::before,
::after {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
background-color: black;
}
div.Hero-container {
display: flex;
flex-direction: column;
width: 80%;
}
p {
display: flex;
}
p.intro-text {
order: 1;
color: #f9faf8;
font-weight: bold;
font-size: 48px;
align-self: left;
width: 80%;
}
p.secondary-text {
order: 3;
color: #e5e7eb;
font-size: 18px;
}
img {
margin-right: 10px;
width: 350px;
height: 150px;
}
.image-container {
display: flex;
flex-direction: row;
justify-content: right;
height: 72px;
padding: 10px 0;
}
<div class="header">
<header class="Hero">Header Logo</header>
<ol>
<li>Link One</li>
<li>Link Two</li>
<li>Link Three</li>
</ol>
</div>
<div class="Hero-container">
<p class="intro-text">
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...
</p>
<p class="secondary-text">Blah blah Blah</p>
</div>
<div class="image-container">
<img src="https://via.placeholder.com/350x150" alt="Placeholder Image">
</div>
You need another container to wrap around the text to make it easier on yourself. The new .hero-text-container element has a flex width calculated to 100% - 350px because your image is 350px so the calc can take care of the text container size. I also recommend cleaning up some unnecessary flex displays on the children, like the .image-container that only has one child element. Add align-items: center; to .hero-text-container if you want the image to be vertically aligned middle
body {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
background-color: black;
}
.hero-container {
display: flex;
width: 100%;
}
.hero-text-container {
flex: 0 0 calc(100% - 350px);
max-width: calc(100% - 350px);
}
p {
margin: 0;
}
p.intro-text {
color: #F9FAF8;
font-weight: bold;
font-size: 48px;
}
p.secondary-text {
color: #e5e7eb;
font-size: 18px;
}
.image-container {
height: 72px;
padding: 10px 0;
}
img {
width: 350px;
height: 150px;
}
<html>
<body>
<div class="header">
<header class="Hero">Header Logo</header>
<ol>
<li>Link One</li>
<li>Link Two</li>
<li>Link Three</li>
</ol>
</div>
<div class="hero-container">
<div class="hero-text-container">
<p class="intro-text">
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...
</p>
<p class="secondary-text">Blah blah Blah</p>
</div>
<div class="image-container">
<img src="https://via.placeholder.com/350x150" alt="Placeholder Image">
</div>
</div>
</body>
</html>
so I was making a dashboard page for this bot and the page looks good on desktop , but isn't responsive on mobile devices.
THE PAGE ON DESKTOP
THE PAGE ON MOBILE DEVICES
THE CODE FOR PAGE
HTML
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link id="theme" href="/static/css/light.css" aria-labelledby="dark" rel="stylesheet">
<link href="/static/css/main.css" rel="stylesheet">
<title>Steve.</title>
</head>
<body>
<nav class="navbar navbar-expand-lg text-div">
<div class="container">
<ul class="nav navbar-nav navbar-left">
<img id="navbar_dicord_brand" src="/static/images/discord_logo_black.svg" width="120" height="60">
</ul>
<ul class="nav navbar-nav navbar-center">
<li>
<a class="spacing" style="padding-right:.5em" href="#"></span><strong>Commands</strong></a>
<span id="number_badge" class="top-0 start-100 translate-middle badge rounded-pill" style="background-color: crimson;">16<span class="visually-hidden">unread messages</span>
</li>
<li><a class="spacing" href="https://top.gg/bot/834409783502438480/invite/"><strong>Invite</strong></a></li>
<li><a class="spacing" href="https://discord.gg/JEDu42vVBX"><strong>Support Server</strong></a></li>
<li><a class="spacing" href="https://www.patreon.com/ks47"><strong>Patreon</strong></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<a class="navbar-brand a_text" href="https://top.gg/bot/834409783502438480">
<img src="/static/images/avtar.webp" width="45" height="45">
<strong>Steve.</strong>
</a>
</ul>
</div>
</nav>
<div class="body_container">
<div>
<center>
<div class="container text-div" style="width: fit-content;" >
<h1 class="display1 text_font">Anime and Manga in your Discord Server.</h1>
</div>
</center>
<div class="container text-div" style="margin-top:3%">
<div class="row">
<div class="col" style="text-align: left;">
<h1 class="display1"><img id="clyde_icon" src="/static/images/icon_clyde_black_RGB.svg" width="45px" height="45px"> {{count}} Guilds</h1>
</div>
<div class="col" style="text-align: center;">
<h1 class="display1"><img id="hash_icon" src="/static/images/hashtag.svg" width="45px" height="30px">{{channels}} Channels</h1>
</div>
<div class="col" style="text-align: right;">
<h1 class="display1"><img id="user_icon" src="/static/images/user_svg.svg"> {{users}} Users</h1>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container-fluid text-center text-md-left">
<div class="row">
<div class="col-md-6 mt-md-0 mt-3">
<h5 class="text-uppercase font-weight-bold">Footer text 1</h5>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Expedita sapiente sint, nulla, nihil
repudiandae commodi voluptatibus corrupti animi sequi aliquid magnam debitis, maxime quam recusandae
harum esse fugiat. Itaque, culpa?
</p>
</div>
<hr class="clearfix w-100 d-md-none pb-3">
<div class="col-md-6 mb-md-0 mb-3">
<h5 class="text-uppercase font-weight-bold">Footer text 2</h5>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Optio deserunt fuga perferendis modi earum
commodi aperiam temporibus quod nulla nesciunt aliquid debitis ullam omnis quos ipsam, aspernatur id
excepturi hic.
</p>
</div>
</div>
</div>
</footer>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</html>
CSS 1
.spacing{
font-family: 'Whitney','Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif;
text-decoration: none;
font-size: 20px;
}
a.spacing{
padding-left: 1.5em;
padding-right: 1.5em;
}
a.spacing:hover{
color: crimson;
}
.text_font{
font-family: 'Whitney','Helvetica Neue',Helvetica,Arial,'Lucida Grande','sans-serif';
}
.body_container{
margin-top: 10%;
margin-left: 10%;
margin-right: 10%;
font-family: 'Whitney','Helvetica Neue',Helvetica,Arial,'Lucida Grande','sans-serif';
font-size: 2vw;
}
CSS 2
body{
background-color: white;
background-image:url(/static/images/background1.jpg);
background-size: cover;
color: black;
}
.a_text{
color:rgb(0, 0, 0);
font-family: Whitney,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif;
}
a.a_text:hover{
color: crimson;
text-decoration: none;
}
.footer{
background-color:rgba(247, 247, 247, 0.884);
color: black;
margin-top: 10%;
padding-bottom: 2%;
position: fixed;
bottom: 0;
}
.text-div{
background-color: rgba(247, 247, 247, 0.882);
color: black;
}
.spacing{
color: black;
}
So I need to make sure that the divs in nav bar are responsive I TRIED Some #media queries but didn't got the desired results so is there a way that the navbar can be responsive and the center div objects would appear like a list
something like the image below
This is a simple example... But before...
Add <meta name="viewport" content="width=device-width, initial-scale=1.0"> to the head section in your code -> Viewport Meta Tag.
Don't use <center> element to center content:
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
sourse: MDN - Center Element
Use flexbox, grid or positioning property -> Center Anything is CSS.
Some elements in your code (in navbar) doesn't have a closing tag.
The Code:
Open code in full screen and resize the window.
var burger = document.querySelector('.burger');
var list_container = document.querySelector('.list-container');
burger.addEventListener('click', () => {
list_container.classList.toggle('active');
});
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul {list-style-type: none;}
a {text-decoration: none;}
.navbar-container {
width: 100%;
padding: 0 15px;
margin: 0 auto;
position: relative;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
#media (min-width: 576px) {.navbar-container {max-width: 100%;}}
#media (min-width: 768px) {.navbar-container {max-width: 760px;}}
#media (min-width: 992px) {.navbar-container {max-width: 960px;}}
#media (min-width: 1200px) {.navbar-container {max-width: 1180px;}}
header {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #fafafa;
border: 1px solid #eee;
height: 80px;
z-index: 999;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
height: 100%;
}
.logo-container a:link,
.logo-container a:visited {
display: flex;
justify-content: center;
align-items: center;
color: #151515;
}
.logo-container ion-icon {
color: #151515;
margin-right: 5px;
font-size: 40px;
}
.logo-container span {
font-size: 30px;
}
.list-container {
transition: all 0.2s;
}
.list-container.active {
transform: translateX(0);
}
.list-container ul {
display: flex;
}
.list-container ul li {
margin: 0 15px;
}
.list-container ul li a:link,
.list-container ul li a:visited,
.brand-container a:link,
.brand-container a:visited {
color: #151515;
font-weight: 600;
font-size: 20px;
}
.burger {
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 20px;
display: none;
}
.burger span {
display: block;
width: 30px;
height: 4px;
background-color: #121212;
}
.burger span:not(:last-of-type) {
margin-bottom: 5px;
}
#media screen and (max-width:992px){
.list-container ul li a:link,
.list-container ul li a:visited {
font-size: 18px;
}
}
#media screen and (max-width:768px){
body {
overflow-x: hidden;
}
.burger {
display: block;
}
.brand-container {
display: none;
}
.list-container {
position: fixed;
width: 100vw;
height: 100vh;
background-color: #fafafa;
top: 80px;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
transform: translateX(-100%);
}
.list-container ul {
flex-direction: column;
padding: 20px 10px;
}
.list-container ul li {
margin: unset;
}
.list-container ul li {
margin: 0 0 30px 0;
}
}
<script type="module" src="https://unpkg.com/ionicons#5.4.0/dist/ionicons/ionicons.esm.js"></script>
<header>
<nav class="navbar navbar-container">
<div class="logo-container">
<a href="#">
<ion-icon name="logo-discord"></ion-icon>
<span>Discord</span>
</a>
</div>
<div class="list-container">
<ul class="list">
<li>Commands</li>
<li>Invite</li>
<li>Support Server</li>
<li>Patreon</li>
</ul>
</div>
<div class="brand-container">
<a href="#">
<img src="..." alt="...">
<span>Steve</span>
</a>
</div>
<div class="burger">
<span></span>
<span></span>
<span></span>
</div>
</nav>
</header>
Use flexbox with #media queries, it will help you. Change the flex-direction from raw to column on mobile device width. :)
This question already has answers here:
how to add vertical line between two divs
(6 answers)
Closed 3 years ago.
I'm trying to divide the content of a webpage in two parts. The left side for a navbar and the right side for the main content of the page. I'm trying to use hr tag to create a line and divide the two parts but I'm having problems.
This is the HTML code:
<div id="left_content">
<nav class="main-menu">
<ul>
<li class="has-subnav">
<a href="#">
<i class="fa fa-laptop fa-2x"></i>
<span class="nav-text">Stars Components</span>
</a>
</li>
</ul>
</nav>
</div>
<div class="vertical-line" style="height: 500px;"></div>
<div id="right_content>
...
</div>
This is the CSS code:
div.vertical-line{
width: 0px;
height: 100%;
float: left;
border: 1px inset;
background-color: #eeeeee;
margin-left: 250px;
}
This is one screenshot of the problem.
Any suggestion? Thanks for reading.
Here is the minimal layout technique with modern flexbox layout
.split-layout {
display: flex;
flex-direction: column;
}
#media screen and (min-width: 30em) {
.split-layout {
flex-direction: row;
align-items: stretch;
}
}
.split-layout__item {
flex: 1;
}
#media screen and (min-width: 30em) {
.split-layout__item {
padding-left: 1em;
}
.split-layout__item:first-child {
padding: 0;
}
}
.split-layout__divider {
display: flex;
flex-direction: row;
align-items: center;
}
#media screen and (min-width: 30em) {
.split-layout__divider {
flex-direction: column;
}
}
.split-layout__label {
padding: 1em;
}
.split-layout__rule {
flex: 1;
border-style: solid;
border-color: rgba(255, 255, 255, 0.3);
border-width: 1px 0 0 0;
}
#media screen and (min-width: 30em) {
.split-layout__rule {
border-width: 0 1px 0 0;
}
}
/* =DEMO STYLES
--------------------------------------------------------------------*/
html {
padding: 2em;
background: #3B4558;
color: #fff;
}
<div class="wrapper">
<div class="split-layout">
<div class="split-layout__item">
<h2>Navigation</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id eos esse voluptates cupiditate expedita inventore, temporibus? In beatae hic tenetur molestiae facilis illo neque esse repellendus harum. A, consequatur, labore.
</p>
</div>
<div class="split-layout__divider">
<div class="split-layout__rule"></div>
<div class="split-layout__rule"></div>
</div>
<div class="split-layout__item">
<h2>Content</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id eos esse voluptates cupiditate expedita inventore, temporibus?
</p>
</div>
</div>
</div>
Use CSS grid. CSS grid is great for content layout.
body {
font-family: Tahoma, sans-serif;
}
.grid {
display: grid;
grid-template-areas: 'cell-navbar cell-content cell-content cell-content';
}
.cell-navbar {
grid-area: cell-navbar;
border-right: thin solid #ccc;
}
.cell-content {
grid-area: cell-content;
}
body,
main,
.cell-navbar,
.cell-content {
height: 100vh;
}
<main class="grid">
<div class="cell-navbar">Navbar</div>
<div class="cell-content">Content</div>
</main>
More on CSS grid:
enter link description here
Try adding the following line to your CSS style
#left_content, #right_content { float:left; }
my preferred way of doing this,
<style>
#content { height: 100%; }
#left_content, #right_content {
float:left;
}
#left_content {
width:300px;
}
#right_content {
height:inherit;
padding-left:30px;
border-left:2px solid #000;
}
</style>
<body>
<div id="content">
<div id="left_content">
left side content goes here
</div>
<div id="right_content">
right side content goes here
</div>
</div>
</body>
Use flexbox instead, and draw the vertical line as border-right on #left_content:
.container{
display:flex
}
#left_content{
border-right: solid 1px #333;
padding-right:20px;
}
#right_content{
flex: 1 1 100%;
background-color: lightblue;
padding-left:20px;
}
<div class="container">
<div id="left_content">
<nav class="main-menu">
<ul>
<li class="has-subnav">
<a href="#">
<i class="fa fa-laptop fa-2x"></i>
<span class="nav-text">Stars Components</span>
</a>
</li>
</ul>
</nav>
</div>
<div id="right_content">
...
</div>
</div>
I'm trying to build a dynamic dialog control that can be used for any type of content required for that dialog. It contains a primary container, header (for dialog title), body content and footer (for buttons). I've managed to get it working so the height is dynamically adjusting based on the content and view height of the window, but I can't get the width to do the same.
Here's what I've got so far. As you can see the width of the dialog is being forced to use the max-width that is defined as apposed to using that CSS definition only when the content requires it.
.dialog-box2{
position: relative;
min-width: 400px;
max-width: calc(90vw - 100px);
margin: 20px auto;
margin-bottom: 0;
}
.dialog-content{
position: relative;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba (0,0,0,.2);
outline: 0;
box-shadow:0 3px 9px rgba(0,0,0,.2);
margin-top: 100px;
min-height: 185px;
}
.dialog-header{
min-height: 6.43px
padding: 15px;
padding-bottom: 0;
margin-bottom: -1px;
}
.dialog-title{
padding-bottom: 5px;
margin:0;
line-height: 1.43;
border-bottom: 1px solid #0290d7;
}
h3{
font-size: 16px;
}
.dialog-body{
position: relative;
padding: 15px;
max-height: calc(85vh - 250px);
overflow-y: scroll;
margin-bottom: 30px;
}
.dialog-footer{
padding: 15px;
overflow: hidden;
background-color: #eee;
border-top: 1px solid #ccc;
}
/*---------- for testing only ---------------------*/
.profile-btn{
border: 1px solid #CCCCCC;
border-bottom: 15px solid #0290D7;
width: 120px;
height: 140px;
margin: 20px 20px 0 0;
padding-top: 35px;
color: #0290D7;
text-align: center;
float: left;
}
<div class="dialog-box2">
<div class="dialog-content">
<div class="dialog-header">
<h3 class="dialog-title" id="myDialogLabelDefault">Dialog Title</h3>
</div>
<div class="dialog-body">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum nisi est sed incidunt magni maxime? Praesentium itaque sed nihil veritatis. Dolorem autem, alias reprehenderit facilis deserunt voluptatum dolore natus. Impedit.</p>
<div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div><!--
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>
<div class="profile-btn">Thing</div>-->
</div>
</div>
<div class="dialog-footer">
<div class="prev">
<button type="button" class="btn btn-primary-outline">Save as Profile</button>
</div>
<div class="sc-next">
<button type="button" class="btn-link dialog-cancel" data-close="dialog">Cancel</button>
<span class="sc-dialog-bullet"></span>
<button type="button" class="btn btn-primary-outline">Outlined 2nd Btn</button>
<button type="button" class="btn btn-primary">OK</button>
</div>
</div>
</div>
</div>
Here is an example of what I'm getting with the above code and where the issue lies, in case my explanation of what I'm trying to accomplish isn't clear.
What am I doing wrong, I feel like I've tried everything I can think of.
Thanks in advance for your help!
You can try using display: flex; or display:inline-block;
.dialog-box2{
display: flex;
justify-content: center;
min-width: 400px;
max-width: 90%;
margin: 20px auto;
margin-bottom: 0;
}
You'll probably have to properly center the div, but the content should adapt just fine.
Remove the max-width property from the .dialog-box2 div.
Setting any of the width columns prevents the div from stretching but unsetting all the widths allows the element to stretch...
.dialog-box2{
min-width: unset;
width: unset;
max-width: unset;
}
The flex attribute is needed for the page layout with respect to other elements on the page but doesn't play into the solution to the question, so I've omitted it.
I'm trying to vertically align content inside column relatively to it's inline column, which is higher.
It's pretty hard for me to explain in words, so:
Here's the HTML structure.
<div class="row">
<div class="col-sm-7">
<div class="i-need-to-be-in-the-middle">
<!--some content-->
</div>
</div>
<div class="col-sm-5">
<div class="btns">
<button>
first btn
</button>
<button>
second btn
</button>
<button>
third btn
</button>
</div><!--btns-->
</div>
</div><!--.row-->
Here's how it looks like:
Here's the desire result:
I've tried a lot of solutions, but the only solutions which work for me made a mess with boostrap because they involved absolute or flexing elements.
I've also notice that the height of the first col is relative to the content length, which is less then the height of the button.
What is required is to make the columns the same height and then align the content in the center of each column
Flexbox Method
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
.row {
display: flex;
}
.column {
display: flex;
flex-direction: column;
border: 1px solid grey;
justify-content: center;
}
button {
margin: 1em;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-sm-7 column">
<div class="i-need-to-be-in-the-middle">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate molestias soluta deserunt eligendi eius totam nisi fuga, esse sit voluptas praesentium, tempore laudantium placeat aperiam?
</div>
</div>
<div class="col-sm-5 column">
<div class="btns column">
<button>
first btn
</button>
<button>
second btn
</button>
<button>
third btn
</button>
</div>
<!--btns-->
</div>
</div>
<!--.row-->
</div>
Codepen Demo
CSS Tables Method
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
.table {
display: table;
}
.column {
float: none;
/* remove bootstrap default */
display: table-cell;
vertical-align: middle;
border: 1px solid grey;
justify-content: center;
}
button {
display: block;
margin: .5em auto;
width: 95%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row table">
<div class="col-sm-7 column">
<div class="i-need-to-be-in-the-middle">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate molestias soluta deserunt eligendi eius totam nisi fuga, esse sit voluptas praesentium, tempore laudantium placeat aperiam?
</div>
</div>
<div class="col-sm-5 column">
<div class="btns">
<button>
first btn
</button>
<button>
second btn
</button>
<button>
third btn
</button>
</div>
<!--btns-->
</div>
</div>
<!--.row-->
</div>
Codepen Demo
Try this:
<div class="center-vertically">
<p>
I'm vertically aligned.
</p>
</div>
The CSS:
.center-vertically{
vertical-align: middle;
}
Looks like your having some grid troubles, try something like this:
HTML:
<body>
<div class="row header">
<div class="column column-2">Logo</div>
<div class="column column-4">-</div>
<div class="column column-6">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>FAQ</li>
</ul>
</div>
</div>
<div class="row middle">
<div class="column column-2">Left-</div>
<div class="column column-8">So much content.</div>
<div class="column column-2">Right-</div>
</div>
<div class="row footer">
<div class="column column-12">(c) 2016</div>
</div>
</body>
CSS:
.row {
border: 2px solid rebeccapurple;
}
.column {
border: 2px solid blue;
margin: 1%;
float: left;
border-radius: 20px;
text-align: center;
}
.row:before,
.row:after {
content: "";
display: table;
}
.row:after {
clear: both;
}
.row,
.column {
box-sizing: border-box;
}
.column-1 {
width: 6.333%;
}
.column-2 {
width: 14.66%;
}
.column-3 {
width: 23%;
}
.column-4 {
width: 31.33%;
}
.column-5 {
width: 39.66%;
}
.column-6 {
width: 48%;
}
.column-7 {
width: 56.33%;
}
.column-8 {
width: 64.66%;
}
.column-9 {
width: 73%;
}
.column-10 {
width: 81.33%;
}
.column-11 {
width: 89.66%;
}
.column-12 {
width: 98%;
}
.header > .column,
.footer > .column {
padding: 25px;
}
.middle > .column {
height: 400px;
line-height: 400px;
}
.header ul {
margin: auto;
}
.header li {
display: inline-block;
list-style-type: none;
}
All you will have to do is edit the size in CSS for each grid element and you should be good!