Lay <HR> on top of a box in CSS - html

I have a specific box style that I'm trying to accomplish and it's got me stumped. Here is a reference image:
box with border and additional line styling
A few items, first and foremost, I'm beginning to learn responsive design and I've been able to accomplish this but as soon as I start to resize it breaks. I would like it the box and hr to work all as one item.
What I've tried:
- Box with border
- HR styled within the box div and outside
- HR with Z-Index
Here is the code:
#valuesContainer {
border: 1px;
border-style: solid;
border-color: #ccc;
font-family: sans-serif;
font: Source;
font-weight: normal;
font-size: 20px;
margin: 8%;
padding: 5%;
line-height: 1;
}
#valueTitle {
font-family: sans-serif;
font: Source;
font-weight: 600;
font-size: 22px;
}
#hrTop {
width: 30vh;
color: red;
border-top: 5px solid #E7503D;
position: relative;
margin-right: -.2%;
margin-top: -.75%;
z-index: 999;
}
#hrTopRight {
border: none;
border-left: 5px solid #E7503D;
height: 10vw;
width: 1px;
margin-top: -16%;
}
<div class="row">
<div class="col-6">
<div id="valuesContainer" class="box">
<hr id="hrTop"align="right">
<h1 id="valueTitle">Title</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat scelerisque varius morbi enim nunc.
</p>
<hr id="hrTopRight"align="right">
</div>
</div>
I'm not entirely sure I'm going about this the right way, but any help would greatly appreciate it. I have tried to search around and this is as far as I've been able to get with the information I found.'
UPDATE:
I couldn't see a way to award this answer since it was a comment. But I believe I may have found a much better way of doing this without using an HR tag.
t looks like you are using to decorate the box and not to indicate a separation in your content (since they are at the very start and end). You can use a pseudo-element on your #valuesContainer instead to layer a box on top with absolute positioning (make sure #valuesContainer is relatively positioned).

Try using position: absolute and relative on the parent div
#valuesContainer {
border: 1px;
border-style: solid;
border-color: #ccc;
font-family: sans-serif;
font: Source;
font-weight: normal;
font-size: 20px;
margin: 8%;
padding: 5%;
line-height: 1;
position: relative;
}
#valueTitle {
font-family: sans-serif;
font: Source;
font-weight: 600;
font-size: 22px;
}
#hrTop {
width: 30vh;
color: red;
border-top: 5px solid #E7503D;
position: absolute;
top: -17px;
right: -7px;
z-index: -999999;
}
#hrTopRight {
border: none;
border-left: 5px solid #E7503D;
height: 10vw;
width: 1px;
position: absolute;
top: -14px;
right: -8px;
}
<div class="row">
<div class="col-6">
<div id="valuesContainer" class="box">
<hr id="hrTop"align="right">
<h1 id="valueTitle">Title</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Feugiat scelerisque varius morbi enim nunc.
</p>
<hr id="hrTopRight"align="right">
</div>
</div>

Related

Image Shifting when Webpage is Resized after Floating Left

I have no idea why my image is shifting when my webpage is resized. There is no absolute positioning, the image just floats left, and the parents only give it some padding and margin.
Here is the HTML:
.section-title {
color: black;
font-size: 30px;
font-weight: bold;
text-align: center;
}
.section-title-info {
margin-bottom: 1.5em;
margin-top: 0;
}
.section-words-info {
font-size: 20px;
color: black;
font-weight: 550;
line-height: 30px;
}
.section-info {
background-color: #706D9F;
padding: 2em 1em;
}
.container {
margin: 0 auto;
}
.img-main {
float: left;
height: 12em;
border-radius: 50%;
}
<section class="section-info container">
<h2 class="section-title section-title-info">Information</h2>
<img class="img-main" src="https://ibb.co/g7LnzSc">
<span class="section-words-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span>
</section>
You need to add overflow: auto; to your .section-info By using float it takes that element out of the flow of the document so you need to force the parent to include it by using overflow auto. See here:
.section-title {
color: black;
font-size: 30px;
font-weight: bold;
text-align: center;
}
.section-title-info {
margin-bottom: 1.5em;
margin-top: 0;
}
.section-words-info {
font-size: 20px;
color: black;
font-weight: 550;
line-height: 30px;
}
.section-info {
background-color: #706D9F;
padding: 2em 1em;
overflow: auto;
}
.container {
margin: 0 auto;
}
.img-main {
float: left;
height: 12em;
border-radius: 50%;
}
<section class="section-info container">
<h2 class="section-title section-title-info">Information</h2>
<img class="img-main" src="https://w3schools.com/html/img_girl.jpg" />
<span class="section-words-info">Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span>
</section>

