I have the following link with a padding. On mobile screen, it has a line break. Would it be possible to add a padding on the end of the first and the start of the second line as well?
div {
max-width: 30rem;
margin: 5rem auto;
}
a {
padding: 10px 20px;
background: red;
line-height: 200%;
}
<div>
Read More: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
</div>
Use box-decoration-break:
div {
max-width: 30rem;
margin: 5rem auto;
}
a {
padding: 10px 20px;
background: red;
line-height: 200%;
-webkit-box-decoration-break: clone;
box-decoration-break: clone;
}
<div>
Read More: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
</div>
I have a menu div inside another div, and I want to move it slightly up so it's level with the rest of its section, but it will not move. I've tried padding-bottom and margin-bottom. I'm not sure what is wrong.
I am very new to HTML and CSS so please bare with me if its something very obvious I'm not seeing...
Here is the code. If you preview it, you'll notice that the menu is slightly lower than it should be.
Hope someone can help.
Thanks a lot.
html,
body {
background-image: url(img/roshi2.jpg);
background-size: cover;
font-family: "Bitstream Charter";
font-size: small;
}
#title {
font-size: 4em;
color: white;
padding: 100px 0px 0px 100px;
}
.content {
background-color: rgba(255, 255, 255, 0.67);
width: 100%;
height: 500px;
margin-top: 150px;
}
.section {
padding: 30px 30px 0px 60px;
color: rgba(0, 0, 0, 0.57);
}
.section h1 {
font-size: 4em;
border-bottom: dashed 1px black;
}
.section p {
font-size: 2em;
width: 1500px;
}
#menu {
text-align: right;
padding: 12px 150px 200px 0px;
line-height: 2em;
font-size: 2em;
color: rgba(0, 0, 0, 0.57);
}
a {
text-decoration: none;
}
a:link {
color: rgba(0, 0, 0, 0.57);
}
a:visited {
color: rgba(255, 0, 0, 0.5);
}
a:hover {
color: rgba(255, 0, 0, 0.5);
}
<body>
<header>
<div id="title">Shunryu Suzuki Roshi</div>
</header>
<div class="content">
<div class="section">
<h1>Section 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut. adipisicing elit, sed do eiusmod tempor incididunt ut adipisicing elit, sed do eiusmod tempor incididunt adipisicing elit, sed do eiusmod tempor incididunt
ut
</p>
</div>
<div id="menu">
About<br>
Contact<br>
Donate<br>
</div>
</div>
<div class="content">
<div class="section">
<h1>Section 2</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut. adipisicing elit, sed do eiusmod tempor incididunt ut adipisicing elit, sed do eiusmod tempor incididunt adipisicing elit, sed do eiusmod tempor incididunt
ut
</p>
</div>
</div>
</body>
Make .content use the flexbox layout mode, then remove the width from your p element
.content {
display: flex;
}
.section p {
font-size: 2em;
/*width: 1500px;*/
}
It's always better to put the menu div in another div that controls its position
Like this:
<div id = "menu-area">
<div id="menu">
About<br>
Contact<br>
Donate<br>
</div>
</div>
And then you can control the div's position easier:
#menu-area{
float:right;
margin-right:20px;
border:1px solid black;
}
#menu
{
text-align: right;
line-height: 2em;
font-size: 2em;
color: rgba(0, 0, 0, 0.57);
}
I'm not sure what you are trying to do here.
The problem is that you are not using display
There are already a few answers here about how you can use the display property
flex is probably the best value for your case
You want your menu to be aligned with your first section? I would just add a flexbox. See below:
.content {
background-color: rgba(255, 255, 255, 0.67);
width: 100%;
height: 500px;
margin-top: 150px;
display:flex;
}
Or if you just want to move your menu up. You can use negative margin for your menu. See below:
html, body {
background-image: url(img/roshi2.jpg);
background-size: cover;
font-family: "Bitstream Charter";
font-size: small;
}
#title
{ font-size: 4em;
color: white;
padding: 100px 0px 0px 100px;
}
.content {
background-color: rgba(255, 255, 255, 0.67);
width: 100%;
height: 500px;
margin-top: 150px;
}
.section {
padding: 30px 30px 0px 60px;
color: rgba(0, 0, 0, 0.57);
}
.section h1 {
font-size: 4em;
border-bottom: dashed 1px black;
}
.section p {
font-size: 2em;
width: 1500px;
}
#menu
{
text-align: right;
padding: 12px 150px 200px 0px;
line-height: 2em;
font-size: 2em;
color: rgba(0, 0, 0, 0.57);
margin-top:-40px
}
a{
text-decoration: none;
}
a:link {
color: rgba(0, 0, 0, 0.57);
}
a:visited {
color: rgba(255, 0, 0, 0.5);
}
a:hover {
color: rgba(255, 0, 0, 0.5);
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Shunryu Suzuki Roshi</title>
</head><link rel="stylesheet" type="text/css" href="index.css">
<body>
<header>
<div id="title">Shunryu Suzuki Roshi</div>
</header>
<div class="content">
<div class="section">
<h1>Section 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
adipisicing elit, sed do eiusmod tempor incididunt ut
adipisicing elit, sed do eiusmod tempor incididunt adipisicing elit, sed do eiusmod tempor incididunt ut
</p>
</div>
<div id="menu">
About<br>
Contact<br>
Donate<br>
</div>
</div>
<div class="content">
<div class="section">
<h1>Section 2</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
adipisicing elit, sed do eiusmod tempor incididunt ut
adipisicing elit, sed do eiusmod tempor incididunt adipisicing elit, sed do eiusmod tempor incididunt ut
</p>
</div>
</div>
</body>
</html>
Html blocks are automatically aligned vertically so you need to style the html blocks to make them align horizontally , i used a css attribute called flex , you can learn about it through this website : https://css-tricks.com/snippets/css/a-guide-to-flexbox/ check it out it's very helpful , compare my code to yours to understand more
html, body {
background-image: url(img/roshi2.jpg);
background-size: cover;
font-family: "Bitstream Charter";
font-size: small;
}
#title
{ font-size: 4em;
color: white;
padding: 100px 0px 0px 100px;
}
.content {
background-color: rgba(255, 255, 255, 0.67);
width: 100%;
height: 500px;
margin-top: 150px;
}
.section {
padding: 30px 30px 0px 60px;
color: rgba(0, 0, 0, 0.57);
}
.section-content {
display: flex;
}
.section h1 {
font-size: 4em;
border-bottom: dashed 1px black;
}
.section p {
font-size: 2em;
width: 1500px;
}
#menu
{
text-align: right;
padding: 12px 150px 200px 0px;
line-height: 2em;
font-size: 2em;
color: rgba(0, 0, 0, 0.57);
}
a{
text-decoration: none;
}
a:link {
color: rgba(0, 0, 0, 0.57);
}
a:visited {
color: rgba(255, 0, 0, 0.5);
}
a:hover {
color: rgba(255, 0, 0, 0.5);
}
<header>
<div id="title">Shunryu Suzuki Roshi</div>
</header>
<div class="content">
<div class="section">
<h1>Section 1</h1>
<div class="section-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
adipisicing elit, sed do eiusmod tempor incididunt ut
adipisicing elit, sed do eiusmod tempor incididunt adipisicing elit, sed do eiusmod tempor incididunt ut
</p>
<div id="menu">
About<br>
Contact<br>
Donate<br>
</div>
</div>
</div>
</div>
<div class="content">
<div class="section">
<h1>Section 2</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.
adipisicing elit, sed do eiusmod tempor incididunt ut
adipisicing elit, sed do eiusmod tempor incididunt adipisicing elit, sed do eiusmod tempor incididunt ut
</p>
</div>
</div>
I have a group of items which display an icon (image) with title + text below.
This mostly works fine. However on some pages there isn't a paragraph of text for each item, just a title. So when the icon is displayed horizontally alongside only a title it looks odd when the title is aligned to the top.
My question is, is it possible to center the icon alongside the text, until the content is tall enough to hit the top of the icon/container?
Example with title + text (1): https://codepen.io/moy/pen/YOZyeG
Example with only a title (2): https://codepen.io/moy/pen/RYpWBp
As you can see in example (1) on mobile the icons work well responsively as the text fills up the same.
On the second example (2), the title is positioned at the top of the icon which looks a bit crap!
I have tried vertically centring the title alongside the icon but then when text is added it looks odd. So is it possible to centre the icons until the title/text takes up enough vertical space to hit the top of the container, then it would just be top aligned?
Or am I going to need to have 2 different classes like .features and then .features--centred or .features--no-text for items with not as much content?
Thanks in advance, tying myself in knots here!
/**
* Base `html` styling.
*/
html {
background: white;
font-size: 62.5%;
}
/**
* Base `body` styling.
*/
body {
background-color: white;
color: grey;
font-family: "Roboto", sans-serif;
font-size: 13px;
font-size: 1.3rem;
font-weight: 400;
line-height: 1.8;
margin: 0;
padding: 30px 0 0;
text-rendering: optimizeLegibility;
}
#media (min-width: 64em) {
body {
font-size: 14px;
font-size: 1.4rem;
}
}
/* ==========================================================================
#FEATURES
========================================================================== */
/**
* Features/service panel. Each item has an icon, title and short text entry.
*
* 1. The number of items can change from 5 - 6, so I've set flex-direction to
* 'row' on desktop (when the items are in a row) so the items will always be
* spaced evenly.
* 2. Need to overwrite `align-items` so the icons are vertically aligned to the
* top of the container.
*/
.features {
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
padding: 0;
}
.features:before,
.features:after {
content: "";
display: table;
}
.features:after {
clear: both;
}
#media (min-width: 48em) {
.features {
display: block;
margin-left: -30px;
}
}
#media (min-width: 64em) {
.features {
margin-left: 0;
display: flex;
flex-direction: row;
align-items: flex-start;
}
}
/**
* The wrapper for each featured item that contains an icon, title and short
* sentence.
*
* 1. I've removed the width, which was always 20% as there were always 5 items
* but now that can change and we've added `flex-direction: row;` to the
* parent div we shouldn't need it.
* 2. Make items have equal widths. If not applied they'll be uneven.
*
*/
.features__item {
background: none;
box-sizing: border-box;
margin: 0;
padding: 0 0 0 65px;
width: 100%;
max-width: 500px;
}
.features__item:before,
.features__item:after {
content: "";
display: table;
}
.features__item:after {
clear: both;
}
#media (min-width: 48em) {
.features__item {
float: left;
padding: 0 0 0 95px;
width: 50%;
max-width: none;
}
.features__item:nth-child(odd) {
clear: left;
}
}
#media (min-width: 64em) {
.features__item {
flex-grow: 1;
flex-basis: 0;
text-align: center;
padding: 0 15px;
width: auto;
}
.features__item:nth-child(odd) {
clear: none;
}
}
.features__icon-wrap {
background-color: teal;
border-radius: 100%;
display: inline-block;
height: 50px;
line-height: 50px;
margin: 0 0 30px -65px;
float: left;
text-align: center;
width: 50px;
}
.features__icon-wrap .icon {
fill: white;
height: 25px;
width: 25px;
}
#media (min-width: 64em) {
.features__icon-wrap {
float: none;
margin-left: 0;
height: 100px;
line-height: 100px;
width: 100px;
}
.features__icon-wrap .icon {
height: 50px;
width: 50px;
}
}
.features__title {
color: black;
font-size: 14px;
font-size: 1.4rem;
font-weight: 900;
margin-bottom: 7.5px;
}
#media (min-width: 64em) {
.features__title {
font-size: 16px;
font-size: 1.6rem;
}
}
.features__text {
font-size: 13px;
font-size: 1.3rem;
line-height: 1.4;
}
<link href="https://fonts.googleapis.com/css?family=Montserrat:700,900|Roboto:400,400i,700,700i" rel="stylesheet">
<ul class="features">
<li class="features__item">
<div class="features__icon-wrap">
<svg class="icon icon--24-hour"><use xlink:href="img/sprite/sprite.svg#icon-24hour"></use></svg>
</div>
<h3 class="features__title">Lorem ipsum dolor</h3>
<p class="features__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
</li>
<li class="features__item">
<div class="features__icon-wrap">
<svg class="icon icon--room"><use xlink:href="img/sprite/sprite.svg#icon-room"></use></svg>
</div>
<h3 class="features__title">Lorem ipsum dolor</h3>
<p class="features__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</li>
<li class="features__item">
<div class="features__icon-wrap">
<svg class="icon icon--rosette"><use xlink:href="img/sprite/sprite.svg#icon-rosette"></use></svg>
</div>
<h3 class="features__title">Lorem ipsum dolor</h3>
<p class="features__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.</p>
</li>
<li class="features__item">
<div class="features__icon-wrap">
<svg class="icon icon--taxi"><use xlink:href="img/sprite/sprite.svg#icon-taxi"></use></svg>
</div>
<h3 class="features__title">Lorem ipsum dolor</h3>
<p class="features__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.</p>
</li>
<li class="features__item">
<div class="features__icon-wrap">
<svg class="icon icon--ticket"><use xlink:href="img/sprite/sprite.svg#icon-ticket"></use></svg>
</div>
<h3 class="features__title">Lorem ipsum dolor</h3>
<p class="features__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Lorem ipsum dolor sit amet.</p>
</li>
</ul>
You can do this with flexbox. You make the text always centered and the icon flex-start. When the text is taller the center will be equivalent to flex-start.
Here is a simplified example:
.box {
max-width: 320px;
display: flex;
align-items: flex-start;
border: 1px solid;
}
.icon {
width: 80px;
height: 80px;
background: teal;
margin-right:10px;
border-radius: 50%;
flex-shrink: 0;
}
.text {
align-self: center;
border: 1px solid;
}
h3,p {
margin: 5px 0;
}
<div class="box">
<div class="icon"></div>
<div class="text">
<h3>a title</h3>
<p>orem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel orci orci. Suspendisse ultrices velit sit amet venenatis venenatis. Pellentesque non leo nec ipsum pulvinar aliquet ut ac lorem</p>
</div>
</div>
<div class="box">
<div class="icon"></div>
<div class="text">
<h3>a title</h3>
</div>
</div>
<div class="box">
<div class="icon"></div>
<div class="text">
<h3>a title</h3>
<p>orem ipsum dolor sit amet, </p>
</div>
</div>
Here's the challenge. I have a left-aligned text container (width: 40%;) that changes height with the window. I need my right half of the screen set as an image container (width: 60%) to which the image centers horizontally in the container, and vertically with the center of the text container.
Here is what my current code is doing:
Here is what I would like it to do:
I'm barely savvy in JS, so I'm trying to avoid it pending the need for tweaks. Here is my current code for the section:
.design-portfolio {
position: relative;
.web-img-container {
position: relative;
width: 60%;
margin-left: auto;
.web-img-lg {
img {
max-height: 40em;
}
}
}
.web-img-sm {
#media (min-width:75.063em) {
position: absolute;
visibility: hidden;
}
}
.web-design-box {
#media (min-width:75.063em) {
$font-title: 25px NexaBook;
$font-sub-title: 25px NexaHeavy;
$font-copy-title: 20px NexaHeavy;
$font-copy: 20px NexaBook;
position: relative;
width: 40%;
padding-right: 2em;
.size-fix {
position: relative;
}
.bg-box {
position: absolute;
background-color: $pink;
top: 2em;
bottom: 2em;
left: 0;
right: -2em;
}
.border-box {
position: relative;
border: .3em solid $black;
padding-left: 2em;
padding-right: 2em;
padding-bottom: 2em;
padding-top: 3em;
width: 60%;
margin-left: auto;
.h1 {
font: $font-title;
color: $white;
text-align: right;
}
.h2 {
font: $font-sub-title;
text-align: right;
}
.copy {
font: $font-copy;
color: $white;
text-align: left;
width: 100%;
height: 100%;
.h3 {
font: $font-copy-title;
color: $white;
text-align: left;
}
}
.copy p {
line-height: 1.2;
}
}
}
}
}
<section>
<div class="web-img-container">
<div class="web-img-lg">
<img src="assets/img/website-design.png" alt="web-design">
</div>
</div>
<div class="web-design-box">
<div class="size-fix">
<div class="bg-box"></div>
<div class="border-box">
<div class="h1">
my approach on
</div>
<div class="h2">
website design
</div>
<br>
<div class="copy">
<div class="h3">purpose</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<div class="h3">simplicity</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<div class="h3">mobile first</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
</div>
</div>
</div>
</section>
I don't know how to set it up to run, as it's in SASS rather than regular CSS. :/
I am trying to achieve this plus sign in rectangle in red
I tried it using css
<p align="left">
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt
<span style="color:red; margin-left:47px; border: 1px solid red;">
+
</span>
</p>
Its showing like below:
I am not able to understand why there is space at top and bottom of the plus sign.
How can I get that plus sign in proper rectangle?
Try like this: Demo
CSS:
p:after{
content:"+";
margin:0 0 0 47px !important;
color:red;
border: 1px solid red;
height:8px;
width:8px;
line-height:8px;
display: inline-block;
font-size:12px;
vertical-align:middle;
}
HTML:
<p align="left">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt</p>
Try this
span.plus {
display: inline-block;
border: 1px solid red;
font-size: 9px;
height: 9px;
width: 9px;
vertical-align: middle;
text-align: center;
color: red;
}
<span class="plus">+
</span>
Try this:
HTML:
<span class="plus">+</span>
CSS:
.plus
{
display:inline-block;
width:auto;
height:auto;
line-height:10px;
padding:1px;
border:1px solid red;
color:red;
}
This can be done without (a lot of) CSS, by simply using a ⊞ character:
<p align="left">
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt
<span style="color: red; margin-left: 47px;" >⊞</span>
</p>
Try like this:
HTML:
<p> some content</p>
CSS:
p:after{
content:"+";
margin:0 0 0 47px !important;
color:red;
border: 1px solid red;
height:8px;
width:8px;
line-height:8px;
display: inline-block;
font-size:12px;
vertical-align:middle;
}
Actually in HTML Document each line has particular line height, same is the case here the extra height you see here is actually the minimum line height.
You need to add a line-height to the span therefore overidding the line height in your p
For Example:
line-height:10px;
Check DEMO