I need to style a blockquote so that it floats to the right, but I also want it to be

I want to enhance the appearance of my blockquotes by giving them a different color background and ensuring they stand out from the regular text. Although using float:right helps achieve this effect, I prefer not to force the blockquote to the right side of the paragraph. Is there a way to center it instead?

Just to clarify, I'd like the text within the block quote to remain left-justified while only the overall form of the blockquote is centered.

Check out this jsfiddle example for reference.

.blockquote {
    width: 75%;
    float: right;
    margin-top:20px;
    margin-bottom: 20px;
    padding: 20px;
    background: #0fddaf;
    background: rgb(15, 221, 175); /* Fall-back for browsers that don't support rgba */
    background: rgba(15, 221, 175, .15);
    font-family: fanwood_italic-webfont;
}

.blockquote p {
    padding: 10px

}

<span class="blockquote">Being good in business is the most fascinating kind of art. Making money is art and working is art and good business is the best art.</span>

Answer №1

Have you considered changing the display property of your .blockquote to block instead of floating it? This way, you can easily position it using margins and paddings without the risk of content resizing unexpectedly.

A much simpler solution indeed!

Answer №2

Replace the span tags with div tags and delete the float:right property, then add margin: 0 auto;

Check out this example on jsFiddle

<div class="blockquote">Being proficient in business is a captivating form of art. Making money, working, and excelling in business represent the finest forms of art.</div>

.blockquote {
    width: 75%;
    margin: 0 auto;
    margin-top:20px;
    margin-bottom: 20px;
    padding: 20px;
    background: #0fddaf;
    background: rgb(15, 221, 175); /* Fall-back for browsers that don't support rgba */
    background: rgba(15, 221, 175, .15);
    font-family: fanwood_italic-webfont;
}

Answer №3

Here is a possible solution for your needs:

In addition, I have included the text-align: right property just in case, as per your request to align the text to the right without affecting the entire blockquote/container.


UPDATE I realized that you had specified float: right, so here is an updated version without it:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

flash beneath the div tag

There seems to be an issue with the orange box and navigation showing up behind the flash on our main site. Any suggestions on how to resolve this? This problem is specifically occurring in Google Chrome. -- I've tried adding a certain parameter, bu ...

Fade out the div element when clicked

For my game project, I needed a way to make a div fade out after an onclick event. However, the issue I encountered was that after fading out, the div would reappear. Ideally, I wanted it to simply disappear without any sort of fade effect. Below is the co ...

Tips for detecting when multiple image sources have finished loading in an *ngFor loop

I have an array of image URLs that are displayed in a repetitive manner using the *ngFor directive in my HTML code. The technology stack used for this project includes Ionic 4 and Angular 10. <div *ngFor="let url of imagesToLoad; let i = index&quo ...

Activate a button with jQuery when a key is pressed

Currently, I have two buttons set up with jQuery: $('#prev').click(function() { // code for previous button }); $('#next').click(function() { // code for next button }); My goal now is to implement a .keypress() handler on the ...

iOS 7.0.x causing issues with the height of tabs being trimmed

Struggling to fix a nightmare of an issue with my app, so I'm reaching out for some help. Everything is working fine on Android and iOS versions 7.1.x, 8, and 9. However, when installed on iOS 7.0.4, the bottom tabs are getting cut off. See below: O ...

How to achieve a Dropbox-inspired footer effect using CSS?

Take a look at dropbox's website here: Have you noticed how the footer with "Learn more" remains fixed at the bottom regardless of window resizing until you click or scroll down? position: absolute; bottom: 50px; left: 0; width: 100%; text-align: ce ...

Choose a single dynamic image from a collection of multiple images

In the process of developing a Shopping cart website, I encountered an issue regarding allowing users to upload multiple images of a single product. Using jQuery, I successfully cloned the file input section to enable uploading additional images of the sam ...

Using AngularJS to add external scripts to partials with ng-include

Why won't my main javascript files (located in index.html) work in the partials (such as page1.html)? For example, jQuery and syntax highlighting scripts are not functioning properly when I click on my menu items. HTML CODE: <div data-ng-controll ...

Fixing content at the bottom inside a container with Bootstrap 4

My app is contained within a <div class="container">. Inside this container, I have an editor and some buttons that I always want to be displayed at the bottom of the screen. Here's how it looks: <div class="container> // content here.. ...

Challenges with border-color and CSS input:focus

The dilemma Currently, I am immersed in a project focusing on constructing a front end using bootstrap4. In order to align with the company's main color scheme, I decided to alter the highlighting color of inputs. To achieve this, I made the followi ...

Trouble displaying REACT.jsx in browser

I'm currently learning React and struggling to get it running smoothly. HTML function Person(){ return ( <div class="person"> <h1>Max</h1> <p>Your Age: 28</p> </div> ); } ...

What causes a header to appear transparent when it has a background color set in HTML?

I'm attempting to create a webpage that resembles Gmail. I have a header with a background color, but when I scroll, the content in the body becomes visible. Here is the view without scrolling: https://i.stack.imgur.com/UQ2sO.png However, while scr ...

Tips for preloading content into a Bootstrap markdown editor

My issue involves using bootstrap markdown and figuring out how to convert the text area content from parsed HTML. Adding text using markdown is not a problem initially, but when it comes to editing, I find myself needing to manually input what I had orig ...

Showing an error message without causing any displacement of elements positioned underneath

https://i.sstatic.net/2QvQb.jpg Is there a way to insert an error message text without displacing the element by 4 units using CSS or Javascript? ...

The disabled button is not displayed when it is disabled

Encountering an issue specific to Chrome version 60.0.3112.90 where changing the disabled attribute of a button causes it to disappear. A minimal, complete, and verifiable example has been prepared wherein clicking the + button toggles the disabled attri ...

Neglecting to automatically align text

My goal is to automatically align text based on the language, so that Arabic text starts from the right and English text starts from the left. After some online research, I discovered that I need to use dir="auto" in the tag and text-align: auto; in the CS ...

Connecting an Angular application to a URL hosted on localhost

I am currently working on an Angular project where one of the links needs to redirect to a different website. During development, this link points to a localhost URL like localhost:4210. However, due to security reasons in Angular, using such URLs is cons ...

What is the reason that the css backdrop-filter: blur() is functioning properly everywhere except on the active bootstrap-4 list-group-item?

I have a gallery with an album-card component inside, and within that is a carousel. I noticed that when I add a list-group and set one of the items as active, it remains unblurred. Can anyone help me understand why? Here is the HTML for the gallery com ...

MatDialog displaying no content

I found this tutorial on how to implement a simple dialog. The issue I'm facing is that the dialog appears empty with no errors in the console. Even after making changes to my dialog.component.html or dress-form.ts, nothing seems to reflect in the o ...

Hover Effect for 3D Images

I recently came across an interesting 3D Hover Image Effect that I wanted to implement - https://codepen.io/kw7oe/pen/mPeepv. After going through various tutorials and guides, I decided to try styling a component with Materials UI and apply CSS in a differ ...