What can I improve to make a responsive design

When resizing the <p > tag breaks out of its parent <div>, how can I
make it responsive and stay in the <div> HTML code. That's what I
want to achieved with HTML and CSS: I tried to wrap everything in a div so I can control elements using absolute elements so I can center it in the middle.
Thank you in advance for your advices to help me make nicely written websites in the future.
#import url('https://fonts.googleapis.com/css?family=Didact+Gothic');
html,body {
height: 100%;
}
body {
margin: 0;
background-color: #eee;
}
header {
height: 100vh;
background-size: cover;
position: relative;
height: 100%;
background-image: url("/images/background.jpeg")
}
.text {
position: relative;
width: 100%;
height: 100%;
}
.text1 {
font-size: 35vh;
position:absolute;
top: 5%;
left: 5%;
color: #fff;
font-weight: bold;
margin: 0;
height: auto;
}
.text2 {
margin: 0;
font-size: 35vh;
position:absolute;
left:33%;
top: 40%;
font-size: 5vh;
text-transform: uppercase;
}
.text3 {
position:absolute;
left: 15%;
top: 50%;
width: 50vh;
height: auto;
margin: 0;
font-weight: 4vh;
font-weight: bold;
font-style: italic;
font-family: 'Didact Gothic', sans-serif;
color: #fff;
}
.text4 {
position:absolute;
left: 15%;
top: 65%;
margin: 0;
width: 50vh;
font-weight: bold;
font-style: italic;
color: #fff;
font-family: 'Didact Gothic', sans-serif;
}
<header id="showcase">
<div class="text">
<h1 class="text1">-20%</h1>
<h1 class="text2">Rabbat</h1>
<p class="text3">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel facilisis volutpat est velit egestas dui.
</p>
<p class="text4">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel facilisis volutpat est velit egestas dui.
</p>
</div>
</header>
Use this in your head tag, and try not to use absolute positions for inner controls
<style>
p{
work-break: break-all;
}
</style>

Equally Marginalize a Left-Aligned Size-Changing Box w/ Image Container in CSS/SASS

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. :/

Align divs to the right and prevent container to collapse

