So I am styling this horizonal line with the idea of image and text in the middle and got stuck. How could I align the image on the left side of "TEXT" and not under it? Here's the link to demonstrate the current state:
http://codepen.io/anon/pen/MJWJad
Appreciate all the help.
.horizontal__rule--modified {
line-height: 1em;
position: relative;
border: 0;
color: #666666;
text-align: center;
height: 1.5em;
opacity: 0.7;
letter-spacing: 1px;
font-size: 16px;
&:before {
content: url(http://www.metalguitarist.org/forum/images/mgtwitter.png);
background: red;
position: absolute;
left: 0;
top: 50%;
width: 100%;
height: 2px;
}
&:after {
content: attr(data-content);
position: relative;
display: inline-block;
color: black;
padding: 0 .5em;
line-height: 1.5em;
color: red;
background-color: #fcfcfa;
}
}
<hr class="horizontal__rule--modified" data-content="TEXT">
Actually you don't need a <hr /> at all here. You can just use pseudo elements and make it possible:
* {
font-family: 'Segoe UI';
font-weight: normal;
}
h1 {
text-align: center;
}
h1 span {
background-color: #fff;
padding: 15px;
}
h1::after {
display: block;
content: "";
border: 1px solid #ccc;
margin-top: -0.5em;
}
<h1><span>Hello</span></h1>
If an image is needed for this like having a twitter icon, you can use: Source:
* {
font-family: 'Segoe UI';
font-weight: normal;
vertical-align: middle;
}
h1 {
text-align: center;
font-size: 14pt;
}
h1 span {
background-color: #fff;
padding: 15px;
}
h1::after {
display: block;
content: "";
border: 1px solid #ccc;
margin-top: -0.5em;
}
<h1>
<span>
<img src="http://www.metalguitarist.org/forum/images/mgtwitter.png" alt="" />
Hello
</span>
</h1>
Preview
Another solution apart from Praveen's is to use flex-box.
HTML
<div class="wrapper">
<div class="line"></div>
<div class="text">
Test
</div>
<div class="line"></div>
</div>
CSS
.wrapper {
display: flex;
justify-content: space-between;
align-items: center;
}
.line {
height: 10px;
background: black;
width: 100%;
}
.text {
padding: 0 10px;
}
fiddle: https://jsfiddle.net/jdgqmmv5/
Related
I'm trying to overlap the text over the div below it. The problem is that I need it all in the bottom right of the page so it already has position: absolute.
This is what I currently have.
And this is what I'm trying to make it look like:
https://jsfiddle.net/7ow5p192/
body {
background-color: black;
}
.title {
color: white;
text-align: left;
}
.artist {
color: black;
font-size: 60px;
line-height: 60px;
}
.artist-container {
text-align: left;
width: 100%;
background-color: white;
display: block;
}
.nameContain {
font-weight: bold;
position: absolute;
display: block;
right: 0;
bottom: 0;
max-width: 50%;
font-size: 50px;
}
.nameContain2 {
position: relative;
}
<div class="nameContain">
<span class="title">Smells Like Teen Spirit</span>
<div class="artist-container"><span class="artist">Nirvana</span></div>
</div>
A simple text-align: right should do the trick.
body {
background-color: black;
}
.title {
color: white;
}
.artist {
color: black;
font-size: 60px;
line-height: 60px;
}
.artist-container {
width: 100%;
background-color: white;
display: block;
}
.nameContain {
font-weight: bold;
position: absolute;
display: block;
right: 0;
bottom: 0;
max-width: 50%;
font-size: 50px;
text-align: right;
}
<div class="nameContain">
<span class="title">Smells Like Teen Spirit</span>
<div class="artist-container"><span class="artist">Nirvana</span></div>
</div>
I want this line to be placed in the middle under the title, but it doesn't work when I try text-align.
body {
background-color: #000;
color: #FFF;
font-family: 'Noto Sans KR', sans-serif;
}
.title{
position: relative;
top: 70px;
line-height: 15px;
letter-spacing: 1em;
font-size: 30px;
display: block;
text-align: center;
}
.title::after {
display: block;
width: 300px;
height: 20px;
border-bottom: 3px solid #FFF;
content: "";
color: #FFF;
text-align: center;
}
enter image description here
I'm sorry in advance because it's not the time for me to click on the recommendation yet. Thank you for all your answers.
Will this do?
body {
background-color: #000;
}
section {
position:relative;
}
.title{
color: #fff;
line-height: 15px;
letter-spacing: 1em;
font-size: 30px;
display: block;
text-align: center;
border-bottom-width: 50%;
}
.title::after {
position:absolute;
display: block;
width: 300px;
height: 20px;
border-bottom: 3px solid #FFF;
content: "";
color: #FFF;
text-align: center;
left: 25%;
}
<body>
<section>
<div class="title">What I Play</title>
</section>
</body>
text-align: center aligns the inline content of that element, not the element itself.
you probably want to use margin: 0 auto; for .title::after.
I found a solution to your issue. you have to change small changes in your CSS and also you have to add some css in .title-box class.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
body {
background-color: #000;
color: #FFF;
font-family: 'Noto Sans KR', sans-serif;
}
.title-box{
text-align:center;
}
.title{
line-height: 15px;
letter-spacing: 1em;
font-size: 30px;
display: block;
text-align: center;
display: inline-flex;
flex-direction: column;
}
.title::after {
display: flex;
width: 300px;
height: 20px;
border-bottom: 3px solid #FFF;
content: "";
color: #FFF;
text-align: center;
margin-left: 10%;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12 title-box">
<h1 class="title">What I Play</h1>
</div>
</div>
</div>
</body>
</html>
I have a site and it has 2 sections. the left section is a navigation bar with menus below.
The section next to it is the main section or where the website content must be placed. My problem is the right section is positioned a few pixels from the header. How can i fix this? I provided some image to let you see how the website should look like.
/*WRITTEN USING SASS*/
#side-menu{
margin-top: 25px;
.side-menu-bg {
width: max-content;
h3 {
position: absolute;
color: white;
padding: 0px 18px;
font-size: 27px;
}
img {
display: -webkit-box;
}
}
.side-nav-bar {
width: 210px;
position: unset;
margin-top: -3px;
display: inline-flex;
z-index: 1;
flex-direction: column;
overflow-x: hidden;
background-color: #ffffff;
a {
display: inherit;
color: #707070;
text-decoration: none;
font-size: 15px;
padding: 10px 18px;
position: relative;
border-bottom: 1px solid #e8e8e8;
}
.active-link{
color: #a40022;
border-bottom: 2px solid #8a001c;
}
}
.right-contents {
float: right;
.title h3 {
font-size: 38px;
}
.body-content {
background-color: #d3d3d3;
height: 1094px;
width: 738px;
}
}
}
<div class="wrapper"> <!--to make contents center-->
<div id="side-menu">
<div class="side-menu-bg">
<h3>KU 스타트업</h3>
<img src="images/bg/bg_03.png">
</div>
<div class="side-nav-bar">
인사말
창업 비전
창업 프로세스
창업부서소개
찾아오시는 길
</div>
<div class="right-contents">
<div class="title">
<h3>인사말</h3>
<div class="body-content">
sample text
</div>
</div>
</div>
</div>
</div>
Add margin: 0 to your h3 tag.. h3 has margin-to and margin-bottom by default. thanks
.right-contents {
float: right;
.title h3 {
font-size: 38px;
margin: 0; /*add this*/
}
.body-content {
background-color: #d3d3d3;
height: 1094px;
width: 738px;
}
<style>
/*WRITTEN USING SASS*/
#side-menu{
margin-top: 25px;
.side-menu-bg {
width: max-content;
h3 {
position: absolute;
color: white;
padding: 0px 18px;
font-size: 27px;
}
img {
display: -webkit-box;
}
}
.side-nav-bar {
width: 210px;
position: unset;
margin-top: -3px;
display: inline-flex;
z-index: 1;
flex-direction: column;
overflow-x: hidden;
background-color: #ffffff;
}
a {
display: inherit;
color: #707070;
text-decoration: none;
font-size: 15px;
padding: 10px 18px;
position: relative;
border-bottom: 1px solid #e8e8e8;
}
.active-link{
color: #a40022;
border-bottom: 2px solid #8a001c;
}
}
.right-contents {
width: 65%;
margin-top: -3px;
display: inline-flex;
.title h3 {
font-size: 38px;
}
.body-content {
background-color: #d3d3d3;
height: 1094px;
width: 738px;
}
</style>
I want to left align text in a drop-down menu but I'm having some problems. I have this HTML
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
and this CSS for the drop down menu
nav {
display: none;
width: 30rem;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
But as you can see, when you click the menu icon the text isn't even visible. Interestingly, when I change:
text-align: left;
to
text-align: center;
I can see the text again, but it is not aligned where i want it. How do I left align my text and keep it visible?
$('.menu-btn').click(function() {
$('nav').toggleClass('nav-open');
});
style* {
margin: 0 auto;
font-family: sans-serif;
}
body {
margin: 0 auto;
font-family: Benton Sans, -apple-system, BlinkMacSystemFont, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
}
header {
width: 100%;
background-color: orange;
text-align: center;
position: relative;
}
#pageTitle {
display: flex;
padding: 10px;
}
#pageTitle h2 {
justify-content: center;
/* align horizontal */
align-items: center;
width: 95%;
}
.menu-btn {
position: absolute;
display: inline-block;
cursor: pointer;
}
.menu-btn div {
position: absolute;
left: 100%;
top: 0%;
padding-right: 8px;
margin-top: -0.50em;
line-height: 1.2;
font-weight: 200;
vertical-align: middle;
z-index: 99;
}
.menu-btn span {
display: block;
width: 20px;
height: 2px;
margin: 4px 0;
background: #989da1;
z-index: 99;
}
nav {
display: none;
width: 30rem;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
nav a:hover {
background-color: #111;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div id="pageTitle">
<h2>Page Title</h2>
<div class="mobile-nav">
<button class="menu-btn" id="menu-btn">
<div></div>
<span></span>
<span></span>
<span></span>
</button>
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
</div>
</div>
</header>
The problem comes from the rem unit you are using when giving width to your nav. You should use vw viewport width. This is relative from the screen width going from 0 to 100 turning the viewport width into a percentage.
Hope this helps
$('.menu-btn').click(function() {
$('nav').toggleClass('nav-open');
});
style* {
margin: 0 auto;
font-family: sans-serif;
}
body {
margin: 0 auto;
font-family: Benton Sans, -apple-system, BlinkMacSystemFont, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
}
header {
width: 100%;
background-color: orange;
text-align: center;
position: relative;
}
#pageTitle {
display: flex;
padding: 10px;
}
#pageTitle h2 {
justify-content: center;
/* align horizontal */
align-items: center;
width: 95%;
}
.menu-btn {
position: absolute;
display: inline-block;
cursor: pointer;
}
.menu-btn div {
position: absolute;
left: 100%;
top: 0%;
padding-right: 8px;
margin-top: -0.50em;
line-height: 1.2;
font-weight: 200;
vertical-align: middle;
z-index: 99;
}
.menu-btn span {
display: block;
width: 20px;
height: 2px;
margin: 4px 0;
background: #989da1;
z-index: 99;
}
nav {
display: none;
width: 100vw;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
.nav-open {
display: block;
}
nav a {
display: block;
width: 100%;
text-align: left;
padding: 1.4rem 1.6rem;
text-decoration: none;
cursor: pointer;
font-size: 1.2rem;
color: #000;
}
nav a:hover {
background-color: #111;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div id="pageTitle">
<h2>Page Title</h2>
<div class="mobile-nav">
<button class="menu-btn" id="menu-btn">
<div></div>
<span></span>
<span></span>
<span></span>
</button>
<nav>
<a>Vote</a>
<a>Search</a>
<a>About</a>
</nav>
</div>
</div>
</header>
As others have pointed out already, the text is actually aligned left, but your screen size might prevent it from showing up due to the big width of your menu.
Try changing the width of your nav element to something relative to the page width, like 80%:
nav {
display: none;
width: 80%;
padding: 0rem;
background-color: red;
position: absolute;
right: 0%;
top: 100%;
text-align: left;
}
https://jsfiddle.net/1y8n08aq/1/
I received help centering an image within a box using a "helper" pseudo element element, which was working until I published it live. I'm not sure what's going on.
you can see whats going on at live link. And this is the code I was using for the layout
Code:
.offer {
width: 288px;
float: left;
margin-right: 25px;
}
.box {
position: relative;
display: block;
border: solid 3px #19468d;
height: 310px;
width: 100%;
margin-top: 11px;
text-align: center;
}
.price span {
font-family: avenir next;
font-weight: 700;
background-color: #19468d;
color: white;
font-size: 21px;
padding: 0px 5px;
left: 0;
padding-left: 0;
}
.price a {
position: relative;
font-family: avenir next;
font-weight: 700;
background-color: #19468d;
color: white;
font-size: 21px;
padding: 1px 7px;
left: 3px;
bottom: 1px;
border-style: solid;
border-color: #19468d;
}
.price a:hover {
color: #19468d;
background-color: white;
border-style: solid;
}
#cost {
position: absolute;
left: 0px
}
#info {
position: absolute;
bottom: 0px;
right: 0px
}
.box img {
display: inline-block;
margin: 0 auto;
text-align: center;
max-width: 252px;
vertical-align: center;
}
#grid {
margin: 0px;
display: flex;
display: -webkit-flex;
/* Safari 8 */
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
/* Safari 8 */
-webkit-justify-content: center;
/* Safari 8 */
margin-left: 20px;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.price {
text-align: left
}
.price #dollar {
padding-right: 0px;
padding-left: 5px;
}
<div class="offer">
<div class="box">
<div class="price">
<span id="dollar">$</span><span>27</span>
</div>
<span class="helper"></span>
<img src="http://cdn2.hubspot.net/hubfs/75704/JPs-Slices/2016_Yes/img/floorexammat.jpg">
<div class="price" id="info">
Buy Now
</div>
</div>
Rather use flex for the images. On the ".box" you can do
display:flex;
justify-content: center;
and remove the helper.