I'm having trouble trying to get the event-info class text to align to the right of the events calendar as a vertical list. Floating the events-list to the right seems to collapse my text altogether, which I don't want. Here is my HTML and CSS:
.workshop-events {
width: 100%;
background-color: #f2f2f2;
padding: 1px 20px;
/*padding: 20px;*/
}
.calendar {
width: 75px;
display: table-cell;
}
.calendar .month {
text-transform: uppercase;
font-size: 16px;
border: 1px solid #b2b2b2;
padding: 3px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.events-info {
font-weight: bold;
font-size: 14px;
}
<div class="workshop-events">
<h1 class="section-heading">WORKSHOP & EVENTS</h1>
<!-- EVENT CALENDAR -->
<div class="calendar">
<div class="month text-center">June</div>
<div class="day text-center">30</div>
</div>
<!--EVENTS CALENDAR-->
<div class="events-info">Lorem Ipsum</div>
<div class="events-info">Dolor Sit Amet Sed</div>
<div class="events-info">Libero</div>
<button class="view-all-events">VIEW ALL</button>
</div>
<!-- WORKSHOP AND EVENTS-->
You can simply float the calendar box to the left. For a better result, wrap all events-info + button into a container (to avoid the text to wrap to new lines below the calendar box, see the demo).
HTML updates:
<div class="events-container">
<div class="events-info">Lorem Ipsum</div>
<div class="events-info">Dolor Sit Amet Sed</div>
<div class="events-info">Libero</div>
<button class="view-all-events">VIEW ALL</button>
</div>
CSS updates:
.workshop-events {
overflow: auto; /*fix possible collapses caused by floating*/
}
.calendar {
float: left;
margin-right: 20px;
}
.events-container {
overflow: auto; /*prevent the text to wrap below the calendar*/
}
.workshop-events {
width: 100%;
background-color: #f2f2f2;
padding: 20px;
}
.calendar {
width: 75px;
display: table-cell;
}
.calendar .month {
text-transform: uppercase;
font-size: 16px;
border: 1px solid #b2b2b2;
padding: 3px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.calendar .day {
font-size: 30px;
font-weight: 500;
border: 1px solid #b2b2b2;
border-top: none;
padding: 7px 0;
background: #FFF;
}
.events-info {
font-weight: bold;
font-size: 14px;
}
/*NEW RULES BELOW*/
.workshop-events {
overflow: auto;
}
.calendar {
float: left;
margin-right: 20px;
}
.events-container {
overflow: auto;
}
<div class="workshop-events">
<h1 class="section-heading">WORKSHOP & EVENTS</h1>
<!-- EVENT CALENDAR -->
<div class="calendar">
<div class="month text-center">June</div>
<div class="day text-center">30</div>
</div>
<!-- EVENTS INFO-->
<div class="events-container">
<div class="events-info">1. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="events-info">2. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="events-info">3. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<button class="view-all-events">VIEW ALL</button>
</div>
</div>
<!-- WORKSHOP AND EVENTS-->

CSS Weird Column Paragraph Empty Space

I created a 3 column grid with 3 paragraphs. The first paragraph has an extra space from the top than the other two. Can anyone help? I attached an image if it helps at all. I'm still a beginner at coding so you'll notice a bunch of weird things that I'm doing that aren't practical.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Qualenist</title>
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<div class="mainBanner">
<div class="menuBox"></div>
<img src="menuBars.png" style="position: absolute; margin-top: 35px; margin-left: 260px;"/>
<h6><span>already a member?</span> Sign in</h6>
<h1>Qualenist</h1>
<h2>Lorem ipsum dolor sit amet & consectetur adipisicing elit</h2>
<div class="divider"></div>
<div class="signUpBox"></div>
<h3>Sign Up</h3>
<h4>learn more</h4>
<img src="downArrow.png" style="display: block; margin-left: auto; margin-right: auto; margin-top: -10px"/>
<div class="whatWeDo">
<h5>What we do</h5>
<img src="doSearch.png" style="position: absolute; margin-left: 292px; margin-top: 5px;"/>
<img src="doGraph.png" style="position: absolute; margin-left: 572px; margin-top: 5px;"/>
<img src="doPay.png" style="position: absolute; margin-left: 851px; margin-top: 5px;"/>
<div id="descriptions">
<p>Lorem ipsum dolor sit amet, consectetur <br>
adipisicing elit, sed do eiusmod tempor <br>
incididunt ut labore et dolore magna.</p>
<p>Lorem ipsum dolor sit amet, consectetur <br>
adipisicing elit, sed do eiusmod tempor <br>
incididunt ut labore et dolore magna.</p>
<p>Lorem ipsum dolor sit amet, consectetur <br>
adipisicing elit, sed do eiusmod tempor <br>
incididunt ut labore et dolore magna.</p>
</div>
</div>
<footer class="main-footer">
</footer>
</body>
</html>
.mainBanner {
background-image: url(/Users/omaramin/Documents/Competition/project/mainBanner.png);
background-repeat: no-repeat;
position: absolute;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
font-family: Bariol;
color: #ffffff;
border-color: #ffffff;
}
.menuBox {
width: 35px;
height: 35px;
border-style: solid;
margin-top: 25px;
margin-left: 252px;
position: absolute;
border-width: 1px;
border-radius: 2px;
}
h6 {
padding-left: 825px;
letter-spacing: 1px;
font-size: 12px;
}
h6 span {
color: #b3b4b4;
}
h1 {
text-align: center;
padding-top: 90px;
font-size: 36px;
letter-spacing: 1.5px;
font-weight: lighter;
}
h2 {
text-align: center;
margin-top: -15px;
letter-spacing: 1px;
font-size: 13px;
}
.divider {
border: 0;
height: 1px;
width: 45px;
margin: auto;
margin-top: 21px;
background: #ffffff;
}
.signUpBox {
width: 150px;
height: 47px;
border-style: solid;
border-width: 1px;
margin: auto;
margin-top: 25px;
border-radius: 2px;
}
h3 {
text-align: center;
margin-top: -35px;
letter-spacing: 1px;
font-size: 17px;
}
h4 {
text-align: center;
margin-top: 115px;
letter-spacing: 1px;
font-size: 12px;
}
.whatWeDo {
margin-top: -20px;
color: #5c5d5d;
font-family: Bariol;
}
h5 {
text-align: center;
margin-top: 100px;
letter-spacing: 1px;
font-size: 25px;
}
#descriptions {
-moz-column-count: 3;
-moz-column-gap: 0px;
-webkit-column-count: 3;
-webkit-column-gap: 0px;
font-size: 13px;
letter-spacing: 1px;
text-align: center;
margin-left: 200px;
margin-right: 200px;
margin-top: 170px;
line-height: 20px;
}
Looks like margins on the paragraphs. Add:
p {
margin:0;
}
jsFiddle example
You'll want to add this to your CSS:
description p {
-webkit-margin-before: 0;
-moz-margin-before: 0;
}
The moz-margin-before is necessary for some Firefox browsers. Otherwise, they'll see the weird whitespace as well.
Going to have to agree with #j08691 here...
http://jsfiddle.net/SinisterSystems/v4n7G/1/
p {
margin:0;
}
The other answers are nice, and work just fine, but I think you should change your markup. Rather than relying on CSS columns to layout the text, then absolutely positioning the images to center above the columns, just make three container <div>s for the text AND the images. Give the containers a percentage width and float:left or use flexbox to get the columns side-by-side.
If the images are the same height, you'll be assured that your text will align.
jsFiddle Example
Another benefit of this approach is that now your .column class is reusable AND you don't need to use inline or special styles for the positioning.
In my case I was placing a set of text in paragraphs into columns, so I wanted to keep spacing after each paragraph. The solution here is to remove the margin from the paragraph tag, and use padding instead.
Markup:
<div class="columns">
<p>Lorem ipsum...</p>
<p>Lorem ipsum...</p>
<p>Lorem ipsum...</p>
<p>Lorem ipsum...</p>
</div>
CSS:
.columns {
column-count: 2;
column-gap: 12px;
}
.columns p {
/* don't break paragraphs */
break-inside: avoid;
/* Use padding instead of margin to avoid weird space at top of the second column.*/
margin: 0;
padding-bottom: 14px;
}
Couldn't find it called out in the spec, but this appears to be down to the interplay between CSS multicol and margins. As others mentioned, setting margin to zero makes the symptom go away.
#descriptions > p { margin: 0; }
However if it were me, I'd not have used CSS multicol at all, since text flows between cols as the browser evens the height across all cols, whereas here you presumably want each description to stay in its own box.
Also CSS3 columns has poor IE support: http://caniuse.com/multicolumn
I'd have used table CSS properties, inline block, flex box, or even floats before attempting to use columns for this.
#descriptions { display: table; }
#descriptions > p { display: table-cell; }
Using table markup for non-tabular data is usually a bad idea, but using CSS's table display properties is perfectly okay.
#descriptions p {
-webkit-margin-before: 0;
margin: 0;
}
http://jsfiddle.net/helmutgranda/84jky/3/